Author: shadowmaster
Date: Sun Aug 24 00:24:20 2008
New Revision: 28909
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28909&view=rev
Log:
* Extended [filter_attack] and [filter_second_attack] and [fire_event]
to use the same syntax as AnimationWML attack filters.
This causes some WML syntax to be deprecated and scheduled for removal in
1.5.5; namely [fire_event][primary_unit]weapon=,
[event][filter_attack]weapon= and suchlike. Details to be provided in
ChangeLog and wiki... soon.
Modified:
trunk/src/actions.cpp
trunk/src/game_events.cpp
trunk/src/unit_types.cpp
Modified: trunk/src/actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=28909&r1=28908&r2=28909&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Sun Aug 24 00:24:20 2008
@@ -762,12 +762,16 @@
LOG_NG << "firing " << n << " event\n";
if(n == "attack_end") {
config dat;
- dat.add_child("first");
- dat.add_child("second");
- if(a_ != units_.end()) {
- (*(dat.child("first")))["weapon"]= a_stats_->weapon ?
a_stats_->weapon->id() : "none";
-
- }
+ config a_weapon_cfg = (a_stats_->weapon != NULL && units_.end()
!= a_) ? a_stats_->weapon->get_cfg() : config();
+ config d_weapon_cfg = (d_stats_->weapon != NULL && units_.end()
!= a_) ? a_stats_->weapon->get_cfg() : config();
+ if(a_weapon_cfg["name"].empty())
+ a_weapon_cfg["name"] = "none";
+ if(d_weapon_cfg["name"].empty())
+ d_weapon_cfg["name"] = "none";
+ dat.add_child("first", a_weapon_cfg);
+ dat.add_child("second", d_weapon_cfg);
+
+#if 0
if(d_ != units_.end()) {
config *tempcfg = dat.child("second");
t_string d_weap = "none";
@@ -777,6 +781,7 @@
std::pair<std::string,t_string> to_insert("weapon",
d_weap);
tempcfg->values.insert(to_insert);
}
+#endif
// We want to fire attack_end event in any case! Even if one of
units was removed by WML
DELAY_END_LEVEL(delayed_exception, game_events::fire(n,
@@ -789,10 +794,14 @@
const int defender_side = d_->second.side();
const int attacker_side = a_->second.side();
config dat;
- dat.add_child("first");
- dat.add_child("second");
- (*(dat.child("first")))["weapon"]=a_stats_->weapon->id();
- (*(dat.child("second")))["weapon"]=d_stats_->weapon != NULL ?
d_stats_->weapon->id() : "none";
+ config a_weapon_cfg = (a_stats_->weapon != NULL && units_.end() != a_)
? a_stats_->weapon->get_cfg() : config();
+ config d_weapon_cfg = (d_stats_->weapon != NULL && units_.end() != a_)
? a_stats_->weapon->get_cfg() : config();
+ if(a_weapon_cfg["name"].empty())
+ a_weapon_cfg["name"] = "none";
+ if(d_weapon_cfg["name"].empty())
+ d_weapon_cfg["name"] = "none";
+ dat.add_child("first", a_weapon_cfg);
+ dat.add_child("second", d_weapon_cfg);
DELAY_END_LEVEL(delayed_exception, game_events::fire(n,
game_events::entity_location(attacker_,a_id_),
game_events::entity_location(defender_,d_id_),dat));
@@ -1110,10 +1119,14 @@
// get weapon info for last_breath and die
events
config dat;
- dat.add_child("first");
- dat.add_child("second");
- (*(dat.child("first")))["weapon"] =
d_stats_->weapon != NULL ? d_stats_->weapon->id() : "none";
- (*(dat.child("second")))["weapon"] =
a_stats_->weapon != NULL ? a_stats_->weapon->id() : "none";
+ config a_weapon_cfg = (a_stats_->weapon != NULL
&& units_.end() != a_) ? a_stats_->weapon->get_cfg() : config();
+ config d_weapon_cfg = (d_stats_->weapon != NULL
&& units_.end() != a_) ? a_stats_->weapon->get_cfg() : config();
+ if(a_weapon_cfg["name"].empty())
+ a_weapon_cfg["name"] = "none";
+ if(d_weapon_cfg["name"].empty())
+ d_weapon_cfg["name"] = "none";
+ dat.add_child("first", d_weapon_cfg);
+ dat.add_child("second", a_weapon_cfg);
DELAY_END_LEVEL(delayed_exception,
game_events::fire("last breath", death_loc, attacker_loc, dat));
@@ -1368,10 +1381,14 @@
// get weapon info for last_breath and die
events
config dat;
- dat.add_child("first");
- dat.add_child("second");
- (*(dat.child("first")))["weapon"] =
a_stats_->weapon != NULL ? a_stats_->weapon->id() : "none";
- (*(dat.child("second")))["weapon"] =
d_stats_->weapon != NULL ? d_stats_->weapon->id() : "none";
+ config a_weapon_cfg = (a_stats_->weapon != NULL
&& units_.end() != a_) ? a_stats_->weapon->get_cfg() : config();
+ config d_weapon_cfg = (d_stats_->weapon != NULL
&& units_.end() != a_) ? a_stats_->weapon->get_cfg() : config();
+ if(a_weapon_cfg["name"].empty())
+ a_weapon_cfg["name"] = "none";
+ if(d_weapon_cfg["name"].empty())
+ d_weapon_cfg["name"] = "none";
+ dat.add_child("first" , a_weapon_cfg);
+ dat.add_child("second", d_weapon_cfg);
DELAY_END_LEVEL(delayed_exception,
game_events::fire("last breath", death_loc, defender_loc,dat));
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=28909&r1=28908&r2=28909&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Sun Aug 24 00:24:20 2008
@@ -2106,18 +2106,32 @@
if (u.has_attribute("x") && u.has_attribute("y"))
loc1 = cfg_to_loc(u);
if (u.has_attribute("weapon")) {
+ lg::wml_error << "weapon= in [fire_event] has
been deprecated; support for this will be removed in 1.5.5\n";
+
config& f = data.add_child("first");
- f["weapon"] = u.get_attribute("weapon");
- }
+ f["name"] = u.get_attribute("weapon");
+ }
+ }
+ if (cfg.has_child("primary_attack")) {
+ // mixing this with deprecated [primary_unit] weapon=
above may
+ // cause undefined behavior!
+ data.add_child("first",
cfg.child("primary_attack").get_parsed_config());
}
if (cfg.has_child("secondary_unit")) {
vconfig u = cfg.child("secondary_unit");
if (u.has_attribute("x") && u.has_attribute("y"))
loc2 = cfg_to_loc(u);
if (u.has_attribute("weapon")) {
+ lg::wml_error << "weapon= in [fire_event] has
been deprecated; support for this will be removed in 1.5.5\n";
+
config& s = data.add_child("second");
- s["weapon"] = u.get_attribute("weapon");
- }
+ s["name"] = u.get_attribute("weapon");
+ }
+ }
+ if (cfg.has_child("secondary_attack")) {
+ // mixing this with deprecated [secondary_unit] weapon=
above may
+ // cause undefined behavior!
+ data.add_child("second",
cfg.child("secondary_attack").get_parsed_config());
}
game_events::fire(cfg["name"],loc1,loc2,data);
}
@@ -3349,16 +3363,14 @@
{
//! @todo FIXME: This filter should be deprecated and
removed,
// instead we should just auto-store $attacker_weapon
and check it in a conditional
+ //! @todo FIXME: ^ what?
if(!cfg) {
- return false;
- }
- bool matches = true;
- if(filter["weapon"] != "") {
- if(filter["weapon"] != (*cfg)["weapon"]) {
- matches = false;
- }
- }
+ return false; //! @todo FIXME: shouldn't this
be true!?
+ }
+ const config& attack_cfg = *cfg;
+ const attack_type attack(attack_cfg);
+ bool matches =
attack.matches_filter(filter.get_parsed_config());
// Handle [and], [or], and [not] with in-order
precedence
vconfig::all_children_iterator cond_i =
filter.ordered_begin();
Modified: trunk/src/unit_types.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=28909&r1=28908&r2=28909&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Sun Aug 24 00:24:20 2008
@@ -105,10 +105,15 @@
bool attack_type::matches_filter(const config& cfg,bool self) const
{
+ const bool deprecated_style = cfg["name"].empty() &&
!cfg["weapon"].empty();
+
const std::vector<std::string>& filter_range =
utils::split(cfg["range"]);
- const std::vector<std::string> filter_name = utils::split(cfg["name"]);
+ const std::vector<std::string> filter_name = !deprecated_style ?
utils::split(cfg["name"]) : utils::split(cfg["weapon"]);
const std::vector<std::string> filter_type = utils::split(cfg["type"]);
const std::string filter_special = cfg["special"];
+
+ if(deprecated_style)
+ lg::wml_error << "deprecated 'weapon' attribute in attack
filter; support for this will be removed in 1.5.5 (use 'name' instead)\n";
if(filter_range.empty() == false &&
std::find(filter_range.begin(),filter_range.end(),range()) ==
filter_range.end())
return false;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits