Skip to content

Commit

Permalink
Remove handling of maps' usage= key
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 7, 2015
1 parent 798c59c commit abd5dfd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 50 deletions.
4 changes: 1 addition & 3 deletions src/game_events/action_wml.cpp
Expand Up @@ -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;
Expand Down
37 changes: 4 additions & 33 deletions src/map.cpp
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";

Expand All @@ -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";

Expand All @@ -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_ +
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
15 changes: 1 addition & 14 deletions src/map.hpp
Expand Up @@ -74,11 +74,6 @@ class gamemap
SINGLE_TILE_BORDER
};

enum tusage {
IS_MAP,
IS_MASK
};

/**
* Loads a map, with the given terrain configuration.
*
Expand All @@ -104,7 +99,7 @@ class gamemap

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;

Expand Down Expand Up @@ -201,9 +196,6 @@ class gamemap
*/
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().
Expand Down Expand Up @@ -234,8 +226,6 @@ class gamemap

private:

void set_usage(const std::string& usage);

/**
* Reads the header of a map which is saved in the deprecated map_data format.
*
Expand Down Expand Up @@ -269,9 +259,6 @@ class gamemap
private:
/** The size of the border around the map. */
int border_size_;

/** The kind of map is being loaded. */
tusage usage_;
};

#endif

0 comments on commit abd5dfd

Please sign in to comment.