Remove handling of maps' usage= key

This commit is contained in:
Charles Dang 2015-10-07 20:24:55 +11:00
parent 798c59c7bd
commit abd5dfdcc0
3 changed files with 6 additions and 50 deletions

View file

@ -1183,17 +1183,15 @@ WML_HANDLER_FUNCTION(terrain_mask, /*event_info*/, cfg)
//config level;
std::string mask = cfg["mask"];
std::string usage = "mask";
int border_size = 0;
if (mask.empty()) {
usage = cfg["usage"].str();
border_size = cfg["border_size"];
mask = cfg["data"].str();
}
try {
mask_map.read(mask, false, border_size, usage);
mask_map.read(mask, false, border_size);
} catch(incorrect_map_format_error&) {
ERR_NG << "terrain mask is in the incorrect format, and couldn't be applied" << std::endl;
return;

View file

@ -40,7 +40,7 @@ static lg::log_domain log_config("config");
#define LOG_G LOG_STREAM(info, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general)
const std::string gamemap::default_map_header = "usage=map\nborder_size=1\n\n";
const std::string gamemap::default_map_header = "border_size=1\n\n";
const gamemap::tborder gamemap::default_border = gamemap::SINGLE_TILE_BORDER;
/** Gets the list of terrains. */
@ -116,8 +116,7 @@ gamemap::gamemap(const tdata_cache& tdata, const std::string& data):
h_(-1),
total_width_(0),
total_height_(0),
border_size_(gamemap::SINGLE_TILE_BORDER),
usage_(IS_MAP)
border_size_(gamemap::SINGLE_TILE_BORDER)
{
DBG_G << "loading map: '" << data << "'\n";
@ -134,8 +133,7 @@ gamemap::gamemap(const tdata_cache& tdata, const config& level):
h_(-1),
total_width_(0),
total_height_(0),
border_size_(gamemap::SINGLE_TILE_BORDER),
usage_(IS_MAP)
border_size_(gamemap::SINGLE_TILE_BORDER)
{
DBG_G << "loading map: '" << level.debug() << "'\n";
@ -154,11 +152,10 @@ gamemap::~gamemap()
{
}
void gamemap::read(const std::string& data, const bool allow_invalid, int border_size, std::string usage) {
void gamemap::read(const std::string& data, const bool allow_invalid, int border_size) {
// Initial stuff
border_size_ = border_size;
set_usage(usage);
tiles_.clear();
villages_.clear();
std::fill(startingPositions_, startingPositions_ +
@ -242,31 +239,6 @@ void gamemap::read(const std::string& data, const bool allow_invalid, int border
}
}
void gamemap::set_usage(const std::string& usage)
{
utils::string_map symbols;
symbols["border_size_key"] = "border_size";
symbols["usage_key"] = "usage";
symbols["usage_val"] = usage;
const std::string msg = "'$border_size_key|' should be "
"'$border_size_val|' when '$usage_key| = $usage_val|'";
if(usage == "map") {
usage_ = IS_MAP;
symbols["border_size_val"] = "1";
VALIDATE(border_size_ == 1, vgettext(msg.c_str(), symbols));
} else if(usage == "mask") {
usage_ = IS_MASK;
symbols["border_size_val"] = "0";
VALIDATE(border_size_ == 0, vgettext(msg.c_str(), symbols));
} else if(usage == "") {
throw incorrect_map_format_error("Map has a header but no usage");
} else {
std::string msg = "Map has a header but an unknown usage:" + usage;
throw incorrect_map_format_error(msg);
}
}
int gamemap::read_header(const std::string& data)
{
// Test whether there is a header section
@ -291,7 +263,6 @@ int gamemap::read_header(const std::string& data)
::read(header, header_str);
border_size_ = header["border_size"];
set_usage(header["usage"]);
return header_offset + 2;
}

View file

@ -74,11 +74,6 @@ public:
SINGLE_TILE_BORDER
};
enum tusage {
IS_MAP,
IS_MASK
};
/**
* Loads a map, with the given terrain configuration.
*
@ -104,7 +99,7 @@ public:
virtual ~gamemap();
void read(const std::string& data, const bool allow_invalid = true, const int border_size = 1, const std::string usage = "map");
void read(const std::string& data, const bool allow_invalid = true, const int border_size = 1);
std::string write() const;
@ -201,9 +196,6 @@ public:
*/
enum { MAX_PLAYERS = 9 };
/** Returns the usage of the map. */
tusage get_usage() const { return usage_; }
/**
* The default map header, needed for maps created with
* terrain_translation::write_game_map().
@ -234,8 +226,6 @@ protected:
private:
void set_usage(const std::string& usage);
/**
* Reads the header of a map which is saved in the deprecated map_data format.
*
@ -269,9 +259,6 @@ protected:
private:
/** The size of the border around the map. */
int border_size_;
/** The kind of map is being loaded. */
tusage usage_;
};
#endif