Author: sapient
Date: Wed Apr 18 00:59:13 2007
New Revision: 16878
URL: http://svn.gna.org/viewcvs/wesnoth?rev=16878&view=rev
Log:
now unit::matches_filter uses a vconfig instead of a config...
WML variables can be used in some more places
Modified:
trunk/src/ai_dfool.cpp
trunk/src/ai_move.cpp
trunk/src/game_events.cpp
trunk/src/map.cpp
trunk/src/unit.cpp
trunk/src/unit.hpp
trunk/src/unit_abilities.cpp
trunk/src/unit_animation.cpp
Modified: trunk/src/ai_dfool.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_dfool.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/ai_dfool.cpp (original)
+++ trunk/src/ai_dfool.cpp Wed Apr 18 00:59:13 2007
@@ -1,5 +1,6 @@
#include "global.hpp"
#include "ai_dfool.hpp"
+#include "variable.hpp"
#include <set>
@@ -117,7 +118,7 @@
config ff=**sf;
LOG_STREAM(info, ai)<<"ff:"<<(**com)["type"]<<" "<<ff["type"]<<"
"<<ff["x"]<<","<<ff["y"]<<std::endl;
LOG_STREAM(info, ai)<<"ff?"<<u->second.id()<<"
"<<u->first.x<<","<<u->first.y<<std::endl;
- if(! u->second.matches_filter(ff,u->first)) {
+ if(! u->second.matches_filter(&ff,u->first)) {
found=false;
break;
}
@@ -162,7 +163,7 @@
// LOG_STREAM(info,
ai)<<"j:"<<j->second.underlying_description()<<":"<<j->first.x<<","<<j->first.y<<std::endl;
if(j->second.underlying_description().size()>0){
// LOG_STREAM(info, ai)<<"filter3:"<<std::endl;
- if(j->second.matches_filter(filter,j->first)) {
+ if(j->second.matches_filter(&filter,j->first)) {
// LOG_STREAM(info, ai)<<"filter4:"<<std::endl;
filtered_units_.push_back(*i);
}
Modified: trunk/src/ai_move.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_move.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/ai_move.cpp (original)
+++ trunk/src/ai_move.cpp Wed Apr 18 00:59:13 2007
@@ -18,6 +18,7 @@
#include "log.hpp"
#include "map.hpp"
#include "util.hpp"
+#include "variable.hpp"
#include "wassert.hpp"
#include <iostream>
@@ -153,7 +154,7 @@
//explicit targets for this team
for(std::vector<team::target>::iterator j =
team_targets.begin();
j != team_targets.end(); ++j) {
- if(u->second.matches_filter(j->criteria,u->first)) {
+ if(u->second.matches_filter(&(j->criteria),u->first)) {
LOG_AI << "found explicit target..." <<
j->value << "\n";
targets.push_back(target(u->first,j->value,target::EXPLICIT));
}
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Wed Apr 18 00:59:13 2007
@@ -2338,7 +2338,7 @@
bool unit_matches_filter(const unit& u, const vconfig filter,const
gamemap::location& loc)
{
- const bool res = u.matches_filter(filter.get_config(),loc);
+ const bool res = u.matches_filter(filter,loc);
if(res == true) {
const vconfig::child_list& nots = filter.get_children("not");
for(vconfig::child_list::const_iterator i = nots.begin(); i !=
nots.end(); ++i) {
@@ -2353,7 +2353,7 @@
bool unit_matches_filter(unit_map::const_iterator itor, const vconfig filter)
{
- const bool res = filter_loc(itor->first,filter) &&
itor->second.matches_filter(filter.get_config(),itor->first);
+ const bool res = filter_loc(itor->first,filter) &&
itor->second.matches_filter(filter,itor->first);
if(res == true) {
const vconfig::child_list& nots = filter.get_children("not");
for(vconfig::child_list::const_iterator i = nots.begin(); i !=
nots.end(); ++i) {
Modified: trunk/src/map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Wed Apr 18 00:59:13 2007
@@ -658,7 +658,7 @@
//Allow filtering on unit
if(cfg.has_child("filter")) {
- const config& unit_filter = cfg.child("filter").get_config();
+ const vconfig& unit_filter = cfg.child("filter");
const unit_map::const_iterator u = units.find(loc);
if (u == units.end() || !u->second.matches_filter(unit_filter,
loc, flat_tod))
return false;
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Wed Apr 18 00:59:13 2007
@@ -716,21 +716,19 @@
return false;
}
-bool unit::matches_filter(const config& orig_cfg,const gamemap::location& loc,
bool use_flat_tod) const
+bool unit::matches_filter(const vconfig& cfg, const gamemap::location& loc,
bool use_flat_tod) const
{
if(loc.valid()) {
wassert(units_ != NULL);
scoped_xy_unit auto_store("this_unit", loc.x, loc.y, *units_);
- return internal_matches_filter(orig_cfg, loc, use_flat_tod);
+ return internal_matches_filter(cfg, loc, use_flat_tod);
}
//if loc is invalid, then this is a recall list unit which should have
already been scoped
- return internal_matches_filter(orig_cfg, loc, use_flat_tod);
-}
-
-bool unit::internal_matches_filter(const config& orig_cfg,const
gamemap::location& loc, bool use_flat_tod) const
-{
- vconfig tmp_vconf(&orig_cfg);
- config cfg = tmp_vconf.get_parsed_config();
+ return internal_matches_filter(cfg, loc, use_flat_tod);
+}
+
+bool unit::internal_matches_filter(const vconfig& cfg, const
gamemap::location& loc, bool use_flat_tod) const
+{
const std::string& description = cfg["description"];
const std::string& speaker = cfg["speaker"];
const std::string& type = cfg["type"];
@@ -753,12 +751,11 @@
return false;
}
- const config* filter_location = cfg.child("filter_location");
- if(filter_location) {
+ if(cfg.has_child("filter_location")) {
wassert(map_ != NULL);
wassert(gamestatus_ != NULL);
wassert(units_ != NULL);
- bool res =
map_->terrain_matches_filter(loc,filter_location,*gamestatus_,*units_,use_flat_tod);
+ bool res = map_->terrain_matches_filter(loc,
cfg.child("filter_location"), *gamestatus_, *units_, use_flat_tod);
if(res == false) {
return false;
}
@@ -867,9 +864,9 @@
//if there are [not] tags below this tag, it means that the filter
//should not match if what is in the [not] tag does match
- const config::child_list& negatives = cfg.get_children("not");
- for(config::child_list::const_iterator not_it = negatives.begin();
not_it != negatives.end(); ++not_it) {
- if(internal_matches_filter(**not_it,loc,use_flat_tod)) {
+ const vconfig::child_list& negatives = cfg.get_children("not");
+ for(vconfig::child_list::const_iterator not_it = negatives.begin();
not_it != negatives.end(); ++not_it) {
+ if(internal_matches_filter(*not_it,loc,use_flat_tod)) {
return false;
}
}
@@ -878,13 +875,13 @@
// if a key is in the unit and in the filter, they should match
// filter only => not for us
// unit only => not filtered
- config::const_child_itors my_range = cfg.child_range("wml_filter");
- if (my_range.first != my_range.second) {
+ const vconfig::child_list& wmlcfgs = cfg.get_children("wml_filter");
+ if (!wmlcfgs.empty()) {
config unit_cfg;
write(unit_cfg);
//now, match the kids, WML based
- for(config::const_child_iterator i = my_range.first; i !=
my_range.second; ++i) {
- if(!unit_cfg.matches(**i)) {
+ for(int i=0; i < wmlcfgs.size(); ++i) {
+ if(!unit_cfg.matches(wmlcfgs[i].get_parsed_config())) {
return false;
}
}
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Wed Apr 18 00:59:13 2007
@@ -146,7 +146,7 @@
bool has_goto() const { return get_goto().valid(); }
int emits_zoc() const { return (incapacitated()) ? false :
emit_zoc_; }
/* cfg: standard unit filter */
- bool matches_filter(const config& cfg,const gamemap::location&
loc,bool use_flat_tod=false) const;
+ bool matches_filter(const vconfig& cfg,const gamemap::location&
loc,bool use_flat_tod=false) const;
void add_overlay(const std::string& overlay) {
overlays_.push_back(overlay); }
void remove_overlay(const std::string& overlay) {
overlays_.erase(std::remove(overlays_.begin(),overlays_.end(),overlay),overlays_.end());
}
const std::vector<std::string>& overlays() const { return
overlays_; }
@@ -295,7 +295,7 @@
private:
- bool internal_matches_filter(const config& cfg,const
gamemap::location& loc,
+ bool internal_matches_filter(const vconfig& cfg,const
gamemap::location& loc,
bool use_flat_tod) const;
/*
* cfg: an ability WML structure
Modified: trunk/src/unit_abilities.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_abilities.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/unit_abilities.cpp (original)
+++ trunk/src/unit_abilities.cpp Wed Apr 18 00:59:13 2007
@@ -304,7 +304,7 @@
{
int illuminates = -1;
if (config const *filter = cfg.child("filter_self")) {
- if (!matches_filter(*filter, loc,
cache_illuminates(illuminates, ability)))
+ if (!matches_filter(filter, loc, cache_illuminates(illuminates,
ability)))
return false;
}
wassert(units_ && map_ && gamestatus_);
@@ -323,7 +323,7 @@
unit_map::const_iterator unit =
units_->find(adjacent[index]);
if (unit == units_->end())
return false;
- if (!unit->second.matches_filter(**i, unit->first,
+ if (!unit->second.matches_filter(*i, unit->first,
cache_illuminates(illuminates, ability)))
return false;
}
@@ -359,7 +359,7 @@
std::vector<std::string> dirs = utils::split((**i)["adjacent"]);
if(std::find(dirs.begin(),dirs.end(),adjacent_names[dir]) !=
dirs.end()) {
if (config const *filter = (*i)->child("filter")) {
- if (matches_filter(*filter, loc,
+ if (matches_filter(filter, loc,
cache_illuminates(illuminates,
ability)))
return true;
} else
@@ -378,7 +378,7 @@
config const *filter = cfg.child("filter");
bool affect_self = utils::string_bool(cfg["affect_self"], true);
if (filter == NULL || !affect_self) return affect_self;
- return matches_filter(*filter, loc, ability == "illuminates");
+ return matches_filter(filter, loc, ability == "illuminates");
}
bool unit::has_ability_type(const std::string& ability) const
@@ -626,7 +626,7 @@
}
if (config const *filter_self = cfg.child("filter_self")) {
if (att == unitmap_->end() ||
- !att->second.matches_filter(*filter_self, aloc_))
+ !att->second.matches_filter(filter_self, aloc_))
return false;
if (config const *filter_weapon =
filter_self->child("filter_weapon")) {
if (!matches_filter(*filter_weapon, true))
@@ -635,7 +635,7 @@
}
if (config const *filter_opponent =
cfg.child("filter_opponent")) {
if (def == unitmap_->end() ||
- !def->second.matches_filter(*filter_opponent,
dloc_))
+ !def->second.matches_filter(filter_opponent, dloc_))
return false;
if (config const *filter_weapon =
filter_opponent->child("filter_weapon")) {
if (!other_attack_ ||
@@ -651,7 +651,7 @@
}
if (config const *filter_self = cfg.child("filter_self")) {
if (def == unitmap_->end() ||
- !def->second.matches_filter(*filter_self, dloc_))
+ !def->second.matches_filter(filter_self, dloc_))
return false;
if (config const *filter_weapon =
filter_self->child("filter_weapon")) {
if (!matches_filter(*filter_weapon, true))
@@ -660,7 +660,7 @@
}
if (config const *filter_opponent =
cfg.child("filter_opponent")) {
if (att == unitmap_->end() ||
- !att->second.matches_filter(*filter_opponent,
aloc_))
+ !att->second.matches_filter(filter_opponent, aloc_))
return false;
if (config const *filter_weapon =
filter_opponent->child("filter_weapon")) {
if (!other_attack_ ||
@@ -671,7 +671,7 @@
}
if (config const *filter_attacker = cfg.child("filter_attacker")) {
if (att == unitmap_->end() ||
- !att->second.matches_filter(*filter_attacker, aloc_))
+ !att->second.matches_filter(filter_attacker, aloc_))
return false;
if (config const *filter_weapon =
filter_attacker->child("filter_weapon")) {
if (attacker_) {
@@ -686,7 +686,7 @@
}
if (config const *filter_defender = cfg.child("filter_defender")) {
if (def == unitmap_->end() ||
- !def->second.matches_filter(*filter_defender, dloc_))
+ !def->second.matches_filter(filter_defender, dloc_))
return false;
if (config const *filter_weapon =
filter_defender->child("filter_weapon")) {
if (!attacker_) {
@@ -717,7 +717,7 @@
continue;
unit_map::const_iterator unit =
unitmap_->find(adjacent[index]);
if (unit == unitmap_->end() ||
- !unit->second.matches_filter(**i, unit->first))
+ !unit->second.matches_filter(*i, unit->first))
return false;
}
}
Modified: trunk/src/unit_animation.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=16878&r1=16877&r2=16878&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Wed Apr 18 00:59:13 2007
@@ -13,18 +13,19 @@
#include "global.hpp"
+#include "color_range.hpp"
+#include "display.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "log.hpp"
+#include "pathutils.hpp"
+#include "unit.hpp"
#include "unit_animation.hpp"
#include "unit_types.hpp"
#include "util.hpp"
+#include "variable.hpp"
#include "wassert.hpp"
#include "serialization/string_utils.hpp"
-#include "color_range.hpp"
-#include "unit.hpp"
-#include "display.hpp"
-#include "pathutils.hpp"
#include <algorithm>
@@ -161,7 +162,7 @@
}
std::vector<config>::const_iterator myitor;
for(myitor = unit_filter_.begin(); myitor !=
unit_filter_.end(); myitor++) {
- if(!my_unit->matches_filter(*myitor,loc)) return -1;
+ if(!my_unit->matches_filter(&(*myitor),loc)) return -1;
result++;
}
if(!secondary_unit_filter_.empty()) {
@@ -171,7 +172,7 @@
if(unit->first == facing_loc) {
std::vector<config>::const_iterator
second_itor;
for(second_itor =
secondary_unit_filter_.begin(); second_itor != secondary_unit_filter_.end();
second_itor++) {
-
if(!unit->second.matches_filter(*second_itor,facing_loc)) return -1;
+
if(!unit->second.matches_filter(&(*second_itor),facing_loc)) return -1;
result++;
}
@@ -190,7 +191,7 @@
for(unit=disp.get_const_units().begin() ; unit
!= disp.get_const_units().end() ; unit++) {
for(int dir =0; dir < 6 ;dir++) {
if(unit->first ==
neighbour_loc[dir]) {
-
if(unit->second.matches_filter(*second_itor,neighbour_loc[dir])) {
+
if(unit->second.matches_filter(&(*second_itor),neighbour_loc[dir])) {
result++;
found=true;
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits