Author: esr
Date: Mon Jul 2 15:39:34 2007
New Revision: 18613
URL: http://svn.gna.org/viewcvs/wesnoth?rev=18613&view=rev
Log:
Separate reasding of configurations from the map class.
Modified:
trunk/src/ai.cpp
trunk/src/config_adapter.cpp
trunk/src/game_events.cpp
trunk/src/map.cpp
trunk/src/map.hpp
trunk/src/map_label.cpp
trunk/src/playsingle_controller.cpp
trunk/src/replay.cpp
trunk/src/team.cpp
Modified: trunk/src/ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Mon Jul 2 15:39:34 2007
@@ -783,7 +783,7 @@
items.push_back(protected_item(
lexical_cast_default<double>((**i)["value"], 1.0),
lexical_cast_default<int>((**i)["radius"], 20),
- location(**i)));
+ read_location(**i)));
}
//look for directions to protect a unit
@@ -1895,7 +1895,7 @@
return;
}
- const gamemap::location dst(*goal);
+ const gamemap::location dst = read_location(*goal);
if (!dst.valid()) {
ERR_AI << "Invalid goal\n";
return;
Modified: trunk/src/config_adapter.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config_adapter.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/config_adapter.cpp (original)
+++ trunk/src/config_adapter.cpp Mon Jul 2 15:39:34 2007
@@ -107,7 +107,7 @@
//see if the side specifies its location. Otherwise start it at
the map-given
//starting position
- gamemap::location start_pos(cfg);
+ gamemap::location start_pos = read_location(cfg);
if(map.empty()) {
throw game::load_game_failed("Map not found");
@@ -163,7 +163,7 @@
const std::string& x = (**su)["x"];
const std::string& y = (**su)["y"];
- gamemap::location loc(**su);
+ gamemap::location loc = read_location(**su);
if(x.empty() && y.empty()) {
if(player) {
player->available_units.push_back(new_unit);
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Mon Jul 2 15:39:34 2007
@@ -21,6 +21,7 @@
#include "image.hpp"
#include "language.hpp"
#include "log.hpp"
+#include "map.hpp"
#include "menu_events.hpp"
#include "preferences.hpp"
#include "replay.hpp"
@@ -48,6 +49,27 @@
#define ERR_NG LOG_STREAM(err, engine)
#define LOG_DP LOG_STREAM(info, display)
#define ERR_CF LOG_STREAM(err, config)
+
+// This is here to avoid creating a cross-dependency with the map class.
+
+gamemap::location read_location(const config& cfg)
+{
+ std::string xs = cfg["x"], ys = cfg["y"];
+ if (game_events::get_state_of_game())
+ {
+ xs = utils::interpolate_variables_into_string( xs,
*game_events::get_state_of_game());
+ ys = utils::interpolate_variables_into_string( ys,
*game_events::get_state_of_game());
+ }
+ //the co-ordinates in config files will be 1-based, while we
+ //want them as 0-based
+ int x = -1, y = -1;
+ if(xs.empty() == false)
+ x = atoi(xs.c_str()) - 1;
+
+ if(ys.empty() == false)
+ y = atoi(ys.c_str()) - 1;
+ return gamemap::location::location(x, y);
+};
namespace {
@@ -1859,7 +1881,7 @@
const unit
u(game_data_ptr,units,game_map,status_ptr,teams,var);
preferences::encountered_units().insert(u.id());
- gamemap::location loc(var);
+ gamemap::location loc = read_location(var);
if(loc.valid()) {
if(utils::string_bool(cfg["find_vacant"])) {
loc =
find_vacant_tile(*game_map,*units,loc);
Modified: trunk/src/map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Mon Jul 2 15:39:34 2007
@@ -126,28 +126,6 @@
return std::string();
}
-}
-
-void gamemap::location::init(const std::string &xstr, const std::string &ystr)
-{
- std::string xs = xstr, ys = ystr;
- if (game_events::get_state_of_game())
- {
- xs = utils::interpolate_variables_into_string( xs,
*game_events::get_state_of_game());
- ys = utils::interpolate_variables_into_string( ys,
*game_events::get_state_of_game());
- }
- //the co-ordinates in config files will be 1-based, while we
- //want them as 0-based
- if(xs.empty() == false)
- x = atoi(xs.c_str()) - 1;
-
- if(ys.empty() == false)
- y = atoi(ys.c_str()) - 1;
-}
-
-gamemap::location::location(const config& cfg) : x(-1), y(-1)
-{
- init(cfg["x"], cfg["y"]);
}
void gamemap::location::write(config& cfg) const
Modified: trunk/src/map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Mon Jul 2 15:39:34 2007
@@ -61,7 +61,6 @@
location() : x(-1), y(-1) {}
location(int x, int y) : x(x), y(y) {}
- explicit location(const config& cfg);
void write(config& cfg) const;
@@ -92,8 +91,6 @@
DIRECTION get_opposite_dir(DIRECTION d) const;
static location null_location;
- private:
- void init(const std::string &x, const std::string &y);
};
const t_translation::t_list& underlying_mvt_terrain(const location&
loc) const
{ return underlying_mvt_terrain(get_terrain(loc)); }
@@ -237,6 +234,9 @@
const std::string& yvals,
const gamemap *const map=NULL);
+// parse a WML location with variable interpolation
+gamemap::location read_location(const config& cfg);
+
//dump a position on a stream for debug purposes
std::ostream &operator<<(std::ostream &s, gamemap::location const &l);
Modified: trunk/src/map_label.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map_label.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/map_label.cpp (original)
+++ trunk/src/map_label.cpp Mon Jul 2 15:39:34 2007
@@ -80,7 +80,7 @@
const config::child_list& items = cfg.get_children("label");
for(config::child_list::const_iterator i = items.begin(); i !=
items.end(); ++i) {
- const gamemap::location loc(**i);
+ const gamemap::location loc = read_location(**i);
terrain_label* label = new terrain_label(*this, **i);
add_label(loc, label);
}
@@ -348,7 +348,7 @@
void terrain_label::read(const config& cfg)
{
- loc_ = gamemap::location(cfg);
+ loc_ = read_location(cfg);
SDL_Color colour = font::LABEL_COLOUR;
std::string tmp_colour = cfg["colour"];
Modified: trunk/src/playsingle_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playsingle_controller.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/playsingle_controller.cpp (original)
+++ trunk/src/playsingle_controller.cpp Mon Jul 2 15:39:34 2007
@@ -151,7 +151,7 @@
//find a list of 'items' (i.e. overlays) on the level, and add them
const config::child_list& overlays = level_.get_children("item");
for(config::child_list::const_iterator overlay = overlays.begin();
overlay != overlays.end(); ++overlay) {
-
gui_->add_overlay(gamemap::location(**overlay),(**overlay)["image"],
(**overlay)["halo"]);
+
gui_->add_overlay(read_location(**overlay),(**overlay)["image"],
(**overlay)["halo"]);
}
victory_conditions::set_victory_when_enemies_defeated(
Modified: trunk/src/replay.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/replay.cpp (original)
+++ trunk/src/replay.cpp Mon Jul 2 15:39:34 2007
@@ -60,7 +60,7 @@
std::set<gamemap::location> locs;
const config::child_list& items =
cfg.get_children("unit");
for(config::child_list::const_iterator i =
items.begin(); i != items.end(); ++i) {
- const gamemap::location loc(**i);
+ const gamemap::location loc =
read_location(**i);
locs.insert(loc);
if(units.count(loc) == 0) {
@@ -81,7 +81,7 @@
const config::child_list& items = cfg.get_children("unit");
for(config::child_list::const_iterator i = items.begin(); i !=
items.end(); ++i) {
- const gamemap::location loc(**i);
+ const gamemap::location loc = read_location(**i);
const unit_map::const_iterator u = units.find(loc);
if(u == units.end()) {
errbuf << "SYNC VERIFICATION FAILED: data
source says there is a '"
@@ -578,7 +578,7 @@
return;
}
for(config::child_list::const_iterator ci =
cfg.get_children("checksum").begin(); ci != cfg.get_children("checksum").end();
++ci) {
- gamemap::location loc(**ci);
+ gamemap::location loc = read_location(**ci);
unit_map::const_iterator u = units.find(loc);
if(u == units.end()) {
std::stringstream message;
@@ -706,7 +706,7 @@
}
else if((child = cfg->child("rename")) != NULL) {
- const gamemap::location loc(*child);
+ const gamemap::location loc = read_location(*child);
const std::string& name = (*child)["name"];
unit_map::iterator u = units.find(loc);
@@ -739,7 +739,7 @@
const std::string& recruit_num = (*child)["value"];
const int val = atoi(recruit_num.c_str());
- gamemap::location loc(*child);
+ gamemap::location loc = read_location(*child);
const std::set<std::string>& recruits =
current_team.recruits();
@@ -797,7 +797,7 @@
const std::string& recall_num = (*child)["value"];
const int val = atoi(recall_num.c_str());
- gamemap::location loc(*child);
+ gamemap::location loc = read_location(*child);
if(val >= 0 && val <
int(player->available_units.size())) {
statistics::recall_unit(player->available_units[val]);
@@ -850,8 +850,8 @@
replay::throw_error("no destination/source
found in movement\n");
}
- const gamemap::location src(*source);
- const gamemap::location dst(*destination);
+ const gamemap::location src = read_location(*source);
+ const gamemap::location dst =
read_location(*destination);
unit_map::iterator u = units.find(dst);
if(u != units.end()) {
@@ -951,8 +951,8 @@
replay::throw_error("no destination/source
found in attack\n");
}
- const gamemap::location src(*source);
- const gamemap::location dst(*destination);
+ const gamemap::location src = read_location(*source);
+ const gamemap::location dst =
read_location(*destination);
const std::string& weapon = (*child)["weapon"];
const int weapon_num = atoi(weapon.c_str());
@@ -1016,7 +1016,7 @@
if ((event != "side turn") && (event != "turn 1") &&
(event != "new_turn")){
const config* const source =
child->child("source");
if(source != NULL) {
- game_events::fire(event,
gamemap::location(*source));
+ game_events::fire(event,
read_location(*source));
} else {
game_events::fire(event);
}
Modified: trunk/src/team.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.cpp?rev=18613&r1=18612&r2=18613&view=diff
==============================================================================
--- trunk/src/team.cpp (original)
+++ trunk/src/team.cpp Mon Jul 2 15:39:34 2007
@@ -356,7 +356,7 @@
//load in the villages the side controls at the start
const config::child_list& villages = cfg.get_children("village");
for(config::child_list::const_iterator v = villages.begin(); v !=
villages.end(); ++v) {
- villages_.insert(gamemap::location(**v));
+ villages_.insert(read_location(**v));
}
countdown_time_=lexical_cast_default<int>(cfg["countdown_time"],0);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits