Added some typedefs for the terrain_translations and shorted the names a little.
Added some extra comment to terrain_translation.hpp. Applied these changes to all users and did some whitespace enhancement. Various minor code cleanups while busy.
This commit is contained in:
parent
a7714f80ff
commit
c347e9790b
46 changed files with 815 additions and 985 deletions
|
@ -4,11 +4,8 @@ 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
|
||||
|
||||
* split the builder specific terrain letters
|
||||
|
||||
* Make * sytanx work in builder rules
|
||||
started this but is tricker than expected
|
||||
|
||||
|
@ -22,12 +19,7 @@ Main TODO list is here
|
|||
* convert the aliases to read the new list
|
||||
conversion done but not fully tested yet
|
||||
|
||||
* Make Wesnoth work again it doesn't
|
||||
* all users of "map_data" should be checked, busy
|
||||
* Help systems is broken DONE BUT NOT TESTED
|
||||
* Load / save is DONE BUT NOT TESTED
|
||||
* Random map generators are broken, compiles but doesn't work,
|
||||
FIXED BUT NOT TESTED, NOTE the code looks ugly with the calls
|
||||
to terrain_translation, this needs to be fixed after the
|
||||
final conversion
|
||||
* cavegen works again, can be tested with Httt scepter of fire
|
||||
* terrain.cfg and terrain-graphics.cfg need to be translated
|
||||
to the new system
|
||||
|
||||
* test everything
|
||||
|
|
66
TODO
66
TODO
|
@ -1,39 +1,33 @@
|
|||
src/builder.cpp:27://FIXME MdW this file is filled with debug output and should be cleaned
|
||||
src/builder.cpp:785: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:819: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:934://FIXME MdW keep or remove this part, at least disable
|
||||
src/builder.cpp:987: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:1060: //FIXME MdW remove debug code
|
||||
src/cavegen.cpp:112: out << terrain_translation::write_letter(map_[x][y]); //FIXME MdW, should this be done by the map converter??
|
||||
src/display.cpp:1692: //FIXME MdW cleanup but why was this coded like it was WHY and INT instead of CHAR????
|
||||
src/display.cpp:1705: tiles[i] = 0; //FIXME MdW we should define an invalid terrain (prob. 0)
|
||||
src/builder.cpp:781: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:821: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:936://FIXME MdW keep or remove this part, at least disable
|
||||
src/builder.cpp:989: //FIXME MdW remove debug code from this function
|
||||
src/builder.cpp:1063: //FIXME MdW remove debug code
|
||||
src/cavegen.cpp:110: out << t_translation::write_letter(map_[x][y]); //FIXME MdW, should this be done by the map converter??
|
||||
src/display.cpp:1694: // FIXME MdW might be nice to rewrite as a vector
|
||||
src/game.cpp:1936://FIXME MdW this catch is disabled in order to trace memory overflows.
|
||||
src/game_events.cpp:1163: if(terrain_type.size() > 0) { //FIXME MdW we need a proper way to set and invalid terrain
|
||||
src/game_events.cpp:1780: const terrain_translation::TERRAIN_NUMBER c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
src/help.cpp:1458: //FIXME MdW the changes here seem to compile but they have to
|
||||
src/map.cpp:315: // FIXME MdW think about this part
|
||||
src/map.cpp:362: //FIXME MdW remove debug
|
||||
src/map.cpp:455: set_terrain(location(x2,y2),terrain[0]); //FIXME MdW tag is this valid?? (should be but test)
|
||||
src/map.cpp:585: // FIXME MdW rewrote the old part, but haven't looked at what it should do
|
||||
src/mapgen.cpp:378://FIXME MdW test this modification
|
||||
src/map.hpp:198: //The terrain string with TERRAIN_NUMBER should be make FIXME MdW
|
||||
src/game_events.cpp:1164: if(terrain_type.size() > 0) { //FIXME MdW we need a proper way to set and invalid terrain
|
||||
src/game_events.cpp:1783: const t_translation::t_letter c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
src/help.cpp:1459: //FIXME MdW the changes here seem to compile but they have to
|
||||
src/map.cpp:317: // FIXME MdW think about this part
|
||||
src/map.cpp:364: //FIXME MdW remove debug
|
||||
src/map.cpp:461: set_terrain(location(x2,y2),terrain[0]); //FIXME MdW tag is this valid?? (should be but test)
|
||||
src/map.cpp:597: // FIXME MdW rewrote the old part, but haven't looked at what it should do
|
||||
src/mapgen.cpp:380://FIXME MdW test this modification
|
||||
src/preferences.cpp:79: t_translation::t_list terrain; //FIXME MdW geen =
|
||||
src/terrain.cpp:21:#include "wassert.hpp" // FIXME MdW only used for the terrain initalization
|
||||
src/terrain.cpp:45: number_ = terrain_translation::read_letter(cfg["char"]); // FIXME MdW tag should read old format
|
||||
src/terrain.cpp:54: //FIXME MdW this temp hack should be removed
|
||||
src/terrain.cpp:74: terrain_translation::read_list(cfg["aliasof"]); //FIXME MdW the aliasses should also be converted to new format
|
||||
src/terrain.hpp:37: //FIXME MdW maybe reinstall the letter later again after debugging everything
|
||||
src/terrain_translation.cpp:63: static int map_format_ = 1; //FIXME MdW this should be initialized to 0
|
||||
src/terrain_translation.cpp:220: std::vector<std::vector<TERRAIN_NUMBER> > result(1);//FIXME MdW find a way to initialize and empty vector
|
||||
src/terrain_translation.cpp:262: //FIXME MdW remove the debug code
|
||||
src/terrain_translation.cpp:295: //FIXME MdW remove debug code
|
||||
src/terrain_translation.cpp:418: //FIXME MdW remove the debug code
|
||||
src/terrain_translation.cpp:460: //FIXME MdW remove debug code
|
||||
src/terrain_translation.cpp:505: std::vector<TERRAIN_NUMBER> result(1); //FIXME MdW find a way to initialize and empty vector
|
||||
src/terrain_translation.cpp:564: //FIXME MdW there should be tested how slow this
|
||||
src/terrain_translation.cpp:731://FIXME MdW this code is obsolete as soon as the terrain map is converted
|
||||
src/terrain_translation.cpp:804://FIXME MdW this code is ready and tested only the map format needs to be documentated
|
||||
src/terrain_translation.cpp:845: //skip the following newlines FIXME MdW this should be documented "aa<CR><CR>bb<CR><CR><CR>" is now valid
|
||||
src/terrain_translation.cpp:890: //FIXME MdW remove the debug code
|
||||
src/terrain_translation.cpp:908: //FIXME MdW remove debug code
|
||||
src/terrain_translation.hpp:73: //FIXME MdW we throw nobody catches...
|
||||
src/terrain_translation.hpp:131: * FIXME MdW: remove separated before merging, this is only available for the transition phase.
|
||||
src/terrain_translation.cpp:197: t_map result(1);//FIXME MdW find a way to initialize and empty vector
|
||||
src/terrain_translation.cpp:253: //skip the following newlines FIXME MdW this should be documented "aa<CR><CR>bb<CR><CR><CR>" is now valid
|
||||
src/terrain_translation.cpp:406: t_list result(1); //FIXME MdW find a way to initialize and empty vector
|
||||
src/terrain_translation.cpp:463: //FIXME MdW there should be tested how slow this
|
||||
src/terrain_translation.cpp:490: letter[0] = ((terrain & 0xFF000000) >> 24); //FIXME MdW might need an UL behind the masks !!!
|
||||
src/terrain_translation.cpp:547://FIXME MdW, there are some optimizations which can be done here
|
||||
src/terrain_translation.cpp:558: //FIXME MdW add documentation
|
||||
src/terrain_translation.cpp:578://FIXME MdW, there are some optimizations which can be done here
|
||||
src/terrain_translation.cpp:580:// FIXME MdW remove debug code
|
||||
src/terrain_translation.cpp:718: TERRAIN_LETTER terrain = str[0]; //FIXME MdW rename terrain to letter
|
||||
src/terrain_translation.cpp:730://FIXME MdW this code is ready and tested only the map format needs to be documentated
|
||||
src/terrain_translation.cpp:770: //skip the following newlines FIXME MdW this should be documented "aa<CR><CR>bb<CR><CR><CR>" is now valid
|
||||
src/terrain_translation.hpp:66: extern const t_letter NOT; // FIXME MdW remove once no longer used in the builder
|
||||
src/terrain_translation.hpp:71: //FIXME MdW we throw nobody catches...
|
||||
|
|
|
@ -1824,7 +1824,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 terrain_translation::TERRAIN_NUMBER terrain = map[step->x][step->y];
|
||||
const t_translation::t_letter terrain = map[step->x][step->y];
|
||||
|
||||
const unit_map::const_iterator enemy_unit = units.find(*step);
|
||||
|
||||
|
|
12
src/ai.cpp
12
src/ai.cpp
|
@ -75,7 +75,7 @@ protected:
|
|||
const location& src = range.first->second;
|
||||
const unit_map::const_iterator un = get_info().units.find(src);
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = get_info().map.get_terrain(dst);
|
||||
const t_translation::t_letter terrain = get_info().map.get_terrain(dst);
|
||||
|
||||
const int chance_to_hit = un->second.defense_modifier(terrain);
|
||||
|
||||
|
@ -1440,8 +1440,12 @@ 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<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) {
|
||||
const std::map<t_translation::t_letter, size_t>& terrain =
|
||||
map_.get_weighted_terrain_frequencies();
|
||||
|
||||
for(std::map<t_translation::t_letter, 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 +1957,7 @@ bool ai::leader_can_reach_keep() const
|
|||
|
||||
int ai::rate_terrain(const unit& u, const gamemap::location& loc)
|
||||
{
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_.get_terrain(loc);
|
||||
const t_translation::t_letter 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,
|
||||
terrain_translation::TERRAIN_NUMBER t)
|
||||
t_translation::t_letter t)
|
||||
: attacker(a),defender(d),terrain(t),weapon(-1)
|
||||
{}
|
||||
|
||||
const gamemap::location attacker;
|
||||
const gamemap::location defender;
|
||||
const terrain_translation::TERRAIN_NUMBER terrain;
|
||||
const t_translation::t_letter terrain;
|
||||
int weapon;
|
||||
};
|
||||
|
||||
|
@ -615,7 +615,7 @@ double ai::power_projection(const gamemap::location& loc, const move_map& dstsr
|
|||
continue;
|
||||
}
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_[locs[i].x][locs[i].y];
|
||||
const t_translation::t_letter 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 terrain_translation::TERRAIN_NUMBER terrain = map_[loc.x][loc.y];
|
||||
const t_translation::t_letter 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<terrain_translation::TERRAIN_NUMBER,int> move_type_;
|
||||
// mutable std::map<t_translation::t_letter,int> move_type_;
|
||||
const gamemap::location loc_;
|
||||
const ai::move_map dstsrc_, enemy_dstsrc_;
|
||||
const bool avoid_enemies_;
|
||||
|
|
120
src/builder.cpp
120
src/builder.cpp
|
@ -25,8 +25,8 @@
|
|||
|
||||
#define ERR_NG LOG_STREAM(err, engine)
|
||||
//FIXME MdW this file is filled with debug output and should be cleaned
|
||||
//define DEBUG_NG LOG_STREAM(info, engine)
|
||||
#define DEBUG_NG LOG_STREAM(err, engine)
|
||||
#define DEBUG_NG LOG_STREAM(info, engine)
|
||||
//define DEBUG_NG LOG_STREAM(err, engine)
|
||||
|
||||
const int terrain_builder::rule_image::TILEWIDTH = 72;
|
||||
const int terrain_builder::rule_image::UNITPOS = 36 + 18;
|
||||
|
@ -532,7 +532,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::vector<terrain_translation::TERRAIN_NUMBER>& type, const config& global_images)
|
||||
const t_translation::t_list& type, const config& global_images)
|
||||
{
|
||||
if(constraints.find(loc) == constraints.end()) {
|
||||
//the terrain at the current location did not exist, so create it
|
||||
|
@ -552,7 +552,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,
|
||||
terrain_translation::read_list(cfg["type"], -1, terrain_translation::TFORMAT_STRING ),
|
||||
t_translation::read_list(cfg["type"], -1, t_translation::T_FORMAT_STRING ),
|
||||
global_images);
|
||||
|
||||
terrain_constraint& constraint = constraints[loc];
|
||||
|
@ -577,8 +577,7 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
|||
const config& global_images)
|
||||
{
|
||||
|
||||
const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > map =
|
||||
terrain_translation::read_builder_map(mapstring);
|
||||
const t_translation::t_map map = t_translation::read_builder_map(mapstring);
|
||||
|
||||
// if there is an empty map leave directly
|
||||
// determine after conversion, since a non empty
|
||||
|
@ -587,20 +586,20 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
|||
return;
|
||||
}
|
||||
|
||||
int lineno = (map[0][0] == terrain_translation::NONE_TERRAIN) ? 1 : 0;
|
||||
int lineno = (map[0][0] == t_translation::NONE_TERRAIN) ? 1 : 0;
|
||||
int x = lineno;
|
||||
int y = 0;
|
||||
|
||||
for(size_t y_off = 0; y_off < map.size(); ++y_off) {
|
||||
for(size_t x_off = x; x_off < map[y_off].size(); ++x_off) {
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map[y_off][x_off];
|
||||
const int anchor = terrain_translation::builder_get_number(terrain);
|
||||
const t_translation::t_letter terrain = map[y_off][x_off];
|
||||
const int anchor = t_translation::cast_to_builder_number(terrain);
|
||||
|
||||
// std::cerr << "x = " << x << " y = " << y << " lineno = " << lineno
|
||||
// << " terrain = " << terrain << " anchor = " << anchor << "\n";
|
||||
|
||||
if(terrain == terrain_translation::TB_DOT) {
|
||||
if(terrain == t_translation::TB_DOT) {
|
||||
// Dots are simple placeholders, which do not
|
||||
// represent actual terrains.
|
||||
} else if (anchor != 0 ) {
|
||||
|
@ -609,12 +608,12 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
|||
// we have a rule, we filter for validity here
|
||||
// for now only one valid value but might change
|
||||
// in the future
|
||||
wassert(terrain == terrain_translation::TB_STAR);
|
||||
wassert(terrain == t_translation::TB_STAR);
|
||||
|
||||
const gamemap::location loc(x, y);
|
||||
//add_constrain wants a terrain vector, this might change in the
|
||||
//future or an other function which does this trick but keep it for now
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> types(1, terrain);
|
||||
const t_translation::t_list types(1, terrain);
|
||||
|
||||
add_constraints(br.constraints, loc, types, global_images);
|
||||
}
|
||||
|
@ -758,7 +757,7 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
constraint != rule->second.constraints.end(); ++constraint) {
|
||||
|
||||
std::cerr << ">>>> New constraint: location = (" << constraint->second.loc
|
||||
<< "), terrain types = '" << terrain_translation::write_list(constraint->second.terrain_types) << "'\n";
|
||||
<< "), terrain types = '" << t_translation::write_list(constraint->second.terrain_types) << "'\n";
|
||||
|
||||
std::vector<std::string>::const_iterator flag;
|
||||
|
||||
|
@ -776,58 +775,52 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
|
||||
}
|
||||
|
||||
bool terrain_builder::terrain_matches(terrain_translation::TERRAIN_NUMBER letter,
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> &terrains)
|
||||
bool terrain_builder::terrain_matches(t_translation::t_letter letter,
|
||||
const t_translation::t_list &terrains)
|
||||
{
|
||||
bool negative = false;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor;
|
||||
|
||||
//FIXME MdW remove debug code from this function
|
||||
// DEBUG_NG << "Terrain matches:\n";
|
||||
// DEBUG_NG << ">> terrain = '" << terrain_translation::write_letter(letter) << "'\n";
|
||||
// DEBUG_NG << ">> match list = '" << terrain_translation::write_list(terrains) << "'\n";
|
||||
std::cerr << "Terrain matches:\n";
|
||||
std::cerr << ">> terrain = '" << terrain_translation::write_letter(letter) << "'\n";
|
||||
std::cerr << ">> match list = '" << terrain_translation::write_list(terrains) << "'\n";
|
||||
DEBUG_NG << "Terrain matches:\n";
|
||||
DEBUG_NG << ">> terrain = '" << t_translation::write_letter(letter) << "'\n";
|
||||
DEBUG_NG << ">> match list = '" << t_translation::write_list(terrains) << "'\n";
|
||||
|
||||
if(terrains.empty()) {
|
||||
DEBUG_NG << ">> true, empty list\n";
|
||||
return true;
|
||||
}
|
||||
for(itor = terrains.begin(); itor != terrains.end(); ++itor) {
|
||||
if(*itor == terrain_translation::TB_STAR) {
|
||||
// DEBUG_NG << ">> true, STAR char found\n";
|
||||
std::cerr << ">> true, STAR char found\n";
|
||||
bool negative = false;
|
||||
t_translation::t_list::const_iterator itor = terrains.begin();
|
||||
|
||||
for(; itor != terrains.end(); ++itor) {
|
||||
if(*itor == t_translation::TB_STAR) {
|
||||
DEBUG_NG << ">> true, STAR char found\n";
|
||||
return true;
|
||||
}
|
||||
if(*itor == terrain_translation::NOT) {
|
||||
// DEBUG_NG << ">> NOT char found\n";
|
||||
std::cerr << ">> NOT char found\n";
|
||||
if(*itor == t_translation::NOT) {
|
||||
DEBUG_NG << ">> NOT char found\n";
|
||||
negative = true;
|
||||
continue;
|
||||
}
|
||||
// if(*itor == letter) {
|
||||
if(terrain_translation::terrain_matches(*itor, letter)) {
|
||||
if(t_translation::terrain_matches(*itor, letter)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(itor == terrains.end()) {
|
||||
// DEBUG_NG << ">> " << negative << ", itor at end()\n";
|
||||
std::cerr << ">> " << negative << ", itor at end()\n";
|
||||
DEBUG_NG << ">> " << negative << ", itor at end()\n";
|
||||
return negative;
|
||||
}
|
||||
|
||||
// DEBUG_NG << !negative << ">> itor in string\n";
|
||||
std::cerr << !negative << ">> itor in string\n";
|
||||
DEBUG_NG << !negative << ">> itor in string\n";
|
||||
return !negative;
|
||||
}
|
||||
|
||||
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule, const gamemap::location &loc, int rule_index, bool check_loc)
|
||||
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
const gamemap::location &loc, int rule_index, bool check_loc)
|
||||
{
|
||||
//FIXME MdW remove debug code from this function
|
||||
DEBUG_NG << "testing rule " << rule_index << " at " << loc.x << "," << loc.y << "\n";
|
||||
DEBUG_NG << ">> terrain ='" << terrain_translation::write_letter(map_.get_terrain(loc)) << "'\n";
|
||||
DEBUG_NG << ">> terrain ='" << t_translation::write_letter(map_.get_terrain(loc)) << "'\n";
|
||||
|
||||
if(rule.location_constraints.valid() && rule.location_constraints != loc) {
|
||||
DEBUG_NG << ">> false, valid constrains, but invalid location\n";
|
||||
|
@ -840,7 +833,7 @@ bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule, c
|
|||
for(constraint_set::const_iterator cons = rule.constraints.begin();
|
||||
cons != rule.constraints.end(); ++cons) {
|
||||
|
||||
DEBUG_NG << ">>>> terrain types ='" << terrain_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain types ='" << t_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
|
||||
// translated location
|
||||
const gamemap::location tloc = loc + cons->second.loc;
|
||||
|
@ -877,8 +870,8 @@ bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule, c
|
|||
|
||||
const gamemap::location tloc = loc + cons->second.loc;
|
||||
DEBUG_NG << ">>>> second location " << tloc.x << "," << tloc.y << "\n";
|
||||
DEBUG_NG << ">>>> terrain = '" << terrain_translation::write_letter(map_.get_terrain(tloc)) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain types = '" << terrain_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain = '" << t_translation::write_letter(map_.get_terrain(tloc)) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain types = '" << t_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
|
||||
if(!tile_map_.on_map(tloc)) {
|
||||
DEBUG_NG << ">>>> false, tloc not on map\n";
|
||||
|
@ -944,7 +937,7 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, con
|
|||
#if 1
|
||||
|
||||
DEBUG_NG << "Appy rule at " << loc.x << "," << loc.y << "\n";
|
||||
DEBUG_NG << ">> terrain = '" << terrain_translation::write_letter(map_.get_terrain(loc)) << "'\n";
|
||||
DEBUG_NG << ">> terrain = '" << t_translation::write_letter(map_.get_terrain(loc)) << "'\n";
|
||||
|
||||
|
||||
for(constraint_set::const_iterator constraint = rule.constraints.begin();
|
||||
|
@ -953,9 +946,9 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, con
|
|||
const gamemap::location tloc = loc + constraint->second.loc;
|
||||
|
||||
DEBUG_NG << ">>>> second location " << tloc.x << "," << tloc.y << "\n";
|
||||
DEBUG_NG << ">>>> terrain = '" << terrain_translation::write_letter(map_.get_terrain(tloc)) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain = '" << t_translation::write_letter(map_.get_terrain(tloc)) << "'\n";
|
||||
|
||||
DEBUG_NG << ">>>> terrain types = '" << terrain_translation::write_list(constraint->second.terrain_types) << "'\n";
|
||||
DEBUG_NG << ">>>> terrain types = '" << t_translation::write_list(constraint->second.terrain_types) << "'\n";
|
||||
|
||||
std::vector<std::string>::const_iterator flag;
|
||||
for(flag = constraint->second.set_flag.begin(); flag != constraint->second.set_flag.end(); ++flag) {
|
||||
|
@ -991,21 +984,21 @@ 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::vector<terrain_translation::TERRAIN_NUMBER>& types = constraint.terrain_types;
|
||||
const t_translation::t_list& types = constraint.terrain_types;
|
||||
|
||||
//FIXME MdW remove debug code from this function
|
||||
DEBUG_NG << "Constraint size:\n";
|
||||
DEBUG_NG << ">>types = '" << terrain_translation::write_list(types) << "'\n";
|
||||
DEBUG_NG << ">>types = '" << t_translation::write_list(types) << "'\n";
|
||||
|
||||
if(types.empty()) {
|
||||
DEBUG_NG << ">> empty types\n";
|
||||
return INT_MAX;
|
||||
}
|
||||
if(types.front() == terrain_translation::NOT) {
|
||||
if(types.front() == t_translation::NOT) {
|
||||
DEBUG_NG << ">> front == NOT\n";
|
||||
return INT_MAX;
|
||||
}
|
||||
if(std::find(types.begin(), types.end(), terrain_translation::TB_STAR) != types.end()) {
|
||||
if(std::find(types.begin(), types.end(), t_translation::TB_STAR) != types.end()) {
|
||||
DEBUG_NG << ">> STAR not found\n";
|
||||
return INT_MAX;
|
||||
}
|
||||
|
@ -1022,15 +1015,14 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
for(i = 0; i < 6; ++i) {
|
||||
DEBUG_NG << ">>>> run " << i << " of 6\n";
|
||||
if(rule.constraints.find(adj[i]) != rule.constraints.end()) {
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& atypes =
|
||||
const t_translation::t_list& atypes =
|
||||
rule.constraints.find(adj[i])->second.terrain_types;
|
||||
|
||||
DEBUG_NG << ">>>> evaluating '" << terrain_translation::write_list(atypes) << "'\n";
|
||||
DEBUG_NG << ">>>> evaluating '" << t_translation::write_list(atypes) << "'\n";
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor =
|
||||
types.begin();
|
||||
t_translation::t_list::const_iterator itor = types.begin();
|
||||
for(; itor != types.end(); ++itor) {
|
||||
DEBUG_NG << ">>>>>> try to match '" << terrain_translation::write_letter(*itor) << "'\n";
|
||||
DEBUG_NG << ">>>>>> try to match '" << t_translation::write_letter(*itor) << "'\n";
|
||||
if(!terrain_matches(*itor, atypes)) {
|
||||
DEBUG_NG << ">>>>>> border found breaking out of loop\n";
|
||||
border = true;
|
||||
|
@ -1047,15 +1039,15 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
int constraint_size = 0;
|
||||
|
||||
DEBUG_NG << ">> Start to count\n";
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator itor = types.begin();
|
||||
for(t_translation::t_list::const_iterator itor = types.begin();
|
||||
itor != types.end(); ++itor) {
|
||||
if(border) {
|
||||
constraint_size += terrain_by_type_border_[*itor].size();
|
||||
DEBUG_NG << ">>>> terrain " << terrain_translation::write_letter(*itor)
|
||||
DEBUG_NG << ">>>> terrain " << t_translation::write_letter(*itor)
|
||||
<< "(" << *itor <<") border found size = " << constraint_size << "\n;";
|
||||
} else {
|
||||
constraint_size += terrain_by_type_[*itor].size();
|
||||
DEBUG_NG << ">>>> terrain " << terrain_translation::write_letter(*itor)
|
||||
DEBUG_NG << ">>>> terrain " << t_translation::write_letter(*itor)
|
||||
<< "(" << *itor <<") no border found size = " << constraint_size << "\n;";
|
||||
}
|
||||
}
|
||||
|
@ -1075,7 +1067,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 terrain_translation::TERRAIN_NUMBER t = map_.get_terrain(loc);
|
||||
const t_translation::t_letter t = map_.get_terrain(loc);
|
||||
|
||||
terrain_by_type_[t].push_back(loc);
|
||||
|
||||
|
@ -1151,7 +1143,7 @@ void terrain_builder::build_terrains()
|
|||
}
|
||||
}
|
||||
|
||||
util::array<std::vector<terrain_translation::TERRAIN_NUMBER>,7> adjacent_types;
|
||||
util::array<t_translation::t_list, 7> adjacent_types;
|
||||
|
||||
if(biggest_constraint_adjacent > 0) {
|
||||
gamemap::location loc[7];
|
||||
|
@ -1162,23 +1154,25 @@ void terrain_builder::build_terrains()
|
|||
constraint_set::const_iterator cons = rule->second.constraints.find(loc[i]) ;
|
||||
if(cons != rule->second.constraints.end()) {
|
||||
DEBUG_NG << ">>>> " << i << ", found '"
|
||||
<< terrain_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
<< t_translation::write_list(cons->second.terrain_types) << "'\n";
|
||||
adjacent_types[i] = cons->second.terrain_types;
|
||||
} else {
|
||||
DEBUG_NG << ">>>> " << i << ", nothing found\n";
|
||||
adjacent_types[i] = terrain_translation::read_list("", -1, terrain_translation::TFORMAT_STRING);
|
||||
adjacent_types[i] = t_translation::read_list("", -1, t_translation::T_FORMAT_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(smallest_constraint_size != INT_MAX) {
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> &types = smallest_constraint->second.terrain_types;
|
||||
const t_translation::t_list& types = smallest_constraint->second.terrain_types;
|
||||
const gamemap::location loc = smallest_constraint->second.loc;
|
||||
const gamemap::location aloc = constraint_most_adjacents->second.loc;
|
||||
|
||||
DEBUG_NG << ">> smallest_constraint_size\n";
|
||||
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator c = types.begin(); c != types.end(); ++c) {
|
||||
for(t_translation::t_list::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];
|
||||
|
@ -1194,7 +1188,7 @@ void terrain_builder::build_terrains()
|
|||
if(!tile_map_.on_map(pos))
|
||||
continue;
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER *adjacents = tile_map_[pos].adjacents;
|
||||
const t_translation::t_letter *adjacents = tile_map_[pos].adjacents;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 7; ++i) {
|
||||
|
|
|
@ -209,7 +209,7 @@ public:
|
|||
terrain_constraint(gamemap::location loc) : loc(loc) {};
|
||||
|
||||
gamemap::location loc;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain_types;
|
||||
t_translation::t_list 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.
|
||||
*/
|
||||
terrain_translation::TERRAIN_NUMBER adjacents[7];
|
||||
t_translation::t_letter adjacents[7];
|
||||
|
||||
};
|
||||
|
||||
|
@ -542,7 +542,7 @@ private:
|
|||
* describing rule-global images.
|
||||
*/
|
||||
void add_constraints(constraint_set& constraints,
|
||||
const gamemap::location &loc, const std::vector<terrain_translation::TERRAIN_NUMBER>& type,
|
||||
const gamemap::location &loc, const t_translation::t_list& type,
|
||||
const config& global_images);
|
||||
|
||||
/**
|
||||
|
@ -616,7 +616,7 @@ private:
|
|||
*
|
||||
* @return returns true if "letter" matches the list, false if it does not.
|
||||
*/
|
||||
bool terrain_matches(terrain_translation::TERRAIN_NUMBER letter, const std::vector<terrain_translation::TERRAIN_NUMBER> &terrains);
|
||||
bool terrain_matches(t_translation::t_letter letter, const t_translation::t_list &terrains);
|
||||
|
||||
/**
|
||||
* Checks whether a rule matches a given location in the map.
|
||||
|
@ -705,7 +705,7 @@ private:
|
|||
/**
|
||||
* Shorthand typedef for a map associating a list of locations to a terrain type.
|
||||
*/
|
||||
typedef std::map<terrain_translation::TERRAIN_NUMBER, std::vector<gamemap::location> > terrain_by_type_map;
|
||||
typedef std::map<t_translation::t_letter, std::vector<gamemap::location> > terrain_by_type_map;
|
||||
|
||||
/**
|
||||
* A map representing all locations whose terrain is of a given type.
|
||||
|
|
|
@ -22,12 +22,10 @@
|
|||
|
||||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
|
||||
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)
|
||||
cave_map_generator::cave_map_generator(const config* cfg) : wall_(t_translation::CAVE_WALL),
|
||||
clear_(t_translation::CAVE), village_(t_translation::UNDERGROUND_VILLAGE),
|
||||
castle_(t_translation::DWARVEN_CASTLE), cfg_(cfg), width_(50), height_(50),
|
||||
village_density_(0), flipx_(false), flipy_(false)
|
||||
{
|
||||
if(cfg_ == NULL) {
|
||||
static const config default_cfg;
|
||||
|
@ -81,7 +79,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<terrain_translation::TERRAIN_NUMBER> >(width_,std::vector<terrain_translation::TERRAIN_NUMBER>(height_,wall_));
|
||||
map_ = t_translation::t_map(width_, t_translation::t_list(height_, wall_));
|
||||
chambers_.clear();
|
||||
passages_.clear();
|
||||
|
||||
|
@ -109,7 +107,7 @@ config cave_map_generator::create_scenario(const std::vector<std::string>& /*arg
|
|||
std::stringstream out;
|
||||
for(size_t y = 0; y != height_; ++y) {
|
||||
for(size_t x = 0; x != width_; ++x) {
|
||||
out << terrain_translation::write_letter(map_[x][y]); //FIXME MdW, should this be done by the map converter??
|
||||
out << t_translation::write_letter(map_[x][y]); //FIXME MdW, should this be done by the map converter??
|
||||
}
|
||||
|
||||
out << "\n";
|
||||
|
@ -282,14 +280,15 @@ 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<terrain_translation::TERRAIN_NUMBER> >& mapdata, terrain_translation::TERRAIN_NUMBER wall, double laziness, size_t windiness)
|
||||
: map_(mapdata), wall_(wall), laziness_(laziness), windiness_(windiness)
|
||||
passage_path_calculator(const t_translation::t_map& mapdata,
|
||||
t_translation::t_letter 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<terrain_translation::TERRAIN_NUMBER> >& map_;
|
||||
terrain_translation::TERRAIN_NUMBER wall_;
|
||||
const t_translation::t_map& map_;
|
||||
t_translation::t_letter wall_;
|
||||
double laziness_;
|
||||
size_t windiness_;
|
||||
};
|
||||
|
@ -344,14 +343,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, terrain_translation::TERRAIN_NUMBER t)
|
||||
void cave_map_generator::set_terrain(gamemap::location loc, t_translation::t_letter t)
|
||||
{
|
||||
if(on_board(loc)) {
|
||||
if(t == clear_ && (rand()%1000) < (long)village_density_) {
|
||||
t = village_;
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER& c = map_[loc.x][loc.y];
|
||||
t_translation::t_letter& c = map_[loc.x][loc.y];
|
||||
if(c == clear_ || c == wall_ || c == village_) {
|
||||
c = t;
|
||||
}
|
||||
|
@ -361,7 +360,7 @@ void cave_map_generator::set_terrain(gamemap::location loc, terrain_translation:
|
|||
void cave_map_generator::place_castle(const std::string& side, gamemap::location loc)
|
||||
{
|
||||
if(side != "") {
|
||||
set_terrain(loc, terrain_translation::read_letter(side, terrain_translation::TFORMAT_AUTO));
|
||||
set_terrain(loc, t_translation::read_letter(side, t_translation::T_FORMAT_AUTO));
|
||||
}
|
||||
|
||||
gamemap::location adj[6];
|
||||
|
|
|
@ -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, terrain_translation::TERRAIN_NUMBER t);
|
||||
void set_terrain(gamemap::location loc, t_translation::t_letter t);
|
||||
void place_castle(const std::string& side, gamemap::location loc);
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER wall_, clear_, village_, castle_;
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > map_;
|
||||
t_translation::t_letter wall_, clear_, village_, castle_;
|
||||
t_translation::t_map map_;
|
||||
|
||||
std::map<std::string,size_t> chamber_ids_;
|
||||
std::vector<chamber> chambers_;
|
||||
|
|
|
@ -304,15 +304,8 @@ private:
|
|||
const std::vector<config*>* summaries_;
|
||||
int index_;
|
||||
std::map<std::string,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()) {
|
||||
|
|
|
@ -1370,7 +1370,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);
|
||||
terrain_translation::TERRAIN_NUMBER terrain = terrain_translation::VOID_TERRAIN;
|
||||
t_translation::t_letter terrain = t_translation::VOID_TERRAIN;
|
||||
|
||||
if(!is_shrouded) {
|
||||
terrain = map_.get_terrain(loc);
|
||||
|
@ -1689,26 +1689,26 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
|
||||
gamemap::location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
//FIXME MdW cleanup but why was this coded like it was WHY and INT instead of CHAR????
|
||||
// int tiles[6];
|
||||
// static const int terrain_types[] = { terrain_translation::FOGGED, terrain_translation::VOID_TERRAIN, 0 };
|
||||
terrain_translation::TERRAIN_NUMBER tiles[6];
|
||||
static const terrain_translation::TERRAIN_NUMBER terrain_types[] =
|
||||
{ terrain_translation::FOGGED, terrain_translation::VOID_TERRAIN, 0 };
|
||||
t_translation::t_letter tiles[6];
|
||||
|
||||
// FIXME MdW might be nice to rewrite as a vector
|
||||
static const t_translation::t_letter terrain_types[] =
|
||||
{ t_translation::FOGGED, t_translation::VOID_TERRAIN, 0 };
|
||||
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
if(shrouded(adjacent[i].x,adjacent[i].y)) {
|
||||
tiles[i] = terrain_translation::VOID_TERRAIN;
|
||||
tiles[i] = t_translation::VOID_TERRAIN;
|
||||
} else if(!fogged(loc.x,loc.y) && fogged(adjacent[i].x,adjacent[i].y)) {
|
||||
tiles[i] = terrain_translation::FOGGED;
|
||||
tiles[i] = t_translation::FOGGED;
|
||||
} else {
|
||||
tiles[i] = 0; //FIXME MdW we should define an invalid terrain (prob. 0)
|
||||
tiles[i] = t_translation::NONE_TERRAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for(const int * terrain = terrain_types; *terrain != 0; terrain ++) {
|
||||
for(const terrain_translation::TERRAIN_NUMBER * terrain = terrain_types; *terrain != 0; terrain ++) {
|
||||
for(const t_translation::t_letter *terrain = terrain_types;
|
||||
*terrain != 0; terrain ++) {
|
||||
|
||||
//find somewhere that doesn't have overlap to use as a starting point
|
||||
int start;
|
||||
for(start = 0; start != 6; ++start) {
|
||||
|
@ -1808,7 +1808,7 @@ std::vector<surface> display::get_terrain_images(int x, int y, image::TYPE image
|
|||
return res;
|
||||
}
|
||||
|
||||
surface display::get_flag(terrain_translation::TERRAIN_NUMBER terrain, int x, int y)
|
||||
surface display::get_flag(t_translation::t_letter terrain, int x, int y)
|
||||
{
|
||||
const bool village = map_.is_village(terrain);
|
||||
if(!village) {
|
||||
|
|
|
@ -278,7 +278,7 @@ public:
|
|||
|
||||
//functions used in the editor.
|
||||
//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);
|
||||
t_translation::t_letter 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(terrain_translation::TERRAIN_NUMBER, int x, int y);
|
||||
surface get_flag(t_translation::t_letter, int x, int y);
|
||||
|
||||
//this surface must be freed by the caller
|
||||
surface get_minimap(int w, int h);
|
||||
|
|
|
@ -156,8 +156,8 @@ config map_editor::hotkeys_;
|
|||
// Do not init the l_button_func_ to DRAW, since it should be changed in
|
||||
// the constructor to update the report the first time.
|
||||
map_editor::LEFT_BUTTON_FUNC map_editor::l_button_func_ = PASTE;
|
||||
terrain_translation::TERRAIN_NUMBER map_editor::old_fg_terrain_;
|
||||
terrain_translation::TERRAIN_NUMBER map_editor::old_bg_terrain_;
|
||||
t_translation::t_letter map_editor::old_fg_terrain_;
|
||||
t_translation::t_letter map_editor::old_bg_terrain_;
|
||||
int map_editor::old_brush_size_;
|
||||
|
||||
map_editor::map_editor(display &gui, gamemap &map, config &theme, config &game_config)
|
||||
|
@ -393,7 +393,7 @@ void map_editor::left_click(const gamemap::location hex_clicked) {
|
|||
}
|
||||
}
|
||||
else if (key_[SDLK_RCTRL] || key_[SDLK_LCTRL]) {
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_.get_terrain(selected_hex_);
|
||||
const t_translation::t_letter terrain = map_.get_terrain(selected_hex_);
|
||||
if(palette_.selected_fg_terrain() != terrain) {
|
||||
palette_.select_fg_terrain(terrain);
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ void map_editor::left_click(const gamemap::location hex_clicked) {
|
|||
|
||||
void map_editor::right_click(const gamemap::location hex_clicked ) {
|
||||
if (key_[SDLK_RCTRL] || key_[SDLK_LCTRL]) {
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map_.get_terrain(hex_clicked);
|
||||
const t_translation::t_letter terrain = map_.get_terrain(hex_clicked);
|
||||
if(palette_.selected_fg_terrain() != terrain) {
|
||||
palette_.select_bg_terrain(terrain);
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ void map_editor::insert_selection_in_clipboard() {
|
|||
for (it = selected_hexes_.begin(); it != selected_hexes_.end(); it++) {
|
||||
const int x_offset = (*it).x - offset_hex.x;
|
||||
const int y_offset = (*it).y - offset_hex.y;
|
||||
terrain_translation::TERRAIN_NUMBER terrain = map_.get_terrain(*it);
|
||||
t_translation::t_letter terrain = map_.get_terrain(*it);
|
||||
clipboard_.push_back(clipboard_item(x_offset, y_offset, terrain,
|
||||
starting_side_at(map_, *it)));
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ void map_editor::undo() {
|
|||
std::back_inserter(to_invalidate));
|
||||
}
|
||||
if (action.terrain_set()) {
|
||||
for(std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>::const_iterator it =
|
||||
for(std::map<gamemap::location, t_translation::t_letter>::const_iterator it =
|
||||
action.undo_terrains().begin();
|
||||
it != action.undo_terrains().end(); ++it) {
|
||||
map_.set_terrain(it->first, it->second);
|
||||
|
@ -873,7 +873,7 @@ void map_editor::redo() {
|
|||
std::back_inserter(to_invalidate));
|
||||
}
|
||||
if (action.terrain_set()) {
|
||||
for(std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>::const_iterator it =
|
||||
for(std::map<gamemap::location, t_translation::t_letter>::const_iterator it =
|
||||
action.redo_terrains().begin();
|
||||
it != action.redo_terrains().end(); ++it) {
|
||||
map_.set_terrain(it->first, it->second);
|
||||
|
@ -933,9 +933,10 @@ bool map_editor::changed_since_save() const {
|
|||
void map_editor::set_starting_position(const int player, const gamemap::location loc) {
|
||||
if(map_.on_board(loc)) {
|
||||
map_undo_action action;
|
||||
action.add_terrain(map_.get_terrain(selected_hex_), terrain_translation::KEEP,
|
||||
selected_hex_);
|
||||
map_.set_terrain(selected_hex_, terrain_translation::KEEP);
|
||||
action.add_terrain(map_.get_terrain(selected_hex_), t_translation::KEEP,
|
||||
selected_hex_);
|
||||
|
||||
map_.set_terrain(selected_hex_, t_translation::KEEP);
|
||||
terrain_changed(selected_hex_, action);
|
||||
action.add_starting_location(player, player, map_.starting_position(player), loc);
|
||||
map_.set_starting_position(player, loc);
|
||||
|
@ -1030,10 +1031,10 @@ void map_editor::left_button_down(const int mousex, const int mousey) {
|
|||
}
|
||||
}
|
||||
|
||||
void map_editor::draw_on_mouseover_hexes(const terrain_translation::TERRAIN_NUMBER terrain) {
|
||||
void map_editor::draw_on_mouseover_hexes(const t_translation::t_letter terrain) {
|
||||
const gamemap::location hex = selected_hex_;
|
||||
if(map_.on_board(hex)) {
|
||||
const terrain_translation::TERRAIN_NUMBER old_terrain = map_[hex.x][hex.y];
|
||||
const t_translation::t_letter old_terrain = map_[hex.x][hex.y];
|
||||
// optimize for common case
|
||||
if(brush_.selected_brush_size() == 1) {
|
||||
if(terrain != old_terrain) {
|
||||
|
@ -1101,8 +1102,10 @@ void map_editor::perform_selection_move() {
|
|||
save_undo_action(undo_action);
|
||||
}
|
||||
|
||||
void map_editor::draw_terrain(const terrain_translation::TERRAIN_NUMBER terrain, const gamemap::location hex) {
|
||||
const terrain_translation::TERRAIN_NUMBER current_terrain = map_.get_terrain(hex);
|
||||
void map_editor::draw_terrain(const t_translation::t_letter terrain,
|
||||
const gamemap::location hex)
|
||||
{
|
||||
const t_translation::t_letter current_terrain = map_.get_terrain(hex);
|
||||
map_undo_action undo_action;
|
||||
undo_action.add_terrain(current_terrain, terrain, hex);
|
||||
map_.set_terrain(hex, terrain);
|
||||
|
@ -1122,7 +1125,7 @@ void map_editor::terrain_changed(const std::vector<gamemap::location> &hexes,
|
|||
for (std::vector<gamemap::location>::const_iterator it = hexes.begin();
|
||||
it != hexes.end(); it++) {
|
||||
const int start_side = starting_side_at(map_, *it);
|
||||
if (start_side != -1 && map_.get_terrain(*it) != terrain_translation::KEEP) {
|
||||
if (start_side != -1 && map_.get_terrain(*it) != t_translation::KEEP) {
|
||||
// A terrain which had a starting position has changed, save
|
||||
// this position in the undo_action and unset it.
|
||||
map_.set_starting_position(start_side, gamemap::location());
|
||||
|
@ -1160,9 +1163,9 @@ void map_editor::invalidate_all_and_adjacent(const std::vector<gamemap::location
|
|||
std::set<gamemap::location>::const_iterator its;
|
||||
for (its = to_invalidate.begin(); its != to_invalidate.end(); its++) {
|
||||
if (!map_.on_board(*its)) {
|
||||
terrain_translation::TERRAIN_NUMBER terrain_before = map_.get_terrain(*its);
|
||||
t_translation::t_letter terrain_before = map_.get_terrain(*its);
|
||||
map_.remove_from_border_cache(*its);
|
||||
terrain_translation::TERRAIN_NUMBER terrain_after = map_.get_terrain(*its);
|
||||
t_translation::t_letter terrain_after = map_.get_terrain(*its);
|
||||
if (terrain_before != terrain_after) {
|
||||
invalidate_adjacent(*its);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ private:
|
|||
|
||||
/// Draw terrain at a location. The operation is saved in the undo
|
||||
/// stack. Update the map to reflect the change.
|
||||
void draw_terrain(const terrain_translation::TERRAIN_NUMBER terrain,
|
||||
void draw_terrain(const t_translation::t_letter terrain,
|
||||
const gamemap::location hex);
|
||||
|
||||
|
||||
|
@ -285,7 +285,7 @@ private:
|
|||
|
||||
/// Draw the terrain on the hexes the mouse is over, taking account
|
||||
/// for brush size.
|
||||
void draw_on_mouseover_hexes(const terrain_translation::TERRAIN_NUMBER t);
|
||||
void draw_on_mouseover_hexes(const t_translation::t_letter t);
|
||||
|
||||
// Load the tooltips for each button
|
||||
void load_tooltips(void);
|
||||
|
@ -295,11 +295,11 @@ private:
|
|||
/// where to put the pasted hex when calculating from the one
|
||||
/// selected when the paste takes place.
|
||||
struct clipboard_item {
|
||||
clipboard_item(int xo, int yo, terrain_translation::TERRAIN_NUMBER t, int start_side) :
|
||||
clipboard_item(int xo, int yo, t_translation::t_letter t, int start_side) :
|
||||
x_offset(xo), y_offset(yo), terrain(t),
|
||||
starting_side(start_side){}
|
||||
int x_offset, y_offset;
|
||||
terrain_translation::TERRAIN_NUMBER terrain;
|
||||
t_translation::t_letter terrain;
|
||||
int starting_side;
|
||||
};
|
||||
|
||||
|
@ -345,7 +345,7 @@ private:
|
|||
static config hotkeys_;
|
||||
static bool first_time_created_;
|
||||
static LEFT_BUTTON_FUNC l_button_func_;
|
||||
static terrain_translation::TERRAIN_NUMBER old_fg_terrain_, old_bg_terrain_;
|
||||
static t_translation::t_letter old_fg_terrain_, old_bg_terrain_;
|
||||
static int old_brush_size_;
|
||||
bool all_hexes_selected_;
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ bool confirm_modification_disposal(display& disp) {
|
|||
}
|
||||
|
||||
|
||||
std::string new_map_dialog(display& disp, terrain_translation::TERRAIN_NUMBER fill_terrain,
|
||||
bool confirmation_needed, const config &game_config)
|
||||
std::string new_map_dialog(display& disp, t_translation::t_letter fill_terrain,
|
||||
bool confirmation_needed, const config &game_config)
|
||||
{
|
||||
const events::resize_lock prevent_resizing;
|
||||
const events::event_context dialog_events_context;
|
||||
|
|
|
@ -33,8 +33,8 @@ bool confirm_modification_disposal(display &disp);
|
|||
/// map if a new one is created. Return the string representation of the
|
||||
/// new map, or the empty string if the operation failed or was
|
||||
/// cancelled.
|
||||
std::string new_map_dialog(display &disp, terrain_translation::TERRAIN_NUMBER fill_terrain,
|
||||
bool confirmation_needed, const config &gconfig);
|
||||
std::string new_map_dialog(display &disp, t_translation::t_letter fill_terrain,
|
||||
bool confirmation_needed, const config &gconfig);
|
||||
|
||||
/// Show a dialog where the user may set the preferences used in the
|
||||
/// editor.
|
||||
|
|
|
@ -122,15 +122,18 @@ void terrain_palette::scroll_bottom() {
|
|||
}
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_palette::selected_fg_terrain() const {
|
||||
t_translation::t_letter terrain_palette::selected_fg_terrain() const
|
||||
{
|
||||
return selected_fg_terrain_;
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_palette::selected_bg_terrain() const {
|
||||
t_translation::t_letter terrain_palette::selected_bg_terrain() const
|
||||
{
|
||||
return selected_bg_terrain_;
|
||||
}
|
||||
|
||||
void terrain_palette::select_fg_terrain(terrain_translation::TERRAIN_NUMBER terrain) {
|
||||
void terrain_palette::select_fg_terrain(t_translation::t_letter terrain)
|
||||
{
|
||||
if (selected_fg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
selected_fg_terrain_ = terrain;
|
||||
|
@ -138,7 +141,8 @@ void terrain_palette::select_fg_terrain(terrain_translation::TERRAIN_NUMBER terr
|
|||
}
|
||||
}
|
||||
|
||||
void terrain_palette::select_bg_terrain(terrain_translation::TERRAIN_NUMBER terrain) {
|
||||
void terrain_palette::select_bg_terrain(t_translation::t_letter terrain)
|
||||
{
|
||||
if (selected_bg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
selected_bg_terrain_ = terrain;
|
||||
|
@ -149,19 +153,21 @@ void terrain_palette::select_bg_terrain(terrain_translation::TERRAIN_NUMBER terr
|
|||
/**
|
||||
* After the language is changed, the selected terrains needs an update.
|
||||
*/
|
||||
void terrain_palette::update_selected_terrains(void) {
|
||||
void terrain_palette::update_selected_terrains(void)
|
||||
{
|
||||
set_dirty();
|
||||
update_report();
|
||||
}
|
||||
|
||||
std::string terrain_palette::get_terrain_string(const terrain_translation::TERRAIN_NUMBER t) {
|
||||
std::string terrain_palette::get_terrain_string(const t_translation::t_letter t)
|
||||
{
|
||||
std::stringstream str;
|
||||
const std::string& name = map_.get_terrain_info(t).name();
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map_.underlying_union_terrain(t);
|
||||
const t_translation::t_list& underlying = map_.underlying_union_terrain(t);
|
||||
str << name;
|
||||
if(underlying.size() != 1 || underlying[0] != t) {
|
||||
str << " (";
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin();
|
||||
for(t_translation::t_list::const_iterator i = underlying.begin();
|
||||
i != underlying.end(); ++i) {
|
||||
|
||||
str << map_.get_terrain_info(*i).name();
|
||||
|
@ -259,7 +265,7 @@ void terrain_palette::draw(bool force) {
|
|||
const SDL_Rect &loc = location();
|
||||
int y = terrain_start_;
|
||||
for(unsigned int counter = starting; counter < ending; counter++){
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = terrains_[counter];
|
||||
const t_translation::t_letter terrain = terrains_[counter];
|
||||
const std::string filename = "terrain/" + map_.get_terrain_info(terrain).symbol_image() + ".png";
|
||||
surface image(image::get_image(filename, image::UNSCALED));
|
||||
if(image == NULL) {
|
||||
|
|
|
@ -46,14 +46,14 @@ public:
|
|||
void scroll_bottom();
|
||||
|
||||
/// Return the currently selected foreground terrain.
|
||||
terrain_translation::TERRAIN_NUMBER selected_fg_terrain() const;
|
||||
t_translation::t_letter selected_fg_terrain() const;
|
||||
/// Return the currently selected background terrain.
|
||||
terrain_translation::TERRAIN_NUMBER selected_bg_terrain() const;
|
||||
t_translation::t_letter selected_bg_terrain() const;
|
||||
|
||||
|
||||
/// Select a foreground terrain.
|
||||
void select_fg_terrain(terrain_translation::TERRAIN_NUMBER);
|
||||
void select_bg_terrain(terrain_translation::TERRAIN_NUMBER);
|
||||
void select_fg_terrain(t_translation::t_letter);
|
||||
void select_bg_terrain(t_translation::t_letter);
|
||||
|
||||
// Update the selected terrains strings
|
||||
void update_selected_terrains(void);
|
||||
|
@ -87,7 +87,7 @@ private:
|
|||
int tile_selected(const int x, const int y) const;
|
||||
|
||||
/// Return a string represeting the terrain and the underlying ones.
|
||||
std::string get_terrain_string(const terrain_translation::TERRAIN_NUMBER);
|
||||
std::string get_terrain_string(const t_translation::t_letter);
|
||||
|
||||
/// Update the report with the currently selected terrains.
|
||||
void update_report();
|
||||
|
@ -95,8 +95,8 @@ private:
|
|||
const size_specs &size_specs_;
|
||||
display &gui_;
|
||||
unsigned int tstart_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrains_;
|
||||
terrain_translation::TERRAIN_NUMBER selected_fg_terrain_, selected_bg_terrain_;
|
||||
t_translation::t_list terrains_;
|
||||
t_translation::t_letter selected_fg_terrain_, selected_bg_terrain_;
|
||||
const gamemap &map_;
|
||||
gui::button top_button_, bot_button_;
|
||||
size_t button_x_, top_button_y_, bot_button_y_;
|
||||
|
|
|
@ -28,11 +28,13 @@ map_undo_action::map_undo_action() {
|
|||
starting_locations_set_ = false;
|
||||
}
|
||||
|
||||
const std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>& map_undo_action::undo_terrains() const {
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::undo_terrains() const
|
||||
{
|
||||
return old_terrain_;
|
||||
}
|
||||
|
||||
const std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>& map_undo_action::redo_terrains() const {
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::redo_terrains() const
|
||||
{
|
||||
return new_terrain_;
|
||||
}
|
||||
|
||||
|
@ -60,9 +62,10 @@ const std::map<gamemap::location, int>& map_undo_action::redo_starting_locations
|
|||
return new_starting_locations_;
|
||||
}
|
||||
|
||||
void map_undo_action::add_terrain(const terrain_translation::TERRAIN_NUMBER& old_tr,
|
||||
const terrain_translation::TERRAIN_NUMBER& new_tr,
|
||||
const gamemap::location& lc) {
|
||||
void map_undo_action::add_terrain(const t_translation::t_letter& old_tr,
|
||||
const t_translation::t_letter& new_tr,
|
||||
const gamemap::location& lc)
|
||||
{
|
||||
old_terrain_[lc] = old_tr;
|
||||
new_terrain_[lc] = new_tr;
|
||||
terrain_set_ = true;
|
||||
|
|
|
@ -31,8 +31,8 @@ class map_undo_action {
|
|||
public:
|
||||
map_undo_action();
|
||||
|
||||
const std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>& undo_terrains() const;
|
||||
const std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER>& redo_terrains() const;
|
||||
const std::map<gamemap::location, t_translation::t_letter>& undo_terrains() const;
|
||||
const std::map<gamemap::location, t_translation::t_letter>& redo_terrains() const;
|
||||
|
||||
const std::set<gamemap::location> undo_selection() const;
|
||||
const std::set<gamemap::location> redo_selection() const;
|
||||
|
@ -43,8 +43,8 @@ public:
|
|||
const std::map<gamemap::location, int>& undo_starting_locations() const;
|
||||
const std::map<gamemap::location, int>& redo_starting_locations() const;
|
||||
|
||||
void add_terrain(const terrain_translation::TERRAIN_NUMBER& old_tr,
|
||||
const terrain_translation::TERRAIN_NUMBER& new_tr,
|
||||
void add_terrain(const t_translation::t_letter& old_tr,
|
||||
const t_translation::t_letter& new_tr,
|
||||
const gamemap::location& lc);
|
||||
|
||||
/// Return true if a terrain change has been saved in this undo
|
||||
|
@ -74,8 +74,8 @@ public:
|
|||
bool starting_location_set() const;
|
||||
|
||||
private:
|
||||
std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER> old_terrain_;
|
||||
std::map<gamemap::location,terrain_translation::TERRAIN_NUMBER> new_terrain_;
|
||||
std::map<gamemap::location, t_translation::t_letter> old_terrain_;
|
||||
std::map<gamemap::location, t_translation::t_letter> new_terrain_;
|
||||
bool terrain_set_;
|
||||
std::set<gamemap::location> old_selection_;
|
||||
std::set<gamemap::location> new_selection_;
|
||||
|
|
|
@ -32,11 +32,10 @@ namespace {
|
|||
void grow_and_pad(const gamemap &map, std::vector<std::string> &lines,
|
||||
bool grow_height) {
|
||||
int i, j;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrains;
|
||||
terrain_translation::TERRAIN_NUMBER chosen_terrain;
|
||||
t_translation::t_list terrains;
|
||||
t_translation::t_letter chosen_terrain;
|
||||
if (grow_height) {
|
||||
lines.push_back(std::string(lines[0].size(),
|
||||
terrain_translation::FOREST));
|
||||
lines.push_back(std::string(lines[0].size(), t_translation::FOREST));
|
||||
// Shift terrain on odd numbered columns one step downwards.
|
||||
for (i = 0; (unsigned)i < lines[0].size(); i += 2) {
|
||||
for (j = lines.size() - 2; j >= 0; j--) {
|
||||
|
@ -75,7 +74,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
if (map.is_village(chosen_terrain)) {
|
||||
chosen_terrain = terrain_translation::FOREST;
|
||||
chosen_terrain = t_translation::FOREST;
|
||||
}
|
||||
if (is_even(i)) {
|
||||
lines[0][i] = chosen_terrain;
|
||||
|
@ -105,7 +104,7 @@ namespace {
|
|||
chosen_terrain = map.is_village(terrains[0])
|
||||
? terrains[1] : terrains[0];
|
||||
chosen_terrain = map.is_village(chosen_terrain)
|
||||
? terrain_translation::FOREST : chosen_terrain;
|
||||
? t_translation::FOREST : chosen_terrain;
|
||||
lines[i].resize(lines[i].length() + 1, chosen_terrain);
|
||||
}
|
||||
}
|
||||
|
@ -145,8 +144,9 @@ std::vector<gamemap::location> get_tiles(const gamemap &map,
|
|||
|
||||
|
||||
void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
||||
const terrain_translation::TERRAIN_NUMBER fill_with, terrain_log *log) {
|
||||
terrain_translation::TERRAIN_NUMBER terrain_to_fill = map.get_terrain(start_loc);
|
||||
const t_translation::t_letter fill_with, terrain_log *log)
|
||||
{
|
||||
t_translation::t_letter terrain_to_fill = map.get_terrain(start_loc);
|
||||
if (fill_with == terrain_to_fill) {
|
||||
return;
|
||||
}
|
||||
|
@ -161,9 +161,10 @@ void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
|||
}
|
||||
}
|
||||
|
||||
std::set<gamemap::location>
|
||||
get_component(const gamemap &map, const gamemap::location &start_loc) {
|
||||
terrain_translation::TERRAIN_NUMBER terrain_to_fill = map.get_terrain(start_loc);
|
||||
std::set<gamemap::location> get_component(const gamemap &map,
|
||||
const gamemap::location &start_loc)
|
||||
{
|
||||
t_translation::t_letter terrain_to_fill = map.get_terrain(start_loc);
|
||||
std::set<gamemap::location> to_fill;
|
||||
std::set<gamemap::location> filled;
|
||||
std::set<gamemap::location>::iterator it;
|
||||
|
@ -191,7 +192,8 @@ get_component(const gamemap &map, const gamemap::location &start_loc) {
|
|||
}
|
||||
|
||||
std::string resize_map(const gamemap &map, const unsigned new_w,
|
||||
const unsigned new_h, const terrain_translation::TERRAIN_NUMBER fill_with) {
|
||||
const unsigned new_h, const t_translation::t_letter fill_with)
|
||||
{
|
||||
std::string str_map = map.write();
|
||||
std::vector<std::string> lines = utils::split(str_map, '\n');
|
||||
bool map_changed = false;
|
||||
|
|
|
@ -27,14 +27,14 @@ std::vector<gamemap::location> get_tiles(const gamemap &map,
|
|||
const gamemap::location& a,
|
||||
const unsigned int radius);
|
||||
|
||||
typedef std::vector<std::pair<gamemap::location, terrain_translation::TERRAIN_NUMBER> > terrain_log;
|
||||
typedef std::vector<std::pair<gamemap::location, t_translation::t_letter> > terrain_log;
|
||||
|
||||
/// Flood fill the map with the terrain fill_with starting from the
|
||||
/// location start_loc. If log is non-null it will contain the positions
|
||||
/// of the changed tiles and the terrains they had before the filling
|
||||
/// started.
|
||||
void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
||||
const terrain_translation::TERRAIN_NUMBER fill_with, terrain_log *log = NULL);
|
||||
const t_translation::t_letter fill_with, terrain_log *log = NULL);
|
||||
|
||||
/// Return the area that would be flood filled if a flood fill was
|
||||
/// requested.
|
||||
|
@ -48,7 +48,7 @@ get_component(const gamemap &map, const gamemap::location &start_loc);
|
|||
/// new map area appeard at the bottom and/or the right and is filled
|
||||
/// with the terrain fill_with.
|
||||
std::string resize_map(const gamemap &map, const unsigned new_w,
|
||||
const unsigned new_h, const terrain_translation::TERRAIN_NUMBER fill_with);
|
||||
const unsigned new_h, const t_translation::t_letter fill_with);
|
||||
|
||||
enum FLIP_AXIS {NO_FLIP, FLIP_X, FLIP_Y};
|
||||
/// Return the string representation of the map after it has been
|
||||
|
|
|
@ -1156,7 +1156,8 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
//At this point terrain_type contains the letter as known in WML
|
||||
//convert to an internal number
|
||||
terrain_translation::TERRAIN_NUMBER terrain = terrain_translation::read_letter(terrain_type, terrain_translation::TFORMAT_AUTO);
|
||||
t_translation::t_letter terrain =
|
||||
t_translation::read_letter(terrain_type, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
for(std::vector<gamemap::location>::const_iterator loc = locs.begin(); loc != locs.end(); ++loc) {
|
||||
preferences::encountered_terrains().insert(terrain);
|
||||
|
@ -1757,8 +1758,8 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
variable = utils::interpolate_variables_into_string(variable, *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::read_list(wml_terrain, 0, terrain_translation::TFORMAT_AUTO);
|
||||
t_translation::t_list terrain =
|
||||
t_translation::read_list(wml_terrain, 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
x = utils::interpolate_variables_into_string(x, *state_of_game);
|
||||
y = utils::interpolate_variables_into_string(y, *state_of_game);
|
||||
|
@ -1779,7 +1780,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 terrain_translation::TERRAIN_NUMBER c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
const t_translation::t_letter c = game_map->get_terrain(*j); //FIXME MdW test should work
|
||||
if(std::find(terrain.begin(), terrain.end(), c) == terrain.end())
|
||||
continue;
|
||||
}
|
||||
|
|
37
src/help.cpp
37
src/help.cpp
|
@ -1277,13 +1277,13 @@ public:
|
|||
push_header(first_row, _("Movement Cost"));
|
||||
|
||||
table.push_back(first_row);
|
||||
std::set<terrain_translation::TERRAIN_NUMBER>::const_iterator terrain_it =
|
||||
std::set<t_translation::t_letter>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin();
|
||||
|
||||
for (; terrain_it != preferences::encountered_terrains().end();
|
||||
terrain_it++) {
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = *terrain_it;
|
||||
if (terrain == terrain_translation::FOGGED || terrain == terrain_translation::VOID_TERRAIN)
|
||||
const t_translation::t_letter terrain = *terrain_it;
|
||||
if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN)
|
||||
continue;
|
||||
const terrain_type& info = map->get_terrain_info(terrain);
|
||||
|
||||
|
@ -1386,15 +1386,15 @@ struct terrain_topic_generator: topic_generator
|
|||
std::stringstream ss;
|
||||
ss << "<img>src='terrain/" << type.symbol_image() << ".png'</img>\n\n";
|
||||
if (type.mvt_type().size() != 1 || type.mvt_type()[0] != type.number()) {
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> aliased_terrains = type.mvt_type();
|
||||
const t_translation::t_list aliased_terrains = type.mvt_type();
|
||||
std::stringstream alias_ss;
|
||||
for (std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator it = aliased_terrains.begin();
|
||||
for (t_translation::t_list::const_iterator it = aliased_terrains.begin();
|
||||
it != aliased_terrains.end(); it++) {
|
||||
const terrain_translation::TERRAIN_NUMBER t = *it;
|
||||
const t_translation::t_letter 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_"))
|
||||
<< escape(terrain_translation::write_letter(t))
|
||||
<< escape(t_translation::write_letter(t))
|
||||
<< "'</ref>";
|
||||
if (it + 2 == aliased_terrains.end())
|
||||
alias_ss << " " << _("or") << " ";
|
||||
|
@ -1412,15 +1412,16 @@ struct terrain_topic_generator: topic_generator
|
|||
ss << "\n\n";
|
||||
}
|
||||
if (type.def_type().size() != 1 || type.def_type()[0] != type.number()) {
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> aliased_terrains = type.def_type();
|
||||
const t_translation::t_list aliased_terrains = type.def_type();
|
||||
std::stringstream alias_ss;
|
||||
for (std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator it = aliased_terrains.begin();
|
||||
for (t_translation::t_list::const_iterator it = aliased_terrains.begin();
|
||||
it != aliased_terrains.end(); it++) {
|
||||
const terrain_translation::TERRAIN_NUMBER t = *it;
|
||||
|
||||
const t_translation::t_letter 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_"))
|
||||
<< escape(terrain_translation::write_letter(t))
|
||||
<< escape(t_translation::write_letter(t))
|
||||
<< "'</ref>";
|
||||
if (it + 2 == aliased_terrains.end())
|
||||
alias_ss << " " << _("or") << " ";
|
||||
|
@ -1450,14 +1451,14 @@ struct terrain_topic_generator: topic_generator
|
|||
std::vector<topic> generate_terrains_topics(const bool sort_generated)
|
||||
{
|
||||
std::vector<topic> res;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> show_info_about;
|
||||
t_translation::t_list show_info_about;
|
||||
if (game_config::debug) {
|
||||
show_info_about = map->get_terrain_list();
|
||||
}
|
||||
else {
|
||||
//FIXME MdW the changes here seem to compile but they have to
|
||||
//be tested whether they really work
|
||||
for (std::set<terrain_translation::TERRAIN_NUMBER>::const_iterator terrain_it =
|
||||
for (std::set<t_translation::t_letter>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin();
|
||||
terrain_it != preferences::encountered_terrains().end();
|
||||
terrain_it++) {
|
||||
|
@ -1465,16 +1466,18 @@ std::vector<topic> generate_terrains_topics(const bool sort_generated)
|
|||
}
|
||||
}
|
||||
show_info_about.erase(std::remove(show_info_about.begin(), show_info_about.end(),
|
||||
terrain_translation::VOID_TERRAIN), show_info_about.end());
|
||||
t_translation::VOID_TERRAIN), show_info_about.end());
|
||||
|
||||
show_info_about.erase(std::remove(show_info_about.begin(), show_info_about.end(),
|
||||
terrain_translation::FOGGED), show_info_about.end());
|
||||
t_translation::FOGGED), show_info_about.end());
|
||||
|
||||
for (std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator terrain_it = show_info_about.begin();
|
||||
for (t_translation::t_list::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_translation::write_letter(*terrain_it), new terrain_topic_generator(info));
|
||||
topic t(name, std::string("terrain_") + t_translation::write_letter(*terrain_it),
|
||||
new terrain_topic_generator(info));
|
||||
res.push_back(t);
|
||||
}
|
||||
if (sort_generated)
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace image {
|
|||
|
||||
typedef std::vector<cache_item<surface> > image_cache;
|
||||
typedef std::vector<cache_item<locator> > locator_cache;
|
||||
typedef std::map<terrain_translation::TERRAIN_NUMBER, surface> mini_terrain_cache_map;
|
||||
typedef std::map<t_translation::t_letter, surface> mini_terrain_cache_map;
|
||||
extern mini_terrain_cache_map mini_terrain_cache;
|
||||
|
||||
void flush_cache();
|
||||
|
|
141
src/map.cpp
141
src/map.cpp
|
@ -40,58 +40,61 @@ std::ostream &operator<<(std::ostream &s, gamemap::location const &l) {
|
|||
|
||||
gamemap::location gamemap::location::null_location;
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_mvt_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
const t_translation::t_list& gamemap::underlying_mvt_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<t_translation::t_letter,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;
|
||||
static t_translation::t_list result(1, terrain);
|
||||
return result;
|
||||
} else {
|
||||
return i->second.mvt_type();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_def_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
const t_translation::t_list& gamemap::underlying_def_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<t_translation::t_letter, 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;
|
||||
static t_translation::t_list result(1, terrain);
|
||||
return result;
|
||||
} else {
|
||||
return i->second.def_type();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::underlying_union_terrain(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
const t_translation::t_list& gamemap::underlying_union_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i = letterToTerrain_.find(terrain);
|
||||
const std::map<t_translation::t_letter,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;
|
||||
static t_translation::t_list result(1, terrain);
|
||||
return result;
|
||||
} else {
|
||||
return i->second.union_type();
|
||||
}
|
||||
}
|
||||
|
||||
bool gamemap::is_village(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
bool gamemap::is_village(t_translation::t_letter terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_village();
|
||||
}
|
||||
|
||||
int gamemap::gives_healing(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
int gamemap::gives_healing(t_translation::t_letter terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).gives_healing();
|
||||
}
|
||||
|
||||
bool gamemap::is_castle(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
bool gamemap::is_castle(t_translation::t_letter terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_castle();
|
||||
}
|
||||
|
||||
bool gamemap::is_keep(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
bool gamemap::is_keep(t_translation::t_letter terrain) const
|
||||
{
|
||||
return get_terrain_info(terrain).is_keep();
|
||||
}
|
||||
|
@ -125,8 +128,7 @@ bool gamemap::filter_location(const gamemap::location &loc,const config & /*con*
|
|||
|
||||
void gamemap::write_terrain(const gamemap::location &loc, config& cfg) const
|
||||
{
|
||||
terrain_translation::TERRAIN_NUMBER loc_terrain = get_terrain(loc);
|
||||
cfg["terrain"] = terrain_translation::write_letter(loc_terrain);
|
||||
cfg["terrain"] = t_translation::write_letter(get_terrain(loc));
|
||||
}
|
||||
|
||||
gamemap::location::DIRECTION gamemap::location::parse_direction(const std::string& str)
|
||||
|
@ -307,11 +309,11 @@ void gamemap::read(const std::string& data)
|
|||
tiles_.clear();
|
||||
villages_.clear();
|
||||
std::fill(startingPositions_,startingPositions_+sizeof(startingPositions_)/sizeof(*startingPositions_),location());
|
||||
std::map<int, terrain_translation::coordinate> starting_positions;
|
||||
std::map<int, t_translation::coordinate> starting_positions;
|
||||
|
||||
try {
|
||||
tiles_ = terrain_translation::read_game_map(data, starting_positions);
|
||||
} catch(terrain_translation::error& e) {
|
||||
tiles_ = t_translation::read_game_map(data, starting_positions);
|
||||
} catch(t_translation::error& e) {
|
||||
// FIXME MdW think about this part
|
||||
// for now we just convert the error and throw it to our callers
|
||||
// might not be the best way but keep it for now
|
||||
|
@ -319,7 +321,7 @@ void gamemap::read(const std::string& data)
|
|||
}
|
||||
|
||||
//convert the starting positions to the array
|
||||
std::map<int, terrain_translation::coordinate>::const_iterator itor =
|
||||
std::map<int, t_translation::coordinate>::const_iterator itor =
|
||||
starting_positions.begin();
|
||||
|
||||
for(; itor != starting_positions.end(); ++itor) {
|
||||
|
@ -343,7 +345,7 @@ void gamemap::read(const std::string& data)
|
|||
|
||||
// is the terrain valid?
|
||||
if(letterToTerrain_.count(tiles_[x][y]) == 0) {
|
||||
ERR_CF << "Illegal character in map: (" << terrain_translation::write_letter(tiles_[x][y])
|
||||
ERR_CF << "Illegal character in map: (" << t_translation::write_letter(tiles_[x][y])
|
||||
<< ") '" << tiles_[x][y] << "'\n";
|
||||
throw incorrect_format_exception("Illegal character found in map. The scenario cannot be loaded.");
|
||||
}
|
||||
|
@ -373,20 +375,20 @@ void gamemap::read(const std::string& data)
|
|||
|
||||
std::string gamemap::write() const
|
||||
{
|
||||
std::map<int, terrain_translation::coordinate> starting_positions;
|
||||
std::map<int, t_translation::coordinate> starting_positions;
|
||||
|
||||
// convert the starting positions to a map
|
||||
for(int i = 0; i < STARTING_POSITIONS; ++i) {
|
||||
if(on_board(startingPositions_[i])) {
|
||||
const struct terrain_translation::coordinate position =
|
||||
const struct t_translation::coordinate position =
|
||||
{startingPositions_[i].x, startingPositions_[i].y};
|
||||
|
||||
starting_positions.insert(std::pair<int, terrain_translation::coordinate>(i, position));
|
||||
starting_positions.insert(std::pair<int, t_translation::coordinate>(i, position));
|
||||
}
|
||||
}
|
||||
|
||||
// let the low level convertor do the conversion
|
||||
return terrain_translation::write_game_map(tiles_, starting_positions);
|
||||
return t_translation::write_game_map(tiles_, starting_positions);
|
||||
}
|
||||
|
||||
void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos, const int ypos)
|
||||
|
@ -405,10 +407,10 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
if (y2 < 0 || y2 >= y()) {
|
||||
continue;
|
||||
}
|
||||
const terrain_translation::TERRAIN_NUMBER t = m[x1][y1];
|
||||
const terrain_translation::TERRAIN_NUMBER current = (*this)[x2][y2];
|
||||
const t_translation::t_letter t = m[x1][y1];
|
||||
const t_translation::t_letter current = (*this)[x2][y2];
|
||||
|
||||
if(t == terrain_translation::FOGGED || t == terrain_translation::VOID_TERRAIN) {
|
||||
if(t == t_translation::FOGGED || t == t_translation::VOID_TERRAIN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -418,26 +420,30 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
static const std::string src_key = "old", src_not_key = "old_not",
|
||||
dst_key = "new", dst_not_key = "new_not";
|
||||
const config& cfg = **rule;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& src =
|
||||
terrain_translation::read_list(cfg[src_key], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& src =
|
||||
t_translation::read_list(cfg[src_key], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(!src.empty() && std::find(src.begin(),src.end(),current) == src.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& src_not =
|
||||
terrain_translation::read_list(cfg[src_not_key], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& src_not =
|
||||
t_translation::read_list(cfg[src_not_key], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(!src_not.empty() && std::find(src_not.begin(),src_not.end(),current) != src_not.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& dst =
|
||||
terrain_translation::read_list(cfg[dst_key], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& dst =
|
||||
t_translation::read_list(cfg[dst_key], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(!dst.empty() && std::find(dst.begin(),dst.end(),t) == dst.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& dst_not =
|
||||
terrain_translation::read_list(cfg[dst_not_key], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& dst_not =
|
||||
t_translation::read_list(cfg[dst_not_key], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(!dst_not.empty() && std::find(dst_not.begin(),dst_not.end(),t) != dst_not.end()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -448,8 +454,8 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
|
||||
if(rule != rules.end()) {
|
||||
const config& cfg = **rule;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain =
|
||||
terrain_translation::read_list(cfg["terrain"], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& terrain =
|
||||
t_translation::read_list(cfg["terrain"], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(! terrain.empty()) {
|
||||
set_terrain(location(x2,y2),terrain[0]); //FIXME MdW tag is this valid?? (should be but test)
|
||||
|
@ -462,7 +468,10 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
}
|
||||
}
|
||||
|
||||
for(const location* pos = m.startingPositions_; pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_); ++pos) {
|
||||
for(const location* pos = m.startingPositions_;
|
||||
pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_);
|
||||
++pos) {
|
||||
|
||||
if(pos->valid()) {
|
||||
startingPositions_[pos - m.startingPositions_] = *pos;
|
||||
}
|
||||
|
@ -472,22 +481,22 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
int gamemap::x() const { return tiles_.size(); }
|
||||
int gamemap::y() const { return tiles_.empty() ? 0 : tiles_.front().size(); }
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::operator[](int index) const
|
||||
const t_translation::t_list& gamemap::operator[](int index) const
|
||||
{
|
||||
return tiles_[index];
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER gamemap::get_terrain(const gamemap::location& loc) const
|
||||
t_translation::t_letter gamemap::get_terrain(const gamemap::location& loc) const
|
||||
{
|
||||
if(on_board(loc))
|
||||
return tiles_[loc.x][loc.y];
|
||||
|
||||
const std::map<location,terrain_translation::TERRAIN_NUMBER>::const_iterator itor = borderCache_.find(loc);
|
||||
const std::map<location, t_translation::t_letter>::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_translation::TERRAIN_NUMBER items[6];
|
||||
t_translation::t_letter items[6];
|
||||
int nitems = 0;
|
||||
|
||||
location adj[6];
|
||||
|
@ -501,7 +510,7 @@ terrain_translation::TERRAIN_NUMBER gamemap::get_terrain(const gamemap::location
|
|||
|
||||
//count all the terrain types found, and see which one
|
||||
//is the most common, and use it.
|
||||
terrain_translation::TERRAIN_NUMBER used_terrain = 0;
|
||||
t_translation::t_letter 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])) {
|
||||
|
@ -513,7 +522,7 @@ terrain_translation::TERRAIN_NUMBER gamemap::get_terrain(const gamemap::location
|
|||
}
|
||||
}
|
||||
|
||||
borderCache_.insert(std::pair<location,terrain_translation::TERRAIN_NUMBER>(loc,used_terrain));
|
||||
borderCache_.insert(std::pair<location, t_translation::t_letter>(loc,used_terrain));
|
||||
|
||||
return used_terrain;
|
||||
}
|
||||
|
@ -558,11 +567,12 @@ void gamemap::set_starting_position(int side, const gamemap::location& loc)
|
|||
}
|
||||
}
|
||||
|
||||
const terrain_type& gamemap::get_terrain_info(terrain_translation::TERRAIN_NUMBER terrain) const
|
||||
const terrain_type& gamemap::get_terrain_info(t_translation::t_letter terrain) const
|
||||
{
|
||||
static const terrain_type default_terrain;
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
const std::map<t_translation::t_letter,terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
|
||||
if(i != letterToTerrain_.end())
|
||||
return i->second;
|
||||
else
|
||||
|
@ -573,27 +583,28 @@ const terrain_type& gamemap::get_terrain_info(const gamemap::location &loc) cons
|
|||
{
|
||||
return get_terrain_info(get_terrain(loc));
|
||||
}
|
||||
bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config& cfg, const gamestatus& game_status, const unit_map& units,bool flat_tod) const
|
||||
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::vector<terrain_translation::TERRAIN_NUMBER>& terrain =
|
||||
terrain_translation::read_list(cfg["terrain"], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& terrain =
|
||||
t_translation::read_list(cfg["terrain"], 0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
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::vector<terrain_translation::TERRAIN_NUMBER> terrain_letter;
|
||||
terrain_letter.push_back(get_terrain_info(loc).number());
|
||||
t_translation::t_list terrain_letter(1, get_terrain_info(loc).number());
|
||||
|
||||
// FIXME MdW rewrote the old part, but haven't looked at what it should do
|
||||
// but some documentation would be nice
|
||||
// but some documentation would be nice, not sure whether this function
|
||||
// still works after the latest modifications
|
||||
if(!terrain.empty()) {
|
||||
if(terrain != terrain_letter) {
|
||||
if(std::find(terrain.begin(),terrain.end(),terrain_translation::COMMA) != terrain.end() &&
|
||||
if(std::find(terrain.begin(),terrain.end(),t_translation::COMMA) != terrain.end() &&
|
||||
std::search(terrain.begin(),terrain.end(),
|
||||
terrain_letter.begin(),terrain_letter.end()) != terrain.end()) {
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& vals =
|
||||
terrain_translation::read_list(cfg["terrain"], 1, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list& vals =
|
||||
t_translation::read_list(cfg["terrain"], 1, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
if(std::find(vals.begin(),vals.end(),terrain_letter.front()) == vals.end()) {
|
||||
return false;
|
||||
|
@ -646,12 +657,12 @@ bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config&
|
|||
return true;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& gamemap::get_terrain_list() const
|
||||
const t_translation::t_list& gamemap::get_terrain_list() const
|
||||
{
|
||||
return terrainList_;
|
||||
}
|
||||
|
||||
void gamemap::set_terrain(const gamemap::location& loc, terrain_translation::TERRAIN_NUMBER ter)
|
||||
void gamemap::set_terrain(const gamemap::location& loc, t_translation::t_letter ter)
|
||||
{
|
||||
if(!on_board(loc))
|
||||
return;
|
||||
|
@ -701,7 +712,7 @@ std::vector<gamemap::location> parse_location_range(const std::string& x, const
|
|||
return res;
|
||||
}
|
||||
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,size_t>& gamemap::get_weighted_terrain_frequencies() const
|
||||
const std::map<t_translation::t_letter, size_t>& gamemap::get_weighted_terrain_frequencies() const
|
||||
{
|
||||
if(terrainFrequencyCache_.empty() == false) {
|
||||
return terrainFrequencyCache_;
|
||||
|
|
51
src/map.hpp
51
src/map.hpp
|
@ -37,12 +37,9 @@ public:
|
|||
//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::vector<terrain_translation::TERRAIN_NUMBER>&
|
||||
underlying_mvt_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>&
|
||||
underlying_def_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>&
|
||||
underlying_union_terrain(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const t_translation::t_list& underlying_mvt_terrain(t_translation::t_letter terrain) const;
|
||||
const t_translation::t_list& underlying_def_terrain(t_translation::t_letter terrain) const;
|
||||
const t_translation::t_list& underlying_union_terrain(t_translation::t_letter terrain) const;
|
||||
|
||||
//exception thrown if the map file is not in the correct format.
|
||||
struct incorrect_format_exception {
|
||||
|
@ -95,25 +92,25 @@ public:
|
|||
private:
|
||||
void init(const std::string &x, const std::string &y);
|
||||
};
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_mvt_terrain(const location& loc) const
|
||||
const t_translation::t_list& underlying_mvt_terrain(const location& loc) const
|
||||
{ return underlying_mvt_terrain(get_terrain(loc)); }
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_def_terrain(const location& loc) const
|
||||
const t_translation::t_list& underlying_def_terrain(const location& loc) const
|
||||
{ return underlying_def_terrain(get_terrain(loc)); }
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying_union_terrain(const location& loc) const
|
||||
const t_translation::t_list& underlying_union_terrain(const location& loc) const
|
||||
{ return underlying_union_terrain(get_terrain(loc)); }
|
||||
|
||||
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(t_translation::t_letter terrain) const;
|
||||
int gives_healing(t_translation::t_letter terrain) const;
|
||||
bool is_castle(t_translation::t_letter terrain) const;
|
||||
bool is_keep(t_translation::t_letter terrain) const;
|
||||
|
||||
bool is_village(const location& loc) const;
|
||||
int gives_healing(const location& loc) const;
|
||||
bool is_castle(const location& loc) const;
|
||||
bool is_keep(const location& loc) const;
|
||||
|
||||
//function to filter whether a location matches a set of criteria
|
||||
bool filter_location(const location &loc,const config &con) const;
|
||||
//function to filter whether a location matches a set of criteria
|
||||
bool filter_location(const location &loc,const config &con) const;
|
||||
|
||||
//loads a map, with the given terrain configuration.
|
||||
//data should be a series of lines, with each character representing
|
||||
|
@ -132,12 +129,12 @@ public:
|
|||
int y() const;
|
||||
|
||||
//allows lookup of terrain at a particular location.
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& operator[](int index) const;
|
||||
const t_translation::t_list& 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_translation::TERRAIN_NUMBER get_terrain(const location& loc) const;
|
||||
t_translation::t_letter get_terrain(const location& loc) const;
|
||||
|
||||
//writes the terrain at loc to cfg
|
||||
void write_terrain(const gamemap::location &loc, config& cfg) const;
|
||||
|
@ -168,7 +165,7 @@ public:
|
|||
|
||||
//function to get the corresponding terrain_type information object
|
||||
//for a given type of terrain
|
||||
const terrain_type& get_terrain_info(terrain_translation::TERRAIN_NUMBER terrain) const;
|
||||
const terrain_type& get_terrain_info(t_translation::t_letter terrain) const;
|
||||
|
||||
//shortcut to get_terrain_info(get_terrain(loc))
|
||||
const terrain_type& get_terrain_info(const location &loc) const;
|
||||
|
@ -176,14 +173,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_translation::TERRAIN_NUMBER>& get_terrain_list() const;
|
||||
const t_translation::t_list& get_terrain_list() const;
|
||||
|
||||
//clobbers over the terrain at location 'loc', with the given terrain
|
||||
void set_terrain(const location& loc, terrain_translation::TERRAIN_NUMBER ter);
|
||||
void set_terrain(const location& loc, t_translation::t_letter 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_translation::TERRAIN_NUMBER,size_t>& get_weighted_terrain_frequencies() const;
|
||||
const std::map<t_translation::t_letter, 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.
|
||||
|
@ -191,20 +188,18 @@ public:
|
|||
private:
|
||||
int num_starting_positions() const;
|
||||
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrainList_;
|
||||
std::map<terrain_translation::TERRAIN_NUMBER,terrain_type> letterToTerrain_;
|
||||
//The terrain string with TERRAIN_LETTER
|
||||
t_translation::t_list terrainList_;
|
||||
std::map<t_translation::t_letter, terrain_type> letterToTerrain_;
|
||||
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_;
|
||||
t_translation::t_map tiles_;
|
||||
std::vector<location> villages_;
|
||||
|
||||
enum { STARTING_POSITIONS = 10 };
|
||||
location startingPositions_[STARTING_POSITIONS];
|
||||
|
||||
mutable std::map<location,terrain_translation::TERRAIN_NUMBER> borderCache_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,size_t> terrainFrequencyCache_;
|
||||
mutable std::map<location, t_translation::t_letter> borderCache_;
|
||||
mutable std::map<t_translation::t_letter, size_t> terrainFrequencyCache_;
|
||||
};
|
||||
|
||||
//a utility function which parses ranges of locations
|
||||
|
|
132
src/mapgen.cpp
132
src/mapgen.cpp
|
@ -48,7 +48,7 @@ namespace {
|
|||
|
||||
typedef std::vector<std::vector<int> > height_map;
|
||||
//typedef std::vector<std::vector<char> > terrain_map;
|
||||
typedef std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > terrain_map;
|
||||
typedef t_translation::t_map terrain_map;
|
||||
|
||||
typedef gamemap::location location;
|
||||
|
||||
|
@ -187,7 +187,7 @@ bool generate_lake(terrain_map& terrain, int x, int y, int lake_fall_off, std::s
|
|||
return false;
|
||||
}
|
||||
|
||||
terrain[x][y] = terrain_translation::SHALLOW_WATER;
|
||||
terrain[x][y] = t_translation::SHALLOW_WATER;
|
||||
locs_touched.insert(location(x,y));
|
||||
|
||||
if((rand()%100) < lake_fall_off) {
|
||||
|
@ -230,13 +230,15 @@ 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] == terrain_translation::SHALLOW_WATER || terrain[x][y] == terrain_translation::DEEP_WATER) {
|
||||
if(!on_map || terrain[x][y] == t_translation::SHALLOW_WATER ||
|
||||
terrain[x][y] == t_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] = terrain_translation::SHALLOW_WATER;
|
||||
terrain[i->x][i->y] = t_translation::SHALLOW_WATER;
|
||||
}
|
||||
|
||||
LOG_NG << "done generating river\n";
|
||||
|
@ -299,7 +301,7 @@ location random_point_at_side(size_t width, size_t height)
|
|||
|
||||
//function which, given the map will output it in a valid format.
|
||||
std::string output_map(const terrain_map& terrain,
|
||||
std::map<int, terrain_translation::coordinate> starting_positions)
|
||||
std::map<int, t_translation::coordinate> starting_positions)
|
||||
{
|
||||
//remember that we only want the middle 1/9th of the map. All other
|
||||
//segments of the map are there only to give the important middle part
|
||||
|
@ -322,13 +324,13 @@ std::string output_map(const terrain_map& terrain,
|
|||
|
||||
// Since the map has been resize the starting
|
||||
// locations also need to be fixed
|
||||
std::map<int, terrain_translation::coordinate>::iterator itor = starting_positions.begin();
|
||||
std::map<int, t_translation::coordinate>::iterator itor = starting_positions.begin();
|
||||
for(; itor != starting_positions.end(); ++itor) {
|
||||
itor->second.x -= begin_x;
|
||||
itor->second.y -= begin_y;
|
||||
}
|
||||
|
||||
return terrain_translation::write_game_map(map, starting_positions);
|
||||
return t_translation::write_game_map(map, starting_positions);
|
||||
}
|
||||
|
||||
//an object that will calculate the cost of building a road over terrain
|
||||
|
@ -348,8 +350,8 @@ private:
|
|||
const terrain_map& map_;
|
||||
const config& cfg_;
|
||||
int windiness_;
|
||||
mutable std::map<location,double> loc_cache_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,double> cache_;
|
||||
mutable std::map<location, double> loc_cache_;
|
||||
mutable std::map<t_translation::t_letter, double> cache_;
|
||||
};
|
||||
|
||||
double road_path_calculator::cost(const location& /*src*/, const location& loc, const double /*so_far*/, const bool /*isDst*/) const
|
||||
|
@ -369,8 +371,8 @@ 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 terrain_translation::TERRAIN_NUMBER c = map_[loc.x][loc.y];
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER, double>::const_iterator itor = cache_.find(c);
|
||||
const t_translation::t_letter c = map_[loc.x][loc.y];
|
||||
const std::map<t_translation::t_letter, double>::const_iterator itor = cache_.find(c);
|
||||
if(itor != cache_.end()) {
|
||||
return itor->second*windiness;
|
||||
}
|
||||
|
@ -378,8 +380,7 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
//FIXME MdW test this modification
|
||||
// static std::string terrain(1,'x');
|
||||
// terrain[0] = c;
|
||||
static std::string terrain;
|
||||
terrain = terrain_translation::write_letter(c);
|
||||
static std::string terrain = t_translation::write_letter(c);
|
||||
|
||||
const config* const child = cfg_.find_child("road_cost","terrain",terrain);
|
||||
double res = getNoPathValue();
|
||||
|
@ -387,23 +388,23 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
res = double(atof((*child)["cost"].c_str()));
|
||||
}
|
||||
|
||||
cache_.insert(std::pair<terrain_translation::TERRAIN_NUMBER, double>(c,res));
|
||||
cache_.insert(std::pair<t_translation::t_letter, double>(c,res));
|
||||
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<terrain_translation::TERRAIN_NUMBER> >& map,
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_list);
|
||||
is_valid_terrain(const t_translation::t_map& map,
|
||||
const t_translation::t_list& terrain_list);
|
||||
bool operator()(int x, int y) const;
|
||||
private:
|
||||
std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> > map_;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_;
|
||||
t_translation::t_map map_;
|
||||
const t_translation::t_list& terrain_;
|
||||
};
|
||||
|
||||
is_valid_terrain::is_valid_terrain(const std::vector<std::vector<terrain_translation::TERRAIN_NUMBER> >& map,
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_list)
|
||||
is_valid_terrain::is_valid_terrain(const t_translation::t_map& map,
|
||||
const t_translation::t_list& terrain_list)
|
||||
: map_(map), terrain_(terrain_list)
|
||||
{}
|
||||
|
||||
|
@ -481,8 +482,8 @@ 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<terrain_translation::TERRAIN_NUMBER> >& map,
|
||||
size_t x, size_t y, size_t radius, const config& cfg)
|
||||
gamemap::location place_village(const t_translation::t_map& map,
|
||||
size_t x, size_t y, size_t radius, const config& cfg)
|
||||
{
|
||||
const gamemap::location loc(x,y);
|
||||
std::set<gamemap::location> locs;
|
||||
|
@ -505,9 +506,11 @@ gamemap::location place_village(const std::vector<std::vector<terrain_translatio
|
|||
continue;
|
||||
}
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER t = map[adj[n].x][adj[n].y];
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& adjacent_liked =
|
||||
terrain_translation::read_list((*child)["adjacent_liked"], 0, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_letter t = map[adj[n].x][adj[n].y];
|
||||
const t_translation::t_list& adjacent_liked =
|
||||
t_translation::read_list((*child)["adjacent_liked"],
|
||||
0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
rating += std::count(adjacent_liked.begin(),adjacent_liked.end(),t);
|
||||
}
|
||||
|
||||
|
@ -564,20 +567,20 @@ public:
|
|||
explicit terrain_height_mapper(const config& cfg);
|
||||
|
||||
bool convert_terrain(int height) const;
|
||||
terrain_translation::TERRAIN_NUMBER convert_to() const;
|
||||
t_translation::t_letter convert_to() const;
|
||||
|
||||
private:
|
||||
int terrain_height;
|
||||
terrain_translation::TERRAIN_NUMBER to;
|
||||
t_translation::t_letter to;
|
||||
};
|
||||
|
||||
terrain_height_mapper::terrain_height_mapper(const config& cfg) :
|
||||
terrain_height(lexical_cast_default<int>(cfg["height"],0)),
|
||||
to(terrain_translation::GRASS_LAND)
|
||||
to(t_translation::GRASS_LAND)
|
||||
{
|
||||
const std::string& terrain = cfg["terrain"];
|
||||
if(terrain != "") {
|
||||
to = terrain_translation::read_letter(terrain, terrain_translation::TFORMAT_AUTO);
|
||||
to = t_translation::read_letter(terrain, t_translation::T_FORMAT_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -586,7 +589,7 @@ bool terrain_height_mapper::convert_terrain(int height) const
|
|||
return height >= terrain_height;
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_height_mapper::convert_to() const
|
||||
t_translation::t_letter terrain_height_mapper::convert_to() const
|
||||
{
|
||||
return to;
|
||||
}
|
||||
|
@ -596,19 +599,19 @@ class terrain_converter
|
|||
public:
|
||||
explicit terrain_converter(const config& cfg);
|
||||
|
||||
bool convert_terrain(terrain_translation::TERRAIN_NUMBER terrain, int height, int temperature) const;
|
||||
terrain_translation::TERRAIN_NUMBER convert_to() const;
|
||||
bool convert_terrain(t_translation::t_letter terrain, int height, int temperature) const;
|
||||
t_translation::t_letter convert_to() const;
|
||||
|
||||
private:
|
||||
int min_temp, max_temp, min_height, max_height;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> from;
|
||||
terrain_translation::TERRAIN_NUMBER to;
|
||||
t_translation::t_list from;
|
||||
t_translation::t_letter to;
|
||||
};
|
||||
|
||||
terrain_converter::terrain_converter(const config& cfg) : min_temp(-1),
|
||||
max_temp(-1), min_height(-1), max_height(-1),
|
||||
from(terrain_translation::read_list(cfg["from"],0 , terrain_translation::TFORMAT_AUTO)),
|
||||
to(terrain_translation::NONE_TERRAIN)
|
||||
from(t_translation::read_list(cfg["from"],0 , t_translation::T_FORMAT_AUTO)),
|
||||
to(t_translation::NONE_TERRAIN)
|
||||
{
|
||||
min_temp = lexical_cast_default<int>(cfg["min_temperature"],-100000);
|
||||
max_temp = lexical_cast_default<int>(cfg["max_temperature"],100000);
|
||||
|
@ -617,17 +620,18 @@ terrain_converter::terrain_converter(const config& cfg) : min_temp(-1),
|
|||
|
||||
const std::string& to_str = cfg["to"];
|
||||
if(to_str != "") {
|
||||
to = terrain_translation::read_letter(to_str, terrain_translation::TFORMAT_AUTO);
|
||||
to = t_translation::read_letter(to_str, t_translation::T_FORMAT_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
bool terrain_converter::convert_terrain(terrain_translation::TERRAIN_NUMBER terrain, int height, int temperature) const
|
||||
bool terrain_converter::convert_terrain(t_translation::t_letter 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;
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_converter::convert_to() const
|
||||
t_translation::t_letter terrain_converter::convert_to() const
|
||||
{
|
||||
return to;
|
||||
}
|
||||
|
@ -650,11 +654,11 @@ 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 = terrain_translation::write_letter(terrain_translation::GRASS_LAND);
|
||||
flatland = t_translation::write_letter(t_translation::GRASS_LAND);
|
||||
}
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER grassland =
|
||||
terrain_translation::read_letter(flatland, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_letter grassland =
|
||||
t_translation::read_letter(flatland, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
//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
|
||||
|
@ -686,7 +690,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<terrain_translation::TERRAIN_NUMBER>(height, grassland));
|
||||
terrain_map terrain(width, t_translation::t_list(height, grassland));
|
||||
size_t x, y;
|
||||
for(x = 0; x != heights.size(); ++x) {
|
||||
for(y = 0; y != heights[x].size(); ++y) {
|
||||
|
@ -848,8 +852,10 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
//castle configuration tag contains a 'valid_terrain' attribute which is a list of
|
||||
//terrains that the castle may appear on.
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER> list =
|
||||
terrain_translation::read_list((*castle_config)["valid_terrain"],0 , terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_list list =
|
||||
t_translation::read_list((*castle_config)["valid_terrain"],
|
||||
0, t_translation::T_FORMAT_AUTO);
|
||||
|
||||
const is_valid_terrain terrain_tester(terrain, list);
|
||||
|
||||
//attempt to place castles at random. Once we have placed castles, we run a sanity
|
||||
|
@ -962,7 +968,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
//find the configuration which tells us what to convert this tile to
|
||||
//to make it into a road.
|
||||
const config* const child = cfg.find_child("road_cost", "terrain",
|
||||
terrain_translation::write_letter(terrain[x][y]));
|
||||
t_translation::write_letter(terrain[x][y]));
|
||||
if(child != NULL) {
|
||||
//convert to bridge means that we want to convert depending
|
||||
//upon the direction the road is going.
|
||||
|
@ -1012,7 +1018,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
if(direction != -1) {
|
||||
const std::vector<std::string> items = utils::split(convert_to_bridge);
|
||||
if(size_t(direction) < items.size() && items[direction].empty() == false) {
|
||||
terrain[x][y] = terrain_translation::read_letter(items[direction], terrain_translation::TFORMAT_AUTO);
|
||||
terrain[x][y] = t_translation::read_letter(items[direction],
|
||||
t_translation::T_FORMAT_AUTO);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
@ -1024,7 +1031,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
//just a plain terrain substitution for a road
|
||||
const std::string& convert_to = (*child)["convert_to"];
|
||||
if(convert_to.empty() == false) {
|
||||
const terrain_translation::TERRAIN_NUMBER letter = terrain_translation::read_letter(convert_to, terrain_translation::TFORMAT_AUTO);
|
||||
const t_translation::t_letter letter =
|
||||
t_translation::read_letter(convert_to, t_translation::T_FORMAT_AUTO);
|
||||
if(labels != NULL && terrain[x][y] != letter && name_count++ == name_frequency && on_bridge == false) {
|
||||
labels->insert(std::pair<gamemap::location,std::string>(gamemap::location(x-width/3,y-height/3),name));
|
||||
name_count = 0;
|
||||
|
@ -1040,7 +1048,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
|
||||
//now that road drawing is done, we can plonk down the castles.
|
||||
std::map<int, terrain_translation::coordinate> starting_positions;
|
||||
std::map<int, t_translation::coordinate> starting_positions;
|
||||
for(std::vector<location>::const_iterator c = castles.begin(); c != castles.end(); ++c) {
|
||||
if(c->valid() == false) {
|
||||
continue;
|
||||
|
@ -1049,8 +1057,8 @@ 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() + 1;
|
||||
const struct terrain_translation::coordinate coord = {x, y};
|
||||
starting_positions.insert(std::pair<int, terrain_translation::coordinate>(player, coord));
|
||||
const struct t_translation::coordinate coord = {x, y};
|
||||
starting_positions.insert(std::pair<int, t_translation::coordinate>(player, coord));
|
||||
|
||||
const int castles[13][2] = {
|
||||
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
|
||||
|
@ -1058,7 +1066,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]] = terrain_translation::CASTLE;
|
||||
terrain[x+castles[i][0]][y+castles[i][1]] = t_translation::CASTLE;
|
||||
}
|
||||
|
||||
//remove all labels under the castle tiles
|
||||
|
@ -1114,12 +1122,14 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const gamemap::location res = place_village(terrain,x,y,2,cfg);
|
||||
|
||||
if(res.x >= (long)width/3 && res.x < (long)(width*2)/3 && res.y >= (long)height/3 && res.y < (long)(height*2)/3) {
|
||||
const std::string str = terrain_translation::write_letter(terrain[res.x][res.y]);
|
||||
const std::string str = t_translation::write_letter(terrain[res.x][res.y]);
|
||||
const config* const child = cfg.find_child("village","terrain",str);
|
||||
if(child != NULL) {
|
||||
const std::string& convert_to = (*child)["convert_to"];
|
||||
if(convert_to != "") {
|
||||
terrain[res.x][res.y] = terrain_translation::read_letter(convert_to, terrain_translation::TFORMAT_AUTO);
|
||||
terrain[res.x][res.y] = t_translation::read_letter(convert_to,
|
||||
t_translation::T_FORMAT_AUTO);
|
||||
|
||||
villages.insert(res);
|
||||
|
||||
if(labels != NULL && naming_cfg.empty() == false) {
|
||||
|
@ -1129,11 +1139,11 @@ 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::vector<terrain_translation::TERRAIN_NUMBER>
|
||||
field = std::vector<terrain_translation::TERRAIN_NUMBER>(1, terrain_translation::GRASS_LAND),
|
||||
forest = std::vector<terrain_translation::TERRAIN_NUMBER>(1, terrain_translation::FOREST),
|
||||
mountain = std::vector<terrain_translation::TERRAIN_NUMBER>(1, terrain_translation::MOUNTAIN),
|
||||
hill = std::vector<terrain_translation::TERRAIN_NUMBER>(1, terrain_translation::HILL);
|
||||
const t_translation::t_list
|
||||
field = t_translation::t_list(1, t_translation::GRASS_LAND),
|
||||
forest = t_translation::t_list(1, t_translation::FOREST),
|
||||
mountain = t_translation::t_list(1, t_translation::MOUNTAIN),
|
||||
hill = t_translation::t_list(1, t_translation::HILL);
|
||||
|
||||
size_t field_count = 0, forest_count = 0, mountain_count = 0, hill_count = 0;
|
||||
|
||||
|
@ -1160,8 +1170,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
break;
|
||||
}
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER terr = terrain[adj[n].x+width/3][adj[n].y+height/3];
|
||||
|
||||
const t_translation::t_letter terr =
|
||||
terrain[adj[n].x+width/3][adj[n].y+height/3];
|
||||
|
||||
if(std::count(field.begin(),field.end(),terr) > 0) {
|
||||
++field_count;
|
||||
|
|
|
@ -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 terrain_translation::TERRAIN_NUMBER terrain = shrouded ? terrain_translation::VOID_TERRAIN : map[x][y];
|
||||
const t_translation::t_letter terrain = shrouded ? t_translation::VOID_TERRAIN : map[x][y];
|
||||
cache_map::iterator i = cache.find(terrain);
|
||||
|
||||
if(i == cache.end()) {
|
||||
|
|
|
@ -29,7 +29,6 @@ class gamebrowser : public gui::menu {
|
|||
public:
|
||||
struct game_item {
|
||||
surface mini_map;
|
||||
// std::vector<terrain_translation::TERRAIN_NUMBER> map_data;
|
||||
std::string map_data;
|
||||
std::string name;
|
||||
std::string map_info;
|
||||
|
|
|
@ -406,7 +406,7 @@ namespace {
|
|||
continue;
|
||||
|
||||
//find the terrain of the adjacent location
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map[currentloc.x][currentloc.y];
|
||||
const t_translation::t_letter terrain = map[currentloc.x][currentloc.y];
|
||||
|
||||
//find the movement cost of this type onto the terrain
|
||||
const int move_cost = u.movement_cost(terrain);
|
||||
|
|
|
@ -51,7 +51,7 @@ bool fps = false;
|
|||
bool lobby_minimaps = true;
|
||||
|
||||
std::set<std::string> encountered_units_set;
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> encountered_terrains_set;
|
||||
std::set<t_translation::t_letter> encountered_terrains_set;
|
||||
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,8 @@ manager::manager()
|
|||
v = utils::split(prefs["encountered_units"]);
|
||||
std::copy(v.begin(), v.end(),
|
||||
std::inserter(encountered_units_set, encountered_units_set.begin()));
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain;
|
||||
terrain_translation::read_list(prefs["encountered_terrain_list"], -1, terrain_translation::TFORMAT_STRING);
|
||||
t_translation::t_list terrain; //FIXME MdW geen =
|
||||
t_translation::read_list(prefs["encountered_terrain_list"], -1, t_translation::T_FORMAT_STRING);
|
||||
std::copy(terrain.begin(), terrain.end(),
|
||||
std::inserter(encountered_terrains_set, encountered_terrains_set.begin()));
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ 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);
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> terrain;
|
||||
t_translation::t_list terrain;
|
||||
std::copy(encountered_terrains_set.begin(), encountered_terrains_set.end(),
|
||||
std::back_inserter(terrain));
|
||||
prefs["encountered_terrain_list"] = terrain_translation::write_list(terrain);
|
||||
prefs["encountered_terrain_list"] = t_translation::write_list(terrain);
|
||||
|
||||
encountered_units_set.clear();
|
||||
encountered_terrains_set.clear();
|
||||
|
@ -957,7 +957,7 @@ std::set<std::string> &encountered_units() {
|
|||
return encountered_units_set;
|
||||
}
|
||||
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> &encountered_terrains() {
|
||||
std::set<t_translation::t_letter> &encountered_terrains() {
|
||||
return encountered_terrains_set;
|
||||
}
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ 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 terrain_translation::TERRAIN_NUMBER t = map.get_terrain(gamemap::location(map_x, map_y));
|
||||
const t_translation::t_letter t = map.get_terrain(gamemap::location(map_x, map_y));
|
||||
preferences::encountered_terrains().insert(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ namespace preferences {
|
|||
bool compress_saves();
|
||||
|
||||
std::set<std::string> &encountered_units();
|
||||
std::set<terrain_translation::TERRAIN_NUMBER> &encountered_terrains();
|
||||
std::set<t_translation::t_letter> &encountered_terrains();
|
||||
|
||||
enum CACHE_SAVES_METHOD { CACHE_SAVES_ASK, CACHE_SAVES_NEVER, CACHE_SAVES_ALWAYS };
|
||||
CACHE_SAVES_METHOD cache_saves();
|
||||
|
|
|
@ -374,8 +374,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 terrain_translation::TERRAIN_NUMBER terrain = map.get_terrain(mouseover);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_union_terrain(terrain);
|
||||
const t_translation::t_letter terrain = map.get_terrain(mouseover);
|
||||
const t_translation::t_list& underlying = map.underlying_union_terrain(terrain);
|
||||
|
||||
if(map.is_village(mouseover)) {
|
||||
const unsigned int owner = village_owner(mouseover,teams)+1;
|
||||
|
@ -397,8 +397,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
str << "(";
|
||||
|
||||
// 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) {
|
||||
for(t_translation::t_list::const_iterator i =
|
||||
underlying.begin(); i != underlying.end(); ++i) {
|
||||
|
||||
str << map.get_terrain_info(*i).name();
|
||||
if(i+1 != underlying.end()) {
|
||||
str << ",";
|
||||
|
@ -418,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 terrain_translation::TERRAIN_NUMBER terrain = map[mouseover.x][mouseover.y];
|
||||
const t_translation::t_letter terrain = map[mouseover.x][mouseover.y];
|
||||
|
||||
const int move_cost = u->second.movement_cost(terrain);
|
||||
const int defense = 100 - u->second.defense_modifier(terrain);
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
|
||||
terrain_type::terrain_type() : symbol_image_("void"),
|
||||
number_(terrain_translation::VOID_TERRAIN),
|
||||
mvt_type_(1, terrain_translation::VOID_TERRAIN),
|
||||
def_type_(1, terrain_translation::VOID_TERRAIN),
|
||||
union_type_(1, terrain_translation::VOID_TERRAIN),
|
||||
number_(t_translation::VOID_TERRAIN),
|
||||
mvt_type_(1, t_translation::VOID_TERRAIN),
|
||||
def_type_(1, t_translation::VOID_TERRAIN),
|
||||
union_type_(1, t_translation::VOID_TERRAIN),
|
||||
height_adjust_(0), submerge_(0.0),
|
||||
heals_(false), village_(false), castle_(false), keep_(false)
|
||||
{}
|
||||
|
@ -41,49 +41,40 @@ terrain_type::terrain_type(const config& cfg)
|
|||
name_ = cfg["name"];
|
||||
id_ = cfg["id"];
|
||||
|
||||
#if 0
|
||||
number_ = terrain_translation::read_letter(cfg["char"]); // FIXME MdW tag should read old format
|
||||
#endif
|
||||
|
||||
#ifdef TERRAIN_TRANSLATION_COMPATIBLE
|
||||
// load the old char and the new string part
|
||||
std::string terrain_char = cfg["char"];
|
||||
std::string terrain_string = cfg["string"];
|
||||
|
||||
//this hack makes sure the string is defined, ugly but works
|
||||
//FIXME MdW this temp hack should be removed
|
||||
// if(terrain_string == "") {
|
||||
// terrain_string = "_ _" + terrain_char;
|
||||
// }
|
||||
wassert(terrain_string != "");
|
||||
|
||||
number_ = terrain_translation::read_letter(terrain_string, terrain_translation::TFORMAT_STRING);
|
||||
number_ = t_translation::read_letter(terrain_string, t_translation::T_FORMAT_STRING);
|
||||
//if both a char and a string are defined load it in the translation
|
||||
//table. This to maintain backwards compability
|
||||
if(terrain_char != "") {
|
||||
terrain_translation::add_translation(terrain_char, number_);
|
||||
t_translation::add_translation(terrain_char, number_);
|
||||
}
|
||||
#else
|
||||
number_ = terrain_translation::read_letter(terrain_string);
|
||||
number_ = t_translation::read_letter(terrain_string);
|
||||
#endif
|
||||
|
||||
|
||||
mvt_type_.push_back(number_);
|
||||
def_type_.push_back(number_);
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& alias =
|
||||
terrain_translation::read_list(cfg["aliasof"], -1, terrain_translation::TFORMAT_STRING);
|
||||
const t_translation::t_list& alias =
|
||||
t_translation::read_list(cfg["aliasof"], -1, t_translation::T_FORMAT_STRING);
|
||||
if(!alias.empty()) {
|
||||
mvt_type_ = alias;
|
||||
def_type_ = alias;
|
||||
}
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& mvt_alias =
|
||||
terrain_translation::read_list(cfg["mvt_alias"], -1, terrain_translation::TFORMAT_STRING);
|
||||
|
||||
const t_translation::t_list& mvt_alias =
|
||||
t_translation::read_list(cfg["mvt_alias"], -1, t_translation::T_FORMAT_STRING);
|
||||
if(!mvt_alias.empty()) {
|
||||
mvt_type_ = mvt_alias;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& def_alias =
|
||||
terrain_translation::read_list(cfg["def_alias"], -1, terrain_translation::TFORMAT_STRING);
|
||||
const t_translation::t_list& def_alias =
|
||||
t_translation::read_list(cfg["def_alias"], -1, t_translation::T_FORMAT_STRING);
|
||||
if(!def_alias.empty()) {
|
||||
def_type_ = def_alias;
|
||||
}
|
||||
|
@ -92,10 +83,11 @@ terrain_type::terrain_type(const config& cfg)
|
|||
|
||||
// remove + and -
|
||||
union_type_.erase(std::remove(union_type_.begin(), union_type_.end(),
|
||||
terrain_translation::MINUS), union_type_.end());
|
||||
t_translation::MINUS), union_type_.end());
|
||||
|
||||
union_type_.erase(std::remove(union_type_.begin(), union_type_.end(),
|
||||
terrain_translation::PLUS), union_type_.end());
|
||||
t_translation::PLUS), union_type_.end());
|
||||
|
||||
// remove doubles
|
||||
std::sort(union_type_.begin(),union_type_.end());
|
||||
union_type_.erase(std::unique(union_type_.begin(), union_type_.end()), union_type_.end());
|
||||
|
@ -130,27 +122,27 @@ const std::string& terrain_type::id() const
|
|||
return id_;
|
||||
}
|
||||
|
||||
terrain_translation::TERRAIN_NUMBER terrain_type::number() const
|
||||
t_translation::t_letter terrain_type::number() const
|
||||
{
|
||||
return number_;
|
||||
}
|
||||
|
||||
bool terrain_type::is_nonnull() const
|
||||
{
|
||||
return (number_ != 0) && (number_ != terrain_translation::VOID_TERRAIN );
|
||||
return (number_ != 0) && (number_ != t_translation::VOID_TERRAIN );
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::mvt_type() const
|
||||
const t_translation::t_list& terrain_type::mvt_type() const
|
||||
{
|
||||
return mvt_type_;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::def_type() const
|
||||
const t_translation::t_list& terrain_type::def_type() const
|
||||
{
|
||||
return def_type_;
|
||||
}
|
||||
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& terrain_type::union_type() const
|
||||
const t_translation::t_list& terrain_type::union_type() const
|
||||
{
|
||||
return union_type_;
|
||||
}
|
||||
|
@ -191,16 +183,17 @@ bool terrain_type::is_keep() const
|
|||
}
|
||||
|
||||
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)
|
||||
t_translation::t_list& terrain_list,
|
||||
std::map<t_translation::t_letter, 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.number());
|
||||
letter_to_terrain.insert(std::pair<terrain_translation::TERRAIN_NUMBER,terrain_type>(
|
||||
letter_to_terrain.insert(std::pair<t_translation::t_letter, terrain_type>(
|
||||
terrain.number(),terrain));
|
||||
|
||||
str_to_terrain.insert(std::pair<std::string,terrain_type>(
|
||||
terrain.id(),terrain));
|
||||
}
|
||||
|
|
|
@ -33,18 +33,12 @@ public:
|
|||
const std::string& id() const;
|
||||
|
||||
//the character representing this terrain
|
||||
//this is the old type will be obsoleted
|
||||
//FIXME MdW maybe reinstall the letter later again after debugging everything
|
||||
// TERRAIN_LETTER letter() const;
|
||||
//
|
||||
//the number representing this terrain
|
||||
//this is the new type
|
||||
terrain_translation::TERRAIN_NUMBER number() const;
|
||||
t_translation::t_letter number() const;
|
||||
|
||||
//the underlying type of the terrain
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& mvt_type() const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& def_type() const;
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& union_type() const;
|
||||
const t_translation::t_list& mvt_type() const;
|
||||
const t_translation::t_list& def_type() const;
|
||||
const t_translation::t_list& union_type() const;
|
||||
|
||||
bool is_nonnull() const;
|
||||
int light_modification() const;
|
||||
|
@ -66,10 +60,10 @@ private:
|
|||
//terrain type. The 'type' is a list of the 'underlying types'
|
||||
//of the terrain. This may simply be the same as the number.
|
||||
//This is the internal number used, WML still used characters
|
||||
terrain_translation::TERRAIN_NUMBER number_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> mvt_type_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> def_type_;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER> union_type_;
|
||||
t_translation::t_letter number_;
|
||||
t_translation::t_list mvt_type_;
|
||||
t_translation::t_list def_type_;
|
||||
t_translation::t_list union_type_;
|
||||
|
||||
int height_adjust_;
|
||||
|
||||
|
@ -83,7 +77,7 @@ private:
|
|||
|
||||
|
||||
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);
|
||||
t_translation::t_list& terrain_list,
|
||||
std::map<t_translation::t_letter, terrain_type>& letter_to_terrain,
|
||||
std::map<std::string, terrain_type>& str_to_terrain);
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,41 +33,39 @@
|
|||
|
||||
#include "variable.hpp"
|
||||
|
||||
namespace terrain_translation {
|
||||
namespace t_translation {
|
||||
|
||||
//The new definition of terrain
|
||||
typedef char TERRAIN_LETTER;
|
||||
typedef Uint32 TERRAIN_NUMBER;
|
||||
//The definitions for a terrain
|
||||
typedef Uint32 t_letter;
|
||||
typedef std::vector<t_letter> t_list;
|
||||
typedef std::vector<std::vector<t_letter> > t_map;
|
||||
|
||||
//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.
|
||||
extern const TERRAIN_NUMBER VOID_TERRAIN;
|
||||
extern const TERRAIN_NUMBER FOGGED;
|
||||
extern const TERRAIN_NUMBER KEEP;
|
||||
extern const t_letter VOID_TERRAIN;
|
||||
extern const t_letter FOGGED;
|
||||
extern const t_letter KEEP;
|
||||
|
||||
extern const TERRAIN_NUMBER CASTLE;
|
||||
extern const TERRAIN_NUMBER SHALLOW_WATER;
|
||||
extern const TERRAIN_NUMBER DEEP_WATER;
|
||||
extern const TERRAIN_NUMBER GRASS_LAND;
|
||||
extern const TERRAIN_NUMBER FOREST;
|
||||
extern const TERRAIN_NUMBER MOUNTAIN;
|
||||
extern const TERRAIN_NUMBER HILL;
|
||||
extern const t_letter CASTLE;
|
||||
extern const t_letter SHALLOW_WATER;
|
||||
extern const t_letter DEEP_WATER;
|
||||
extern const t_letter GRASS_LAND;
|
||||
extern const t_letter FOREST;
|
||||
extern const t_letter MOUNTAIN;
|
||||
extern const t_letter HILL;
|
||||
|
||||
extern const TERRAIN_NUMBER CAVE_WALL;
|
||||
extern const TERRAIN_NUMBER CAVE;
|
||||
extern const TERRAIN_NUMBER UNDERGROUND_VILLAGE;
|
||||
extern const TERRAIN_NUMBER DWARVEN_CASTLE;
|
||||
extern const t_letter CAVE_WALL;
|
||||
extern const t_letter CAVE;
|
||||
extern const t_letter UNDERGROUND_VILLAGE;
|
||||
extern const t_letter DWARVEN_CASTLE;
|
||||
|
||||
extern const TERRAIN_NUMBER PLUS;
|
||||
extern const TERRAIN_NUMBER MINUS;
|
||||
extern const TERRAIN_NUMBER TB_STAR;
|
||||
extern const TERRAIN_NUMBER NOT;
|
||||
// extern const TERRAIN_NUMBER EOL;
|
||||
extern const TERRAIN_NUMBER TB_DOT;
|
||||
extern const TERRAIN_NUMBER COMMA;
|
||||
extern const TERRAIN_NUMBER NONE_TERRAIN;
|
||||
extern const t_letter PLUS; // +
|
||||
extern const t_letter MINUS; // -
|
||||
extern const t_letter NOT; // FIXME MdW remove once no longer used in the builder
|
||||
extern const t_letter COMMA; // ,
|
||||
const t_letter NONE_TERRAIN = 0;
|
||||
|
||||
//exception thrown if there's an error with the terrain
|
||||
//FIXME MdW we throw nobody catches...
|
||||
|
@ -75,58 +73,51 @@ namespace terrain_translation {
|
|||
error(const std::string& msg) : message(msg) {}
|
||||
std::string message;
|
||||
};
|
||||
|
||||
|
||||
#ifdef TERRAIN_TRANSLATION_COMPATIBLE
|
||||
//the terrain format lets the terrain functions know what to expect
|
||||
// TFORMAT_LETTER the string is a terrain letter (single char)
|
||||
// TFORMAT_STRING the string is a terrain string (multiple chars)
|
||||
// TFORMAT_AUTO uses map_format_ to determine the type
|
||||
enum { TFORMAT_LETTER = 1, TFORMAT_STRING = 2, TFORMAT_AUTO = 3 };
|
||||
// T_FORMAT_LETTER the string is a terrain letter (single char)
|
||||
// T_FORMAT_STRING the string is a terrain string (multiple chars)
|
||||
// T_FORMAT_AUTO uses map_format_ to determine the type
|
||||
enum { T_FORMAT_LETTER = 1, T_FORMAT_STRING = 2, T_FORMAT_AUTO = 3 };
|
||||
|
||||
#endif
|
||||
|
||||
struct coordinate {
|
||||
size_t x;
|
||||
size_t y;
|
||||
};
|
||||
|
||||
/** Reads a single terrain from a string
|
||||
* FIXME: remove tformat
|
||||
* FIXME: remove t_format
|
||||
*
|
||||
* @param letter The string which should contain 1 letter
|
||||
* @param tformat The format to read
|
||||
* @param str The string which should contain 1 letter
|
||||
* @param t_format The format to read
|
||||
*
|
||||
* @return A single terrain letter
|
||||
*/
|
||||
TERRAIN_NUMBER read_letter(const std::string& letter, const int tformat);
|
||||
t_letter read_letter(const std::string& str, const int t_format);
|
||||
|
||||
/** Writes a single letter to a string
|
||||
/** Writes a single letter to a string.
|
||||
* The writers only support the new format
|
||||
*
|
||||
* @param letter The letter to convert to a string
|
||||
*
|
||||
* @return A string containing the letter
|
||||
*/
|
||||
std::string write_letter(const TERRAIN_NUMBER& letter);
|
||||
std::string write_letter(const t_letter& letter);
|
||||
|
||||
/** Reads a list of terrain from a string, when reading the
|
||||
* old format the comma separator is optional the new format
|
||||
* only reads with a separator and ignores
|
||||
* FIXME: remove separated and tformat
|
||||
* FIXME: remove separated and t_format
|
||||
*
|
||||
* @param list A string with one or more terrain letters
|
||||
* @param str A string with one or more terrain letters
|
||||
* @param separated The old terrain format is optional separated by a comma
|
||||
* the new format is always separated by a comma and
|
||||
* ignores this parameter. Possible values:
|
||||
* 0 = no
|
||||
* 1 = yes
|
||||
* @param format The format to read.
|
||||
* @param t_format The format to read.
|
||||
*
|
||||
* @returns A vector which contains the string
|
||||
* @returns A vector which contains the letters found in the string
|
||||
*/
|
||||
// std::vector<TERRAIN_NUMBER> read_list(const std::string& list, const int separated = 0, const int tformat);
|
||||
std::vector<TERRAIN_NUMBER> read_list(const std::string& list, const int separated, const int tformat);
|
||||
t_list read_list(const std::string& str, const int separated, const int t_format);
|
||||
|
||||
/** Writes a list of terrains to a string, only writes the new format.
|
||||
*
|
||||
|
@ -135,11 +126,19 @@ namespace terrain_translation {
|
|||
* @returns A string with the terrain numbers, comma separated and
|
||||
* a space behind the comma's. Not padded.
|
||||
*/
|
||||
std::string write_list(const std::vector<TERRAIN_NUMBER>& list);
|
||||
std::string write_list(const t_list& list);
|
||||
|
||||
/** Reads a gamemap string into a vector
|
||||
/** Contains an x and c coordinate used for starting positions
|
||||
* in maps
|
||||
*/
|
||||
struct coordinate {
|
||||
size_t x;
|
||||
size_t y;
|
||||
};
|
||||
|
||||
/** Reads a gamemap string into a 2D vector
|
||||
*
|
||||
* @param map A string containing the gamemap, the following rules
|
||||
* @param str A string containing the gamemap, the following rules
|
||||
* are stated for a gamemap:
|
||||
* * The map is square
|
||||
* * The map can be prefixed with one or more empty lines,
|
||||
|
@ -168,8 +167,7 @@ namespace terrain_translation {
|
|||
* @returns A 2D vector with the terrains found the vector data is stored
|
||||
* like result[x][y] where x the column number is and y the row number.
|
||||
*/
|
||||
std::vector<std::vector<TERRAIN_NUMBER> > read_game_map(const std::string& map,
|
||||
std::map<int, coordinate>& starting_positions);
|
||||
t_map read_game_map(const std::string& str, std::map<int, coordinate>& starting_positions);
|
||||
|
||||
/** Write a gamemap in to a vector string
|
||||
*
|
||||
|
@ -180,30 +178,62 @@ namespace terrain_translation {
|
|||
* For readability the map is padded to groups of 7 chars
|
||||
* followed by a comma and space
|
||||
*/
|
||||
std::string write_game_map(const std::vector<std::vector<TERRAIN_NUMBER> >& map,
|
||||
std::map<int, coordinate> starting_positions);
|
||||
std::string write_game_map(const t_map& map, std::map<int, coordinate> starting_positions);
|
||||
|
||||
//read a string and convert it to a map
|
||||
//upon error is throws an incorrect_format_exception
|
||||
std::vector<std::vector<TERRAIN_NUMBER> > read_builder_map(const std::string& map);
|
||||
|
||||
// fixme maybe we should assume
|
||||
TERRAIN_NUMBER builder_get_number(TERRAIN_NUMBER terrain);
|
||||
|
||||
/** Tests whether a certain terrain matches another terrain
|
||||
/** Tests whether a certain terrain matches a list of terrains the terrains can
|
||||
* use wildcard matching with *. It also has an inversion function. When a !
|
||||
* is found the result of the match is inverted. The matching stops at the
|
||||
* first match (regardless of the ! found) the data is match from start to end.
|
||||
*
|
||||
* Example:
|
||||
* W*, Ww does match and returns true
|
||||
* W*, {!, Ww} does match and returns false (due to the !)
|
||||
* Ww, WW doesn't match and return false
|
||||
*
|
||||
* @param src the value to match (may also contain the wildcard)
|
||||
* @param dest the list of values to match against
|
||||
*
|
||||
* @returns the result of the match (depending on the !'s)
|
||||
*/
|
||||
bool terrain_matches(const TERRAIN_NUMBER src, const TERRAIN_NUMBER dest);
|
||||
|
||||
/** Tests whether a certain terrain matches a list of terrains
|
||||
bool terrain_matches(const t_letter src, const t_list& dest);
|
||||
|
||||
/** Tests whether a certain terrain matches another terrain,
|
||||
* for matching rules see above.
|
||||
*
|
||||
* @param src the value to match (may also contain the wildcard)
|
||||
* @param dest the value to match against
|
||||
*
|
||||
* @returns the result of the match (depending on the !'s)
|
||||
*/
|
||||
bool terrain_matches(const TERRAIN_NUMBER src, const std::vector<TERRAIN_NUMBER>& dest);
|
||||
bool terrain_matches(const t_letter src, const t_letter dest);
|
||||
|
||||
/** Reads a builder map, a builder map differs much from a normal map hence
|
||||
* the different functions
|
||||
*
|
||||
* @param str The map data, the exact rules are not stated yet since still
|
||||
* in development
|
||||
*
|
||||
* @returns A 2D vector with the data found the vector data is stored
|
||||
* like result[y][x] where x the column number is and y the row number.
|
||||
*/
|
||||
t_map read_builder_map(const std::string& str);
|
||||
|
||||
/** Translates a terrain number to the map number, since
|
||||
* there are some differences between the two
|
||||
*/
|
||||
t_letter cast_to_builder_number(t_letter terrain);
|
||||
|
||||
// these terrain letters are in the builder
|
||||
// format, so not usable in other parts of
|
||||
// the engine
|
||||
const t_letter TB_STAR = '*';
|
||||
const t_letter TB_DOT = '.';
|
||||
|
||||
/***************************************************************************************/
|
||||
|
||||
#ifdef TERRAIN_TRANSLATION_COMPATIBLE
|
||||
// The terrain letter is an old letter and will be converted with get_letter
|
||||
void add_translation(const std::string& letter, const TERRAIN_NUMBER number);
|
||||
void add_translation(const std::string& letter, const t_letter number);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
|
36
src/unit.cpp
36
src/unit.cpp
|
@ -1900,7 +1900,7 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
|
|||
|
||||
|
||||
if(!anim_) set_standing(disp,hex);
|
||||
const terrain_translation::TERRAIN_NUMBER terrain = map.get_terrain(hex);
|
||||
const t_translation::t_letter 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());
|
||||
|
||||
|
@ -2178,34 +2178,36 @@ bool unit::is_flying() const
|
|||
return flying_;
|
||||
}
|
||||
|
||||
int unit::movement_cost_internal(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
int unit::movement_cost_internal(t_translation::t_letter terrain, int recurse_count) const
|
||||
{
|
||||
const int impassable = 10000000;
|
||||
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = movement_costs_.find(terrain);
|
||||
const std::map<t_translation::t_letter,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::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
const t_translation::t_list& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
|
||||
wassert(!underlying.empty());
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) { // We fail here but first test underlying_mvt_terrain
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
bool revert = (underlying.front() == t_translation::MINUS ? true : false);
|
||||
if(recurse_count >= 100) {
|
||||
return impassable;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:impassable;
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin();
|
||||
for(t_translation::t_list::const_iterator i = underlying.begin();
|
||||
i != underlying.end(); ++i) {
|
||||
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
if(*i == t_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
} else if(*i == t_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -2217,7 +2219,7 @@ int unit::movement_cost_internal(terrain_translation::TERRAIN_NUMBER terrain, in
|
|||
}
|
||||
}
|
||||
|
||||
movement_costs_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
movement_costs_.insert(std::pair<t_translation::t_letter, int>(terrain, ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -2247,11 +2249,11 @@ int unit::movement_cost_internal(terrain_translation::TERRAIN_NUMBER terrain, in
|
|||
res = impassable;
|
||||
}
|
||||
|
||||
movement_costs_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
movement_costs_.insert(std::pair<t_translation::t_letter, int>(terrain,res));
|
||||
return res;
|
||||
}
|
||||
|
||||
int unit::movement_cost(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
int unit::movement_cost(t_translation::t_letter terrain, int recurse_count) const
|
||||
{
|
||||
int res = movement_cost_internal(terrain,recurse_count);
|
||||
if(utils::string_bool(get_state("slowed"))) {
|
||||
|
@ -2260,7 +2262,7 @@ int unit::movement_cost(terrain_translation::TERRAIN_NUMBER terrain, int recurse
|
|||
return res;
|
||||
}
|
||||
|
||||
int unit::defense_modifier(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
int unit::defense_modifier(t_translation::t_letter terrain, int recurse_count) const
|
||||
{
|
||||
// const std::map<terrain_type::TERRAIN,int>::const_iterator i = defense_mods_.find(terrain);
|
||||
// if(i != defense_mods_.end()) {
|
||||
|
@ -2269,21 +2271,21 @@ int unit::defense_modifier(terrain_translation::TERRAIN_NUMBER terrain, int recu
|
|||
|
||||
wassert(map_ != NULL);
|
||||
//if this is an alias, then select the best of all underlying terrains
|
||||
const std::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map_->underlying_def_terrain(terrain);
|
||||
const t_translation::t_list& underlying = map_->underlying_def_terrain(terrain);
|
||||
wassert(underlying.size() > 0);
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
bool revert = (underlying.front() == t_translation::MINUS ? true : false);
|
||||
if(recurse_count >= 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:100;
|
||||
std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin();
|
||||
t_translation::t_list::const_iterator i = underlying.begin();
|
||||
for(; i != underlying.end(); ++i) {
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
if(*i == t_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
} else if(*i == t_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -195,8 +195,8 @@ class unit
|
|||
bool is_flying() const;
|
||||
bool is_fearless() const { return is_fearless_; }
|
||||
bool is_healthy() const { return is_healthy_; }
|
||||
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 movement_cost(t_translation::t_letter terrain, int recurse_count=0) const;
|
||||
int defense_modifier(t_translation::t_letter terrain, int recurse_count=0) const;
|
||||
int resistance_against(const attack_type& damage_type,bool attacker,const gamemap::location& loc) const;
|
||||
// std::map<terrain_type::TERRAIN,int> movement_type() const;
|
||||
|
||||
|
@ -289,7 +289,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(terrain_translation::TERRAIN_NUMBER terrain, int recurse_count=0) const;
|
||||
int movement_cost_internal(t_translation::t_letter terrain, int recurse_count=0) const;
|
||||
bool has_ability_by_id(const std::string& ability) const;
|
||||
|
||||
config cfg_;
|
||||
|
@ -327,7 +327,7 @@ class unit
|
|||
|
||||
int movement_;
|
||||
int max_movement_, max_movement_b_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> movement_costs_; // movement cost cache
|
||||
mutable std::map<t_translation::t_letter, int> movement_costs_; // movement cost cache
|
||||
bool hold_position_;
|
||||
bool end_turn_;
|
||||
bool resting_;
|
||||
|
|
|
@ -98,9 +98,8 @@ unit_animation::unit_animation(int start_time,const unit_frame & frame ):animate
|
|||
}
|
||||
|
||||
unit_animation::unit_animation(const config& cfg,const std::string frame_string )
|
||||
//:terrain_types_(terrain_translation::read_list(cfg["terrain"], 1, terrain_translation::TFORMAT_AUTO))
|
||||
//this format hasn't been used yet, so force the new format
|
||||
:terrain_types_(terrain_translation::read_list(cfg["terrain"], -1, terrain_translation::TFORMAT_STRING))
|
||||
//this format hasn't been used yet, so force the new terrain format
|
||||
:terrain_types_(t_translation::read_list(cfg["terrain"], -1, t_translation::T_FORMAT_STRING))
|
||||
{
|
||||
config::const_child_itors range = cfg.child_range(frame_string);
|
||||
if(cfg["start_time"].empty() &&range.first != range.second) {
|
||||
|
@ -144,7 +143,7 @@ int unit_animation::matches(const display& disp, const gamemap::location& loc,co
|
|||
{
|
||||
int result = 0;
|
||||
if(terrain_types_.empty() == false) {
|
||||
if(terrain_translation::terrain_matches(disp.get_map().get_terrain(loc), terrain_types_)) {
|
||||
if(t_translation::terrain_matches(disp.get_map().get_terrain(loc), terrain_types_)) {
|
||||
result ++;
|
||||
} else {
|
||||
return -1;
|
||||
|
|
|
@ -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<terrain_translation::TERRAIN_NUMBER> terrain_types_;
|
||||
t_translation::t_list terrain_types_;
|
||||
std::vector<config> unit_filter_;
|
||||
std::vector<config> secondary_unit_filter_;
|
||||
std::vector<config> neighbour_unit_filter_;
|
||||
|
|
|
@ -72,7 +72,7 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
|
|||
return;
|
||||
}
|
||||
|
||||
const terrain_translation::TERRAIN_NUMBER dst_terrain = map.get_terrain(b);
|
||||
const t_translation::t_letter dst_terrain = map.get_terrain(b);
|
||||
|
||||
const int acceleration = disp.turbo_speed();
|
||||
|
||||
|
|
|
@ -395,31 +395,34 @@ const t_string& unit_movement_type::name() const
|
|||
return res;
|
||||
}
|
||||
|
||||
int unit_movement_type::movement_cost(const gamemap& map,terrain_translation::TERRAIN_NUMBER terrain,int recurse_count) const
|
||||
int unit_movement_type::movement_cost(const gamemap& map,
|
||||
t_translation::t_letter terrain, int recurse_count) const
|
||||
{
|
||||
const int impassable = 10000000;
|
||||
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = moveCosts_.find(terrain);
|
||||
const std::map<t_translation::t_letter, 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::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_mvt_terrain(terrain);
|
||||
const t_translation::t_list& underlying = map.underlying_mvt_terrain(terrain);
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS ?true:false);
|
||||
bool revert = (underlying.front() == t_translation::MINUS ? true : false);
|
||||
if(recurse_count >= 100) {
|
||||
return impassable;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:impassable;
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin();
|
||||
for(t_translation::t_list::const_iterator i = underlying.begin();
|
||||
i != underlying.end(); ++i) {
|
||||
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
if(*i == t_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
} else if(*i == t_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -431,7 +434,7 @@ int unit_movement_type::movement_cost(const gamemap& map,terrain_translation::TE
|
|||
}
|
||||
}
|
||||
|
||||
moveCosts_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
moveCosts_.insert(std::pair<t_translation::t_letter, int>(terrain,ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -465,34 +468,39 @@ int unit_movement_type::movement_cost(const gamemap& map,terrain_translation::TE
|
|||
res = impassable;
|
||||
}
|
||||
|
||||
moveCosts_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
moveCosts_.insert(std::pair<t_translation::t_letter, int>(terrain,res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int unit_movement_type::defense_modifier(const gamemap& map,terrain_translation::TERRAIN_NUMBER terrain, int recurse_count) const
|
||||
int unit_movement_type::defense_modifier(const gamemap& map,
|
||||
t_translation::t_letter terrain, int recurse_count) const
|
||||
{
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>::const_iterator i = defenseMods_.find(terrain);
|
||||
const std::map<t_translation::t_letter, 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::vector<terrain_translation::TERRAIN_NUMBER>& underlying = map.underlying_def_terrain(terrain);
|
||||
const t_translation::t_list& underlying =
|
||||
map.underlying_def_terrain(terrain);
|
||||
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
bool revert = (underlying.front() == terrain_translation::MINUS?true:false);
|
||||
bool revert = (underlying.front() == t_translation::MINUS ? true : false);
|
||||
if(recurse_count >= 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
int ret_value = revert?0:100;
|
||||
for(std::vector<terrain_translation::TERRAIN_NUMBER>::const_iterator i = underlying.begin();
|
||||
for(t_translation::t_list::const_iterator i = underlying.begin();
|
||||
i != underlying.end(); ++i) {
|
||||
|
||||
if(*i == terrain_translation::PLUS) {
|
||||
if(*i == t_translation::PLUS) {
|
||||
revert = false;
|
||||
continue;
|
||||
} else if(*i == terrain_translation::MINUS) {
|
||||
} else if(*i == t_translation::MINUS) {
|
||||
revert = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -504,7 +512,7 @@ int unit_movement_type::defense_modifier(const gamemap& map,terrain_translation:
|
|||
}
|
||||
}
|
||||
|
||||
defenseMods_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,ret_value));
|
||||
defenseMods_.insert(std::pair<t_translation::t_letter, int>(terrain, ret_value));
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
@ -537,7 +545,7 @@ int unit_movement_type::defense_modifier(const gamemap& map,terrain_translation:
|
|||
res = 50;
|
||||
}
|
||||
|
||||
defenseMods_.insert(std::pair<terrain_translation::TERRAIN_NUMBER,int>(terrain,res));
|
||||
defenseMods_.insert(std::pair<t_translation::t_letter, int>(terrain, res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -607,11 +615,11 @@ void unit_movement_type::set_parent(const unit_movement_type* parent)
|
|||
parent_ = parent;
|
||||
}
|
||||
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& unit_movement_type::movement_costs() const
|
||||
const std::map<t_translation::t_letter, int>& unit_movement_type::movement_costs() const
|
||||
{
|
||||
return moveCosts_;
|
||||
}
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& unit_movement_type::defense_mods() const
|
||||
const std::map<t_translation::t_letter, 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, 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 movement_cost(const gamemap& map, t_translation::t_letter terrain, int recurse_count=0) const;
|
||||
int defense_modifier(const gamemap& map, t_translation::t_letter 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<terrain_translation::TERRAIN_NUMBER,int>& movement_costs() const;
|
||||
const std::map<terrain_translation::TERRAIN_NUMBER,int>& defense_mods() const;
|
||||
const std::map<t_translation::t_letter, int>& movement_costs() const;
|
||||
const std::map<t_translation::t_letter, int>& defense_mods() const;
|
||||
|
||||
const config& get_cfg() const;
|
||||
const unit_movement_type* get_parent() const;
|
||||
private:
|
||||
const config cfg_;
|
||||
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> moveCosts_;
|
||||
mutable std::map<terrain_translation::TERRAIN_NUMBER,int> defenseMods_;
|
||||
mutable std::map<t_translation::t_letter, int> moveCosts_;
|
||||
mutable std::map<t_translation::t_letter, int> defenseMods_;
|
||||
|
||||
const unit_movement_type* parent_;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue