mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 16:36:58 +00:00
remove border parameter from gamemap::overlay
This also moves the "map_data" atribute_value->sting conversion to the game_board class becasue the config writing also happens in there. This prepares a patch to remove the border_size_ member from the gamemap object.
This commit is contained in:
parent
62bbab330d
commit
49621e3d2a
@ -268,7 +268,7 @@ editor_action_apply_mask* editor_action_apply_mask::clone() const
|
||||
}
|
||||
void editor_action_apply_mask::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
mc.get_map().overlay(mask_, config(), 0, 0, false);
|
||||
mc.get_map().overlay(mask_, config(), {0, 0});
|
||||
mc.set_needs_terrain_rebuild();
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ static lg::log_domain log_engine_enemies("engine/enemies");
|
||||
|
||||
game_board::game_board(const tdata_cache & tdata, const config & level)
|
||||
: teams_()
|
||||
, map_(new gamemap(tdata, level))
|
||||
, map_(new gamemap(tdata, level["map_data"]))
|
||||
, unit_id_manager_(level["next_underlying_unit_id"])
|
||||
, units_()
|
||||
{
|
||||
@ -291,8 +291,8 @@ boost::optional<std::string> game_board::replace_map(const gamemap & newmap) {
|
||||
|
||||
|
||||
|
||||
void game_board::overlay_map(const gamemap & mask_map, const config & cfg, map_location loc, bool border) {
|
||||
map_->overlay(mask_map, cfg, loc.x, loc.y, border);
|
||||
void game_board::overlay_map(const gamemap & mask_map, const config & cfg, map_location loc) {
|
||||
map_->overlay(mask_map, cfg, loc);
|
||||
}
|
||||
|
||||
bool game_board::change_terrain(const map_location &loc, const std::string &t_str,
|
||||
|
@ -131,7 +131,7 @@ public:
|
||||
|
||||
bool try_add_unit_to_recall_list(const map_location& loc, const unit_ptr u);
|
||||
boost::optional<std::string> replace_map (const gamemap & r);
|
||||
void overlay_map (const gamemap & o, const config & cfg, map_location loc, bool border);
|
||||
void overlay_map (const gamemap & o, const config & cfg, map_location loc);
|
||||
|
||||
bool change_terrain(const map_location &loc, const std::string &t,
|
||||
const std::string & mode, bool replace_if_failed); //used only by lua
|
||||
|
@ -817,21 +817,19 @@ WML_HANDLER_FUNCTION(terrain_mask,, cfg)
|
||||
{
|
||||
map_location loc = cfg_to_loc(cfg, 1, 1);
|
||||
|
||||
gamemap mask_map(resources::gameboard->map());
|
||||
|
||||
bool border = cfg["border"].to_bool(true);
|
||||
gamemap mask_map(resources::gameboard->map().tdata(), "");
|
||||
|
||||
try {
|
||||
if(!cfg["mask_file"].empty()) {
|
||||
const std::string& maskfile = filesystem::get_wml_location(cfg["mask_file"].str());
|
||||
|
||||
if(filesystem::file_exists(maskfile)) {
|
||||
mask_map.read(filesystem::read_file(maskfile), false, border);
|
||||
mask_map.read(filesystem::read_file(maskfile), false);
|
||||
} else {
|
||||
throw incorrect_map_format_error("Invalid file path");
|
||||
}
|
||||
} else {
|
||||
mask_map.read(cfg["mask"], false, border);
|
||||
mask_map.read(cfg["mask"], false);
|
||||
}
|
||||
} catch(incorrect_map_format_error&) {
|
||||
ERR_NG << "terrain mask is in the incorrect format, and couldn't be applied" << std::endl;
|
||||
@ -840,7 +838,12 @@ WML_HANDLER_FUNCTION(terrain_mask,, cfg)
|
||||
e.show(resources::screen->video());
|
||||
return;
|
||||
}
|
||||
resources::gameboard->overlay_map(mask_map, cfg.get_parsed_config(), loc, border);
|
||||
|
||||
if (!cfg["border"].to_bool(true)) {
|
||||
mask_map.add_fog_border();
|
||||
}
|
||||
|
||||
resources::gameboard->overlay_map(mask_map, cfg.get_parsed_config(), loc);
|
||||
resources::screen->needs_rebuild(true);
|
||||
}
|
||||
|
||||
|
@ -120,27 +120,6 @@ gamemap::gamemap(const tdata_cache& tdata, const std::string& data):
|
||||
read(data);
|
||||
}
|
||||
|
||||
gamemap::gamemap(const tdata_cache& tdata, const config& level):
|
||||
tiles_(1, 1),
|
||||
tdata_(tdata),
|
||||
villages_(),
|
||||
borderCache_(),
|
||||
terrainFrequencyCache_(),
|
||||
w_(-1),
|
||||
h_(-1),
|
||||
border_size_(default_border)
|
||||
{
|
||||
DBG_G << "loading map: '" << level.debug() << "'\n";
|
||||
|
||||
const std::string& map_data = level["map_data"];
|
||||
if (!map_data.empty()) {
|
||||
read(map_data);
|
||||
} else {
|
||||
w_ = 0;
|
||||
h_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gamemap::~gamemap()
|
||||
{
|
||||
}
|
||||
@ -260,8 +239,11 @@ namespace
|
||||
}
|
||||
};
|
||||
}
|
||||
void gamemap::overlay(const gamemap& m, const config& rules_cfg, int xpos, int ypos, bool border)
|
||||
void gamemap::overlay(const gamemap& m, const config& rules_cfg, map_location loc)
|
||||
{
|
||||
bool border = true;
|
||||
int xpos = loc.x;
|
||||
int ypos = loc.y;
|
||||
//const config::const_child_itors &rules = rules_cfg.child_range("rule");
|
||||
std::vector<overlay_rule> rules(rules_cfg.child_count("rule"));
|
||||
for(size_t i = 0; i <rules.size(); ++i)
|
||||
@ -545,3 +527,17 @@ std::vector<map_location> gamemap::parse_location_range(const std::string &x, co
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void gamemap::add_fog_border()
|
||||
{
|
||||
t_translation::t_map tiles_new(tiles_.w + 1, tiles_.h + 1);
|
||||
for (int x = 0, x_end = tiles_new.w; x != x_end; ++x) {
|
||||
for (int y = 0, y_end = tiles_new.h; y != y_end; ++y) {
|
||||
tiles_new.get(x, y) = (x == 0 || y == 0) ? t_translation::VOID_TERRAIN : tiles_.get(x - 1, y - 1);
|
||||
}
|
||||
}
|
||||
++w_;
|
||||
++h_;
|
||||
tiles_ = tiles_new;
|
||||
}
|
||||
|
||||
|
@ -78,18 +78,6 @@ public:
|
||||
*/
|
||||
gamemap(const tdata_cache &tdata, const std::string &data); //throw(incorrect_map_format_error)
|
||||
|
||||
|
||||
/**
|
||||
* Loads a map, from the [map] wml config in @a level.
|
||||
*
|
||||
* Data should be a series of lines, with each character representing one
|
||||
* hex on the map. Starting locations are represented by numbers
|
||||
*
|
||||
* @param tdata the terrain data
|
||||
* @param level the scenario config to load from.
|
||||
*/
|
||||
gamemap(const tdata_cache &tdata, const config &level); //throw(incorrect_map_format_error)
|
||||
|
||||
virtual ~gamemap();
|
||||
|
||||
void read(const std::string& data, const bool allow_invalid = true, const int border_size = 1);
|
||||
@ -97,7 +85,7 @@ public:
|
||||
std::string write() const;
|
||||
|
||||
/** Overlays another map onto this one at the given position. */
|
||||
void overlay(const gamemap& m, const config& rules, int x=0, int y=0, bool border=false);
|
||||
void overlay(const gamemap& m, const config& rules, map_location loc);
|
||||
|
||||
/** Effective map width. */
|
||||
int w() const { return w_; }
|
||||
@ -224,7 +212,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void add_fog_border();
|
||||
protected:
|
||||
t_translation::t_map tiles_;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user