Move fog/shroud image definition into game_config

Put there image variants for fog, and now shroud too (but not used and
still WIP). Few minor optimizations and fix broken fog in trunk
This commit is contained in:
Ali El Gariani 2010-07-09 01:28:37 +00:00
parent 6a4bf1f195
commit a658bd23bb
5 changed files with 38 additions and 30 deletions

View file

@ -97,6 +97,11 @@
grid_image_bottom="terrain/grid-bottom.png"
unreachable_image="terrain/darken.png"
fog_prefix="terrain/fog"
fog_variants="terrain/fog1.png,terrain/fog2.png,terrain/fog3.png"
shroud_prefix="terrain/void"
shroud_variants="terrain/void.png"
observer_image="misc/eye.png"
tod_bright_image="misc/tod-bright.png"
tod_dark_image="misc/tod-dark.png"

View file

@ -98,8 +98,6 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
turbo_(false),
invalidateGameStatus_(true),
map_labels_(new map_labels(*this, 0)),
shroud_image_("terrain/" + get_map().get_terrain_info(t_translation::VOID_TERRAIN).minimap_image() + ".png"),
fog_image_("terrain/" + get_map().get_terrain_info(t_translation::FOGGED).minimap_image()),
scroll_event_("scrolled"),
nextDraw_(0),
report_(),
@ -142,13 +140,10 @@ display::~display()
{
}
std::string display::fog_image(const map_location &loc)
const std::string& display::get_variant(const std::vector<std::string>& variants, const map_location &loc)
{
std::ostringstream tmp;
tmp << fog_image_;
tmp << abs(loc.x + loc.y) % 3 + 1;
tmp << ".png";
return tmp.str();
//TODO use better noise function
return variants[abs(loc.x + loc.y) % variants.size()];
}
void display::rebuild_all()
@ -582,29 +577,29 @@ std::vector<std::string> display::get_fog_shroud_graphics(const map_location& lo
map_location adjacent[6];
get_adjacent_tiles(loc,adjacent);
t_translation::t_terrain tiles[6];
enum visibility {FOG=0, SHROUD=1, CLEAR=2};
visibility tiles[6];
static const t_translation::t_terrain terrain_types[] =
{ t_translation::FOGGED, t_translation::VOID_TERRAIN, t_translation::NONE_TERRAIN };
const std::string* image_prefix[] =
{ &game_config::fog_prefix, &game_config::shroud_prefix};
for(int i = 0; i != 6; ++i) {
if(shrouded(adjacent[i])) {
tiles[i] = t_translation::VOID_TERRAIN;
tiles[i] = SHROUD;
} else if(!fogged(loc) && fogged(adjacent[i])) {
tiles[i] = t_translation::FOGGED;
tiles[i] = FOG;
} else {
tiles[i] = t_translation::NONE_TERRAIN;
tiles[i] = CLEAR;
}
}
for(const t_translation::t_terrain *terrain = terrain_types;
*terrain != t_translation::NONE_TERRAIN; terrain ++) {
for(int v = FOG; v != CLEAR; ++v) {
// Find somewhere that doesn't have overlap to use as a starting point
int start;
for(start = 0; start != 6; ++start) {
if(tiles[start] != *terrain) {
if(tiles[start] != v) {
break;
}
}
@ -615,16 +610,12 @@ std::vector<std::string> display::get_fog_shroud_graphics(const map_location& lo
// Find all the directions overlap occurs from
for(int i = (start+1)%6, n = 0; i != start && n != 6; ++n) {
if(tiles[i] == *terrain) {
if(tiles[i] == v) {
std::ostringstream stream;
std::string name;
// if(*terrain == terrain_type::VOID_TERRAIN)
// stream << "void";
//else
// stream << "fog";
stream << "terrain/" << get_map().get_terrain_info(*terrain).minimap_image();
stream << *image_prefix[v];
for(int n = 0; *terrain == tiles[i] && n != 6; i = (i+1)%6, ++n) {
for(int n = 0; v == tiles[i] && n != 6; i = (i+1)%6, ++n) {
stream << get_direction(i);
if(!image::exists(stream.str() + ".png")) {
@ -1976,11 +1967,13 @@ void display::draw_hex(const map_location& loc) {
if(shrouded(loc)) {
// We apply void also on off-map tiles
// to shroud the half-hexes too
const std::string& shroud_image = get_variant(game_config::shroud_variants, loc);
drawing_buffer_add(LAYER_FOG_SHROUD, loc, tblit(xpos, ypos,
image::get_image(shroud_image_, image_type)));
image::get_image(shroud_image, image_type)));
} else if(fogged(loc)) {
const std::string& fog_image = get_variant(game_config::fog_variants, loc);
drawing_buffer_add(LAYER_FOG_SHROUD, loc, tblit(xpos, ypos,
image::get_image(fog_image(loc), image_type)));
image::get_image(fog_image, image_type)));
}
if(!shrouded(loc)) {

View file

@ -546,7 +546,7 @@ protected:
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type,bool force = true);
std::string fog_image(const map_location &loc);
const std::string& get_variant(const std::vector<std::string>& variants, const map_location &loc);
CVideo& screen_;
const gamemap* map_;
@ -568,8 +568,6 @@ protected:
bool turbo_;
bool invalidateGameStatus_;
boost::scoped_ptr<map_labels> map_labels_;
std::string shroud_image_;
std::string fog_image_;
/** Event raised when the map is being scrolled */
mutable events::generic_event scroll_event_;

View file

@ -64,6 +64,11 @@ namespace game_config
std::string unreachable_image = "terrain/darken.png"; /**< overlay image for unreachable tiles. */
std::string linger_image = "terrain/darken-linger.png"; /**< overlay image for tiles in linger mode. */
std::string shroud_prefix;
std::string fog_prefix;
std::vector<std::string> fog_variants;
std::vector<std::string> shroud_variants;
std::string energy_image = "misc/bar-energy.png";
std::string moved_ball_image = "misc/ball-moved.png";
std::string unmoved_ball_image = "misc/ball-unmoved.png";
@ -198,6 +203,11 @@ namespace game_config
grid_image_bottom = v["grid_image_bottom"].str();
unreachable_image = v["unreachable_image"].str();
shroud_prefix = v["shroud_prefix"].str();
fog_prefix = v["fog_prefix"].str();
fog_variants = utils::split(v["fog_variants"].str());
shroud_variants = utils::split(v["shroud_variants"].str());
observer_image = v["observer_image"].str();
tod_bright_image = v["tod_bright_image"].str();
tod_dark_image = v["tod_dark_image"].str();

View file

@ -71,6 +71,7 @@ namespace game_config
terrain_mask_image,
grid_image_top, grid_image_bottom,
unreachable_image, linger_image,
shroud_prefix, fog_prefix,
observer_image, tod_bright_image, tod_dark_image,
checked_menu_image, unchecked_menu_image, wml_menu_image, level_image,
ellipsis_image, default_victory_music, default_defeat_music;
@ -81,6 +82,7 @@ namespace game_config
extern std::vector<Uint32> red_green_scale;
extern std::vector<Uint32> red_green_scale_text;
extern std::vector<std::string> fog_variants, shroud_variants;
extern std::vector<std::string> foot_speed_prefix;
extern std::string foot_teleport_enter, foot_teleport_exit;