mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-08 22:21:36 +00:00
Lift some code to use the basemap type rather than the derived gamemap type.
This commit is contained in:
parent
c73e8cc3f3
commit
9feb3c2dcc
@ -121,7 +121,7 @@ void terrain_builder::tilemap::reset()
|
||||
it->clear();
|
||||
}
|
||||
|
||||
bool terrain_builder::tilemap::on_map(const gamemap::location &loc) const
|
||||
bool terrain_builder::tilemap::on_map(const basemap::location &loc) const
|
||||
{
|
||||
if(loc.x < -1 || loc.y < -1 || loc.x > x_ || loc.y > y_)
|
||||
return false;
|
||||
@ -129,30 +129,30 @@ bool terrain_builder::tilemap::on_map(const gamemap::location &loc) const
|
||||
return true;
|
||||
}
|
||||
|
||||
terrain_builder::tile& terrain_builder::tilemap::operator[](const gamemap::location &loc)
|
||||
terrain_builder::tile& terrain_builder::tilemap::operator[](const basemap::location &loc)
|
||||
{
|
||||
wassert(on_map(loc));
|
||||
|
||||
return map_[(loc.x+1) + (loc.y+1)*(x_+2)];
|
||||
}
|
||||
|
||||
const terrain_builder::tile& terrain_builder::tilemap::operator[] (const gamemap::location &loc) const
|
||||
const terrain_builder::tile& terrain_builder::tilemap::operator[] (const basemap::location &loc) const
|
||||
{
|
||||
wassert(on_map(loc));
|
||||
|
||||
return map_[(loc.x+1) + (loc.y+1)*(x_+2)];
|
||||
}
|
||||
|
||||
terrain_builder::terrain_builder(const config& cfg, const config& level, const gamemap& gmap) :
|
||||
terrain_builder::terrain_builder(const config& cfg, const config& level, const basemap& gmap) :
|
||||
map_(gmap), tile_map_(gmap.x(), gmap.y())
|
||||
{
|
||||
parse_config(cfg);
|
||||
parse_config(level);
|
||||
build_terrains();
|
||||
//rebuild_terrain(gamemap::location(0,0));
|
||||
//rebuild_terrain(basemap::location(0,0));
|
||||
}
|
||||
|
||||
const terrain_builder::imagelist *terrain_builder::get_terrain_at(const gamemap::location &loc,
|
||||
const terrain_builder::imagelist *terrain_builder::get_terrain_at(const basemap::location &loc,
|
||||
const std::string &tod, const ADJACENT_TERRAIN_TYPE terrain_type)
|
||||
{
|
||||
if(!tile_map_.on_map(loc))
|
||||
@ -178,7 +178,7 @@ const terrain_builder::imagelist *terrain_builder::get_terrain_at(const gamemap:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool terrain_builder::update_animation(const gamemap::location &loc)
|
||||
bool terrain_builder::update_animation(const basemap::location &loc)
|
||||
{
|
||||
if(!tile_map_.on_map(loc))
|
||||
return false;
|
||||
@ -205,7 +205,7 @@ bool terrain_builder::update_animation(const gamemap::location &loc)
|
||||
}
|
||||
|
||||
// TODO: rename this function
|
||||
void terrain_builder::rebuild_terrain(const gamemap::location &loc)
|
||||
void terrain_builder::rebuild_terrain(const basemap::location &loc)
|
||||
{
|
||||
if (tile_map_.on_map(loc)) {
|
||||
tile& btile = tile_map_[loc];
|
||||
@ -483,7 +483,7 @@ terrain_builder::building_rule terrain_builder::rotate_rule(const terrain_builde
|
||||
|
||||
for(cons2 = tmp_cons.begin(); cons2 != tmp_cons.end(); ++cons2) {
|
||||
//Adjusts positions
|
||||
cons2->second.loc += gamemap::location(-minx, -((miny-1)/2));
|
||||
cons2->second.loc += basemap::location(-minx, -((miny-1)/2));
|
||||
ret.constraints[cons2->second.loc] = cons2->second;
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
|
||||
|
||||
void terrain_builder::add_constraints(
|
||||
terrain_builder::constraint_set& constraints,
|
||||
const gamemap::location& loc,
|
||||
const basemap::location& loc,
|
||||
const t_translation::t_match& type, const config& global_images)
|
||||
{
|
||||
if(constraints.find(loc) == constraints.end()) {
|
||||
@ -560,7 +560,7 @@ void terrain_builder::add_constraints(
|
||||
}
|
||||
|
||||
void terrain_builder::add_constraints(terrain_builder::constraint_set &constraints,
|
||||
const gamemap::location& loc, const config& cfg, const config& global_images)
|
||||
const basemap::location& loc, const config& cfg, const config& global_images)
|
||||
|
||||
{
|
||||
add_constraints(constraints, loc, t_translation::t_match(cfg["type"], t_translation::WILDCARD), global_images);
|
||||
@ -608,9 +608,9 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
||||
// Dots are simple placeholders, which do not
|
||||
// represent actual terrains.
|
||||
} else if (terrain.overlay != 0 ) {
|
||||
anchors.insert(std::pair<int, gamemap::location>(terrain.overlay, gamemap::location(x, y)));
|
||||
anchors.insert(std::pair<int, basemap::location>(terrain.overlay, basemap::location(x, y)));
|
||||
} else if (terrain.base == t_translation::TB_STAR) {
|
||||
add_constraints(br.constraints, gamemap::location(x, y), builder_letter(t_translation::STAR), global_images);
|
||||
add_constraints(br.constraints, basemap::location(x, y), builder_letter(t_translation::STAR), global_images);
|
||||
} else {
|
||||
ERR_NG << "Invalid terrain (" << t_translation::write_letter(terrain) << ") in builder map\n";
|
||||
wassert(false);
|
||||
@ -665,7 +665,7 @@ void terrain_builder::parse_config(const config &cfg)
|
||||
// add_images_from_config(pbr.images, **br);
|
||||
|
||||
if(!((**br)["x"].empty() || (**br)["y"].empty()))
|
||||
pbr.location_constraints = gamemap::location(atoi((**br)["x"].c_str()), atoi((**br)["y"].c_str()));
|
||||
pbr.location_constraints = basemap::location(atoi((**br)["x"].c_str()), atoi((**br)["y"].c_str()));
|
||||
|
||||
pbr.probability = (**br)["probability"].empty() ? -1 : atoi((**br)["probability"].c_str());
|
||||
pbr.precedence = (**br)["precedence"].empty() ? 0 : atoi((**br)["precedence"].c_str());
|
||||
@ -683,7 +683,7 @@ void terrain_builder::parse_config(const config &cfg)
|
||||
//Adds the terrain constraint to the current built
|
||||
//terrain's list of terrain constraints, if it does not
|
||||
//exist.
|
||||
gamemap::location loc;
|
||||
basemap::location loc;
|
||||
if((**tc)["x"].size()) {
|
||||
loc.x = atoi((**tc)["x"].c_str());
|
||||
}
|
||||
@ -772,7 +772,7 @@ void terrain_builder::parse_config(const config &cfg)
|
||||
}
|
||||
|
||||
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
const gamemap::location &loc, const int rule_index, const bool check_loc) const
|
||||
const basemap::location &loc, const int rule_index, const bool check_loc) const
|
||||
{
|
||||
if(rule.location_constraints.valid() && rule.location_constraints != loc) {
|
||||
return false;
|
||||
@ -783,7 +783,7 @@ bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
cons != rule.constraints.end(); ++cons) {
|
||||
|
||||
// translated location
|
||||
const gamemap::location tloc = loc + cons->second.loc;
|
||||
const basemap::location tloc = loc + cons->second.loc;
|
||||
|
||||
if(!tile_map_.on_map(tloc)) {
|
||||
return false;
|
||||
@ -811,7 +811,7 @@ bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
for(constraint_set::const_iterator cons = rule.constraints.begin();
|
||||
cons != rule.constraints.end(); ++cons) {
|
||||
|
||||
const gamemap::location tloc = loc + cons->second.loc;
|
||||
const basemap::location tloc = loc + cons->second.loc;
|
||||
|
||||
if(!tile_map_.on_map(tloc)) {
|
||||
return false;
|
||||
@ -838,13 +838,13 @@ bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
return true;
|
||||
}
|
||||
|
||||
void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, const gamemap::location &loc)
|
||||
void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, const basemap::location &loc)
|
||||
{
|
||||
for(constraint_set::const_iterator constraint = rule.constraints.begin();
|
||||
constraint != rule.constraints.end(); ++constraint) {
|
||||
|
||||
rule_imagelist::const_iterator img;
|
||||
const gamemap::location tloc = loc + constraint->second.loc;
|
||||
const basemap::location tloc = loc + constraint->second.loc;
|
||||
if(!tile_map_.on_map(tloc))
|
||||
return;
|
||||
|
||||
@ -867,11 +867,11 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, con
|
||||
}
|
||||
}
|
||||
|
||||
int terrain_builder::get_constraint_adjacents(const building_rule& rule, const gamemap::location& loc)
|
||||
int terrain_builder::get_constraint_adjacents(const building_rule& rule, const basemap::location& loc)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
gamemap::location adj[6];
|
||||
basemap::location adj[6];
|
||||
int i;
|
||||
get_adjacent_tiles(loc, adj);
|
||||
|
||||
@ -905,7 +905,7 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
gamemap::location adj[6];
|
||||
basemap::location adj[6];
|
||||
get_adjacent_tiles(constraint.loc, adj);
|
||||
|
||||
border = false;
|
||||
@ -952,11 +952,11 @@ void terrain_builder::build_terrains()
|
||||
//builds the terrain_by_type_ cache
|
||||
for(int x = -1; x <= map_.x(); ++x) {
|
||||
for(int y = -1; y <= map_.y(); ++y) {
|
||||
const gamemap::location loc(x,y);
|
||||
const basemap::location loc(x,y);
|
||||
const t_translation::t_letter t = builder_letter(map_.get_terrain(loc));
|
||||
|
||||
terrain_by_type_[t].push_back(loc);
|
||||
gamemap::location adj[6];
|
||||
basemap::location adj[6];
|
||||
int i;
|
||||
bool border = false;
|
||||
|
||||
@ -1018,7 +1018,7 @@ void terrain_builder::build_terrains()
|
||||
util::array<t_translation::t_list, 7> adjacent_types;
|
||||
|
||||
if(biggest_constraint_adjacent > 0) {
|
||||
gamemap::location loc[7];
|
||||
basemap::location loc[7];
|
||||
loc[0] = constraint_most_adjacents->second.loc;
|
||||
get_adjacent_tiles(loc[0], loc+1);
|
||||
for(int i = 0; i < 7; ++i) {
|
||||
@ -1033,24 +1033,24 @@ void terrain_builder::build_terrains()
|
||||
}
|
||||
if(smallest_constraint_size != INT_MAX) {
|
||||
const t_translation::t_list& types = smallest_constraint->second.terrain_types_match.terrain;
|
||||
const gamemap::location loc = smallest_constraint->second.loc;
|
||||
const gamemap::location aloc = constraint_most_adjacents->second.loc;
|
||||
const basemap::location loc = smallest_constraint->second.loc;
|
||||
const basemap::location aloc = constraint_most_adjacents->second.loc;
|
||||
|
||||
for(t_translation::t_list::const_iterator c = types.begin();
|
||||
c != types.end(); ++c) {
|
||||
|
||||
const std::vector<gamemap::location>* locations;
|
||||
const std::vector<basemap::location>* locations;
|
||||
if(smallest_constraint_border) {
|
||||
locations = &terrain_by_type_border_[*c];
|
||||
} else {
|
||||
locations = &terrain_by_type_[*c];
|
||||
}
|
||||
|
||||
for(std::vector<gamemap::location>::const_iterator itor = locations->begin();
|
||||
for(std::vector<basemap::location>::const_iterator itor = locations->begin();
|
||||
itor != locations->end(); ++itor) {
|
||||
|
||||
if(biggest_constraint_adjacent > 0) {
|
||||
const gamemap::location pos = (*itor - loc) + aloc;
|
||||
const basemap::location pos = (*itor - loc) + aloc;
|
||||
if(!tile_map_.on_map(pos))
|
||||
continue;
|
||||
|
||||
@ -1079,7 +1079,7 @@ void terrain_builder::build_terrains()
|
||||
// a hack, so still need to figure out the best number -- Mordante
|
||||
for(int x = -2; x <= map_.x(); ++x) {
|
||||
for(int y = -2; y <= map_.y(); ++y) {
|
||||
const gamemap::location loc(x,y);
|
||||
const basemap::location loc(x,y);
|
||||
if(rule_matches(rule->second, loc, rule_index, true))
|
||||
apply_rule(rule->second, loc);
|
||||
}
|
||||
|
@ -54,10 +54,10 @@ public:
|
||||
* [terrain_graphics] rule reside.
|
||||
* @param level A level (scenario)-specific configuration file,
|
||||
* containing scenario-specific [terrain_graphics] rules.
|
||||
* @param gmap A properly-initialized gamemap object representing the
|
||||
* @param gmap A properly-initialized basemap object representing the
|
||||
* current terrain map.
|
||||
*/
|
||||
terrain_builder(const config& cfg, const config &level, const gamemap& gmap);
|
||||
terrain_builder(const config& cfg, const config &level, const basemap& gmap);
|
||||
|
||||
/** Returns a vector of strings representing the images to load & blit
|
||||
* together to get the built content for this tile.
|
||||
@ -74,7 +74,7 @@ public:
|
||||
* @return Returns a pointer list of animated images corresponding
|
||||
* to the parameters, or NULL if there is none.
|
||||
*/
|
||||
const imagelist *get_terrain_at(const gamemap::location &loc,
|
||||
const imagelist *get_terrain_at(const basemap::location &loc,
|
||||
const std::string &tod, ADJACENT_TERRAIN_TYPE const terrain_type);
|
||||
|
||||
/** Updates the animation at a given tile. returns true if something has
|
||||
@ -84,7 +84,7 @@ public:
|
||||
*
|
||||
* @return true: this tile must be redrawn.
|
||||
*/
|
||||
bool update_animation(const gamemap::location &loc);
|
||||
bool update_animation(const basemap::location &loc);
|
||||
|
||||
/** Performs a "quick-rebuild" of the terrain in a given location. The
|
||||
* "quick-rebuild" is no proper rebuild: it only clears the terrain
|
||||
@ -93,7 +93,7 @@ public:
|
||||
*
|
||||
* @param loc the location where to rebuild terrains
|
||||
*/
|
||||
void rebuild_terrain(const gamemap::location &loc);
|
||||
void rebuild_terrain(const basemap::location &loc);
|
||||
|
||||
/** Performs a complete rebuild of the list of terrain graphics
|
||||
* attached to a map. Should be called when a terrain is changed in the
|
||||
@ -186,9 +186,9 @@ public:
|
||||
{
|
||||
terrain_constraint() : loc() {};
|
||||
|
||||
terrain_constraint(gamemap::location loc) : loc(loc) {};
|
||||
terrain_constraint(basemap::location loc) : loc(loc) {};
|
||||
|
||||
gamemap::location loc;
|
||||
basemap::location loc;
|
||||
t_translation::t_match terrain_types_match;
|
||||
std::vector<std::string> set_flag;
|
||||
std::vector<std::string> no_flag;
|
||||
@ -267,7 +267,7 @@ private:
|
||||
/**
|
||||
* The list of constraints attached to a terrain_graphics WML rule.
|
||||
*/
|
||||
typedef std::map<gamemap::location, terrain_constraint> constraint_set;
|
||||
typedef std::map<basemap::location, terrain_constraint> constraint_set;
|
||||
|
||||
/**
|
||||
* The in-memory representation of a [terrain_graphics] WML rule.
|
||||
@ -281,10 +281,10 @@ private:
|
||||
|
||||
/**
|
||||
* The location on which this map may match. Set to a valid
|
||||
* gamemap::location if the "x" and "y" parameters of the
|
||||
* basemap::location if the "x" and "y" parameters of the
|
||||
* [terrain_graphics] rule are set.
|
||||
*/
|
||||
gamemap::location location_constraints;
|
||||
basemap::location location_constraints;
|
||||
|
||||
/**
|
||||
* The probability of this rule to match, when all conditions
|
||||
@ -321,11 +321,11 @@ private:
|
||||
*
|
||||
* @return A reference to the tile at this location.
|
||||
*/
|
||||
tile &operator[](const gamemap::location &loc);
|
||||
tile &operator[](const basemap::location &loc);
|
||||
/**
|
||||
* a const variant of operator[]
|
||||
*/
|
||||
const tile &operator[] (const gamemap::location &loc) const;
|
||||
const tile &operator[] (const basemap::location &loc) const;
|
||||
|
||||
/**
|
||||
* Tests if a location is on the map
|
||||
@ -334,7 +334,7 @@ private:
|
||||
*
|
||||
* @return true if loc is on the map, false otherwise.
|
||||
*/
|
||||
bool on_map(const gamemap::location &loc) const;
|
||||
bool on_map(const basemap::location &loc) const;
|
||||
|
||||
/**
|
||||
* Resets the whole tile map
|
||||
@ -517,7 +517,7 @@ private:
|
||||
* describing rule-global images.
|
||||
*/
|
||||
void add_constraints(constraint_set& constraints,
|
||||
const gamemap::location &loc, const t_translation::t_match& type,
|
||||
const basemap::location &loc, const t_translation::t_match& type,
|
||||
const config& global_images);
|
||||
|
||||
/**
|
||||
@ -533,10 +533,10 @@ private:
|
||||
* describing rule-global images.
|
||||
*/
|
||||
void add_constraints(constraint_set& constraints,
|
||||
const gamemap::location &loc, const config &cfg,
|
||||
const basemap::location &loc, const config &cfg,
|
||||
const config& global_images);
|
||||
|
||||
typedef std::multimap<int, gamemap::location> anchormap;
|
||||
typedef std::multimap<int, basemap::location> anchormap;
|
||||
|
||||
/**
|
||||
* Parses a map string (the map= element of a [terrain_graphics] rule,
|
||||
@ -622,7 +622,7 @@ private:
|
||||
* already checked, only flags and probability will be
|
||||
* checked.
|
||||
*/
|
||||
bool rule_matches(const building_rule &rule, const gamemap::location &loc,
|
||||
bool rule_matches(const building_rule &rule, const basemap::location &loc,
|
||||
const int rule_index, const bool check_loc) const;
|
||||
|
||||
/**
|
||||
@ -633,7 +633,7 @@ private:
|
||||
* @param rule The rule to apply
|
||||
* @param loc The location to which to apply the rule.
|
||||
*/
|
||||
void apply_rule(const building_rule &rule, const gamemap::location &loc);
|
||||
void apply_rule(const building_rule &rule, const basemap::location &loc);
|
||||
|
||||
/**
|
||||
* Returns the number of constraints adjacent to a given constraint in
|
||||
@ -651,7 +651,7 @@ private:
|
||||
*
|
||||
* @return the number of constraints adjacent to the location loc
|
||||
*/
|
||||
int get_constraint_adjacents(const building_rule& rule, const gamemap::location& loc);
|
||||
int get_constraint_adjacents(const building_rule& rule, const basemap::location& loc);
|
||||
|
||||
/**
|
||||
* Returns the "size" of a constraint, that is, the number of tiles, in
|
||||
@ -675,14 +675,14 @@ private:
|
||||
|
||||
/**
|
||||
* Calculates the list of terrains, and fills the tile_map_ member,
|
||||
* from the gamemap and the building_rules_.
|
||||
* from the basemap and the building_rules_.
|
||||
*/
|
||||
void build_terrains();
|
||||
|
||||
/**
|
||||
* A reference to the gamemap class used in the current level.
|
||||
* A reference to the basemap class used in the current level.
|
||||
*/
|
||||
const gamemap& map_;
|
||||
const basemap& map_;
|
||||
/**
|
||||
* The tile_map_ for the current level, which is filled by the
|
||||
* build_terrains_ method to contain "tiles" representing images
|
||||
@ -693,7 +693,7 @@ private:
|
||||
/**
|
||||
* Shorthand typedef for a map associating a list of locations to a terrain type.
|
||||
*/
|
||||
typedef std::map<t_translation::t_letter, std::vector<gamemap::location> > terrain_by_type_map;
|
||||
typedef std::map<t_translation::t_letter, std::vector<basemap::location> > terrain_by_type_map;
|
||||
|
||||
/**
|
||||
* A map representing all locations whose terrain is of a given type.
|
||||
|
@ -40,7 +40,7 @@ terrain_group::terrain_group(const config& cfg, display& gui):
|
||||
}
|
||||
|
||||
terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
||||
const gamemap &map, const config& cfg)
|
||||
const basemap &map, const config& cfg)
|
||||
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0),
|
||||
checked_group_btn_(0), map_(map),
|
||||
top_button_(gui.video(), "", gui::button::TYPE_PRESS, "uparrow-button"),
|
||||
|
@ -46,7 +46,7 @@ struct terrain_group
|
||||
class terrain_palette : public gui::widget {
|
||||
public:
|
||||
terrain_palette(display &gui, const size_specs &sizes,
|
||||
const gamemap &map, const config& cfg);
|
||||
const basemap &map, const config& cfg);
|
||||
|
||||
/// Scroll the terrain palette up one step if possible.
|
||||
void scroll_up();
|
||||
@ -136,7 +136,7 @@ private:
|
||||
gui::button *checked_group_btn_;
|
||||
|
||||
t_translation::t_letter selected_fg_terrain_, selected_bg_terrain_;
|
||||
const gamemap &map_;
|
||||
const basemap &map_;
|
||||
gui::button top_button_, bot_button_;
|
||||
size_t button_x_, top_button_y_, bot_button_y_;
|
||||
size_t nterrains_, terrain_start_;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace image {
|
||||
|
||||
surface getMinimap(int w, int h, const gamemap& map, const viewpoint* vw)
|
||||
surface getMinimap(int w, int h, const basemap& map, const viewpoint* vw)
|
||||
{
|
||||
const int scale = 8;
|
||||
|
||||
@ -53,7 +53,7 @@ surface getMinimap(int w, int h, const gamemap& map, const viewpoint* vw)
|
||||
|
||||
surface surf(NULL);
|
||||
|
||||
const gamemap::location loc(x,y);
|
||||
const basemap::location loc(x,y);
|
||||
if(map.on_board(loc)) {
|
||||
const bool shrouded = vw != NULL && vw->shrouded(x,y);
|
||||
const bool fogged = vw != NULL && vw->fogged(x,y) && !shrouded;
|
||||
|
@ -22,7 +22,7 @@ class team;
|
||||
namespace image {
|
||||
///function to create the minimap for a given map
|
||||
///the surface returned must be freed by the user
|
||||
surface getMinimap(int w, int h, const gamemap& map_, const viewpoint* vm=NULL);
|
||||
surface getMinimap(int w, int h, const basemap& map_, const viewpoint* vm=NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user