A big merge with the local changes so far.
Removed most of the terrain char assumptions but not ready yet. Also a lot of bugs are left.
This commit is contained in:
parent
f854c7eff7
commit
7ad017f6f3
52 changed files with 1373 additions and 399 deletions
26
README.BRANCH
Normal file
26
README.BRANCH
Normal file
|
@ -0,0 +1,26 @@
|
|||
This branch tries to improve the terrain system.
|
||||
Changes are in the changelog
|
||||
TODO contains the points to be done which are tagged in the source
|
||||
|
||||
README.FILES contains files modified so far
|
||||
|
||||
|
||||
Main TODO list is here
|
||||
|
||||
* Make Wesnoth work again it doesn't
|
||||
* all users of "map_data" should be checked, busy
|
||||
* Blitz map can't be loaded, fails with segfault underlaying terrain problems
|
||||
* Terrain transitions are broken, this also hides all villages
|
||||
* All terrain seems to have same defence and movement cost as base terrain....
|
||||
* The preferences "encountered_terrains" should be converted
|
||||
also should the help display be able to use this part.
|
||||
The preferences should work now, but not tested
|
||||
* Help systems is broken
|
||||
* Load / save is broken
|
||||
* Multiplayer is broken, not sure but quite
|
||||
* Random map generators are broken, compiles but doesn't work
|
||||
* The editor is broken has to be fixed, won't compiler
|
||||
* move all things name xx2 back to xx
|
||||
The rename is done to trace down the entire caller tree
|
||||
and find functions which assume the terrain type is a char
|
||||
and thus a string can be used for an array or vector.
|
52
README.FILES
Normal file
52
README.FILES
Normal file
|
@ -0,0 +1,52 @@
|
|||
B = broken (compiles but is known not to work properly)
|
||||
\ = busy
|
||||
T = testing (no compiles warnings but unsure about working)
|
||||
V = ready (no compiler warnings and seems to work that is)
|
||||
R = ready, works code beautified etc etc
|
||||
|
||||
V Index: src/actions.cpp
|
||||
V Index: src/ai_attack.cpp
|
||||
V Index: src/ai.cpp
|
||||
V Index: src/ai_move.cpp
|
||||
T Index: src/builder.cpp
|
||||
T Index: src/builder.hpp
|
||||
B Index: src/cavegen.cpp returns a string for the map instead of vector
|
||||
B Index: src/cavegen.hpp
|
||||
V Index: src/dialogs.cpp
|
||||
V Index: src/display.cpp
|
||||
V Index: src/display.hpp
|
||||
B Index: src/editor/editor.cpp doesn't compile later
|
||||
V Index: src/filesystem.cpp
|
||||
V Index: src/filesystem.hpp
|
||||
V Index: src/game.cpp
|
||||
B Index: src/game_events.cpp
|
||||
B Index: src/help.cpp
|
||||
V Index: src/image.hpp
|
||||
V Index: src/Makefile.am
|
||||
B Index: src/map.cpp
|
||||
B Index: src/map.hpp
|
||||
B Index: src/map_create.cpp
|
||||
B Index: src/map_create.hpp
|
||||
B Index: src/mapgen.cpp
|
||||
V Index: src/minimap.cpp
|
||||
V Index: src/multiplayer_create.cpp
|
||||
V Index: src/multiplayer_lobby.cpp
|
||||
V Index: src/multiplayer_lobby.hpp
|
||||
V Index: src/pathfind.cpp guess unchanged but not 100% sure
|
||||
V Index: src/playcampaign.cpp
|
||||
V Index: src/play_controller.cpp
|
||||
V Index: src/preferences.cpp
|
||||
V Index: src/preferences.hpp
|
||||
V Index: src/reports.cpp
|
||||
\ Index: src/terrain.cpp
|
||||
\ Index: src/terrain.hpp
|
||||
\ Index: src/terrain_translation.cpp
|
||||
\ Index: src/terrain_translation.hpp
|
||||
\ Index: src/unit_animation.cpp
|
||||
\ Index: src/unit_animation.hpp
|
||||
\ Index: src/unit.cpp
|
||||
\ Index: src/unit.hpp
|
||||
\ Index: src/unit_display.cpp
|
||||
\ Index: src/unit_types.cpp
|
||||
\ Index: src/unit_types.hpp
|
||||
V Index: src/wesconfig.h
|
59
TODO
Normal file
59
TODO
Normal file
|
@ -0,0 +1,59 @@
|
|||
src/builder.cpp:598://FIXME MdW this is a total rewrite not sure whether is really works
|
||||
src/builder.cpp:1095: //FIXME MdW the previous code set the value to an empty
|
||||
src/game_events.cpp:1136: if(terrain_type.size() > 0) { //FIXME MdW we need a proper way to set and invalid terrain
|
||||
src/game_events.cpp:1138: //FIXME MdW cleanup
|
||||
src/game_events.cpp:1160: //FIXME MdW cleanup
|
||||
src/game_events.cpp:1753: const terrain_translation::TERRAIN_NUMBER c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
src/help.cpp:1280: //FIXME MdW cleanup
|
||||
src/help.cpp:1295://FIXME MdW enable
|
||||
src/help.cpp:1397://FIXME MdW enable
|
||||
src/help.cpp:1407:// << escape(std::string("terrain_") + t) << "'</ref>"; //FIXME MdW remove
|
||||
src/help.cpp:1432:// << escape(std::string("terrain_") + t) << "'</ref>"; //FIXME MdW remove
|
||||
src/help.cpp:1468:#if 0 //FIXME MdW enable
|
||||
src/help.cpp:1479: // FIXME MdW typecast to char
|
||||
src/help.cpp:1481: (char)terrain_translation::VOID_TERRAIN), show_info_about.end());//FIXME MdW typecast
|
||||
src/help.cpp:1483: (char)terrain_translation::FOGGED), show_info_about.end());//FIXME MdW typecast
|
||||
src/help.cpp:1488://FIXME MdW make it work again
|
||||
src/map.cpp:82://FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
src/map.cpp:96: //FIXME MdW debug hack use the one below once the error is found
|
||||
src/map.cpp:181: if(str == "n") { //FIXME MdW case??
|
||||
src/map.cpp:410://FIXME MdW the entire routine should be cleaned up
|
||||
src/map.cpp:502:#if 0 //FIXME MdW remove enable
|
||||
src/map.cpp:556: //FIXME MdW cleanup
|
||||
src/map.cpp:684:#if 1 //FIXME MdW remove the if
|
||||
src/map.cpp:696://FIXME MdW enable
|
||||
src/map_create.cpp:54:// return generator.get()->create_map(parameters); FIXME MdW enable
|
||||
src/mapgen.cpp:342: mutable std::map<char,double> cache_; //FIXME MdW are we allowed to be char
|
||||
src/mapgen.cpp:362: const char c = map_[loc.x][loc.y]; //FIXME MdW are we allowed to be char
|
||||
src/mapgen.cpp:363: const std::map<char,double>::const_iterator itor = cache_.find(c); //FIXME MdW are we allowed to be char
|
||||
src/mapgen.cpp:368: static std::string terrain(1,'x'); //FIXME MdW are we allowed to be char x is special char reserved for UMC
|
||||
src/mapgen.cpp:377: cache_.insert(std::pair<char,double>(c,res)); //FIXME MdW are we allowed to be char
|
||||
src/mapgen.cpp:558://FIXME MdW g = grass
|
||||
src/mapgen.cpp:636: const char grassland = flatland[0]; //FIXME MdW are we allowed to be char
|
||||
src/mapgen.cpp:1027: terrain[x][y] = '1' + player; //FIXME MdW keep 1 or not??
|
||||
src/mapgen.cpp:1106://FIXME MdW use gamemap constants
|
||||
src/mapgen.cpp:1135://FIXME MdW enable
|
||||
src/map.hpp:45: //FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
src/map.hpp:109: //FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
src/map.hpp:136:// void read(const std::string& data); //FIXME MdW cleanup
|
||||
src/map.hpp:213: //The terrain string with TERRAIN_NUMBER should be make FIXME MdW
|
||||
src/multiplayer_create.cpp:364: //FIXME MdW we do a double conversion, might be nice to have a direct way
|
||||
src/terrain.cpp:42: //FIXME MdW remove obsolete part
|
||||
src/terrain.cpp:52: //FIXME MdW what do the next 4 lines do?? guess nothing, since seems to be overwritten
|
||||
src/terrain.cpp:126: //FIXME MdW test the union
|
||||
src/terrain.cpp:164://FIXME MdW obsolete
|
||||
src/terrain.cpp:182://FIXME MdW obsolete
|
||||
src/terrain.cpp:254: //FIXME MdW is an empty letter allowed???
|
||||
src/terrain.hpp:49: //FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
src/terrain.hpp:87: //FIXME MdW rename these as soon as the originals are killed
|
||||
src/terrain.hpp:100: //FIXME MdW remove
|
||||
src/terrain_translation.cpp:67: //FIXME MdW is an empty letter allowed???
|
||||
src/terrain_translation.cpp:106://FIXME MdW make a generic function which gets a string, since only the vconfig is different
|
||||
src/terrain_translation.cpp:220: //FIXME MdW remove assigment, only used as debug aid
|
||||
src/terrain_translation.hpp:15://FIXME MdW is Makefile.am good modified
|
||||
src/unit_animation.cpp:101://FIXME MdW not sure what the terrain string is but guess
|
||||
src/unit_animation.cpp:148: //FIXME MdW enable change to underlying_union_terrain2 doesn't work
|
||||
src/unit.cpp:2147: //FIXME MdW cleanup
|
||||
src/unit.cpp:2150: if(underlying.size() == 0) { //FIXME MdW debug hack
|
||||
src/unit.cpp:2234: //FIXME MdW cleanup
|
||||
src/unit_types.cpp:408: //FIXME MdW cleanup
|
26
changelog
26
changelog
|
@ -1,3 +1,29 @@
|
|||
Version 1.3-terrain-branch: also read README.BRANCH
|
||||
* Changed TERRAIN to TERRAIN_LETTER and TERRAIN_NUMBER
|
||||
* TERRAIN_LETTER is a char fully compatible with the previous type
|
||||
* TERRAIN_NUMBER is a unsigned long the new type
|
||||
* Moved the TERRAIN to terrain_translation since terrain_type needs this info
|
||||
but can't load map.hpp due dependancies and terrain_translaion is the
|
||||
highest level now
|
||||
* Started to convert all users to use the TERRAIN_NUMBER and remove
|
||||
the assumption the type is a char. Notable offenders
|
||||
* terrain_type
|
||||
* mapgen (also had letters hard coded eg g=grass)
|
||||
* cavegen (also had letters hard coded)
|
||||
* help
|
||||
* Created terrain_translation class
|
||||
* map.hpp no longer includes terrain.hpp but terrain_translation.hpp (which
|
||||
include terrain.hpp)
|
||||
* terrain converted seems oke
|
||||
* builder mostly done but has some UGLY hacks, doesn't work either <<<<
|
||||
* map started <<<<
|
||||
* dicovered terrain in preferences not started <<<<
|
||||
* loading / saving a game not started <<<<
|
||||
* help not started <<<<
|
||||
* mapgen not started <<<<
|
||||
* cavegen not started <<<<
|
||||
* editor not started <<<<
|
||||
|
||||
Version 1.3-svn:
|
||||
* editor
|
||||
* allow maps to be loaded from scenario files and written back to them
|
||||
|
|
|
@ -9,16 +9,16 @@
|
|||
#define PACKAGE_NAME "Battle for Wesnoth"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "Battle for Wesnoth 1.3-svn"
|
||||
#define PACKAGE_STRING "Battle for Wesnoth 1.3-terrain-branch"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "wesnoth"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.3-svn"
|
||||
#define PACKAGE_VERSION "1.3-terrain-branch"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.3-svn"
|
||||
#define VERSION "1.3-terrain-branch"
|
||||
|
||||
/* The default server for this version */
|
||||
#define WESNOTH_DEFAULT_SERVER "devsrv.wesnoth.org:14998"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
AC_PREREQ([2.57])
|
||||
|
||||
define([WESNOTH_VERSION],[1.3-svn])
|
||||
define([WESNOTH_VERSION],[1.3-terrain-branch])
|
||||
|
||||
dnl define([DEFAULT_SERVER],[server.wesnoth.org])
|
||||
define([DEFAULT_SERVER],[devsrv.wesnoth.org:14998])
|
||||
|
|
|
@ -365,6 +365,7 @@ noinst_HEADERS = \
|
|||
publish_campaign.hpp \
|
||||
game_config.hpp \
|
||||
terrain.hpp \
|
||||
terrain_translation.hpp \
|
||||
config.hpp \
|
||||
network_worker.hpp \
|
||||
util.hpp \
|
||||
|
@ -457,6 +458,7 @@ libwesnoth_core_a_SOURCES = \
|
|||
race.cpp \
|
||||
random.cpp \
|
||||
terrain.cpp \
|
||||
terrain_translation.cpp \
|
||||
thread.cpp \
|
||||
tstring.cpp \
|
||||
util.cpp \
|
||||
|
|
|
@ -1812,7 +1812,7 @@ size_t move_unit(display* disp, const game_data& gamedata,
|
|||
bool should_clear_stack = false;
|
||||
std::vector<gamemap::location>::const_iterator step;
|
||||
for(step = route.begin()+1; step != route.end(); ++step) {
|
||||
const gamemap::TERRAIN terrain = map[step->x][step->y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map[step->x][step->y];
|
||||
|
||||
const unit_map::const_iterator enemy_unit = units.find(*step);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ protected:
|
|||
const location& src = range.first->second;
|
||||
const unit_map::const_iterator un = get_info().units.find(src);
|
||||
|
||||
const gamemap::TERRAIN terrain = get_info().map.get_terrain(dst);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = get_info().map.get_terrain(dst);
|
||||
|
||||
const int chance_to_hit = un->second.defense_modifier(terrain);
|
||||
|
||||
|
@ -1440,8 +1440,8 @@ bool ai::move_to_targets(std::map<gamemap::location,paths>& possible_moves, move
|
|||
int ai::average_resistance_against(const unit_type& a, const unit_type& b) const
|
||||
{
|
||||
int weighting_sum = 0, defense = 0;
|
||||
const std::map<gamemap::TERRAIN,size_t>& terrain = map_.get_weighted_terrain_frequencies();
|
||||
for(std::map<gamemap::TERRAIN,size_t>::const_iterator j = terrain.begin(); j != terrain.end(); ++j) {
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,size_t>& terrain = map_.get_weighted_terrain_frequencies();
|
||||
for(std::map<terrain_translation::TERRAIN_NUMBER,size_t>::const_iterator j = terrain.begin(); j != terrain.end(); ++j) {
|
||||
defense += a.movement_type().defense_modifier(map_,j->first)*j->second;
|
||||
weighting_sum += j->second;
|
||||
}
|
||||
|
@ -1953,7 +1953,7 @@ bool ai::leader_can_reach_keep() const
|
|||
|
||||
int ai::rate_terrain(const unit& u, const gamemap::location& loc)
|
||||
{
|
||||
const gamemap::TERRAIN terrain = map_.get_terrain(loc);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_.get_terrain(loc);
|
||||
const int defense = u.defense_modifier(terrain);
|
||||
int rating = 100 - defense;
|
||||
|
||||
|
|
|
@ -253,13 +253,13 @@ void ai::do_attack_analysis(
|
|||
|
||||
struct battle_type {
|
||||
battle_type(const gamemap::location& a, const gamemap::location& d,
|
||||
gamemap::TERRAIN t)
|
||||
terrain_translation::TERRAIN_NUMBER t)
|
||||
: attacker(a),defender(d),terrain(t),weapon(-1)
|
||||
{}
|
||||
|
||||
const gamemap::location attacker;
|
||||
const gamemap::location defender;
|
||||
const gamemap::TERRAIN terrain;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain;
|
||||
int weapon;
|
||||
};
|
||||
|
||||
|
@ -615,7 +615,7 @@ double ai::power_projection(const gamemap::location& loc, const move_map& dstsr
|
|||
continue;
|
||||
}
|
||||
|
||||
const gamemap::TERRAIN terrain = map_[locs[i].x][locs[i].y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_[locs[i].x][locs[i].y];
|
||||
|
||||
typedef move_map::const_iterator Itor;
|
||||
typedef std::pair<Itor,Itor> Range;
|
||||
|
|
|
@ -55,7 +55,7 @@ struct move_cost_calculator : cost_calculator
|
|||
*/
|
||||
wassert(map_.on_board(loc));
|
||||
|
||||
const gamemap::TERRAIN terrain = map_[loc.x][loc.y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_[loc.x][loc.y];
|
||||
|
||||
const double modifier = 1.0; //move_type_.defense_modifier(map_,terrain);
|
||||
const double move_cost = unit_.movement_cost(terrain);//move_type_[terrain];
|
||||
|
@ -77,7 +77,7 @@ private:
|
|||
const gamemap& map_;
|
||||
const game_data& data_;
|
||||
const unit_map& units_;
|
||||
// mutable std::map<gamemap::TERRAIN,int> move_type_;
|
||||
// mutable std::map<terrain_translation::TERRAIN_NUMBER,int> move_type_;
|
||||
const gamemap::location loc_;
|
||||
const ai::move_map dstsrc_, enemy_dstsrc_;
|
||||
const bool avoid_enemies_;
|
||||
|
|
186
src/builder.cpp
186
src/builder.cpp
|
@ -153,7 +153,7 @@ terrain_builder::terrain_builder(const config& cfg, const config& level, const g
|
|||
}
|
||||
|
||||
const terrain_builder::imagelist *terrain_builder::get_terrain_at(const gamemap::location &loc,
|
||||
const std::string &tod, ADJACENT_TERRAIN_TYPE terrain_type) const
|
||||
const std::string &tod, const ADJACENT_TERRAIN_TYPE terrain_type) const
|
||||
{
|
||||
if(!tile_map_.on_map(loc))
|
||||
return NULL;
|
||||
|
@ -537,7 +537,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 std::string& type, const config& global_images)
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& type, const config& global_images)
|
||||
{
|
||||
if(constraints.find(loc) == constraints.end()) {
|
||||
//the terrain at the current location did not exist, so create it
|
||||
|
@ -556,7 +556,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)
|
||||
{
|
||||
add_constraints(constraints, loc, cfg["type"], global_images);
|
||||
add_constraints(constraints, loc, terrain_translation().get_list(cfg["type"]), global_images);
|
||||
|
||||
terrain_constraint& constraint = constraints[loc];
|
||||
|
||||
|
@ -575,61 +575,112 @@ void terrain_builder::add_constraints(terrain_builder::constraint_set &constrain
|
|||
add_images_from_config(constraint.images, cfg, false);
|
||||
}
|
||||
|
||||
|
||||
void terrain_builder::parse_mapstring(const std::string &mapstring,
|
||||
void terrain_builder::parse_mapstring(const std::vector<terrain_translation::TERRAIN_NUMBER> &mapstring,
|
||||
struct building_rule &br, anchormap& anchors,
|
||||
const config& global_images)
|
||||
{
|
||||
int lineno = 0;
|
||||
/* Copied from http://www.anathas.org/ayin/wesnoth/doc/terrain_graphics_wml
|
||||
Map strings are stings, generally multi-line, which are parsed the following way:
|
||||
|
||||
Starting empty lines are discarded.
|
||||
* If the first non-empty line starts with a space, it is given the line number
|
||||
"1". Else, it is given the line-number "0"
|
||||
* If the line is odd-numbered, its first 2 characters are discarded
|
||||
* The rest of the line is split into 4-character chunks (or smaller if less
|
||||
characters are left in the current line.)
|
||||
* For each of those 4-character chunks:
|
||||
+ If the chunk consists in a dot, it is ignored.
|
||||
+ If the chunk consists a combination of any characters except digits, a new
|
||||
rule is created.
|
||||
+ If the chunk consists in digits, a new anchor_ is created (see below.)
|
||||
+ The column-number is increased by one.
|
||||
*/
|
||||
//FIXME MdW this is a total rewrite not sure whether is really works
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int lineno = 0;
|
||||
int i;
|
||||
|
||||
const std::vector<std::string> &lines = utils::split(mapstring, '\n', 0);
|
||||
std::vector<std::string>::const_iterator line = lines.begin();
|
||||
//if there is an empty map leave directly
|
||||
if(mapstring.empty()) return;
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator map = mapstring.begin();
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator start = mapstring.begin();
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> rule;
|
||||
|
||||
//Strips trailing empty lines
|
||||
while (line != lines.end() && std::find_if(line->begin(), line->end(), utils::notspace) == line->end()) {
|
||||
line++;
|
||||
// eat leading blank lines
|
||||
while(*map == terrain_translation::VOID_TERRAIN || *map == terrain_translation::EOL){
|
||||
// start keep trac of the last beginning of the line
|
||||
if(*map == terrain_translation::EOL){
|
||||
start = ++map;
|
||||
} else {
|
||||
++map;
|
||||
}
|
||||
// when at the end of the map we have empty map data leave
|
||||
if(map == mapstring.end()) return;
|
||||
}
|
||||
//Break if there only are blank lines
|
||||
if(line == lines.end())
|
||||
return;
|
||||
|
||||
//If the strings starts with a space, the first line is an odd line,
|
||||
//else it is an even one
|
||||
if((*line)[0] == ' ')
|
||||
lineno = 1;
|
||||
|
||||
for(; line != lines.end(); ++line) {
|
||||
//cuts each line into chunks of 4 characters, ignoring the 2
|
||||
//first ones if the line is odd
|
||||
|
||||
x = 0;
|
||||
std::string::size_type lpos = 0;
|
||||
if(lineno % 2) {
|
||||
lpos = 2;
|
||||
x = 1;
|
||||
|
||||
map = start;
|
||||
lineno = (*map == terrain_translation::VOID_TERRAIN)?1:0;
|
||||
x = lineno; //odd lines set the odd X (true???)
|
||||
// parse the map
|
||||
for(;map != mapstring.end();){
|
||||
// we're at the start of a line, if odd skip the first 2 items
|
||||
// but make sure we didn't get some half backed data
|
||||
if(lineno % 2 == 1) {//map += 2;
|
||||
++map;
|
||||
wassert(map != mapstring.end());
|
||||
++map;
|
||||
}
|
||||
|
||||
while(lpos < line->size()) {
|
||||
std::string types = line->substr(lpos, 4);
|
||||
utils::strip(types);
|
||||
|
||||
//If there are numbers in the types string, consider it
|
||||
//is an anchor
|
||||
if(types[0] == '.') {
|
||||
// Dots are simple placeholders, which do not
|
||||
// represent actual terrains.
|
||||
} else if(types.find_first_of("0123456789") != std::string::npos) {
|
||||
int anchor = atoi(types.c_str());
|
||||
anchors.insert(std::pair<int, gamemap::location>(anchor, gamemap::location(x, lineno / 2)));
|
||||
// we should try to get a maximum of 4 items but are not allowed
|
||||
// to get either an EOL or go beyond the vector
|
||||
rule.clear();
|
||||
i = 0;
|
||||
while(i < 4){
|
||||
if(map == mapstring.end()){
|
||||
i = 4;
|
||||
} else if(*map == terrain_translation::EOL ){
|
||||
i = 4;
|
||||
//note the map is increased later in case of
|
||||
//an EOL
|
||||
} else {
|
||||
const gamemap::location loc(x, lineno / 2);
|
||||
add_constraints(br.constraints, loc, types, global_images);
|
||||
rule.push_back(*map);
|
||||
++i;
|
||||
++map;
|
||||
}
|
||||
lpos += 4;
|
||||
x += 2;
|
||||
}
|
||||
lineno++;
|
||||
// we the rule evaluate
|
||||
// first try to get the rule as a number, do the comparsion later
|
||||
int anchor = terrain_translation().list_to_int(rule);
|
||||
if(rule.front() == (terrain_translation::DOT)) {
|
||||
// Dots are simple placeholders, which do not
|
||||
// represent actual terrains.
|
||||
} else if(anchor != -1) {
|
||||
anchors.insert(std::pair<int, gamemap::location>(anchor, gamemap::location(x, y)));
|
||||
} else {
|
||||
const gamemap::location loc(x, y);
|
||||
add_constraints(br.constraints, loc, rule, global_images);
|
||||
}
|
||||
|
||||
// if at the end break out of the loop
|
||||
if(map == mapstring.end()) break;
|
||||
|
||||
//set next line value
|
||||
x += 2;
|
||||
if(*map == terrain_translation::EOL){
|
||||
if(lineno % 2 == 1){
|
||||
//add the end of an odd line, go to new even line
|
||||
++y;
|
||||
x = 0;
|
||||
// go to the next position in the map
|
||||
++map;
|
||||
} else {
|
||||
x = 1;
|
||||
}
|
||||
|
||||
++lineno;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -686,7 +737,7 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
anchormap anchors;
|
||||
|
||||
// Parse the map= , if there is one (and fill the anchors list)
|
||||
parse_mapstring((**br)["map"], pbr, anchors, **br);
|
||||
parse_mapstring(terrain_translation().get_map((**br)["map"]), pbr, anchors, **br);
|
||||
|
||||
// Parses the terrain constraints (TCs)
|
||||
config::child_list tcs((*br)->get_children("tile"));
|
||||
|
@ -782,17 +833,17 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
|
||||
}
|
||||
|
||||
bool terrain_builder::terrain_matches(gamemap::TERRAIN letter, const std::string &terrains)
|
||||
bool terrain_builder::terrain_matches(terrain_translation::TERRAIN_NUMBER letter, const std::vector<terrain_translation::TERRAIN_NUMBER> &terrains)
|
||||
{
|
||||
bool negative = false;
|
||||
std::string::const_iterator itor;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor;
|
||||
|
||||
if(terrains.empty())
|
||||
return true;
|
||||
for(itor = terrains.begin(); itor != terrains.end(); ++itor) {
|
||||
if(*itor == '*')
|
||||
if(*itor == terrain_translation::STAR)
|
||||
return true;
|
||||
if(*itor == '!') {
|
||||
if(*itor == terrain_translation::NOT){
|
||||
negative = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -916,13 +967,13 @@ int terrain_builder::get_constraint_adjacents(const building_rule& rule, const g
|
|||
//this constraint may possibly match. INT_MAX means "I don't know / all of them".
|
||||
int terrain_builder::get_constraint_size(const building_rule& rule, const terrain_constraint& constraint, bool& border)
|
||||
{
|
||||
const std::string &types = constraint.terrain_types;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& types = constraint.terrain_types;
|
||||
|
||||
if(types.empty())
|
||||
return INT_MAX;
|
||||
if(types[0] == '!')
|
||||
if(types.front() == terrain_translation::NOT)
|
||||
return INT_MAX;
|
||||
if(types.find('*') != std::string::npos)
|
||||
if(std::find(types.begin(), types.end(), terrain_translation::STAR) == types.end())
|
||||
return INT_MAX;
|
||||
|
||||
gamemap::location adj[6];
|
||||
|
@ -935,9 +986,12 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
//the "border" flag can be set.
|
||||
for(i = 0; i < 6; ++i) {
|
||||
if(rule.constraints.find(adj[i]) != rule.constraints.end()) {
|
||||
const std::string& atypes = rule.constraints.find(adj[i])->second.terrain_types;
|
||||
for(std::string::const_iterator itor = types.begin();
|
||||
itor != types.end(); ++itor) {
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& atypes =
|
||||
rule.constraints.find(adj[i])->second.terrain_types;
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor =
|
||||
types.begin();
|
||||
for(; itor != types.end(); ++itor) {
|
||||
if(!terrain_matches(*itor, atypes)) {
|
||||
border = true;
|
||||
break;
|
||||
|
@ -951,7 +1005,7 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
|
||||
int constraint_size = 0;
|
||||
|
||||
for(std::string::const_iterator itor = types.begin();
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor = types.begin();
|
||||
itor != types.end(); ++itor) {
|
||||
if(border) {
|
||||
constraint_size += terrain_by_type_border_[*itor].size();
|
||||
|
@ -971,7 +1025,7 @@ void terrain_builder::build_terrains()
|
|||
for(int x = -1; x <= map_.x(); ++x) {
|
||||
for(int y = -1; y <= map_.y(); ++y) {
|
||||
const gamemap::location loc(x,y);
|
||||
const gamemap::TERRAIN t = map_.get_terrain(loc);
|
||||
const terrain_translation::TERRAIN_NUMBER t = map_.get_terrain(loc);
|
||||
|
||||
terrain_by_type_[t].push_back(loc);
|
||||
|
||||
|
@ -1033,7 +1087,7 @@ void terrain_builder::build_terrains()
|
|||
}
|
||||
}
|
||||
|
||||
util::array<std::string,7> adjacent_types;
|
||||
util::array<std::vector<terrain_translation::TERRAIN_NUMBER>,7> adjacent_types;
|
||||
|
||||
if(biggest_constraint_adjacent > 0) {
|
||||
gamemap::location loc[7];
|
||||
|
@ -1044,17 +1098,21 @@ void terrain_builder::build_terrains()
|
|||
if(cons != rule->second.constraints.end()) {
|
||||
adjacent_types[i] = cons->second.terrain_types;
|
||||
} else {
|
||||
adjacent_types[i] = "";
|
||||
//FIXME MdW the previous code set the value to an empty
|
||||
//string, not sure whether this part is a valid code part
|
||||
//so assert for now
|
||||
// wassert(false);
|
||||
adjacent_types[i] = std::vector<terrain_translation::TERRAIN_NUMBER>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(smallest_constraint_size != INT_MAX) {
|
||||
const std::string &types = smallest_constraint->second.terrain_types;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> &types = smallest_constraint->second.terrain_types;
|
||||
const gamemap::location loc = smallest_constraint->second.loc;
|
||||
const gamemap::location aloc = constraint_most_adjacents->second.loc;
|
||||
|
||||
for(std::string::const_iterator c = types.begin(); c != types.end(); ++c) {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator c = types.begin(); c != types.end(); ++c) {
|
||||
const std::vector<gamemap::location>* locations;
|
||||
if(smallest_constraint_border) {
|
||||
locations = &terrain_by_type_border_[*c];
|
||||
|
@ -1070,7 +1128,7 @@ void terrain_builder::build_terrains()
|
|||
if(!tile_map_.on_map(pos))
|
||||
continue;
|
||||
|
||||
const gamemap::TERRAIN *adjacents = tile_map_[pos].adjacents;
|
||||
const terrain_translation::TERRAIN_NUMBER *adjacents = tile_map_[pos].adjacents;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 7; ++i) {
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
* to the parameters, or NULL if there is none.
|
||||
*/
|
||||
const imagelist *get_terrain_at(const gamemap::location &loc,
|
||||
const std::string &tod, ADJACENT_TERRAIN_TYPE terrain_type) const;
|
||||
const std::string &tod, ADJACENT_TERRAIN_TYPE const terrain_type) const;
|
||||
|
||||
/** Updates the animation at a given tile. returns true if something has
|
||||
* changed, and must be redrawn.
|
||||
|
@ -209,7 +209,7 @@ public:
|
|||
terrain_constraint(gamemap::location loc) : loc(loc) {};
|
||||
|
||||
gamemap::location loc;
|
||||
std::string terrain_types;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_types;
|
||||
std::vector<std::string> set_flag;
|
||||
std::vector<std::string> no_flag;
|
||||
std::vector<std::string> has_flag;
|
||||
|
@ -285,7 +285,7 @@ public:
|
|||
* The 6 adjacent terrains of this tile, and the terrain on
|
||||
* this tile.
|
||||
*/
|
||||
gamemap::TERRAIN adjacents[7];
|
||||
terrain_translation::TERRAIN_NUMBER adjacents[7];
|
||||
|
||||
};
|
||||
|
||||
|
@ -542,7 +542,7 @@ private:
|
|||
* describing rule-global images.
|
||||
*/
|
||||
void add_constraints(constraint_set& constraints,
|
||||
const gamemap::location &loc, const std::string& type,
|
||||
const gamemap::location &loc, const std::vector<terrain_translation::TERRAIN_NUMBER>& type,
|
||||
const config& global_images);
|
||||
|
||||
/**
|
||||
|
@ -567,14 +567,14 @@ private:
|
|||
* Parses a map string (the map= element of a [terrain_graphics] rule,
|
||||
* and adds constraints from this map to a building_rule.
|
||||
*
|
||||
* @param mapstring The map string to parse
|
||||
* @param mapstring The map vector to parse
|
||||
* @param br The building rule into which to add the extracted
|
||||
* constraints
|
||||
* @param anchors A map where to put "anchors" extracted from the map.
|
||||
* @param global_images A config object representing the images defined
|
||||
* as direct children of the [terrain_graphics] rule.
|
||||
*/
|
||||
void parse_mapstring(const std::string &mapstring, struct building_rule &br,
|
||||
void parse_mapstring(const std::vector<terrain_translation::TERRAIN_NUMBER> &mapstring, struct building_rule &br,
|
||||
anchormap& anchors, const config& global_images);
|
||||
|
||||
/**
|
||||
|
@ -608,15 +608,15 @@ private:
|
|||
/**
|
||||
* Checks whether a terrain letter matches a given list of terrain letters
|
||||
*
|
||||
* @param letter The letter to check
|
||||
* @param terrains The terrain list agains which to check the terrain
|
||||
* letter. May contain the metacharacter '*' meaning
|
||||
* "all terrains" or the character "!" meaning "all
|
||||
* @param letter The terrain to check
|
||||
* @param terrains The terrain list agains which to check the terrain.
|
||||
* May contain the metacharacter '*' STAR meaning
|
||||
* "all terrains" or the character '!' NOT meaning "all
|
||||
* terrains except those present in the list."
|
||||
*
|
||||
* @return returns true if "letter" matches the list, false if it does not.
|
||||
*/
|
||||
bool terrain_matches(gamemap::TERRAIN letter, const std::string &terrains);
|
||||
bool terrain_matches(terrain_translation::TERRAIN_NUMBER letter, const std::vector<terrain_translation::TERRAIN_NUMBER> &terrains);
|
||||
|
||||
/**
|
||||
* Checks whether a rule matches a given location in the map.
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
|
||||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
|
||||
cave_map_generator::cave_map_generator(const config* cfg) : wall_('W'), clear_('u'), village_('D'), castle_('o'),
|
||||
cave_map_generator::cave_map_generator(const config* cfg) : wall_(terrain_translation::CAVE_WALL),
|
||||
clear_(terrain_translation::CAVE),
|
||||
village_(terrain_translation::UNDERGROUND_VILLAGE),
|
||||
castle_(terrain_translation::DWARVEN_CASTLE),
|
||||
cfg_(cfg), width_(50), height_(50), village_density_(0),
|
||||
flipx_(false), flipy_(false)
|
||||
{
|
||||
|
@ -78,7 +81,7 @@ std::string cave_map_generator::create_map(const std::vector<std::string>& args)
|
|||
|
||||
config cave_map_generator::create_scenario(const std::vector<std::string>& /*args*/)
|
||||
{
|
||||
map_ = std::vector<std::vector<gamemap::TERRAIN> >(width_,std::vector<gamemap::TERRAIN>(height_,wall_));
|
||||
map_ = std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >(width_,std::vector<terrain_translation::TERRAIN_NUMBER>(height_,wall_));
|
||||
chambers_.clear();
|
||||
passages_.clear();
|
||||
|
||||
|
@ -279,14 +282,14 @@ void cave_map_generator::place_items(const chamber& c, config::all_children_iter
|
|||
|
||||
struct passage_path_calculator : cost_calculator
|
||||
{
|
||||
passage_path_calculator(const std::vector<std::vector<gamemap::TERRAIN> >& mapdata, gamemap::TERRAIN wall, double laziness, size_t windiness)
|
||||
passage_path_calculator(const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& mapdata, terrain_translation::TERRAIN_NUMBER wall, double laziness, size_t windiness)
|
||||
: map_(mapdata), wall_(wall), laziness_(laziness), windiness_(windiness)
|
||||
{}
|
||||
|
||||
virtual double cost(const gamemap::location& src,const gamemap::location& loc, const double so_far, const bool is_dest) const;
|
||||
private:
|
||||
const std::vector<std::vector<gamemap::TERRAIN> >& map_;
|
||||
gamemap::TERRAIN wall_;
|
||||
const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& map_;
|
||||
terrain_translation::TERRAIN_NUMBER wall_;
|
||||
double laziness_;
|
||||
size_t windiness_;
|
||||
};
|
||||
|
@ -341,14 +344,14 @@ bool cave_map_generator::on_board(const gamemap::location& loc) const
|
|||
return loc.x >= 0 && loc.y >= 0 && loc.x < (long)width_ && loc.y < (long)height_;
|
||||
}
|
||||
|
||||
void cave_map_generator::set_terrain(gamemap::location loc, gamemap::TERRAIN t)
|
||||
void cave_map_generator::set_terrain(gamemap::location loc, terrain_translation::TERRAIN_NUMBER t)
|
||||
{
|
||||
if(on_board(loc)) {
|
||||
if(t == clear_ && (rand()%1000) < (long)village_density_) {
|
||||
t = village_;
|
||||
}
|
||||
|
||||
gamemap::TERRAIN& c = map_[loc.x][loc.y];
|
||||
terrain_translation::TERRAIN_NUMBER& c = map_[loc.x][loc.y];
|
||||
if(c == clear_ || c == wall_ || c == village_) {
|
||||
c = t;
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@ private:
|
|||
void place_passage(const passage& p);
|
||||
|
||||
bool on_board(const gamemap::location& loc) const;
|
||||
void set_terrain(gamemap::location loc, gamemap::TERRAIN t);
|
||||
void set_terrain(gamemap::location loc, terrain_translation::TERRAIN_NUMBER t);
|
||||
void place_castle(const std::string& side, gamemap::location loc);
|
||||
|
||||
gamemap::TERRAIN wall_, clear_, village_, castle_;
|
||||
std::vector<std::vector<gamemap::TERRAIN> > map_;
|
||||
terrain_translation::TERRAIN_NUMBER wall_, clear_, village_, castle_;
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > map_;
|
||||
|
||||
std::map<std::string,size_t> chamber_ids_;
|
||||
std::vector<chamber> chambers_;
|
||||
|
|
|
@ -303,9 +303,17 @@ private:
|
|||
const std::vector<save_info>* info_;
|
||||
const std::vector<config*>* summaries_;
|
||||
int index_;
|
||||
std::map<std::string,surface> map_cache_;
|
||||
// std::map<std::string,surface> map_cache_;
|
||||
std::map<std::vector<terrain_translation::TERRAIN_NUMBER>,surface> map_cache_;
|
||||
// bool vector<terrain_translation::TERRAIN_NUMBER>::operator==(const vector<terrain_translation::TERRAIN_NUMBER>& terrain) const;
|
||||
// bool save_preview_pane::operator==(const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain) const;
|
||||
};
|
||||
|
||||
/*
|
||||
bool save_preview_pane::operator==(const std::vector<terrain_translation::TERRAIN_NUMBER>& lvalue, const std::vector<terrain_translation::TERRAIN_NUMBER>& rvalue) const
|
||||
{
|
||||
return lvalue == rvalue;
|
||||
}
|
||||
*/
|
||||
void save_preview_pane::draw_contents()
|
||||
{
|
||||
if (size_t(index_) >= summaries_->size() || info_->size() != summaries_->size()) {
|
||||
|
@ -350,13 +358,12 @@ void save_preview_pane::draw_contents()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
std::string map_data = summary["map_data"];
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> map_data = terrain_translation().get_map(summary["map_data"]);
|
||||
if(map_data.empty()) {
|
||||
const config* const scenario = game_config_->find_child(summary["campaign_type"],"id",summary["scenario"]);
|
||||
if(scenario != NULL && scenario->find_child("side","shroud","yes") == NULL) {
|
||||
map_data = (*scenario)["map_data"];
|
||||
if(map_data.empty() && (*scenario)["map"].empty() == false) {
|
||||
map_data = terrain_translation().get_map((*scenario)["map_data"]);
|
||||
if(map_data.empty() && (*scenario)["map"].empty() == false) {
|
||||
try {
|
||||
map_data = read_map((*scenario)["map"]);
|
||||
} catch(io_exception& e) {
|
||||
|
@ -364,12 +371,14 @@ void save_preview_pane::draw_contents()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
surface map_surf(NULL);
|
||||
|
||||
if(map_data.empty() == false) {
|
||||
const std::map<std::string,surface>::const_iterator itor = map_cache_.find(map_data);
|
||||
// const std::map<std::string,surface>::const_iterator itor = map_cache_.find(map_data);
|
||||
const std::map<std::vector<terrain_translation::TERRAIN_NUMBER>,surface>::const_iterator itor = map_cache_.find(map_data);
|
||||
// const std::map<std::vector<terrain_translation::TERRAIN_NUMBER>,surface>::const_iterator itor = std::map::find(std::vector<terrain_translation::TERRAIN_NUMBER>, map_data);
|
||||
if(itor != map_cache_.end()) {
|
||||
map_surf = itor->second;
|
||||
} else if(map_ != NULL) {
|
||||
|
@ -383,7 +392,8 @@ void save_preview_pane::draw_contents()
|
|||
|
||||
map_surf = image::getMinimap(minimap_size, minimap_size, *map_);
|
||||
if(map_surf != NULL) {
|
||||
map_cache_.insert(std::pair<std::string,surface>(map_data,surface(map_surf)));
|
||||
// map_cache_.insert(std::pair<std::string,surface>(map_data,surface(map_surf)));
|
||||
map_cache_.insert(std::pair<std::vector<terrain_translation::TERRAIN_NUMBER>,surface>(map_data,surface(map_surf)));
|
||||
}
|
||||
} catch(gamemap::incorrect_format_exception&) {
|
||||
}
|
||||
|
@ -540,7 +550,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
|
|||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(0).set_id_sort(1);
|
||||
|
||||
gamemap map_obj(game_config,"");
|
||||
gamemap map_obj(game_config, std::vector<terrain_translation::TERRAIN_NUMBER>());
|
||||
|
||||
std::vector<gui::preview_pane*> preview_panes;
|
||||
save_preview_pane save_preview(disp.video(),game_config,&map_obj,data,games,summaries);
|
||||
|
|
|
@ -1369,7 +1369,7 @@ void display::draw_tile(const gamemap::location &loc, const SDL_Rect &clip_rect)
|
|||
surface const dst(screen_.getSurface());
|
||||
|
||||
const bool is_shrouded = shrouded(loc.x, loc.y);
|
||||
gamemap::TERRAIN terrain = gamemap::VOID_TERRAIN;
|
||||
terrain_translation::TERRAIN_NUMBER terrain = terrain_translation::VOID_TERRAIN;
|
||||
|
||||
if(!is_shrouded) {
|
||||
terrain = map_.get_terrain(loc);
|
||||
|
@ -1687,13 +1687,13 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
gamemap::location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
int tiles[6];
|
||||
static const int terrain_types[] = { gamemap::FOGGED, gamemap::VOID_TERRAIN, 0 };
|
||||
static const int terrain_types[] = { terrain_translation::FOGGED, terrain_translation::VOID_TERRAIN, 0 };
|
||||
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
if(shrouded(adjacent[i].x,adjacent[i].y)) {
|
||||
tiles[i] = gamemap::VOID_TERRAIN;
|
||||
tiles[i] = terrain_translation::VOID_TERRAIN;
|
||||
} else if(!fogged(loc.x,loc.y) && fogged(adjacent[i].x,adjacent[i].y)) {
|
||||
tiles[i] = gamemap::FOGGED;
|
||||
tiles[i] = terrain_translation::FOGGED;
|
||||
} else {
|
||||
tiles[i] = 0;
|
||||
}
|
||||
|
@ -1718,7 +1718,7 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
if(tiles[i] == *terrain) {
|
||||
std::ostringstream stream;
|
||||
std::string name;
|
||||
// if(*terrain == gamemap::VOID_TERRAIN)
|
||||
// if(*terrain == terrain_type::VOID_TERRAIN)
|
||||
// stream << "void";
|
||||
//else
|
||||
// stream << "fog";
|
||||
|
@ -1800,7 +1800,7 @@ std::vector<surface> display::get_terrain_images(int x, int y, image::TYPE image
|
|||
return res;
|
||||
}
|
||||
|
||||
surface display::get_flag(gamemap::TERRAIN terrain, int x, int y)
|
||||
surface display::get_flag(terrain_translation::TERRAIN_NUMBER terrain, int x, int y)
|
||||
{
|
||||
const bool village = map_.is_village(terrain);
|
||||
if(!village) {
|
||||
|
|
|
@ -277,8 +277,8 @@ public:
|
|||
void update_display();
|
||||
|
||||
//functions used in the editor.
|
||||
//void draw_terrain_palette(int x, int y, gamemap::TERRAIN selected);
|
||||
gamemap::TERRAIN get_terrain_on(int palx, int paly, int x, int y);
|
||||
//void draw_terrain_palette(int x, int y, terrain_type::TERRAIN selected);
|
||||
terrain_translation::TERRAIN_NUMBER get_terrain_on(int palx, int paly, int x, int y);
|
||||
|
||||
//set_team sets the team controlled by the player using the computer,
|
||||
//and it is this team whose data is displayed in the game status.
|
||||
|
@ -404,7 +404,7 @@ private:
|
|||
std::vector<std::string> get_fog_shroud_graphics(const gamemap::location& loc);
|
||||
|
||||
//this surface must be freed by the caller
|
||||
surface get_flag(gamemap::TERRAIN, int x, int y);
|
||||
surface get_flag(terrain_translation::TERRAIN_NUMBER, int x, int y);
|
||||
|
||||
//this surface must be freed by the caller
|
||||
surface get_minimap(int w, int h);
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
//FIXME MdW editor is broken and not builded, should be fixed
|
||||
|
||||
namespace {
|
||||
const int num_players = 9;
|
||||
// Milliseconds to sleep in every iteration of the main loop.
|
||||
|
|
|
@ -570,7 +570,7 @@ void write_file(const std::string& fname, const std::string& data)
|
|||
}
|
||||
|
||||
|
||||
std::string read_map(const std::string& name)
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> read_map(const std::string& name)
|
||||
{
|
||||
std::string res = read_file("data/maps/" + name);
|
||||
if(res == "") {
|
||||
|
@ -581,7 +581,7 @@ std::string read_map(const std::string& name)
|
|||
res = read_file(get_user_data_dir() + "/editor/maps/" + name);
|
||||
}
|
||||
|
||||
return res;
|
||||
return terrain_translation().get_map(res);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "terrain_translation.hpp"
|
||||
|
||||
//an exception object used when an IO error occurs
|
||||
struct io_exception : public std::exception {
|
||||
io_exception() {}
|
||||
|
@ -68,7 +70,7 @@ std::ostream *ostream_file(std::string const &fname);
|
|||
void write_file(const std::string& fname, const std::string& data);
|
||||
std::string read_stdin();
|
||||
|
||||
std::string read_map(const std::string& name);
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> read_map(const std::string& name);
|
||||
|
||||
//function which returns true iff the given file is a directory
|
||||
bool is_directory(const std::string& fname);
|
||||
|
|
|
@ -254,7 +254,10 @@ display& game_controller::disp()
|
|||
|
||||
static unit_map dummy_umap;
|
||||
static config dummy_cfg;
|
||||
static gamemap dummy_map(dummy_cfg, "1");
|
||||
static std::vector<terrain_translation::TERRAIN_NUMBER> dummy_terrain =
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>();
|
||||
|
||||
static gamemap dummy_map(dummy_cfg, dummy_terrain);
|
||||
static gamestatus dummy_status(dummy_cfg, 0);
|
||||
static std::vector<team> dummy_teams;
|
||||
disp_.assign(new display(dummy_umap, video_, dummy_map, dummy_status,
|
||||
|
@ -1817,7 +1820,8 @@ int play_game(int argc, char** argv)
|
|||
continue;
|
||||
} else if(res == gui::SHOW_HELP) {
|
||||
config dummy_help_cfg;
|
||||
gamemap dummy_help_map(dummy_help_cfg, "1");
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> dummy_terrain;
|
||||
gamemap dummy_help_map(dummy_help_cfg, dummy_terrain);
|
||||
help::help_manager help_manager(&game.game_config(), &game.units_data(), &dummy_help_map);
|
||||
help::show_help(game.disp());
|
||||
continue;
|
||||
|
|
|
@ -1122,16 +1122,22 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
//changing the terrain
|
||||
else if(cmd == "terrain") {
|
||||
const std::vector<gamemap::location> locs = multiple_locs(cfg);
|
||||
|
||||
|
||||
std::string terrain_type = cfg["letter"];
|
||||
wassert(state_of_game != NULL);
|
||||
terrain_type = utils::interpolate_variables_into_string(terrain_type, *state_of_game);
|
||||
|
||||
|
||||
//At this point terrain_type contains the letter as known in WML
|
||||
//convert to an internal number
|
||||
terrain_translation::TERRAIN_NUMBER terrain = terrain_translation().get_letter(terrain_type);
|
||||
|
||||
for(std::vector<gamemap::location>::const_iterator loc = locs.begin(); loc != locs.end(); ++loc) {
|
||||
preferences::encountered_terrains().insert(terrain_type);
|
||||
if(terrain_type.size() > 0) {
|
||||
preferences::encountered_terrains().insert(terrain);
|
||||
if(terrain_type.size() > 0) { //FIXME MdW we need a proper way to set and invalid terrain
|
||||
const bool old_village = game_map->is_village(*loc);
|
||||
const bool new_village = game_map->is_village(terrain_type[0]);
|
||||
//FIXME MdW cleanup
|
||||
// const bool new_village = game_map->is_village(terrain_type[0]);
|
||||
const bool new_village = game_map->is_village(terrain);
|
||||
|
||||
if(old_village && !new_village) {
|
||||
int owner = village_owner(*loc, *teams);
|
||||
|
@ -1140,7 +1146,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
}
|
||||
}
|
||||
|
||||
game_map->set_terrain(*loc,terrain_type[0]);
|
||||
game_map->set_terrain(*loc,terrain);
|
||||
}
|
||||
}
|
||||
rebuild_screen_ = true;
|
||||
|
@ -1151,9 +1157,12 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
gamemap::location loc = cfg_to_loc(cfg, 1, 1);
|
||||
|
||||
gamemap mask(*game_map);
|
||||
|
||||
//FIXME MdW cleanup
|
||||
// std::vector<terrain_translation::TERRAIN_NUMBER> map_data = translator.get_terrain_vector(cfg, std::string("mask"), true);
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> map_data = terrain_translation().get_map(cfg["mask"]);
|
||||
|
||||
try {
|
||||
mask.read(cfg["mask"]);
|
||||
mask.read(map_data);
|
||||
} catch(gamemap::incorrect_format_exception&) {
|
||||
ERR_NG << "terrain mask is in the incorrect format, and couldn't be applied\n";
|
||||
return rval;
|
||||
|
@ -1719,13 +1728,15 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
else if(cmd == "store_locations") {
|
||||
log_scope("store_locations");
|
||||
std::string variable = cfg["variable"];
|
||||
std::string terrain = cfg["terrain"];
|
||||
std::string wml_terrain = cfg["terrain"];
|
||||
std::string x = cfg["x"];
|
||||
std::string y = cfg["y"];
|
||||
std::string radius_str = cfg["radius"];
|
||||
wassert(state_of_game != NULL);
|
||||
variable = utils::interpolate_variables_into_string(variable, *state_of_game);
|
||||
terrain = utils::interpolate_variables_into_string(terrain, *state_of_game);
|
||||
wml_terrain = utils::interpolate_variables_into_string(wml_terrain, *state_of_game);
|
||||
//convertert the terrain to a internal vector
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain = terrain_translation().get_list(wml_terrain);
|
||||
x = utils::interpolate_variables_into_string(x, *state_of_game);
|
||||
y = utils::interpolate_variables_into_string(y, *state_of_game);
|
||||
radius_str = utils::interpolate_variables_into_string(radius_str, *state_of_game);
|
||||
|
@ -1745,7 +1756,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
size_t added = 0;
|
||||
for(std::set<gamemap::location>::const_iterator j = res.begin(); j != res.end() && added != MaxLoop; ++j) {
|
||||
if (terrain.empty() == false) {
|
||||
const gamemap::TERRAIN c = game_map->get_terrain(*j);
|
||||
const terrain_translation::TERRAIN_NUMBER c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
if(std::find(terrain.begin(), terrain.end(), c) == terrain.end())
|
||||
continue;
|
||||
}
|
||||
|
|
54
src/help.cpp
54
src/help.cpp
|
@ -1277,15 +1277,23 @@ public:
|
|||
push_header(first_row, _("Movement Cost"));
|
||||
|
||||
table.push_back(first_row);
|
||||
for (std::set<std::string>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin(),
|
||||
terrain_end = preferences::encountered_terrains().end();
|
||||
terrain_it != terrain_end; terrain_it++) {
|
||||
wassert(terrain_it->size() > 0);
|
||||
const gamemap::TERRAIN terrain = (*terrain_it)[0];
|
||||
if (terrain == gamemap::FOGGED || terrain == gamemap::VOID_TERRAIN)
|
||||
//FIXME MdW cleanup
|
||||
// for (std::set<std::string>::const_iterator terrain_it =
|
||||
// preferences::encountered_terrains().begin(),
|
||||
// terrain_end = preferences::encountered_terrains().end();
|
||||
// terrain_it != terrain_end; terrain_it++) {
|
||||
std::set<terrain_translation::TERRAIN_NUMBER>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin();
|
||||
|
||||
for (; terrain_it != preferences::encountered_terrains().end();
|
||||
terrain_it++) {
|
||||
// wassert(terrain_it->size() > 0);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = *terrain_it;
|
||||
if (terrain == terrain_translation::FOGGED || terrain == terrain_translation::VOID_TERRAIN)
|
||||
continue;
|
||||
const terrain_type& info = map->get_terrain_info(terrain);
|
||||
//FIXME MdW enable
|
||||
#if 0
|
||||
if (info.union_type().size() == 1 && info.union_type()[0] == info.letter() && info.is_nonnull()) {
|
||||
std::vector<item> row;
|
||||
const std::string& name = info.name();
|
||||
|
@ -1315,6 +1323,7 @@ public:
|
|||
|
||||
table.push_back(row);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
ss << generate_table(table);
|
||||
}
|
||||
|
@ -1385,15 +1394,18 @@ struct terrain_topic_generator: topic_generator
|
|||
virtual std::string operator()() const {
|
||||
std::stringstream ss;
|
||||
ss << "<img>src='terrain/" << type.symbol_image() << ".png'</img>\n\n";
|
||||
//FIXME MdW enable
|
||||
#if 0
|
||||
if (type.mvt_type().size() != 1 || type.mvt_type()[0] != type.letter()) {
|
||||
const std::string aliased_terrains = type.mvt_type();
|
||||
std::stringstream alias_ss;
|
||||
for (std::string::const_iterator it = aliased_terrains.begin();
|
||||
it != aliased_terrains.end(); it++) {
|
||||
const gamemap::TERRAIN t = *it;
|
||||
const terrain_translation::TERRAIN_NUMBER t = *it;
|
||||
const std::string &alias_name = map->get_terrain_info(t).name();
|
||||
alias_ss << "<ref>text='" << escape(alias_name) << "' dst='"
|
||||
<< escape(std::string("terrain_") + t) << "'</ref>";
|
||||
// << escape(std::string("terrain_") + t) << "'</ref>"; //FIXME MdW remove
|
||||
<< escape(std::string("terrain_")) << t << "'</ref>"; //FIXME cleanup: escape not reuqired
|
||||
if (it + 2 == aliased_terrains.end())
|
||||
alias_ss << " " << _("or") << " ";
|
||||
else if (it + 1 != aliased_terrains.end())
|
||||
|
@ -1414,10 +1426,11 @@ struct terrain_topic_generator: topic_generator
|
|||
std::stringstream alias_ss;
|
||||
for (std::string::const_iterator it = aliased_terrains.begin();
|
||||
it != aliased_terrains.end(); it++) {
|
||||
const gamemap::TERRAIN t = *it;
|
||||
const terrain_translation::TERRAIN_NUMBER t = *it;
|
||||
const std::string &alias_name = map->get_terrain_info(t).name();
|
||||
alias_ss << "<ref>text='" << escape(alias_name) << "' dst='"
|
||||
<< escape(std::string("terrain_") + t) << "'</ref>";
|
||||
// << escape(std::string("terrain_") + t) << "'</ref>"; //FIXME MdW remove
|
||||
<< escape(std::string("terrain_")) << t << "'</ref>"; //FIXME cleanup: escape not reuqired
|
||||
if (it + 2 == aliased_terrains.end())
|
||||
alias_ss << " " << _("or") << " ";
|
||||
else if (it + 1 != aliased_terrains.end())
|
||||
|
@ -1433,6 +1446,7 @@ struct terrain_topic_generator: topic_generator
|
|||
ss << " " << _("The terrain with the worst modifier is chosen automatically.");
|
||||
ss << "\n\n";
|
||||
}
|
||||
#endif
|
||||
if (type.is_keep())
|
||||
ss << _("This terrain acts as a keep, i.e., you can recruit units when a leader is in a location with this terrain.") << "\n\n";
|
||||
if (type.is_castle())
|
||||
|
@ -1446,30 +1460,34 @@ struct terrain_topic_generator: topic_generator
|
|||
std::vector<topic> generate_terrains_topics(const bool sort_generated)
|
||||
{
|
||||
std::vector<topic> res;
|
||||
std::vector<gamemap::TERRAIN> show_info_about;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> show_info_about;
|
||||
if (game_config::debug) {
|
||||
show_info_about = map->get_terrain_list();
|
||||
}
|
||||
else {
|
||||
#if 0 //FIXME MdW enable
|
||||
for (std::set<std::string>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin();
|
||||
terrain_it != preferences::encountered_terrains().end();
|
||||
terrain_it++) {
|
||||
wassert(terrain_it->size() > 0);
|
||||
const gamemap::TERRAIN terrain = (*terrain_it)[0];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = (*terrain_it)[0];
|
||||
show_info_about.push_back(terrain);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// FIXME MdW typecast to char
|
||||
show_info_about.erase(std::remove(show_info_about.begin(), show_info_about.end(),
|
||||
(char)gamemap::VOID_TERRAIN), show_info_about.end());
|
||||
(char)terrain_translation::VOID_TERRAIN), show_info_about.end());//FIXME MdW typecast
|
||||
show_info_about.erase(std::remove(show_info_about.begin(), show_info_about.end(),
|
||||
(char)gamemap::FOGGED), show_info_about.end());
|
||||
for (std::vector<gamemap::TERRAIN>::const_iterator terrain_it = show_info_about.begin();
|
||||
(char)terrain_translation::FOGGED), show_info_about.end());//FIXME MdW typecast
|
||||
for (std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator terrain_it = show_info_about.begin();
|
||||
terrain_it != show_info_about.end(); terrain_it++) {
|
||||
const terrain_type& info = map->get_terrain_info(*terrain_it);
|
||||
const std::string &name = info.name();
|
||||
topic t(name, std::string("terrain_") + *terrain_it, new terrain_topic_generator(info));
|
||||
res.push_back(t);
|
||||
//FIXME MdW make it work again
|
||||
// topic t(name, std::string("terrain_") + *terrain_it, new terrain_topic_generator(info));
|
||||
// res.push_back(t);
|
||||
}
|
||||
if (sort_generated)
|
||||
std::sort(res.begin(), res.end(), title_less());
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace image {
|
|||
|
||||
typedef std::vector<cache_item<surface> > image_cache;
|
||||
typedef std::vector<cache_item<locator> > locator_cache;
|
||||
typedef std::map<gamemap::TERRAIN, surface> mini_terrain_cache_map;
|
||||
typedef std::map<terrain_translation::TERRAIN_NUMBER, surface> mini_terrain_cache_map;
|
||||
extern mini_terrain_cache_map mini_terrain_cache;
|
||||
|
||||
void flush_cache();
|
||||
|
|
214
src/map.cpp
214
src/map.cpp
|
@ -33,13 +33,6 @@
|
|||
#define ERR_CF LOG_STREAM(err, config)
|
||||
#define LOG_G LOG_STREAM(info, general)
|
||||
|
||||
const gamemap::TERRAIN gamemap::VOID_TERRAIN = ' ';
|
||||
const gamemap::TERRAIN gamemap::FOGGED = '~';
|
||||
const gamemap::TERRAIN gamemap::KEEP = 'K';
|
||||
const gamemap::TERRAIN gamemap::CASTLE = 'C';
|
||||
const gamemap::TERRAIN gamemap::VILLAGE = 't';
|
||||
const gamemap::TERRAIN gamemap::FOREST = 'f';
|
||||
|
||||
std::ostream &operator<<(std::ostream &s, gamemap::location const &l) {
|
||||
s << (l.x + 1) << ',' << (l.y + 1);
|
||||
return s;
|
||||
|
@ -47,9 +40,10 @@ std::ostream &operator<<(std::ostream &s, gamemap::location const &l) {
|
|||
|
||||
gamemap::location gamemap::location::null_location;
|
||||
|
||||
const std::string& gamemap::underlying_mvt_terrain(TERRAIN terrain) const
|
||||
#if 0
|
||||
const std::string& gamemap::underlying_mvt_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<TERRAIN,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::string res;
|
||||
res.resize(1);
|
||||
|
@ -59,9 +53,10 @@ const std::string& gamemap::underlying_mvt_terrain(TERRAIN terrain) const
|
|||
return i->second.mvt_type();
|
||||
}
|
||||
}
|
||||
const std::string& gamemap::underlying_def_terrain(TERRAIN terrain) const
|
||||
|
||||
const std::string& gamemap::underlying_def_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<TERRAIN,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::string res;
|
||||
res.resize(1);
|
||||
|
@ -69,11 +64,11 @@ const std::string& gamemap::underlying_def_terrain(TERRAIN terrain) const
|
|||
return res;
|
||||
} else {
|
||||
return i->second.def_type();
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::string& gamemap::underlying_union_terrain(TERRAIN terrain) const
|
||||
const std::string& gamemap::underlying_union_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<TERRAIN,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::string res;
|
||||
res.resize(1);
|
||||
|
@ -83,23 +78,66 @@ const std::string& gamemap::underlying_union_terrain(TERRAIN terrain) const
|
|||
return i->second.union_type();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_mvt_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::vector<terrain_translation::TERRAIN_NUMBER> res;
|
||||
res.push_back(terrain);
|
||||
return res;
|
||||
} else {
|
||||
static std::vector<terrain_translation::TERRAIN_NUMBER> res = i->second.mvt_type2();
|
||||
if(res.empty()){
|
||||
LOG_G << "dummy\n";
|
||||
}
|
||||
return res;
|
||||
//FIXME MdW debug hack use the one below once the error is found
|
||||
return i->second.mvt_type2();
|
||||
}
|
||||
}
|
||||
|
||||
bool gamemap::is_village(gamemap::TERRAIN terrain) const
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_def_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::vector<terrain_translation::TERRAIN_NUMBER> res;
|
||||
res.push_back(terrain);
|
||||
return res;
|
||||
} else {
|
||||
return i->second.def_type2();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_union_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static std::vector<terrain_translation::TERRAIN_NUMBER> res;
|
||||
res.push_back(terrain);
|
||||
return res;
|
||||
} else {
|
||||
return i->second.union_type2();
|
||||
}
|
||||
}
|
||||
|
||||
bool gamemap::is_village(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_village();
|
||||
}
|
||||
|
||||
int gamemap::gives_healing(gamemap::TERRAIN terrain) const
|
||||
int gamemap::gives_healing(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).gives_healing();
|
||||
}
|
||||
|
||||
bool gamemap::is_castle(gamemap::TERRAIN terrain) const
|
||||
bool gamemap::is_castle(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_castle();
|
||||
}
|
||||
|
||||
bool gamemap::is_keep(gamemap::TERRAIN terrain) const
|
||||
bool gamemap::is_keep(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_keep();
|
||||
}
|
||||
|
@ -140,7 +178,7 @@ void gamemap::write_terrain(const gamemap::location &loc, config& cfg) const
|
|||
|
||||
gamemap::location::DIRECTION gamemap::location::parse_direction(const std::string& str)
|
||||
{
|
||||
if(str == "n") {
|
||||
if(str == "n") { //FIXME MdW case??
|
||||
return NORTH;
|
||||
} else if(str == "ne") {
|
||||
return NORTH_EAST;
|
||||
|
@ -302,15 +340,16 @@ gamemap::location::DIRECTION gamemap::location::get_opposite_dir(gamemap::locati
|
|||
}
|
||||
}
|
||||
|
||||
gamemap::gamemap(const config& cfg, const std::string& data) : tiles_(1)
|
||||
gamemap::gamemap(const config& cfg, const std::vector<terrain_translation::TERRAIN_NUMBER>& data) : tiles_(1)
|
||||
{
|
||||
LOG_G << "loading map: '" << data << "'\n";
|
||||
const config::child_list& terrains = cfg.get_children("terrain");
|
||||
LOG_G << "loading map: '" << terrain_translation().set_map(data) << "'\n";
|
||||
const config::child_list& terrains = cfg.get_children("terrain");
|
||||
create_terrain_maps(terrains,terrainList_,letterToTerrain_,terrain_);
|
||||
|
||||
read(data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void gamemap::read(const std::string& data)
|
||||
{
|
||||
tiles_.clear();
|
||||
|
@ -326,7 +365,7 @@ void gamemap::read(const std::string& data)
|
|||
size_t x = 0, y = 0;
|
||||
for(; i != data.end(); ++i) {
|
||||
char c = *i;
|
||||
if(c == '\r') {
|
||||
if(c == '\r') {
|
||||
continue;
|
||||
} if(c == '\n') {
|
||||
x = 0;
|
||||
|
@ -335,7 +374,7 @@ void gamemap::read(const std::string& data)
|
|||
if(letterToTerrain_.count(c) == 0) {
|
||||
if(isdigit(*i)) {
|
||||
startingPositions_[c - '0'] = location(x,y);
|
||||
c = KEEP;
|
||||
c = terrain_translation::KEEP;
|
||||
} else {
|
||||
ERR_CF << "Illegal character in map: (" << int(c) << ") '" << c << "'\n";
|
||||
throw incorrect_format_exception("Illegal character found in map. The scenario cannot be loaded.");
|
||||
|
@ -367,6 +406,72 @@ void gamemap::read(const std::string& data)
|
|||
|
||||
LOG_G << "loaded map: " << this->x() << ',' << ysize << '\n';
|
||||
}
|
||||
#endif
|
||||
//FIXME MdW the entire routine should be cleaned up
|
||||
void gamemap::read(const std::vector<terrain_translation::TERRAIN_NUMBER>& data)
|
||||
{
|
||||
tiles_.clear();
|
||||
villages_.clear();
|
||||
std::fill(startingPositions_,startingPositions_+sizeof(startingPositions_)/sizeof(*startingPositions_),location());
|
||||
|
||||
//ignore leading newlines
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = data.begin();
|
||||
while(i != data.end() && *i == terrain_translation::EOL) {
|
||||
++i;
|
||||
}
|
||||
|
||||
size_t x = 0, y = 0;
|
||||
for(; i != data.end(); ++i) {
|
||||
terrain_translation::TERRAIN_NUMBER c = *i;
|
||||
if(c == terrain_translation::EOL) {
|
||||
x = 0;
|
||||
++y;
|
||||
} else {
|
||||
if(letterToTerrain_.count(c) == 0) {
|
||||
int start_location = terrain_translation().letter_to_start_location(c);
|
||||
if(start_location != -1) {
|
||||
startingPositions_[start_location] = location(x,y);
|
||||
c = terrain_translation::KEEP;
|
||||
} else {
|
||||
ERR_CF << "Illegal character in map: (" << terrain_translation().set_letter(c) << ") '" << c << "'\n";
|
||||
throw incorrect_format_exception("Illegal character found in map. The scenario cannot be loaded.");
|
||||
}
|
||||
}
|
||||
/* if(letterToTerrain_.count(c) == 0) {
|
||||
if(isdigit(*i)) {
|
||||
startingPositions_[c - '0'] = location(x,y);
|
||||
c = terrain_translation::KEEP;
|
||||
} else {
|
||||
ERR_CF << "Illegal character in map: (" << int(c) << ") '" << c << "'\n";
|
||||
throw incorrect_format_exception("Illegal character found in map. The scenario cannot be loaded.");
|
||||
}
|
||||
} */
|
||||
|
||||
if(is_village(c)) {
|
||||
villages_.push_back(location(int(x),int(y)));
|
||||
}
|
||||
|
||||
if(x >= tiles_.size()) {
|
||||
tiles_.resize(x+1);
|
||||
}
|
||||
|
||||
tiles_[x].push_back(c);
|
||||
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ysize = this->y();
|
||||
for(size_t n = 0; n != tiles_.size(); ++n) { // tiles_.size() is not constant
|
||||
if (tiles_[n].size() != ysize) {
|
||||
ERR_CF << "Map is not rectangular!\n";
|
||||
tiles_.erase(tiles_.begin()+n);
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_G << "loaded map: " << this->x() << ',' << ysize << '\n';
|
||||
}
|
||||
|
||||
std::string gamemap::write() const
|
||||
{
|
||||
|
@ -394,6 +499,7 @@ std::string gamemap::write() const
|
|||
|
||||
void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos, const int ypos)
|
||||
{
|
||||
#if 0 //FIXME MdW remove enable
|
||||
const config::child_list& rules = rules_cfg.get_children("rule");
|
||||
|
||||
const int xstart = maximum<int>(0, -xpos);
|
||||
|
@ -408,10 +514,10 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
if (y2 < 0 || y2 >= y()) {
|
||||
continue;
|
||||
}
|
||||
const TERRAIN t = m[x1][y1];
|
||||
const TERRAIN current = (*this)[x2][y2];
|
||||
const terrain_translation::TERRAIN_NUMBER t = m[x1][y1];
|
||||
const terrain_translation::TERRAIN_NUMBER current = (*this)[x2][y2];
|
||||
|
||||
if(t == FOGGED || t == VOID_TERRAIN) {
|
||||
if(t == terrain_translation::FOGGED || t == terrain_translation::VOID_TERRAIN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -447,8 +553,10 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
|
||||
if(rule != rules.end()) {
|
||||
const config& cfg = **rule;
|
||||
const std::string& terrain = cfg["terrain"];
|
||||
if(terrain != "") {
|
||||
//FIXME MdW cleanup
|
||||
// const std::string& terrain = cfg["terrain"];
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain = terrain_translation().get_list(cfg["terrain"]);
|
||||
if(! terrain.empty()) {
|
||||
set_terrain(location(x2,y2),terrain[0]);
|
||||
} else if(cfg["use_old"] != "yes") {
|
||||
set_terrain(location(x2,y2),t);
|
||||
|
@ -464,28 +572,28 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
startingPositions_[pos - m.startingPositions_] = *pos;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int gamemap::x() const { return tiles_.size(); }
|
||||
int gamemap::y() const { return tiles_.empty() ? 0 : tiles_.front().size(); }
|
||||
|
||||
const std::vector<gamemap::TERRAIN>& gamemap::operator[](int index) const
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::operator[](int index) const
|
||||
{
|
||||
return tiles_[index];
|
||||
}
|
||||
|
||||
gamemap::TERRAIN gamemap::get_terrain(const gamemap::location& loc) const
|
||||
terrain_translation::TERRAIN_NUMBER gamemap::get_terrain(const gamemap::location& loc) const
|
||||
{
|
||||
if(on_board(loc))
|
||||
return tiles_[loc.x][loc.y];
|
||||
|
||||
const std::map<location,TERRAIN>::const_iterator itor = borderCache_.find(loc);
|
||||
const std::map<location,terrain_translation::TERRAIN_NUMBER>::const_iterator itor = borderCache_.find(loc);
|
||||
if(itor != borderCache_.end())
|
||||
return itor->second;
|
||||
|
||||
//if not on the board, decide based on what surrounding terrain is
|
||||
TERRAIN items[6];
|
||||
terrain_translation::TERRAIN_NUMBER items[6];
|
||||
int nitems = 0;
|
||||
|
||||
location adj[6];
|
||||
|
@ -499,7 +607,7 @@ gamemap::TERRAIN gamemap::get_terrain(const gamemap::location& loc) const
|
|||
|
||||
//count all the terrain types found, and see which one
|
||||
//is the most common, and use it.
|
||||
TERRAIN used_terrain = 0;
|
||||
terrain_translation::TERRAIN_NUMBER used_terrain = 0;
|
||||
int terrain_count = 0;
|
||||
for(int i = 0; i != nitems; ++i) {
|
||||
if(items[i] != used_terrain && !is_village(items[i]) && !is_keep(items[i])) {
|
||||
|
@ -511,7 +619,7 @@ gamemap::TERRAIN gamemap::get_terrain(const gamemap::location& loc) const
|
|||
}
|
||||
}
|
||||
|
||||
borderCache_.insert(std::pair<location,TERRAIN>(loc,used_terrain));
|
||||
borderCache_.insert(std::pair<location,terrain_translation::TERRAIN_NUMBER>(loc,used_terrain));
|
||||
|
||||
return used_terrain;
|
||||
}
|
||||
|
@ -556,10 +664,10 @@ void gamemap::set_starting_position(int side, const gamemap::location& loc)
|
|||
}
|
||||
}
|
||||
|
||||
const terrain_type& gamemap::get_terrain_info(TERRAIN terrain) const
|
||||
const terrain_type& gamemap::get_terrain_info(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
static const terrain_type default_terrain;
|
||||
const std::map<TERRAIN,terrain_type>::const_iterator i =
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
if(i != letterToTerrain_.end())
|
||||
return i->second;
|
||||
|
@ -573,21 +681,24 @@ const terrain_type& gamemap::get_terrain_info(const gamemap::location &loc) cons
|
|||
}
|
||||
bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config& cfg, const gamestatus& game_status, const unit_map& units,bool flat_tod) const
|
||||
{
|
||||
const std::string& terrain = cfg["terrain"];
|
||||
#if 1 //FIXME MdW remove the if
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain = terrain_translation().get_list(cfg["terrain"]);
|
||||
const std::string& tod_type = cfg["time_of_day"];
|
||||
const std::string& tod_id = cfg["time_of_day_id"];
|
||||
// Any of these may be a CSV
|
||||
std::string terrain_letter;
|
||||
terrain_letter += get_terrain_info(loc).letter();
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_letter;
|
||||
terrain_letter.push_back(get_terrain_info(loc).number());
|
||||
if(!terrain.empty()) {
|
||||
if(terrain != terrain_letter) {
|
||||
if(std::find(terrain.begin(),terrain.end(),',') != terrain.end() &&
|
||||
if(std::find(terrain.begin(),terrain.end(),terrain_translation::COMMA) != terrain.end() &&
|
||||
std::search(terrain.begin(),terrain.end(),
|
||||
terrain_letter.begin(),terrain_letter.end()) != terrain.end()) {
|
||||
const std::vector<std::string>& vals = utils::split(terrain);
|
||||
if(std::find(vals.begin(),vals.end(),terrain_letter) == vals.end()) {
|
||||
return false;
|
||||
}
|
||||
//FIXME MdW enable
|
||||
// const std::vector<std::string>& vals = utils::split(terrain);
|
||||
// if(std::find(vals.begin(),vals.end(),terrain_letter) == vals.end()) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -633,17 +744,16 @@ bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config&
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<gamemap::TERRAIN>& gamemap::get_terrain_list() const
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::get_terrain_list() const
|
||||
{
|
||||
return terrainList_;
|
||||
}
|
||||
|
||||
void gamemap::set_terrain(const gamemap::location& loc, gamemap::TERRAIN ter)
|
||||
void gamemap::set_terrain(const gamemap::location& loc, terrain_translation::TERRAIN_NUMBER ter)
|
||||
{
|
||||
if(!on_board(loc))
|
||||
return;
|
||||
|
@ -693,7 +803,7 @@ std::vector<gamemap::location> parse_location_range(const std::string& x, const
|
|||
return res;
|
||||
}
|
||||
|
||||
const std::map<gamemap::TERRAIN,size_t>& gamemap::get_weighted_terrain_frequencies() const
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,size_t>& gamemap::get_weighted_terrain_frequencies() const
|
||||
{
|
||||
if(terrainFrequencyCache_.empty() == false) {
|
||||
return terrainFrequencyCache_;
|
||||
|
|
79
src/map.hpp
79
src/map.hpp
|
@ -33,27 +33,19 @@ class gamemap
|
|||
{
|
||||
public:
|
||||
|
||||
typedef char TERRAIN;
|
||||
enum { NB_TERRAIN = 256, ADD_INDEX_TERRAIN = 128 };
|
||||
|
||||
//some types of terrain which must be known, and can't just be loaded
|
||||
//in dynamically because they're special. It's asserted that there will
|
||||
//be corresponding entries for these types of terrain in the terrain
|
||||
//configuration file.
|
||||
static const TERRAIN VOID_TERRAIN;
|
||||
static const TERRAIN FOGGED;
|
||||
static const TERRAIN KEEP;
|
||||
static const TERRAIN CASTLE;
|
||||
static const TERRAIN VILLAGE;
|
||||
static const TERRAIN FOREST;
|
||||
|
||||
//the name of the terrain is the terrain itself, the underlying terrain
|
||||
//is the name of the terrain for game-logic purposes. I.e. if the terrain
|
||||
//is simply an alias, the underlying terrain name is the name of the
|
||||
//terrain that it's aliased to
|
||||
const std::string& underlying_mvt_terrain(TERRAIN terrain) const;
|
||||
const std::string& underlying_def_terrain(TERRAIN terrain) const;
|
||||
const std::string& underlying_union_terrain(TERRAIN terrain) const;
|
||||
#if 0
|
||||
const std::string& underlying_mvt_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::string& underlying_def_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::string& underlying_union_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
#endif
|
||||
//FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_mvt_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_def_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_union_terrain2(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
|
||||
//exception thrown if the map file is not in the correct format.
|
||||
struct incorrect_format_exception {
|
||||
|
@ -106,18 +98,26 @@ public:
|
|||
private:
|
||||
void init(const std::string &x, const std::string &y);
|
||||
};
|
||||
|
||||
#if 0
|
||||
const std::string& underlying_mvt_terrain(const location& loc) const
|
||||
{ return underlying_mvt_terrain(get_terrain(loc)); }
|
||||
const std::string& underlying_def_terrain(const location& loc) const
|
||||
{ return underlying_def_terrain(get_terrain(loc)); }
|
||||
const std::string& underlying_union_terrain(const location& loc) const
|
||||
{ return underlying_union_terrain(get_terrain(loc)); }
|
||||
#endif
|
||||
//FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_mvt_terrain2(const location& loc) const
|
||||
{ return underlying_mvt_terrain2(get_terrain(loc)); }
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_def_terrain2(const location& loc) const
|
||||
{ return underlying_def_terrain2(get_terrain(loc)); }
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_union_terrain2(const location& loc) const
|
||||
{ return underlying_union_terrain2(get_terrain(loc)); }
|
||||
|
||||
bool is_village(TERRAIN terrain) const;
|
||||
int gives_healing(TERRAIN terrain) const;
|
||||
bool is_castle(TERRAIN terrain) const;
|
||||
bool is_keep(TERRAIN terrain) const;
|
||||
bool is_village(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
int gives_healing(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
bool is_castle(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
bool is_keep(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
|
||||
bool is_village(const location& loc) const;
|
||||
int gives_healing(const location& loc) const;
|
||||
|
@ -131,10 +131,13 @@ public:
|
|||
//data should be a series of lines, with each character representing
|
||||
//one hex on the map. Starting locations are represented by numbers,
|
||||
//and will be of type keep.
|
||||
gamemap(const config& terrain_cfg, const std::string& data); //throw(incorrect_format_exception)
|
||||
void read(const std::string& data);
|
||||
// gamemap(const config& terrain_cfg, const std::string& data); //throw(incorrect_format_exception)
|
||||
gamemap(const config& terrain_cfg, const std::vector<terrain_translation::TERRAIN_NUMBER>& data); //throw(incorrect_format_exception)
|
||||
// void read(const std::string& data); //FIXME MdW cleanup
|
||||
void read(const std::vector<terrain_translation::TERRAIN_NUMBER>& data);
|
||||
|
||||
std::string write() const;
|
||||
// std::vector<terrain_translation::TERRAIN_NUMBER> 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);
|
||||
|
@ -144,12 +147,12 @@ public:
|
|||
int y() const;
|
||||
|
||||
//allows lookup of terrain at a particular location.
|
||||
const std::vector<TERRAIN>& operator[](int index) const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& operator[](int index) const;
|
||||
|
||||
//looks up terrain at a particular location. Hexes off the map
|
||||
//may be looked up, and their 'emulated' terrain will also be returned.
|
||||
//this allows proper drawing of the edges of the map
|
||||
TERRAIN get_terrain(const location& loc) const;
|
||||
terrain_translation::TERRAIN_NUMBER get_terrain(const location& loc) const;
|
||||
|
||||
//writes the terrain at loc to cfg
|
||||
void write_terrain(const gamemap::location &loc, config& cfg) const;
|
||||
|
@ -180,7 +183,7 @@ public:
|
|||
|
||||
//function to get the corresponding terrain_type information object
|
||||
//for a given type of terrain
|
||||
const terrain_type& get_terrain_info(TERRAIN terrain) const;
|
||||
const terrain_type& get_terrain_info(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
|
||||
//shortcut to get_terrain_info(get_terrain(loc))
|
||||
const terrain_type& get_terrain_info(const location &loc) const;
|
||||
|
@ -188,14 +191,14 @@ public:
|
|||
bool terrain_matches_filter(const location& loc, const config& cfg, const gamestatus& game_status, const unit_map& units,bool flat_tod=false) const;
|
||||
|
||||
//gets the list of terrains
|
||||
const std::vector<TERRAIN>& get_terrain_list() const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& get_terrain_list() const;
|
||||
|
||||
//clobbers over the terrain at location 'loc', with the given terrain
|
||||
void set_terrain(const location& loc, TERRAIN ter);
|
||||
void set_terrain(const location& loc, terrain_translation::TERRAIN_NUMBER ter);
|
||||
|
||||
//function which returns a list of the frequencies of different terrain
|
||||
//types on the map, with terrain nearer the center getting weighted higher
|
||||
const std::map<TERRAIN,size_t>& get_weighted_terrain_frequencies() const;
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,size_t>& get_weighted_terrain_frequencies() const;
|
||||
//remove the cached border terrain at loc. Needed by the editor
|
||||
//to make tiles at the border update correctly when drawing
|
||||
//other tiles.
|
||||
|
@ -203,18 +206,20 @@ public:
|
|||
private:
|
||||
int num_starting_positions() const;
|
||||
|
||||
std::vector<TERRAIN> terrainList_;
|
||||
std::map<TERRAIN,terrain_type> letterToTerrain_;
|
||||
std::map<std::string,terrain_type> terrain_;
|
||||
|
||||
std::vector<std::vector<TERRAIN> > tiles_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrainList_;
|
||||
std::map<terrain_translation::TERRAIN_NUMBER,terrain_type> letterToTerrain_;
|
||||
//The terrain string with TERRAIN_LETTER
|
||||
std::map<std::string,terrain_type> terrain_;
|
||||
//The terrain string with TERRAIN_NUMBER should be make FIXME MdW
|
||||
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > tiles_;
|
||||
std::vector<location> villages_;
|
||||
|
||||
enum { STARTING_POSITIONS = 10 };
|
||||
location startingPositions_[STARTING_POSITIONS];
|
||||
|
||||
mutable std::map<location,TERRAIN> borderCache_;
|
||||
mutable std::map<TERRAIN,size_t> terrainFrequencyCache_;
|
||||
mutable std::map<location,terrain_translation::TERRAIN_NUMBER> borderCache_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,size_t> terrainFrequencyCache_;
|
||||
};
|
||||
|
||||
//a utility function which parses ranges of locations
|
||||
|
|
|
@ -39,7 +39,7 @@ map_generator* create_map_generator(const std::string& name, const config* cfg)
|
|||
|
||||
//function to generate a random map, from a string which describes
|
||||
//the generator to use and its arguments
|
||||
std::string random_generate_map(const std::string& parms, const config* cfg)
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> random_generate_map(const std::string& parms, const config* cfg)
|
||||
{
|
||||
//the first token is the name of the generator, tokens after
|
||||
//that are arguments to the generator
|
||||
|
@ -47,11 +47,11 @@ std::string random_generate_map(const std::string& parms, const config* cfg)
|
|||
util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
|
||||
if(generator == NULL) {
|
||||
ERR_CF << "could not find map generator '" << parameters.front() << "'\n";
|
||||
return std::string();
|
||||
return std::vector<terrain_translation::TERRAIN_NUMBER>();
|
||||
}
|
||||
|
||||
parameters.erase(parameters.begin());
|
||||
return generator.get()->create_map(parameters);
|
||||
// return generator.get()->create_map(parameters); FIXME MdW enable
|
||||
}
|
||||
|
||||
config random_generate_scenario(const std::string& parms, const config* cfg)
|
||||
|
|
|
@ -18,8 +18,11 @@ class config;
|
|||
class map_generator;
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::string random_generate_map(const std::string& parms, const config* cfg);
|
||||
#include "terrain_translation.hpp"
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> random_generate_map(const std::string& parms, const config* cfg);
|
||||
config random_generate_scenario(const std::string& parms, const config* cfg);
|
||||
|
||||
map_generator* create_map_generator(const std::string& name, const config* cfg);
|
||||
|
|
|
@ -47,7 +47,8 @@ config map_generator::create_scenario(const std::vector<std::string>& args)
|
|||
namespace {
|
||||
|
||||
typedef std::vector<std::vector<int> > height_map;
|
||||
typedef std::vector<std::vector<char> > terrain_map;
|
||||
//typedef std::vector<std::vector<char> > terrain_map;
|
||||
typedef std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > terrain_map;
|
||||
|
||||
typedef gamemap::location location;
|
||||
|
||||
|
@ -186,7 +187,7 @@ bool generate_lake(terrain_map& terrain, int x, int y, int lake_fall_off, std::s
|
|||
return false;
|
||||
}
|
||||
|
||||
terrain[x][y] = 'c';
|
||||
terrain[x][y] = terrain_translation::SHALLOW_WATER;
|
||||
locs_touched.insert(location(x,y));
|
||||
|
||||
if((rand()%100) < lake_fall_off) {
|
||||
|
@ -229,13 +230,13 @@ bool generate_river_internal(const height_map& heights, terrain_map& terrain, in
|
|||
}
|
||||
|
||||
//if we're at the end of the river
|
||||
if(!on_map || terrain[x][y] == 'c' || terrain[x][y] == 's') {
|
||||
if(!on_map || terrain[x][y] == terrain_translation::SHALLOW_WATER || terrain[x][y] == terrain_translation::DEEP_WATER) {
|
||||
LOG_NG << "generating river...\n";
|
||||
|
||||
//generate the river
|
||||
for(std::vector<location>::const_iterator i = river.begin();
|
||||
i != river.end(); ++i) {
|
||||
terrain[i->x][i->y] = 'c';
|
||||
terrain[i->x][i->y] = terrain_translation::SHALLOW_WATER;
|
||||
}
|
||||
|
||||
LOG_NG << "done generating river\n";
|
||||
|
@ -338,7 +339,7 @@ private:
|
|||
const config& cfg_;
|
||||
int windiness_;
|
||||
mutable std::map<location,double> loc_cache_;
|
||||
mutable std::map<char,double> cache_;
|
||||
mutable std::map<char,double> cache_; //FIXME MdW are we allowed to be char
|
||||
};
|
||||
|
||||
double road_path_calculator::cost(const location& /*src*/, const location& loc, const double /*so_far*/, const bool /*isDst*/) const
|
||||
|
@ -358,13 +359,13 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
//over-report costs for some segments, to make the road wind a little.
|
||||
const double windiness = windiness_ > 0 ? (double(rand()%windiness_) + 1.0) : 1.0;
|
||||
|
||||
const char c = map_[loc.x][loc.y];
|
||||
const std::map<char,double>::const_iterator itor = cache_.find(c);
|
||||
const char c = map_[loc.x][loc.y]; //FIXME MdW are we allowed to be char
|
||||
const std::map<char,double>::const_iterator itor = cache_.find(c); //FIXME MdW are we allowed to be char
|
||||
if(itor != cache_.end()) {
|
||||
return itor->second*windiness;
|
||||
}
|
||||
|
||||
static std::string terrain(1,'x');
|
||||
static std::string terrain(1,'x'); //FIXME MdW are we allowed to be char x is special char reserved for UMC
|
||||
terrain[0] = c;
|
||||
|
||||
const config* const child = cfg_.find_child("road_cost","terrain",terrain);
|
||||
|
@ -373,21 +374,21 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
res = double(atof((*child)["cost"].c_str()));
|
||||
}
|
||||
|
||||
cache_.insert(std::pair<char,double>(c,res));
|
||||
cache_.insert(std::pair<char,double>(c,res)); //FIXME MdW are we allowed to be char
|
||||
loc_cache_.insert(std::pair<location,double>(loc,windiness*res));
|
||||
return windiness*res;
|
||||
}
|
||||
|
||||
struct is_valid_terrain
|
||||
{
|
||||
is_valid_terrain(const std::vector<std::vector<gamemap::TERRAIN> >& map, const std::string& terrain_list);
|
||||
is_valid_terrain(const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& map, const std::string& terrain_list);
|
||||
bool operator()(int x, int y) const;
|
||||
private:
|
||||
std::vector<std::vector<gamemap::TERRAIN> > map_;
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > map_;
|
||||
const std::string& terrain_;
|
||||
};
|
||||
|
||||
is_valid_terrain::is_valid_terrain(const std::vector<std::vector<gamemap::TERRAIN> >& map, const std::string& terrain_list)
|
||||
is_valid_terrain::is_valid_terrain(const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& map, const std::string& terrain_list)
|
||||
: map_(map), terrain_(terrain_list)
|
||||
{}
|
||||
|
||||
|
@ -465,7 +466,7 @@ int rank_castle_location(int x, int y, const is_valid_terrain& valid_terrain, in
|
|||
return surrounding_ranking + current_ranking;
|
||||
}
|
||||
|
||||
gamemap::location place_village(const std::vector<std::vector<gamemap::TERRAIN> >& map,
|
||||
gamemap::location place_village(const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& map,
|
||||
size_t x, size_t y, size_t radius, const config& cfg)
|
||||
{
|
||||
const gamemap::location loc(x,y);
|
||||
|
@ -489,7 +490,7 @@ gamemap::location place_village(const std::vector<std::vector<gamemap::TERRAIN>
|
|||
continue;
|
||||
}
|
||||
|
||||
const gamemap::TERRAIN t = map[adj[n].x][adj[n].y];
|
||||
const terrain_translation::TERRAIN_NUMBER t = map[adj[n].x][adj[n].y];
|
||||
const std::string& adjacent_liked = (*child)["adjacent_liked"];
|
||||
rating += std::count(adjacent_liked.begin(),adjacent_liked.end(),t);
|
||||
}
|
||||
|
@ -547,13 +548,14 @@ public:
|
|||
explicit terrain_height_mapper(const config& cfg);
|
||||
|
||||
bool convert_terrain(int height) const;
|
||||
gamemap::TERRAIN convert_to() const;
|
||||
terrain_translation::TERRAIN_NUMBER convert_to() const;
|
||||
|
||||
private:
|
||||
int terrain_height;
|
||||
gamemap::TERRAIN to;
|
||||
terrain_translation::TERRAIN_NUMBER to;
|
||||
};
|
||||
|
||||
//FIXME MdW g = grass
|
||||
terrain_height_mapper::terrain_height_mapper(const config& cfg) : terrain_height(lexical_cast_default<int>(cfg["height"],0)), to('g')
|
||||
{
|
||||
const std::string& terrain = cfg["terrain"];
|
||||
|
@ -567,7 +569,7 @@ bool terrain_height_mapper::convert_terrain(int height) const
|
|||
return height >= terrain_height;
|
||||
}
|
||||
|
||||
gamemap::TERRAIN terrain_height_mapper::convert_to() const
|
||||
terrain_translation::TERRAIN_NUMBER terrain_height_mapper::convert_to() const
|
||||
{
|
||||
return to;
|
||||
}
|
||||
|
@ -577,13 +579,13 @@ class terrain_converter
|
|||
public:
|
||||
explicit terrain_converter(const config& cfg);
|
||||
|
||||
bool convert_terrain(gamemap::TERRAIN terrain, int height, int temperature) const;
|
||||
gamemap::TERRAIN convert_to() const;
|
||||
bool convert_terrain(terrain_translation::TERRAIN_NUMBER terrain, int height, int temperature) const;
|
||||
terrain_translation::TERRAIN_NUMBER convert_to() const;
|
||||
|
||||
private:
|
||||
int min_temp, max_temp, min_height, max_height;
|
||||
std::string from;
|
||||
gamemap::TERRAIN to;
|
||||
terrain_translation::TERRAIN_NUMBER to;
|
||||
};
|
||||
|
||||
terrain_converter::terrain_converter(const config& cfg) : min_temp(-1), max_temp(-1), min_height(-1), max_height(-1), from(cfg["from"]), to(0)
|
||||
|
@ -599,13 +601,13 @@ terrain_converter::terrain_converter(const config& cfg) : min_temp(-1), max_temp
|
|||
}
|
||||
}
|
||||
|
||||
bool terrain_converter::convert_terrain(gamemap::TERRAIN terrain, int height, int temperature) const
|
||||
bool terrain_converter::convert_terrain(terrain_translation::TERRAIN_NUMBER terrain, int height, int temperature) const
|
||||
{
|
||||
return std::find(from.begin(),from.end(),terrain) != from.end() && height >= min_height && height <= max_height &&
|
||||
temperature >= min_temp && temperature <= max_temp && to != 0;
|
||||
}
|
||||
|
||||
gamemap::TERRAIN terrain_converter::convert_to() const
|
||||
terrain_translation::TERRAIN_NUMBER terrain_converter::convert_to() const
|
||||
{
|
||||
return to;
|
||||
}
|
||||
|
@ -628,10 +630,10 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
//find out what the 'flatland' on this map is. i.e. grassland.
|
||||
std::string flatland = cfg["default_flatland"];
|
||||
if(flatland == "") {
|
||||
flatland = "g";
|
||||
flatland = "g"; //fixme g = grass
|
||||
}
|
||||
|
||||
const char grassland = flatland[0];
|
||||
const char grassland = flatland[0]; //FIXME MdW are we allowed to be char
|
||||
|
||||
//we want to generate a map that is 9 times bigger than the
|
||||
//actual size desired. Only the middle part of the map will be
|
||||
|
@ -663,7 +665,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
height_conversion.push_back(terrain_height_mapper(**h));
|
||||
}
|
||||
|
||||
terrain_map terrain(width,std::vector<char>(height,grassland));
|
||||
terrain_map terrain(width,std::vector<terrain_translation::TERRAIN_NUMBER>(height,grassland));
|
||||
size_t x, y;
|
||||
for(x = 0; x != heights.size(); ++x) {
|
||||
for(y = 0; y != heights[x].size(); ++y) {
|
||||
|
@ -1022,7 +1024,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const int x = c->x;
|
||||
const int y = c->y;
|
||||
const int player = c - castles.begin();
|
||||
terrain[x][y] = '1' + player;
|
||||
terrain[x][y] = '1' + player; //FIXME MdW keep 1 or not??
|
||||
|
||||
const int castles[13][2] = {
|
||||
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
|
||||
|
@ -1030,7 +1032,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
};
|
||||
|
||||
for (size_t i = 0; i < castle_size - 1; i++) {
|
||||
terrain[x+castles[i][0]][y+castles[i][1]] = 'C';
|
||||
terrain[x+castles[i][0]][y+castles[i][1]] = terrain_translation::CASTLE;
|
||||
}
|
||||
|
||||
//remove all labels under the castle tiles
|
||||
|
@ -1101,8 +1103,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
get_adjacent_tiles(loc,adj);
|
||||
|
||||
std::string name_type = "village_name";
|
||||
|
||||
const std::string field = "g", forest = "f", mountain = "m", hill = "h";
|
||||
//FIXME MdW use gamemap constants
|
||||
// const std::string field = "g", forest = "f", mountain = "m", hill = "h";
|
||||
|
||||
size_t field_count = 0, forest_count = 0, mountain_count = 0, hill_count = 0;
|
||||
|
||||
|
@ -1129,8 +1131,10 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
break;
|
||||
}
|
||||
|
||||
const gamemap::TERRAIN terr = terrain[adj[n].x+width/3][adj[n].y+height/3];
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terr = terrain[adj[n].x+width/3][adj[n].y+height/3];
|
||||
//FIXME MdW enable
|
||||
/*
|
||||
|
||||
if(std::count(field.begin(),field.end(),terr) > 0) {
|
||||
++field_count;
|
||||
} else if(std::count(forest.begin(),forest.end(),terr) > 0) {
|
||||
|
@ -1140,7 +1144,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
} else if(std::count(mountain.begin(),mountain.end(),terr) > 0) {
|
||||
++mountain_count;
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
|
||||
if(n == 6) {
|
||||
if(field_count == 6) {
|
||||
|
|
|
@ -57,7 +57,7 @@ surface getMinimap(int w, int h, const gamemap& map, const team* tm)
|
|||
if(map.on_board(loc)) {
|
||||
const bool shrouded = tm != NULL && tm->shrouded(x,y);
|
||||
const bool fogged = tm != NULL && tm->fogged(x,y) && !shrouded;
|
||||
const gamemap::TERRAIN terrain = shrouded ? gamemap::VOID_TERRAIN : map[x][y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = shrouded ? terrain_translation::VOID_TERRAIN : map[x][y];
|
||||
cache_map::iterator i = cache.find(terrain);
|
||||
|
||||
if(i == cache.end()) {
|
||||
|
|
|
@ -361,7 +361,9 @@ void create::process_event()
|
|||
const config* const generic_multiplayer = game_config().child("generic_multiplayer");
|
||||
if(generic_multiplayer != NULL) {
|
||||
parameters_.scenario_data = *generic_multiplayer;
|
||||
parameters_.scenario_data["map_data"] = read_map(user_maps_[select-1]);
|
||||
//FIXME MdW we do a double conversion, might be nice to have a direct way
|
||||
//but leave ir for now, eg read_map_raw
|
||||
parameters_.scenario_data["map_data"] = terrain_translation().set_map(read_map(user_maps_[select-1]));
|
||||
}
|
||||
|
||||
} else if(select > user_maps_.size() && select <= maps_menu_.nitems()-1) {
|
||||
|
@ -372,12 +374,13 @@ void create::process_event()
|
|||
if(index < levels.size()) {
|
||||
|
||||
parameters_.scenario_data = *levels[index];
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> map_data =
|
||||
terrain_translation().get_map(parameters_.scenario_data["map_data"]);
|
||||
|
||||
t_string& map_data = parameters_.scenario_data["map_data"];
|
||||
if(map_data == "" && parameters_.scenario_data["map"] != "") {
|
||||
if(map_data.empty() && parameters_.scenario_data["map"] != "") {
|
||||
map_data = read_map(parameters_.scenario_data["map"]);
|
||||
}
|
||||
|
||||
|
||||
//if the map should be randomly generated
|
||||
if(parameters_.scenario_data["map_generation"] != "") {
|
||||
generator_.assign(create_map_generator(parameters_.scenario_data["map_generation"],parameters_.scenario_data.child("generator")));
|
||||
|
@ -419,7 +422,8 @@ void create::process_event()
|
|||
generator_settings_.hide(generator_ == NULL);
|
||||
regenerate_map_.hide(generator_ == NULL);
|
||||
|
||||
const std::string& map_data = parameters_.scenario_data["map_data"];
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& map_data =
|
||||
terrain_translation().get_map(parameters_.scenario_data["map_data"]);
|
||||
|
||||
std::auto_ptr<gamemap> map(NULL);
|
||||
try {
|
||||
|
@ -531,7 +535,9 @@ void create::hide_children(bool hide)
|
|||
} else {
|
||||
minimap_restorer_.assign(new surface_restorer(&video(), minimap_rect_));
|
||||
|
||||
const std::string& map_data = parameters_.scenario_data["map_data"];
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& map_data =
|
||||
terrain_translation().get_map(parameters_.scenario_data["map_data"]);
|
||||
|
||||
|
||||
try {
|
||||
gamemap map(game_config(), map_data);
|
||||
|
|
|
@ -310,11 +310,12 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
|
|||
} else {
|
||||
games_.back().map_info = _("Unknown era");
|
||||
}
|
||||
games_.back().map_data = (**game)["map_data"];
|
||||
if(games_.back().map_data == "")
|
||||
games_.back().map_data = terrain_translation().get_map((**game)["map_data"]);
|
||||
if(games_.back().map_data.empty()) {
|
||||
games_.back().map_data = read_map((**game)["map"]);
|
||||
}
|
||||
|
||||
if(games_.back().map_data != "") {
|
||||
if(! games_.back().map_data.empty()) {
|
||||
try {
|
||||
gamemap map(game_config, games_.back().map_data);
|
||||
if (minimaps_)
|
||||
|
|
|
@ -29,7 +29,7 @@ class gamebrowser : public gui::menu {
|
|||
public:
|
||||
struct game_item {
|
||||
surface mini_map;
|
||||
std::string map_data;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> map_data;
|
||||
std::string name;
|
||||
std::string map_info;
|
||||
std::string gold;
|
||||
|
|
|
@ -406,7 +406,7 @@ namespace {
|
|||
continue;
|
||||
|
||||
//find the terrain of the adjacent location
|
||||
const gamemap::TERRAIN terrain = map[currentloc.x][currentloc.y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map[currentloc.x][currentloc.y];
|
||||
|
||||
//find the movement cost of this type onto the terrain
|
||||
const int move_cost = u.movement_cost(terrain);
|
||||
|
|
|
@ -31,7 +31,7 @@ play_controller::play_controller(const config& level, const game_data& gameinfo,
|
|||
menu_handler_(gui_, units_, teams_, level, gameinfo, map_, game_config, status_, state_of_game, undo_stack_, redo_stack_),
|
||||
generator_setter(&recorder), statistics_context_(level["name"]), gameinfo_(gameinfo), level_(level), game_config_(game_config),
|
||||
gamestate_(state_of_game), status_(level, num_turns),
|
||||
map_(game_config, level["map_data"]), ticks_(ticks),
|
||||
map_(game_config, terrain_translation().get_map(level["map_data"])), ticks_(ticks),
|
||||
xp_mod_(atoi(level["experience_modifier"].c_str()) > 0 ? atoi(level["experience_modifier"].c_str()) : 100),
|
||||
loading_game_(level["playing_team"].empty() == false),
|
||||
first_human_team_(-1)
|
||||
|
|
|
@ -222,14 +222,14 @@ LEVEL_RESULT play_game(display& disp, game_state& state, const config& game_conf
|
|||
state.starting_pos = scenario2;
|
||||
scenario = &scenario2;
|
||||
}
|
||||
|
||||
std::string map_data = (*scenario)["map_data"];
|
||||
if(map_data == "" && (*scenario)["map"] != "") {
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> map_data =
|
||||
terrain_translation().get_map((*scenario)["map_data"]);
|
||||
if(map_data.empty() && (*scenario)["map"] != "") {
|
||||
map_data = read_map((*scenario)["map"]);
|
||||
}
|
||||
|
||||
|
||||
//if the map should be randomly generated
|
||||
if(map_data == "" && (*scenario)["map_generation"] != "") {
|
||||
if(map_data.empty() && (*scenario)["map_generation"] != "") {
|
||||
const cursor::setter cursor_setter(cursor::WAIT);
|
||||
map_data = random_generate_map((*scenario)["map_generation"],scenario->child("generator"));
|
||||
|
||||
|
@ -237,7 +237,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, const config& game_conf
|
|||
//it will not ask for the map to be generated again on reload
|
||||
static config new_level;
|
||||
new_level = *scenario;
|
||||
new_level.values["map_data"] = map_data;
|
||||
new_level.values["map_data"] = terrain_translation().set_map(map_data);
|
||||
scenario = &new_level;
|
||||
|
||||
state.starting_pos = new_level;
|
||||
|
|
|
@ -51,7 +51,7 @@ bool fps = false;
|
|||
bool lobby_minimaps = true;
|
||||
|
||||
std::set<std::string> encountered_units_set;
|
||||
std::set<std::string> encountered_terrains_set;
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> encountered_terrains_set;
|
||||
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,9 @@ manager::manager()
|
|||
v = utils::split(prefs["encountered_units"]);
|
||||
std::copy(v.begin(), v.end(),
|
||||
std::inserter(encountered_units_set, encountered_units_set.begin()));
|
||||
v = utils::split(prefs["encountered_terrains"]);
|
||||
std::copy(v.begin(), v.end(),
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain =
|
||||
terrain_translation().get_list(prefs["encountered_terrains"],1);
|
||||
std::copy(terrain.begin(), terrain.end(),
|
||||
std::inserter(encountered_terrains_set, encountered_terrains_set.begin()));
|
||||
}
|
||||
|
||||
|
@ -87,10 +88,11 @@ manager::~manager()
|
|||
std::vector<std::string> v;
|
||||
std::copy(encountered_units_set.begin(), encountered_units_set.end(), std::back_inserter(v));
|
||||
prefs["encountered_units"] = utils::join(v);
|
||||
v.clear();
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain;
|
||||
std::copy(encountered_terrains_set.begin(), encountered_terrains_set.end(),
|
||||
std::back_inserter(v));
|
||||
prefs["encountered_terrains"] = utils::join(v);
|
||||
std::back_inserter(terrain));
|
||||
prefs["encountered_units"] = terrain_translation().set_list(terrain, 1);
|
||||
|
||||
encountered_units_set.clear();
|
||||
encountered_terrains_set.clear();
|
||||
try {
|
||||
|
@ -930,7 +932,7 @@ std::set<std::string> &encountered_units() {
|
|||
return encountered_units_set;
|
||||
}
|
||||
|
||||
std::set<std::string> &encountered_terrains() {
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> &encountered_terrains() {
|
||||
return encountered_terrains_set;
|
||||
}
|
||||
|
||||
|
@ -1022,10 +1024,8 @@ void encounter_recallable_units(game_state& gamestate){
|
|||
void encounter_map_terrain(gamemap& map){
|
||||
for (int map_x = 0; map_x < map.x(); map_x++) {
|
||||
for (int map_y = 0; map_y < map.y(); map_y++) {
|
||||
const gamemap::TERRAIN t = map.get_terrain(gamemap::location(map_x, map_y));
|
||||
std::string s;
|
||||
s += t;
|
||||
preferences::encountered_terrains().insert(s);
|
||||
const terrain_translation::TERRAIN_NUMBER t = map.get_terrain(gamemap::location(map_x, map_y));
|
||||
preferences::encountered_terrains().insert(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ namespace preferences {
|
|||
bool compress_saves();
|
||||
|
||||
std::set<std::string> &encountered_units();
|
||||
std::set<std::string> &encountered_terrains();
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> &encountered_terrains();
|
||||
|
||||
enum CACHE_SAVES_METHOD { CACHE_SAVES_ASK, CACHE_SAVES_NEVER, CACHE_SAVES_ALWAYS };
|
||||
CACHE_SAVES_METHOD cache_saves();
|
||||
|
|
|
@ -375,8 +375,8 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
if(!map.on_board(mouseover) || current_team.shrouded(mouseover.x,mouseover.y))
|
||||
break;
|
||||
|
||||
const gamemap::TERRAIN terrain = map.get_terrain(mouseover);
|
||||
const std::string& underlying = map.underlying_union_terrain(terrain);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map.get_terrain(mouseover);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_union_terrain2(terrain);
|
||||
|
||||
if(map.is_village(mouseover)) {
|
||||
const int owner = village_owner(mouseover,teams)+1;
|
||||
|
@ -394,10 +394,12 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
str << map.get_terrain_info(terrain).name();
|
||||
}
|
||||
|
||||
if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
// if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
str << "(";
|
||||
|
||||
for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
// for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
str << map.get_terrain_info(*i).name();
|
||||
if(i+1 != underlying.end()) {
|
||||
str << ",";
|
||||
|
@ -417,7 +419,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
if(u == units.end() || current_team.shrouded(mouseover.x,mouseover.y))
|
||||
break;
|
||||
|
||||
const gamemap::TERRAIN terrain = map[mouseover.x][mouseover.y];
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map[mouseover.x][mouseover.y];
|
||||
|
||||
const int move_cost = u->second.movement_cost(terrain);
|
||||
const int defense = 100 - u->second.defense_modifier(terrain);
|
||||
|
|
140
src/terrain.cpp
140
src/terrain.cpp
|
@ -23,9 +23,14 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
terrain_type::terrain_type() : symbol_image_("void"), letter_(' '),mvt_type_(" "), def_type_(" "),
|
||||
|
||||
terrain_type::terrain_type() : symbol_image_("void"),
|
||||
number_(terrain_translation::VOID_TERRAIN),
|
||||
mvt_type2_(terrain_translation::VOID_TERRAIN),
|
||||
def_type2_(terrain_translation::VOID_TERRAIN),
|
||||
union_type2_(terrain_translation::VOID_TERRAIN),
|
||||
height_adjust_(0), submerge_(0.0),
|
||||
heals_(false), village_(false), castle_(false), keep_(false)
|
||||
heals_(false), village_(false), castle_(false), keep_(false)
|
||||
{}
|
||||
|
||||
terrain_type::terrain_type(const config& cfg)
|
||||
|
@ -34,6 +39,8 @@ terrain_type::terrain_type(const config& cfg)
|
|||
|
||||
name_ = cfg["name"];
|
||||
id_ = cfg["id"];
|
||||
//FIXME MdW remove obsolete part
|
||||
#if 0
|
||||
const std::string& letter = cfg["char"];
|
||||
|
||||
if(letter == "") {
|
||||
|
@ -41,7 +48,8 @@ terrain_type::terrain_type(const config& cfg)
|
|||
} else {
|
||||
letter_ = letter[0];
|
||||
}
|
||||
|
||||
|
||||
//FIXME MdW what do the next 4 lines do?? guess nothing, since seems to be overwritten
|
||||
mvt_type_.resize(1);
|
||||
mvt_type_[0] = letter_;
|
||||
def_type_.resize(1);
|
||||
|
@ -65,10 +73,66 @@ terrain_type::terrain_type(const config& cfg)
|
|||
union_type_.erase(std::remove(union_type_.begin(),union_type_.end(),'+'),union_type_.end());
|
||||
std::sort(union_type_.begin(),union_type_.end());
|
||||
union_type_.erase(std::unique(union_type_.begin(),union_type_.end()),union_type_.end());
|
||||
#endif
|
||||
|
||||
number_ = terrain_translation().get_letter(cfg["char"]);
|
||||
|
||||
mvt_type2_.push_back(number_);
|
||||
def_type2_.push_back(number_);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& alias =
|
||||
terrain_translation().get_list(cfg["aliasof"]);
|
||||
if(!alias.empty()) {
|
||||
mvt_type2_ = alias;
|
||||
def_type2_ = alias;
|
||||
}
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& mvt_alias =
|
||||
terrain_translation().get_list(cfg["mvt_alias"]);
|
||||
if(!mvt_alias.empty()) {
|
||||
mvt_type2_ = mvt_alias;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& def_alias =
|
||||
terrain_translation().get_list(cfg["def_alias"]);
|
||||
if(!def_alias.empty()) {
|
||||
def_type2_ = def_alias;
|
||||
}
|
||||
union_type2_ = mvt_type2_;
|
||||
union_type2_.insert( union_type2_.end(), def_type2_.begin(), def_type2_.end() );
|
||||
|
||||
union_type2_.erase(std::remove(union_type2_.begin(),union_type2_.end(),terrain_translation::MINUS),union_type2_.end());
|
||||
union_type2_.erase(std::remove(union_type2_.begin(),union_type2_.end(),terrain_translation::PLUS),union_type2_.end());
|
||||
std::sort(union_type2_.begin(),union_type2_.end());
|
||||
union_type2_.erase(std::unique(union_type2_.begin(),union_type2_.end()),union_type2_.end());
|
||||
|
||||
|
||||
#if 0
|
||||
number_ = terrain_translation().get_letter(cfg["char"]);
|
||||
|
||||
def_type2_ = terrain_translation().get_list(cfg["def_alias"]);
|
||||
mvt_type2_ = terrain_translation().get_list(cfg["mvt_alias"]);
|
||||
|
||||
// if the move or defense alias isn't defined use the aliasof
|
||||
if(def_type2_.empty() || mvt_type2_.empty()){
|
||||
union_type2_ = terrain_translation().get_list(cfg["aliasof"]);
|
||||
if(def_type2_.empty()){
|
||||
def_type2_ = union_type2_;
|
||||
}
|
||||
if(mvt_type2_.empty()){
|
||||
mvt_type2_= union_type2_;
|
||||
}
|
||||
union_type2_.clear();
|
||||
}
|
||||
|
||||
//FIXME MdW test the union
|
||||
union_type2_ = mvt_type2_; //+ def_type2_;
|
||||
union_type2_.insert( union_type2_.end(), def_type2_.begin(), def_type2_.end() );
|
||||
|
||||
union_type2_.erase(std::remove(union_type2_.begin(),union_type2_.end(),terrain_translation::MINUS),union_type2_.end());
|
||||
union_type2_.erase(std::remove(union_type2_.begin(),union_type2_.end(),terrain_translation::PLUS),union_type2_.end());
|
||||
union_type2_.erase(std::unique(union_type2_.begin(),union_type2_.end()),union_type2_.end());
|
||||
#endif /////
|
||||
height_adjust_ = atoi(cfg["unit_height_adjust"].c_str());
|
||||
submerge_ = atof(cfg["submerge"].c_str());
|
||||
|
||||
light_modification_ = atoi(cfg["light"].c_str());
|
||||
|
||||
if (cfg["heals"] == "true") {
|
||||
|
@ -97,16 +161,26 @@ const std::string& terrain_type::id() const
|
|||
return id_;
|
||||
}
|
||||
|
||||
char terrain_type::letter() const
|
||||
//FIXME MdW obsolete
|
||||
#if 0
|
||||
terrain_type::TERRAIN_LETTER terrain_type::letter() const
|
||||
{
|
||||
return letter_;
|
||||
}
|
||||
#endif
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_type::number() const
|
||||
{
|
||||
return number_;
|
||||
}
|
||||
|
||||
bool terrain_type::is_nonnull() const
|
||||
{
|
||||
return (letter_ != 0) && (letter_ != ' ');
|
||||
return (number_ != 0) && (number_ != terrain_translation::VOID_TERRAIN );
|
||||
}
|
||||
|
||||
//FIXME MdW obsolete
|
||||
#if 0
|
||||
const std::string& terrain_type::mvt_type() const
|
||||
{
|
||||
return mvt_type_;
|
||||
|
@ -121,7 +195,22 @@ const std::string& terrain_type::union_type() const
|
|||
{
|
||||
return union_type_;
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::mvt_type2() const
|
||||
{
|
||||
return mvt_type2_;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::def_type2() const
|
||||
{
|
||||
return def_type2_;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::union_type2() const
|
||||
{
|
||||
return union_type2_;
|
||||
}
|
||||
|
||||
int terrain_type::light_modification() const
|
||||
{
|
||||
|
@ -157,18 +246,45 @@ bool terrain_type::is_keep() const
|
|||
{
|
||||
return keep_;
|
||||
}
|
||||
#if 0
|
||||
terrain_translation::TERRAIN_NUMBER terrain_type::load_terrain_char_(const config& cfg) const
|
||||
{
|
||||
|
||||
const std::string& letter = cfg["char"];
|
||||
//FIXME MdW is an empty letter allowed???
|
||||
if(letter == ""){
|
||||
return translator_.letter_to_number(0);
|
||||
} else {
|
||||
return translator_.letter_to_number(letter[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_type::load_terrain_alias_(const config& cfg, std::string alias) const
|
||||
{
|
||||
const std::string& def_alias = cfg[alias];
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> result;
|
||||
|
||||
//NOTE MdW the + and - sign are special but they will converted to a proper sign
|
||||
std::string::const_iterator i = def_alias.begin();
|
||||
for( ; i != def_alias.end(); ++i) {
|
||||
result.push_back(translator_.letter_to_number(*i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
void create_terrain_maps(const std::vector<config*>& cfgs,
|
||||
std::vector<char>& terrain_list,
|
||||
std::map<char,terrain_type>& letter_to_terrain,
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_list,
|
||||
std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>& letter_to_terrain,
|
||||
std::map<std::string,terrain_type>& str_to_terrain)
|
||||
{
|
||||
for(std::vector<config*>::const_iterator i = cfgs.begin();
|
||||
i != cfgs.end(); ++i) {
|
||||
terrain_type terrain(**i);
|
||||
terrain_list.push_back(terrain.letter());
|
||||
letter_to_terrain.insert(std::pair<char,terrain_type>(
|
||||
terrain.letter(),terrain));
|
||||
terrain_type terrain(**i);
|
||||
terrain_list.push_back(terrain.number());
|
||||
letter_to_terrain.insert(std::pair<terrain_translation::TERRAIN_NUMBER,terrain_type>(
|
||||
terrain.number(),terrain));
|
||||
str_to_terrain.insert(std::pair<std::string,terrain_type>(
|
||||
terrain.id(),terrain));
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
class config;
|
||||
#include "tstring.hpp"
|
||||
#include "terrain_translation.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
@ -23,6 +24,7 @@ class config;
|
|||
class terrain_type
|
||||
{
|
||||
public:
|
||||
|
||||
terrain_type();
|
||||
terrain_type(const config& cfg);
|
||||
|
||||
|
@ -31,12 +33,24 @@ public:
|
|||
const std::string& id() const;
|
||||
|
||||
//the character representing this terrain
|
||||
char letter() const;
|
||||
//this is the old type will be obsoleted
|
||||
#if 0
|
||||
TERRAIN_LETTER letter() const;
|
||||
|
||||
//the underlying type of the terrain
|
||||
const std::string& mvt_type() const;
|
||||
const std::string& def_type() const;
|
||||
const std::string& union_type() const;
|
||||
#endif
|
||||
//the number representing this terrain
|
||||
//this is the new type
|
||||
terrain_translation::TERRAIN_NUMBER number() const;
|
||||
|
||||
//FIXME MdW rename the ones below to the name of the ones above and kill the ones above
|
||||
//the underlying type of the terrain
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& mvt_type2() const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& def_type2() const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& union_type2() const;
|
||||
|
||||
bool is_nonnull() const;
|
||||
int light_modification() const;
|
||||
|
@ -57,11 +71,24 @@ private:
|
|||
//the 'letter' is the letter that represents this
|
||||
//terrain type. The 'type' is a list of the 'underlying types'
|
||||
//of the terrain. This may simply be the same as the letter.
|
||||
char letter_;
|
||||
#if 0
|
||||
TERRAIN_LETTER letter_;
|
||||
//These strings are no longer bound to contain chars
|
||||
//and only kept for backwards compability
|
||||
std::string mvt_type_;
|
||||
std::string def_type_;
|
||||
std::string union_type_;
|
||||
#endif
|
||||
|
||||
//the 'number' is the new way
|
||||
//NOTE the aliases stay strings for now
|
||||
//will become space separated list of numbers in the future
|
||||
terrain_translation::TERRAIN_NUMBER number_;
|
||||
//FIXME MdW rename these as soon as the originals are killed
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> mvt_type2_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> def_type2_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> union_type2_;
|
||||
|
||||
int height_adjust_;
|
||||
|
||||
double submerge_;
|
||||
|
@ -69,11 +96,20 @@ private:
|
|||
int light_modification_, heals_;
|
||||
|
||||
bool village_, castle_, keep_;
|
||||
|
||||
//FIXME MdW remove
|
||||
// loads the terrain number from the config file
|
||||
// we're the only one who should know what's in the
|
||||
// file. If the terrain system changes we should be
|
||||
// changed, the rest of the world not the old name
|
||||
// is used since it's the known key
|
||||
// terrain_translation::TERRAIN_NUMBER load_terrain_char_(const config& cfg) const;
|
||||
// std::vector<terrain_translation::TERRAIN_NUMBER> load_terrain_alias_(const config& cfg, std::string alias) const;
|
||||
};
|
||||
|
||||
void create_terrain_maps(const std::vector<config*>& cfgs,
|
||||
std::vector<char>& terrain_precedence,
|
||||
std::map<char,terrain_type>& letter_to_terrain,
|
||||
std::map<std::string,terrain_type>& str_to_terrain);
|
||||
|
||||
void create_terrain_maps(const std::vector<config*>& cfgs,
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_list,
|
||||
std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>& letter_to_terrain,
|
||||
std::map<std::string,terrain_type>& str_to_terrain);
|
||||
#endif
|
||||
|
|
242
src/terrain_translation.cpp
Normal file
242
src/terrain_translation.cpp
Normal file
|
@ -0,0 +1,242 @@
|
|||
/* $Id: boilerplate-header.cpp 8092 2005-09-02 16:10:12Z ott $ */
|
||||
/*
|
||||
Copyright (C) 2006 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "util.hpp"
|
||||
#include "terrain_translation.hpp"
|
||||
//include "variable.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "wassert.hpp"
|
||||
|
||||
#define SHIFT 0
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::VOID_TERRAIN = ' ' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::FOGGED = '~' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::KEEP = 'K' << SHIFT;
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::CASTLE = 'C' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::SHALLOW_WATER = 'c' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::DEEP_WATER = 's' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::GRASS_LAND = 'g' << SHIFT;
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::CAVE_WALL = 'W' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::CAVE = 'u' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::UNDERGROUND_VILLAGE = 'D' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::DWARVEN_CASTLE = 'o' << SHIFT;
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::PLUS = '+' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::MINUS = '-' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::STAR = '*' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::NOT = '!' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::EOL = 7 << SHIFT; // char 7 is the bell so no EOL
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::DOT = '.' << SHIFT;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain_translation::COMMA = ',' << SHIFT;
|
||||
|
||||
terrain_translation::terrain_translation() {}
|
||||
terrain_translation::~terrain_translation(){}
|
||||
|
||||
terrain_translation::TERRAIN_LETTER terrain_translation::letter_to_number_(const terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
{
|
||||
TERRAIN_NUMBER tmp = terrain >> SHIFT;
|
||||
return (TERRAIN_LETTER)(tmp);
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_translation::number_to_letter_(const terrain_translation::TERRAIN_LETTER terrain) const
|
||||
{
|
||||
TERRAIN_NUMBER result = (TERRAIN_NUMBER) terrain;
|
||||
result = result << SHIFT;
|
||||
return result;
|
||||
}
|
||||
|
||||
int terrain_translation::list_to_int(const std::vector<terrain_translation::TERRAIN_NUMBER> number)const
|
||||
{
|
||||
std::string data = "";
|
||||
std::vector<TERRAIN_NUMBER>::const_iterator itor = number.begin();
|
||||
|
||||
for(; itor != number.end(); ++itor){
|
||||
data += number_to_letter_(*itor);
|
||||
}
|
||||
|
||||
if(data.find_first_of("0123456789") != std::string::npos) {
|
||||
return atoi(data.c_str());
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int terrain_translation::letter_to_start_location(const terrain_translation::TERRAIN_NUMBER number) const
|
||||
{
|
||||
const TERRAIN_LETTER letter = number_to_letter_(number);
|
||||
if(letter >= '0' && letter <= '9'){
|
||||
return letter - '0';
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > terrain_translation::get_terrain_vector_splitted(const config& cfg, const std::string tag) const
|
||||
{
|
||||
//for now use the standard splitter
|
||||
const std::vector<std::string> data = utils::split(cfg[tag]);
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > res;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> inner_res;
|
||||
std::vector<std::string>::const_iterator iter = data.begin();
|
||||
|
||||
// convert the string version to the TERRAIN_NUMBER version
|
||||
for(; iter != data.end(); ++iter){
|
||||
std::string::const_iterator inner_iter = iter->begin();
|
||||
for(; inner_iter != iter->begin(); ++inner_iter){
|
||||
inner_res.push_back(letter_to_number_(*inner_iter));
|
||||
}
|
||||
res.push_back(inner_res);
|
||||
inner_res.clear();
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
/*
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_translation::string_to_vector(const std::string map_data) const
|
||||
{
|
||||
const std::string& data = map_data;
|
||||
return terrain_translation::string_to_vector_(data, false);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//NEW will stay
|
||||
terrain_translation::TERRAIN_NUMBER terrain_translation::get_letter(const std::string& letter) const
|
||||
{
|
||||
wassert(! letter.empty());
|
||||
return letter_to_number_(letter[0]);
|
||||
}
|
||||
|
||||
//NEW will stay
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_translation::get_list(const std::string& list, const int separated) const
|
||||
{
|
||||
return string_to_vector_(list, false, separated);
|
||||
}
|
||||
|
||||
//NEW will stay
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_translation::get_map(const std::string& map) const
|
||||
{
|
||||
//FIXME MdW remove assigment, only used as debug aid
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> result = string_to_vector_(map, true, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string terrain_translation::set_map(const std::vector<terrain_translation::TERRAIN_NUMBER>& map) const
|
||||
{
|
||||
return vector_to_string_(map, 0);
|
||||
}
|
||||
|
||||
std::string terrain_translation::set_letter(const terrain_translation::TERRAIN_NUMBER& letter) const
|
||||
{
|
||||
// cheap hack reserve space to 1 char and put it in the string
|
||||
std::string res = "a";
|
||||
res[0] = number_to_letter_(letter);
|
||||
return res;
|
||||
}
|
||||
|
||||
//USED private
|
||||
std::string terrain_translation::vector_to_string_(const std::vector<terrain_translation::TERRAIN_NUMBER>& map_data, const int separated) const
|
||||
{
|
||||
std::string result;
|
||||
|
||||
std::vector<TERRAIN_NUMBER>::const_iterator itor = map_data.begin();
|
||||
for( ; itor != map_data.end(); ++itor) {
|
||||
if(*itor == EOL){
|
||||
result.push_back('\n');
|
||||
} else {
|
||||
result.push_back(number_to_letter_(*itor));
|
||||
}
|
||||
// all get a separtor if requested
|
||||
if(separated == 1){
|
||||
result.push_back(',');
|
||||
}
|
||||
}
|
||||
|
||||
//remove the last separator
|
||||
if(! result.empty() && separated == 1){
|
||||
result.erase(result.end() - 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//USED private
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_translation::string_to_vector_(const std::string& data, const bool convert_eol, const int separated) const
|
||||
{
|
||||
bool last_eol = false;
|
||||
std::vector<TERRAIN_NUMBER> result = std::vector<TERRAIN_NUMBER>();
|
||||
|
||||
std::string::const_iterator itor = data.begin();
|
||||
for( ; itor != data.end(); ++itor) {
|
||||
|
||||
if(separated == 1 && *itor == ',') {
|
||||
//ignore the character
|
||||
last_eol = false;
|
||||
|
||||
} else if ((convert_eol) && (*itor == '\n' || *itor == '\r')) {
|
||||
// end of line marker found
|
||||
if(last_eol == false){
|
||||
// last wasn't eol then add us
|
||||
result.push_back(EOL);
|
||||
}
|
||||
last_eol = true;
|
||||
|
||||
} else {
|
||||
// normal just add
|
||||
last_eol = false;
|
||||
result.push_back(letter_to_number_(*itor));
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if(convert_eol){
|
||||
if(*itor == '\n' || *itor == '\r'){
|
||||
// end of line marker found
|
||||
if(last_eol == false){
|
||||
// last wasn't eol then add us
|
||||
result.push_back(EOL);
|
||||
}
|
||||
//else we're ignored
|
||||
}else{
|
||||
last_eol = false;
|
||||
result.push_back(letter_to_number(*itor));
|
||||
}
|
||||
} else {
|
||||
// no EOL conversion just pushback
|
||||
result.push_back(letter_to_number(*itor));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//note 2 exit path for debugging aids
|
||||
if(result.empty()) {
|
||||
return result;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string terrain_translation::set_list(const std::vector<terrain_translation::TERRAIN_NUMBER>& list, const int separated) const
|
||||
{
|
||||
return vector_to_string_(list, separated);
|
||||
}
|
133
src/terrain_translation.hpp
Normal file
133
src/terrain_translation.hpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/* $Id: boilerplate-header.cpp 8092 2005-09-02 16:10:12Z ott $ */
|
||||
/*
|
||||
Copyright (C) 2006 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
|
||||
//FIXME MdW is Makefile.am good modified
|
||||
//do I need to change the $Id line??
|
||||
//
|
||||
|
||||
|
||||
#ifndef TERRAIN_TRANSLATION_H_INCLUDED
|
||||
#define TERRAIN_TRANSLATION_H_INCLUDED
|
||||
|
||||
class config;
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "variable.hpp"
|
||||
|
||||
|
||||
/* The base terrain translation class
|
||||
*
|
||||
* There should be 2 sub classes
|
||||
* terrain_translation map
|
||||
* - adds load_terrain_map
|
||||
* - _if_ we use the XLAT version it has to translation table
|
||||
* terrain_translation_preferences
|
||||
* - should override load_terrain_vector since it loads a , separated list
|
||||
*
|
||||
* It seems the builder can use the base class
|
||||
* The terrain_type will also use the base class
|
||||
*/
|
||||
class terrain_translation
|
||||
{
|
||||
public:
|
||||
|
||||
//The new definition of terrain
|
||||
typedef char TERRAIN_LETTER; //maybe should be private
|
||||
typedef unsigned long TERRAIN_NUMBER;
|
||||
|
||||
//some types of terrain which must be known, and can't just be loaded
|
||||
//in dynamically because they're special. It's asserted that there will
|
||||
//be corresponding entries for these types of terrain in the terrain
|
||||
//configuration file.
|
||||
static const TERRAIN_NUMBER VOID_TERRAIN;
|
||||
static const TERRAIN_NUMBER FOGGED;
|
||||
static const TERRAIN_NUMBER KEEP;
|
||||
// used in mapgen
|
||||
static const TERRAIN_NUMBER CASTLE;
|
||||
static const TERRAIN_NUMBER SHALLOW_WATER;
|
||||
static const TERRAIN_NUMBER DEEP_WATER;
|
||||
static const TERRAIN_NUMBER GRASS_LAND;
|
||||
// used in cavegen
|
||||
static const TERRAIN_NUMBER CAVE_WALL;
|
||||
static const TERRAIN_NUMBER CAVE;
|
||||
static const TERRAIN_NUMBER UNDERGROUND_VILLAGE;
|
||||
static const TERRAIN_NUMBER DWARVEN_CASTLE;
|
||||
// used for special purposes
|
||||
static const TERRAIN_NUMBER PLUS;
|
||||
static const TERRAIN_NUMBER MINUS;
|
||||
static const TERRAIN_NUMBER STAR;
|
||||
static const TERRAIN_NUMBER NOT;
|
||||
static const TERRAIN_NUMBER EOL; //end of line will be translated to a bell character
|
||||
static const TERRAIN_NUMBER DOT;
|
||||
static const TERRAIN_NUMBER COMMA;
|
||||
|
||||
terrain_translation();
|
||||
~terrain_translation();
|
||||
// load_translation(std::string translation);
|
||||
|
||||
//converts a string to a TERRAIN_NUMBER it expects the input to be a string of 1 item
|
||||
//to convert
|
||||
TERRAIN_NUMBER get_letter(const std::string& letter) const;
|
||||
|
||||
|
||||
//converts a string to a vector of TERRAIN_NUMBER it expects the input to be a continues string of items
|
||||
//to convert
|
||||
//separated, is the list separated by a,
|
||||
// 0 = no
|
||||
// 1 = yes
|
||||
// 2 = auto, might be required for the future, make this value the default
|
||||
// This conversion is not implanted, since it's unkown whether it's required
|
||||
std::vector<TERRAIN_NUMBER> get_list(const std::string& list, const int separated=0) const;
|
||||
|
||||
//converts a string to a vector of TERRAIN_NUMBER it expects the input to be a map and converts it accordingly
|
||||
std::vector<TERRAIN_NUMBER> get_map(const std::string& map) const;
|
||||
|
||||
|
||||
//expects a vector of TERRAIN_NUMBER and converts it to s number -1 upon failure
|
||||
int list_to_int(const std::vector<TERRAIN_NUMBER> number)const;
|
||||
|
||||
//converts an map to a string
|
||||
std::string set_map(const std::vector<TERRAIN_NUMBER>& map) const;
|
||||
|
||||
//converts a letter to a string
|
||||
std::string set_letter(const TERRAIN_NUMBER& letter) const;
|
||||
|
||||
//converts a list to a string
|
||||
std::string set_list(const std::vector<TERRAIN_NUMBER>& list, const int separated=0) const;
|
||||
|
||||
//used in unit animation FIXME should probebly also be re-written at some point
|
||||
std::vector<std::vector<TERRAIN_NUMBER> > get_terrain_vector_splitted(const config& cfg, const std::string tag) const;
|
||||
|
||||
int letter_to_start_location(const TERRAIN_NUMBER number) const;
|
||||
|
||||
private:
|
||||
|
||||
// This function can convert EOL's and converts them to EOL
|
||||
// which doesn't need to be and EOL char
|
||||
// this will convert UNIX, Mac and Windows end of line types
|
||||
// this due to the fact they all have a different idea of EOL
|
||||
// Note this also eats all blank lines so the sequence "\n\n\n" will become just 1 EOL
|
||||
std::vector<TERRAIN_NUMBER> string_to_vector_(const std::string& map_data, const bool convert_eol, const int separated) const;
|
||||
|
||||
std::string vector_to_string_(const std::vector<TERRAIN_NUMBER>& map_data, const int separated) const;
|
||||
|
||||
TERRAIN_LETTER letter_to_number_(const TERRAIN_NUMBER terrain) const;
|
||||
TERRAIN_NUMBER number_to_letter_(const TERRAIN_LETTER terrain) const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
71
src/unit.cpp
71
src/unit.cpp
|
@ -1863,7 +1863,7 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
|
|||
|
||||
|
||||
if(!anim_) set_standing(disp,hex);
|
||||
const gamemap::TERRAIN terrain = map.get_terrain(hex);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map.get_terrain(hex);
|
||||
const double submerge = is_flying() ? 0.0 : map.get_terrain_info(terrain).unit_submerge() * disp.zoom();
|
||||
const int height_adjust = is_flying() ? 0 : int(map.get_terrain_info(terrain).unit_height_adjust() * disp.zoom());
|
||||
|
||||
|
@ -2135,30 +2135,42 @@ bool unit::is_flying() const
|
|||
return flying_;
|
||||
}
|
||||
|
||||
int unit::movement_cost_internal(gamemap::TERRAIN terrain, int recurse_count) const
|
||||
int unit::movement_cost_internal(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
{
|
||||
const int impassable = 10000000;
|
||||
|
||||
const std::map<gamemap::TERRAIN,int>::const_iterator i = movement_costs_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = movement_costs_.find(terrain);
|
||||
if(i != movement_costs_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
wassert(map_ != NULL);
|
||||
//if this is an alias, then select the best of all underlying terrains
|
||||
const std::string& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
bool revert = (underlying[0] == '-'?true:false);
|
||||
//FIXME MdW cleanup
|
||||
// const std::string& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map_->underlying_mvt_terrain2(terrain);
|
||||
if(underlying.size() == 0) { //FIXME MdW debug hack
|
||||
int dummy = 0;
|
||||
}
|
||||
|
||||
wassert(!underlying.empty());
|
||||
// if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) { // We fail here but first test underlying_mvt_terrain2
|
||||
// bool revert = (underlying[0] == '-'?true:false);
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
if(recurse_count >= 100) {
|
||||
return impassable;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:impassable;
|
||||
for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
if(*i == '+') {
|
||||
// for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
// if(*i == '+') {
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == '-') {
|
||||
// } else if(*i == '-') {
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -2170,7 +2182,7 @@ int unit::movement_cost_internal(gamemap::TERRAIN terrain, int recurse_count) co
|
|||
}
|
||||
}
|
||||
|
||||
movement_costs_.insert(std::pair<gamemap::TERRAIN,int>(terrain,ret_value));
|
||||
movement_costs_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -2185,7 +2197,8 @@ int unit::movement_cost_internal(gamemap::TERRAIN terrain, int recurse_count) co
|
|||
return impassable;
|
||||
}
|
||||
|
||||
const std::string& id = map_->get_terrain_info(underlying[0]).id();
|
||||
// const std::string& id = map_->get_terrain_info(underlying[0]).id();
|
||||
const std::string& id = map_->get_terrain_info(underlying.front()).id();
|
||||
|
||||
const std::string& val = (*movement_costs)[id];
|
||||
|
||||
|
@ -2198,11 +2211,11 @@ int unit::movement_cost_internal(gamemap::TERRAIN terrain, int recurse_count) co
|
|||
res = impassable;
|
||||
}
|
||||
|
||||
movement_costs_.insert(std::pair<gamemap::TERRAIN,int>(terrain,res));
|
||||
movement_costs_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
return res;
|
||||
}
|
||||
|
||||
int unit::movement_cost(gamemap::TERRAIN terrain, int recurse_count) const
|
||||
int unit::movement_cost(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
{
|
||||
int res = movement_cost_internal(terrain,recurse_count);
|
||||
if(utils::string_bool(get_state("slowed"))) {
|
||||
|
@ -2211,28 +2224,35 @@ int unit::movement_cost(gamemap::TERRAIN terrain, int recurse_count) const
|
|||
return res;
|
||||
}
|
||||
|
||||
int unit::defense_modifier(gamemap::TERRAIN terrain, int recurse_count) const
|
||||
int unit::defense_modifier(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
{
|
||||
// const std::map<gamemap::TERRAIN,int>::const_iterator i = defense_mods_.find(terrain);
|
||||
// const std::map<terrain_type::TERRAIN,int>::const_iterator i = defense_mods_.find(terrain);
|
||||
// if(i != defense_mods_.end()) {
|
||||
// return i->second;
|
||||
// }
|
||||
|
||||
wassert(map_ != NULL);
|
||||
//if this is an alias, then select the best of all underlying terrains
|
||||
const std::string& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
bool revert = (underlying[0] == '-'?true:false);
|
||||
//FIXME MdW cleanup
|
||||
// const std::string& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map_->underlying_mvt_terrain2(terrain);
|
||||
// if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
// bool revert = (underlying[0] == '-'?true:false);
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
if(recurse_count >= 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:100;
|
||||
for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
if(*i == '+') {
|
||||
// for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
// if(*i == '+') {
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == '-') {
|
||||
// } else if(*i == '-') {
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -2247,7 +2267,7 @@ int unit::defense_modifier(gamemap::TERRAIN terrain, int recurse_count) const
|
|||
}
|
||||
}
|
||||
|
||||
// defense_mods_.insert(std::pair<gamemap::TERRAIN,int>(terrain,ret_value));
|
||||
// defense_mods_.insert(std::pair<terrain_type::TERRAIN,int>(terrain,ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -2262,7 +2282,8 @@ int unit::defense_modifier(gamemap::TERRAIN terrain, int recurse_count) const
|
|||
return 100;
|
||||
}
|
||||
|
||||
const std::string& id = map_->get_terrain_info(underlying[0]).id();
|
||||
// const std::string& id = map_->get_terrain_info(underlying[0]).id();
|
||||
const std::string& id = map_->get_terrain_info(underlying.front()).id();
|
||||
const std::string& val = (*defense)[id];
|
||||
|
||||
if(val != "") {
|
||||
|
@ -2274,7 +2295,7 @@ int unit::defense_modifier(gamemap::TERRAIN terrain, int recurse_count) const
|
|||
res = 50;
|
||||
}
|
||||
|
||||
// defense_mods_.insert(std::pair<gamemap::TERRAIN,int>(terrain,res));
|
||||
// defense_mods_.insert(std::pair<terrain_type::TERRAIN,int>(terrain,res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -2333,7 +2354,7 @@ int unit::resistance_against(const attack_type& damage_type,bool attacker,const
|
|||
return 100 - res;
|
||||
}
|
||||
#if 0
|
||||
std::map<gamemap::TERRAIN,int> unit::movement_type() const
|
||||
std::map<terrain_type::TERRAIN,int> unit::movement_type() const
|
||||
{
|
||||
return movement_costs_;
|
||||
}
|
||||
|
|
14
src/unit.hpp
14
src/unit.hpp
|
@ -191,10 +191,10 @@ class unit
|
|||
|
||||
void set_hidden(bool state) {hidden_ = state;};
|
||||
bool is_flying() const;
|
||||
int movement_cost(gamemap::TERRAIN terrain, int recurse_count=0) const;
|
||||
int defense_modifier(gamemap::TERRAIN terrain, int recurse_count=0) const;
|
||||
int movement_cost(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
int defense_modifier(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
int resistance_against(const attack_type& damage_type,bool attacker,const gamemap::location& loc) const;
|
||||
// std::map<gamemap::TERRAIN,int> movement_type() const;
|
||||
// std::map<terrain_type::TERRAIN,int> movement_type() const;
|
||||
|
||||
bool can_advance() const;
|
||||
bool advances() const;
|
||||
|
@ -281,7 +281,7 @@ class unit
|
|||
bool ability_affects_adjacent(const std::string& ability,const config& cfg,int dir,const gamemap::location& loc) const;
|
||||
bool ability_affects_self(const std::string& ability,const config& cfg,const gamemap::location& loc) const;
|
||||
bool resistance_filter_matches(const config& cfg,bool attacker,const attack_type& damage_type) const;
|
||||
int movement_cost_internal(gamemap::TERRAIN terrain, int recurse_count=0) const;
|
||||
int movement_cost_internal(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
bool has_ability_by_id(const std::string& ability) const;
|
||||
|
||||
config cfg_;
|
||||
|
@ -318,7 +318,7 @@ class unit
|
|||
|
||||
int movement_;
|
||||
int max_movement_, max_movement_b_;
|
||||
mutable std::map<gamemap::TERRAIN,int> movement_costs_; // movement cost cache
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> movement_costs_; // movement cost cache
|
||||
bool hold_position_;
|
||||
bool end_turn_;
|
||||
bool resting_;
|
||||
|
@ -341,8 +341,8 @@ class unit
|
|||
gamemap::location goto_, interrupted_move_;
|
||||
bool flying_;
|
||||
|
||||
// std::map<gamemap::TERRAIN,int> movement_costs_, movement_costs_b_;
|
||||
// std::map<gamemap::TERRAIN,int> defense_mods_, defense_mods_b_;
|
||||
// std::map<terrain_type::TERRAIN,int> movement_costs_, movement_costs_b_;
|
||||
// std::map<terrain_type::TERRAIN,int> defense_mods_, defense_mods_b_;
|
||||
|
||||
string_map modification_descriptions_;
|
||||
// animations
|
||||
|
|
|
@ -97,7 +97,13 @@ unit_animation::unit_animation(const unit_frame & frame )
|
|||
|
||||
}
|
||||
|
||||
unit_animation::unit_animation(const config& cfg,const std::string frame_string ):terrain_types(utils::split(cfg["terrain"])){
|
||||
unit_animation::unit_animation(const config& cfg,const std::string frame_string )
|
||||
//FIXME MdW not sure what the terrain string is but guess
|
||||
//normal string due to documentation so use default
|
||||
//translation for now
|
||||
:terrain_types(terrain_translation().get_terrain_vector_splitted(cfg, std::string("terrain")))
|
||||
/*terrain_types(utils::split(cfg["terrain"]))*/{
|
||||
|
||||
config::const_child_itors range = cfg.child_range(frame_string);
|
||||
|
||||
int last_end = INT_MIN;
|
||||
|
@ -133,11 +139,19 @@ int unit_animation::matches(const display& disp, const gamemap::location& loc,co
|
|||
{
|
||||
int result = 0;
|
||||
if(terrain_types.empty()== false) {
|
||||
if (find(terrain_types.begin(),terrain_types.end(),disp.get_map().underlying_union_terrain2(loc))== terrain_types.end()) {
|
||||
// if (terrain_types.find(disp.get_map().underlying_union_terrain2(loc)) == terrain_types.end()) {
|
||||
return -1;
|
||||
} else {
|
||||
result ++;
|
||||
}
|
||||
//FIXME MdW enable change to underlying_union_terrain2 doesn't work
|
||||
/*
|
||||
if (std::find(terrain_types.begin(),terrain_types.end(),disp.get_map().underlying_union_terrain(loc))== terrain_types.end()) {
|
||||
return -1;
|
||||
} else {
|
||||
result ++;
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
if(my_unit) {
|
||||
|
|
|
@ -38,7 +38,7 @@ class unit_animation:public animated<unit_frame>
|
|||
int matches(const display &disp,const gamemap::location& loc,const unit* my_unit) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> terrain_types;
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > terrain_types;
|
||||
std::vector<config> unit_filter_;
|
||||
std::vector<config> secondary_unit_filter_;
|
||||
std::vector<gamemap::location::DIRECTION> directions;
|
||||
|
|
|
@ -72,7 +72,7 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
|
|||
return;
|
||||
}
|
||||
|
||||
const gamemap::TERRAIN dst_terrain = map.get_terrain(b);
|
||||
const terrain_translation::TERRAIN_NUMBER dst_terrain = map.get_terrain(b);
|
||||
|
||||
const int acceleration = disp.turbo_speed();
|
||||
|
||||
|
|
|
@ -395,29 +395,36 @@ const t_string& unit_movement_type::name() const
|
|||
return res;
|
||||
}
|
||||
|
||||
int unit_movement_type::movement_cost(const gamemap& map,gamemap::TERRAIN terrain,int recurse_count) const
|
||||
int unit_movement_type::movement_cost(const gamemap& map,terrain_translation::TERRAIN_NUMBER terrain,int recurse_count) const
|
||||
{
|
||||
const int impassable = 10000000;
|
||||
|
||||
const std::map<gamemap::TERRAIN,int>::const_iterator i = moveCosts_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = moveCosts_.find(terrain);
|
||||
if(i != moveCosts_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
//if this is an alias, then select the best of all underlying terrains
|
||||
const std::string& underlying = map.underlying_mvt_terrain(terrain);
|
||||
if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
bool revert = (underlying[0] == '-'?true:false);
|
||||
//FIXME MdW cleanup
|
||||
// const std::string& underlying = map.underlying_mvt_terrain(terrain);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_mvt_terrain2(terrain);
|
||||
// if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
// bool revert = (underlying[0] == '-'?true:false);
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
if(recurse_count >= 100) {
|
||||
return impassable;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:impassable;
|
||||
for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
if(*i == '+') {
|
||||
// for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
// if(*i == '+') {
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == '-') {
|
||||
// } else if(*i == '-') {
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -429,7 +436,7 @@ int unit_movement_type::movement_cost(const gamemap& map,gamemap::TERRAIN terrai
|
|||
}
|
||||
}
|
||||
|
||||
moveCosts_.insert(std::pair<gamemap::TERRAIN,int>(terrain,ret_value));
|
||||
moveCosts_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -444,7 +451,8 @@ int unit_movement_type::movement_cost(const gamemap& map,gamemap::TERRAIN terrai
|
|||
return impassable;
|
||||
}
|
||||
|
||||
const std::string& id = map.get_terrain_info(underlying[0]).id();
|
||||
// const std::string& id = map.get_terrain_info(underlying[0]).id();
|
||||
const std::string& id = map.get_terrain_info(underlying.front()).id();
|
||||
|
||||
const std::string& val = (*movement_costs)[id];
|
||||
|
||||
|
@ -461,32 +469,32 @@ int unit_movement_type::movement_cost(const gamemap& map,gamemap::TERRAIN terrai
|
|||
res = impassable;
|
||||
}
|
||||
|
||||
moveCosts_.insert(std::pair<gamemap::TERRAIN,int>(terrain,res));
|
||||
moveCosts_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int unit_movement_type::defense_modifier(const gamemap& map,gamemap::TERRAIN terrain, int recurse_count) const
|
||||
int unit_movement_type::defense_modifier(const gamemap& map,terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
{
|
||||
const std::map<gamemap::TERRAIN,int>::const_iterator i = defenseMods_.find(terrain);
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = defenseMods_.find(terrain);
|
||||
if(i != defenseMods_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
//if this is an alias, then select the best of all underlying terrains
|
||||
const std::string& underlying = map.underlying_mvt_terrain(terrain);
|
||||
if(underlying.size() != 1 || underlying[0] != terrain) {
|
||||
bool revert = (underlying[0] == '-'?true:false);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_mvt_terrain2(terrain);
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS?true:false);
|
||||
if(recurse_count >= 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:100;
|
||||
for(std::string::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
if(*i == '+') {
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin(); i != underlying.end(); ++i) {
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == '-') {
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -501,7 +509,7 @@ int unit_movement_type::defense_modifier(const gamemap& map,gamemap::TERRAIN ter
|
|||
}
|
||||
}
|
||||
|
||||
defenseMods_.insert(std::pair<gamemap::TERRAIN,int>(terrain,ret_value));
|
||||
defenseMods_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -516,7 +524,7 @@ int unit_movement_type::defense_modifier(const gamemap& map,gamemap::TERRAIN ter
|
|||
return 100;
|
||||
}
|
||||
|
||||
const std::string& id = map.get_terrain_info(underlying[0]).id();
|
||||
const std::string& id = map.get_terrain_info(underlying.front()).id();
|
||||
const std::string& val = (*defense)[id];
|
||||
|
||||
if(val != "") {
|
||||
|
@ -532,7 +540,7 @@ int unit_movement_type::defense_modifier(const gamemap& map,gamemap::TERRAIN ter
|
|||
res = 50;
|
||||
}
|
||||
|
||||
defenseMods_.insert(std::pair<gamemap::TERRAIN,int>(terrain,res));
|
||||
defenseMods_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -602,11 +610,11 @@ void unit_movement_type::set_parent(const unit_movement_type* parent)
|
|||
parent_ = parent;
|
||||
}
|
||||
|
||||
const std::map<gamemap::TERRAIN,int>& unit_movement_type::movement_costs() const
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& unit_movement_type::movement_costs() const
|
||||
{
|
||||
return moveCosts_;
|
||||
}
|
||||
const std::map<gamemap::TERRAIN,int>& unit_movement_type::defense_mods() const
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& unit_movement_type::defense_mods() const
|
||||
{
|
||||
return defenseMods_;
|
||||
}
|
||||
|
|
|
@ -114,8 +114,8 @@ public:
|
|||
unit_movement_type(const config& cfg, const unit_movement_type* parent=NULL);
|
||||
|
||||
const t_string& name() const;
|
||||
int movement_cost(const gamemap& map, gamemap::TERRAIN terrain, int recurse_count=0) const;
|
||||
int defense_modifier(const gamemap& map, gamemap::TERRAIN terrain, int recurse_count=0) const;
|
||||
int movement_cost(const gamemap& map, terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
int defense_modifier(const gamemap& map, terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
int damage_against(const attack_type& attack) const;
|
||||
int resistance_against(const attack_type& attack) const;
|
||||
|
||||
|
@ -124,16 +124,16 @@ public:
|
|||
void set_parent(const unit_movement_type* parent);
|
||||
|
||||
bool is_flying() const;
|
||||
const std::map<gamemap::TERRAIN,int>& movement_costs() const;
|
||||
const std::map<gamemap::TERRAIN,int>& defense_mods() const;
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& movement_costs() const;
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& defense_mods() const;
|
||||
|
||||
const config& get_cfg() const;
|
||||
const unit_movement_type* get_parent() const;
|
||||
private:
|
||||
const config cfg_;
|
||||
|
||||
mutable std::map<gamemap::TERRAIN,int> moveCosts_;
|
||||
mutable std::map<gamemap::TERRAIN,int> defenseMods_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> moveCosts_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> defenseMods_;
|
||||
|
||||
const unit_movement_type* parent_;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#else
|
||||
# define VERSION "1.3-svn"
|
||||
# define VERSION "1.3-terrain-branch"
|
||||
# define WESNOTH_DEFAULT_SERVER "devsrv.wesnoth.org:14998"
|
||||
# define PACKAGE "wesnoth"
|
||||
# ifndef LOCALEDIR
|
||||
|
|
Loading…
Add table
Reference in a new issue