Cleaned up old code related to border_size, usage, and map header
This commit is contained in:
parent
6b78073b49
commit
2f650419da
4 changed files with 9 additions and 88 deletions
|
@ -44,7 +44,7 @@ editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, c
|
|||
}
|
||||
|
||||
editor_map::editor_map(const config& terrain_cfg)
|
||||
: gamemap(boost::make_shared<terrain_type_data>(terrain_cfg), gamemap::default_map_header)
|
||||
: gamemap(boost::make_shared<terrain_type_data>(terrain_cfg), "")
|
||||
, selection_()
|
||||
{
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ editor_map editor_map::from_string(const config& terrain_cfg, const std::string&
|
|||
}
|
||||
|
||||
editor_map::editor_map(const config& terrain_cfg, size_t width, size_t height, const t_translation::t_terrain & filler)
|
||||
: gamemap(boost::make_shared<terrain_type_data>(terrain_cfg), gamemap::default_map_header + t_translation::write_game_map(
|
||||
: gamemap(boost::make_shared<terrain_type_data>(terrain_cfg), t_translation::write_game_map(
|
||||
t_translation::t_map(width + 2, t_translation::t_list(height + 2, filler))))
|
||||
, selection_()
|
||||
{
|
||||
|
|
|
@ -370,7 +370,7 @@ static std::string output_map(const terrain_map& terrain,
|
|||
itor->second.y -= begin_y;
|
||||
}
|
||||
|
||||
return gamemap::default_map_header + t_translation::write_game_map(map, starting_positions);
|
||||
return t_translation::write_game_map(map, starting_positions);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
62
src/map.cpp
62
src/map.cpp
|
@ -40,8 +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 gamemap::tborder gamemap::default_border = gamemap::SINGLE_TILE_BORDER;
|
||||
const int gamemap::default_border = 1;
|
||||
|
||||
/** Gets the list of terrains. */
|
||||
const t_translation::t_list& gamemap::get_terrain_list() const
|
||||
|
@ -116,8 +115,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::default_border)
|
||||
{
|
||||
DBG_G << "loading map: '" << data << "'\n";
|
||||
|
||||
|
@ -134,8 +132,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::default_border)
|
||||
{
|
||||
DBG_G << "loading map: '" << level.debug() << "'\n";
|
||||
|
||||
|
@ -160,11 +157,9 @@ 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_ +
|
||||
|
@ -248,31 +243,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
|
||||
|
@ -297,7 +267,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;
|
||||
}
|
||||
|
@ -323,29 +292,6 @@ std::string gamemap::write() const
|
|||
return s.str();
|
||||
}
|
||||
|
||||
/*
|
||||
void gamemap::write(config& cfg) const
|
||||
{
|
||||
// Convert the starting positions to a map
|
||||
std::map<int, t_translation::coordinate> starting_positions;
|
||||
for (int i = 0; i < MAX_PLAYERS + 1; ++i)
|
||||
{
|
||||
if (!on_board(startingPositions_[i])) continue;
|
||||
t_translation::coordinate position(
|
||||
startingPositions_[i].x + border_size_
|
||||
, startingPositions_[i].y + border_size_);
|
||||
starting_positions[i] = position;
|
||||
}
|
||||
|
||||
cfg["border_size"] = border_size_;
|
||||
cfg["usage"] = (usage_ == IS_MAP ? "map" : "mask");
|
||||
|
||||
std::ostringstream s;
|
||||
s << t_translation::write_game_map(tiles_, starting_positions);
|
||||
cfg["data"] = s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
void gamemap::overlay(const gamemap& m, const config& rules_cfg, int xpos, int ypos, bool border)
|
||||
{
|
||||
const config::const_child_itors &rules = rules_cfg.child_range("rule");
|
||||
|
|
29
src/map.hpp
29
src/map.hpp
|
@ -69,16 +69,6 @@ public:
|
|||
/* Get the underlying terrain_type_data object. */
|
||||
const tdata_cache & tdata() const { return tdata_; }
|
||||
|
||||
enum tborder {
|
||||
NO_BORDER = 0,
|
||||
SINGLE_TILE_BORDER
|
||||
};
|
||||
|
||||
enum tusage {
|
||||
IS_MAP,
|
||||
IS_MASK
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a map, with the given terrain configuration.
|
||||
*
|
||||
|
@ -104,7 +94,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 = gamemap::default_border);
|
||||
|
||||
std::string write() const;
|
||||
|
||||
|
@ -140,7 +130,6 @@ public:
|
|||
/** Writes the terrain at loc to cfg. */
|
||||
void write_terrain(const map_location &loc, config& cfg) const;
|
||||
|
||||
|
||||
/** Manipulate starting positions of the different sides. */
|
||||
const map_location& starting_position(int side) const;
|
||||
int is_starting_position(const map_location& loc) const;
|
||||
|
@ -201,17 +190,8 @@ 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().
|
||||
*/
|
||||
static const std::string default_map_header;
|
||||
|
||||
/** The default border style for a map. */
|
||||
static const tborder default_border;
|
||||
static const int default_border;
|
||||
|
||||
/** Parses ranges of locations into a vector of locations, using this map's dimensions as bounds. */
|
||||
std::vector<map_location> parse_location_range(const std::string& xvals,
|
||||
|
@ -234,8 +214,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 +247,6 @@ protected:
|
|||
private:
|
||||
/** The size of the border around the map. */
|
||||
int border_size_;
|
||||
|
||||
/** The kind of map is being loaded. */
|
||||
tusage usage_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue