Author: anonymissimus
Date: Wed Oct 19 01:18:05 2011
New Revision: 51537
URL: http://svn.gna.org/viewcvs/wesnoth?rev=51537&view=rev
Log:
fix variable substitution on [unit][event] and [unit][filter_recall]
The unparsed vconfig from the [unit] tag is passed to the unit
constructor and filter_recall and event tags are taken from it.
[side][unit] did already no variable substitution, wesnoth.put_unit does
it only if passed a vconfig userdata to describe the unit.
Modified:
trunk/src/actions.cpp
trunk/src/actions.hpp
trunk/src/game_events.cpp
trunk/src/unit.cpp
trunk/src/unit.hpp
Modified: trunk/src/actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=51537&r1=51536&r2=51537&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Wed Oct 19 01:18:05 2011
@@ -245,7 +245,7 @@
}
-void unit_creator::add_unit(const config &cfg)
+void unit_creator::add_unit(const config &cfg, const vconfig* vcfg)
{
config temp_cfg(cfg);
temp_cfg["side"] = team_.side();
@@ -260,7 +260,7 @@
if(recall_list_element==team_.recall_list().end()) {
//make a temporary unit
- boost::scoped_ptr<unit> temp_unit(new unit(temp_cfg, true,
resources::state_of_game));
+ boost::scoped_ptr<unit> temp_unit(new unit(temp_cfg, true,
resources::state_of_game, vcfg));
map_location loc = find_location(temp_cfg, temp_unit.get());
if(!loc.valid()) {
if(add_to_recall_) {
Modified: trunk/src/actions.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=51537&r1=51536&r2=51537&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Wed Oct 19 01:18:05 2011
@@ -51,7 +51,7 @@
/**
* adds a unit on map without firing any events (so, usable during team
construction in gamestatus)
*/
- void add_unit(const config &cfg);
+ void add_unit(const config &cfg, const vconfig* vcfg = NULL);
private:
void post_create(const map_location &loc, const unit &new_unit, bool
anim);
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=51537&r1=51536&r2=51537&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Wed Oct 19 01:18:05 2011
@@ -1765,7 +1765,7 @@
.allow_rename_side(true)
.allow_show(true);
- uc.add_unit(parsed_cfg);
+ uc.add_unit(parsed_cfg, &cfg);
}
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=51537&r1=51536&r2=51537&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Wed Oct 19 01:18:05 2011
@@ -187,7 +187,7 @@
{
}
-unit::unit(const config &cfg, bool use_traits, game_state* state) :
+unit::unit(const config &cfg, bool use_traits, game_state* state, const
vconfig* vcfg) :
cfg_(),
loc_(cfg["x"] - 1, cfg["y"] - 1),
advances_to_(),
@@ -279,11 +279,29 @@
if (const config &variables = cfg.child("variables")) {
variables_ = variables;
}
- const config::const_child_itors& unit_events = cfg.child_range("event");
- game_events::add_events(unit_events);
- foreach(const config& unit_event, unit_events) {
- events_.add_child("event", unit_event);
- }
+
+ if(vcfg) {
+ config cfilter_recall;
+ const vconfig& vfilter_recall = vcfg->child("filter_recall");
+ if(!vfilter_recall.null())
+ cfilter_recall = vfilter_recall.get_config();
+ cfg_.add_child("filter_recall", cfilter_recall);
+
+ const vconfig::child_list& events = vcfg->get_children("event");
+ foreach(const vconfig& e, events) {
+ events_.add_child("event", e.get_config());
+ }
+ }
+ else
+ {
+ cfg_.add_child("filter_recall",
cfg.child_or_empty("filter_recall"));
+
+ foreach(const config& unit_event, cfg.child_range("event")) {
+ events_.add_child("event", unit_event);
+ }
+ }
+ game_events::add_events(events_.child_range("event"));
+
facing_ = map_location::parse_direction(cfg["facing"]);
if(facing_ == map_location::NDIRECTIONS) facing_ =
static_cast<map_location::DIRECTION>(rand()%map_location::NDIRECTIONS);
@@ -478,7 +496,6 @@
}
set_recruits(utils::split(cfg["extra_recruit"]));
- cfg_.add_child("filter_recall", cfg.child_or_empty("filter_recall"));
/** @todo Are these modified by read? if not they can be removed. */
getsHit_=0;
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=51537&r1=51536&r2=51537&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Wed Oct 19 01:18:05 2011
@@ -58,7 +58,7 @@
// Copy constructor
unit(const unit& u);
/** Initializes a unit from a config */
- unit(const config& cfg, bool use_traits = false, game_state *state =
NULL);
+ unit(const config& cfg, bool use_traits = false, game_state *state =
NULL, const vconfig* vcfg = NULL);
/**
* Initializes a unit from a unit type
* only real_unit may have random traits, name and gender
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits