Made it possible to have [terrain_graphics] rule as childs of [scenario]s.

Fixed a bug where tiles from terrain_graphics rule did not have the per-rule
image when only defined through [map].
This commit is contained in:
Philippe Plantier 2004-09-11 21:22:57 +00:00
parent 4d3eea1723
commit 0598787322
8 changed files with 43 additions and 37 deletions

View file

@ -135,10 +135,11 @@ const terrain_builder::tile& terrain_builder::tilemap::operator[] (const gamemap
return map_[(loc.x+1) + (loc.y+1)*(x_+2)];
}
terrain_builder::terrain_builder(const config& cfg, const gamemap& gmap) :
terrain_builder::terrain_builder(const config& cfg, const config& level, const gamemap& gmap) :
map_(gmap), tile_map_(gmap.x(), gmap.y())
{
parse_config(cfg);
parse_config(level);
build_terrains();
//rebuild_terrain(gamemap::location(0,0));
}
@ -522,8 +523,10 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
}
}
void terrain_builder::add_constraints(std::map<gamemap::location, terrain_builder::terrain_constraint> & constraints,
const gamemap::location& loc, const std::string& type)
void terrain_builder::add_constraints(
terrain_builder::constraint_set& constraints,
const gamemap::location& loc,
const std::string& type, const config& global_images)
{
if(constraints.find(loc) == constraints.end()) {
//the terrain at the current location did not exist, so create it
@ -532,6 +535,12 @@ void terrain_builder::add_constraints(std::map<gamemap::location, terrain_builde
if(!type.empty())
constraints[loc].terrain_types = type;
int x = loc.x * rule_image::TILEWIDTH / 2;
int y = loc.y * rule_image::TILEWIDTH + (loc.x % 2) *
rule_image::TILEWIDTH / 2;
add_images_from_config(constraints[loc].images, global_images, true, x, y);
}
void terrain_builder::add_constraint_item(std::vector<std::string> &list, const config& cfg, const std::string &item)
@ -548,7 +557,7 @@ void terrain_builder::add_constraint_item(std::vector<std::string> &list, const
void terrain_builder::add_constraints(terrain_builder::constraint_set &constraints, const gamemap::location& loc, const config& cfg, const config& global_images)
{
add_constraints(constraints, loc, cfg["type"]);
add_constraints(constraints, loc, cfg["type"], global_images);
terrain_constraint& constraint = constraints[loc];
@ -556,16 +565,12 @@ void terrain_builder::add_constraints(terrain_builder::constraint_set &constrain
add_constraint_item(constraint.has_flag, cfg, "has_flag");
add_constraint_item(constraint.no_flag, cfg, "no_flag");
int x = loc.x * rule_image::TILEWIDTH / 2;
int y = loc.y * rule_image::TILEWIDTH + (loc.x % 2) *
rule_image::TILEWIDTH / 2;
add_images_from_config(constraint.images, cfg, false);
add_images_from_config(constraint.images, global_images, true, x, y);
}
void terrain_builder::parse_mapstring(const std::string &mapstring,
struct building_rule &br, anchormap& anchors)
struct building_rule &br, anchormap& anchors,
const config& global_images)
{
int lineno = 0;
int x = 0;
@ -611,7 +616,7 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
anchors.insert(std::pair<int, gamemap::location>(anchor, gamemap::location(x, lineno / 2)));
} else {
const gamemap::location loc(x, lineno / 2);
add_constraints(br.constraints, loc, types);
add_constraints(br.constraints, loc, types, global_images);
}
lpos += 4;
x += 2;
@ -667,7 +672,7 @@ void terrain_builder::parse_config(const config &cfg)
anchormap anchors;
// Parse the map= , if there is one (and fill the anchors list)
parse_mapstring((**br)["map"], pbr, anchors);
parse_mapstring((**br)["map"], pbr, anchors, **br);
// Parses the terrain constraints (TCs)
config::child_list tcs((*br)->get_children("tile"));
@ -981,6 +986,12 @@ void terrain_builder::build_terrains()
building_ruleset::const_iterator rule;
for(rule = building_rules_.begin(); rule != building_rules_.end(); ++rule) {
if (rule->second.location_constraints.valid()) {
apply_rule(rule->second, rule->second.location_constraints);
continue;
}
constraint_set::const_iterator constraint;
//find the constraint that contains the less terrain of all terrain rules.

View file

@ -40,7 +40,7 @@ public:
enum ADJACENT_TERRAIN_TYPE { ADJACENT_BACKGROUND, ADJACENT_FOREGROUND };
typedef std::vector<animated<image::locator> > imagelist;
terrain_builder(const config& cfg, const gamemap& gmap);
terrain_builder(const config& cfg, const config &level, const gamemap& gmap);
//returns a vector of string representing the images to load & blit together to get the
//built content for this tile.
@ -116,7 +116,7 @@ public:
typedef std::vector<rule_image> rule_imagelist;
/**
* Each terrain_graphics rule consists in a set of constraints.
* Each terrain_graphics rule consists in a set of constraints
*/
struct terrain_constraint
{
@ -210,13 +210,15 @@ private:
int dx=0, int dy=0);
void add_constraints(std::map<gamemap::location, terrain_constraint>& constraints,
const gamemap::location &loc, const std::string& type);
const gamemap::location &loc, const std::string& type,
const config& global_images);
void add_constraints(std::map<gamemap::location, terrain_constraint>& constraints,
const gamemap::location &loc, const config &cfg, const config& global_images);
const gamemap::location &loc, const config &cfg,
const config& global_images);
typedef std::multimap<int, gamemap::location> anchormap;
void parse_mapstring(const std::string &mapstring, struct building_rule &br,
anchormap& anchors);
anchormap& anchors, const config& global_images);
void parse_config(const config &cfg);
bool terrain_matches(gamemap::TERRAIN letter, const std::string &terrains);
bool rule_matches(const building_rule &rule, const gamemap::location &loc, int rule_index, bool check_loc);

View file

@ -74,13 +74,6 @@ line_source get_line_source(const std::vector<line_source>& line_src, int line)
return res;
}
#if 0
struct close_FILE
{
void operator()(FILE* f) const { if(f != NULL) { fclose(f); } }
};
#endif
void read_file_internal(const std::string& fname, std::string& res)
{
const int size = file_size(fname);

View file

@ -54,7 +54,7 @@ namespace {
display::display(unit_map& units, CVideo& video, const gamemap& map,
const gamestatus& status, const std::vector<team>& t, const config& theme_cfg,
const config& built_terrains) :
const config& config, const config& level) :
screen_(video), xpos_(0), ypos_(0),
zoom_(DefaultZoom), map_(map), units_(units),
minimap_(NULL), redrawMinimap_(false),
@ -65,7 +65,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
currentTeam_(0), activeTeam_(0), hideEnergy_(false),
deadAmount_(0.0), advancingAmount_(0.0), updatesLocked_(0),
turbo_(false), grid_(false), sidebarScaling_(1.0),
theme_(theme_cfg,screen_area()), builder_(built_terrains, map),
theme_(theme_cfg,screen_area()), builder_(config, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map),
tod_hex_mask1(NULL), tod_hex_mask2(NULL), diagnostic_label_(0),
help_string_(0)

View file

@ -53,9 +53,9 @@ public:
typedef std::map<gamemap::location,unit> unit_map;
display(unit_map& units, CVideo& video,
const gamemap& map, const gamestatus& status,
const gamemap& map, const gamestatus& status,
const std::vector<team>& t, const config& theme_cfg,
const config& built_terrains);
const config& config, const config& level);
~display();
Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue);

View file

@ -538,7 +538,7 @@ int play_game(int argc, char** argv)
display::unit_map u_map;
config dummy_cfg("");
display disp(u_map,video,gamemap(dummy_cfg,"1"),gamestatus(dummy_cfg,0),
std::vector<team>(),dummy_cfg,dummy_cfg);
std::vector<team>(),dummy_cfg,dummy_cfg,dummy_cfg);
gui::show_dialog(disp,NULL,"","Error loading game configuration files: '" + e.message + "' (The game will now exit)",
gui::MESSAGE);
@ -599,7 +599,7 @@ int play_game(int argc, char** argv)
display::unit_map u_map;
config dummy_cfg("");
display disp(u_map,video,gamemap(dummy_cfg,"1"),gamestatus(dummy_cfg,0),
std::vector<team>(),dummy_cfg,dummy_cfg);
std::vector<team>(),dummy_cfg,dummy_cfg,dummy_cfg);
std::cerr << "initialized display object\n";
std::cerr << (SDL_GetTicks() - start_ticks) << "\n";

View file

@ -112,9 +112,9 @@ namespace {
}
LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story)
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story)
{
const int ticks = SDL_GetTicks();
std::cerr << "in play_level()...\n";
@ -339,7 +339,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
std::cerr << "initializing display... " << (SDL_GetTicks() - ticks) << "\n";
const config dummy_cfg;
display gui(units,video,map,status,teams,theme_cfg != NULL ? *theme_cfg : dummy_cfg, game_config);
display gui(units,video,map,status,teams,theme_cfg != NULL ? *theme_cfg : dummy_cfg, game_config, *level);
std::cerr << "done initializing display... " << (SDL_GetTicks() - ticks) << "\n";

View file

@ -45,8 +45,8 @@ struct end_level_exception {
};
LEVEL_RESULT play_level(game_data& gameinfo, const config& terrain_config,
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story);
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story);
#endif