Author: sapient
Date: Mon Apr 30 05:35:16 2007
New Revision: 17181
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17181&view=rev
Log:
* replace [own_village] with macro {OWN_VILLAGE X Y SIDE}
* new conditional tag [have_location], tests true if any location passes
the standard location filter provided inside the tag
Modified:
trunk/changelog
trunk/data/utils/conditional-utils.cfg
trunk/src/game_events.cpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=17181&r1=17180&r2=17181&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Mon Apr 30 05:35:16 2007
@@ -7,6 +7,9 @@
* [store_villages] and [store_locations] now use the standard location
filter, meaning they accept all the possible keys of [filter_location]
* [store_villages] must now use owner_side= instead of side=
+ * replace [own_village] with macro {OWN_VILLAGE X Y SIDE}
+ * new conditional tag [have_location], tests true if any location passes
+ the standard location filter provided inside the tag
* Miscellaneous and bugfixes
* 1.2 savegames are no longer compatible and thus not loaded
Modified: trunk/data/utils/conditional-utils.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/utils/conditional-utils.cfg?rev=17181&r1=17180&r2=17181&view=diff
==============================================================================
--- trunk/data/utils/conditional-utils.cfg (original)
+++ trunk/data/utils/conditional-utils.cfg Mon Apr 30 05:35:16 2007
@@ -1,114 +1,123 @@
-# Conditionals for MP scenarios.
-
-# These don't depend on any other macros. Please don't change this.
-# ! in comments is used in generating HTML documentation, ignore it otherwise.
-
-#define IF VAR OP VAL CONTENTS
-# Shortcut for IF statements testing the value of a variable. Need to write
-# [then] and [else] tags manually.
-# Use like this:
-#! {IF some_variable equals yes (
-#! [then]
-#! ...
-#! [/then]
-#! )}
- [if]
- [variable]
- name={VAR}
- {OP}={VAL}
- [/variable]
-
- {CONTENTS}
- [/if]
-#enddef
-
-
-#define IF_ALIVE PLAYER ACTION
-# Condition triggering of ACTION om whether PLAYER has at least one unit left.
-# For example, if the player 2 is still alive, kill all his units.
-#! {IF_ALIVE 2 (
-#! [kill]
-#! side=2
-#! [/kill]
-#! )}
- [if]
- [have_unit]
- side={PLAYER}
- [/have_unit]
- [then]
- {ACTION}
- [/then]
- [/if]
-#enddef
-
-
-#define IF_DEAD PLAYER ACTION
-# Condition triggering of ACTION on whether PLAYER has no units left.
-# For example, give player 2 gold if player 1 is dead
-#! {IF_DEAD 1 (
-#! [gold]
-#! side=2
-#! amount=25
-#! [/gold]
-#! )}
- [if]
- [have_unit]
- side={PLAYER}
- [/have_unit]
- [then]
- [/then]
- [else]
- {ACTION}
- [/else]
- [/if]
-#enddef
-
-#define IF_ALLIED PLAYER1 PLAYER2 ACTION
-# Condition that triggers if PLAYER1 and PLAYER2 belong to the same team.
-# NOTE: only works if leaders are alive, are the same leader as the game
-# started and haven't changed teams.
-# For example, if player 3 and 4 is allied, steal 10 gold from each:
-#! {IF_ALLIED 3 4 (
-#! [gold]
-#! side=3
-#! amount=-10
-#! [/gold]
-#! [gold]
-#! side=4
-#! amount=-10
-#! [/gold]
-#! )}
- [store_unit]
- [filter]
- side={PLAYER1}
- canrecruit=1
- [/filter]
- variable=leader1
- mode=replace
- kill=no
- [/store_unit]
- [store_unit]
- [filter]
- side={PLAYER2}
- canrecruit=1
- [/filter]
- variable=leader2
- mode=replace
- kill=no
- [/store_unit]
- [if]
- [variable]
- name=leader1.team_name
- equals=$leader2.team_name
- [/variable]
- [then]
- {ACTION}
- [/then]
- [/if]
- [clear_variable]
- name=leader1
- [/clear_variable]
- [clear_variable]
- name=leader2
- [/clear_variable]
-#enddef
+# Conditionals for MP scenarios.
+
+# These don't depend on any other macros. Please don't change this.
+# ! in comments is used in generating HTML documentation, ignore it otherwise.
+
+#define OWN_VILLAGE X Y SIDE
+# Test if a given side owns the village at the specified location
+[have_location]
+ owner_side={SIDE}
+ x={X}
+ y={Y}
+[/have_location]
+#enddef
+
+#define IF VAR OP VAL CONTENTS
+# Shortcut for IF statements testing the value of a variable. Need to write
+# [then] and [else] tags manually.
+# Use like this:
+#! {IF some_variable equals yes (
+#! [then]
+#! ...
+#! [/then]
+#! )}
+ [if]
+ [variable]
+ name={VAR}
+ {OP}={VAL}
+ [/variable]
+
+ {CONTENTS}
+ [/if]
+#enddef
+
+
+#define IF_ALIVE PLAYER ACTION
+# Condition triggering of ACTION om whether PLAYER has at least one unit left.
+# For example, if the player 2 is still alive, kill all his units.
+#! {IF_ALIVE 2 (
+#! [kill]
+#! side=2
+#! [/kill]
+#! )}
+ [if]
+ [have_unit]
+ side={PLAYER}
+ [/have_unit]
+ [then]
+ {ACTION}
+ [/then]
+ [/if]
+#enddef
+
+
+#define IF_DEAD PLAYER ACTION
+# Condition triggering of ACTION on whether PLAYER has no units left.
+# For example, give player 2 gold if player 1 is dead
+#! {IF_DEAD 1 (
+#! [gold]
+#! side=2
+#! amount=25
+#! [/gold]
+#! )}
+ [if]
+ [have_unit]
+ side={PLAYER}
+ [/have_unit]
+ [then]
+ [/then]
+ [else]
+ {ACTION}
+ [/else]
+ [/if]
+#enddef
+
+#define IF_ALLIED PLAYER1 PLAYER2 ACTION
+# Condition that triggers if PLAYER1 and PLAYER2 belong to the same team.
+# NOTE: only works if leaders are alive, are the same leader as the game
+# started and haven't changed teams.
+# For example, if player 3 and 4 is allied, steal 10 gold from each:
+#! {IF_ALLIED 3 4 (
+#! [gold]
+#! side=3
+#! amount=-10
+#! [/gold]
+#! [gold]
+#! side=4
+#! amount=-10
+#! [/gold]
+#! )}
+ [store_unit]
+ [filter]
+ side={PLAYER1}
+ canrecruit=1
+ [/filter]
+ variable=leader1
+ mode=replace
+ kill=no
+ [/store_unit]
+ [store_unit]
+ [filter]
+ side={PLAYER2}
+ canrecruit=1
+ [/filter]
+ variable=leader2
+ mode=replace
+ kill=no
+ [/store_unit]
+ [if]
+ [variable]
+ name=leader1.team_name
+ equals=$leader2.team_name
+ [/variable]
+ [then]
+ {ACTION}
+ [/then]
+ [/if]
+ [clear_variable]
+ name=leader1
+ [/clear_variable]
+ [clear_variable]
+ name=leader2
+ [/clear_variable]
+#enddef
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=17181&r1=17180&r2=17181&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Mon Apr 30 05:35:16 2007
@@ -226,26 +226,17 @@
}
}
- //if the if statement requires we have a certain village, then
+ //if the if statement requires we have a certain location, then
//check for that.
- const vconfig::child_list& own_village =
cond.get_children("own_village");
-
- for(vconfig::child_list::const_iterator v = own_village.begin(); v !=
own_village.end(); ++v) {
-
- std::string side = (*v)["side"];
- wassert(state_of_game != NULL);
- const int side_index = lexical_cast_default<int>(side,1)-1;
-
- int x = lexical_cast_default((*v)["x"], 0) - 1;
- int y = lexical_cast_default((*v)["y"], 0) - 1;
-
- const gamemap::location vloc = gamemap::location(x, y);
-
- if(game_map->is_village(vloc)) {
- if (village_owner(vloc,*teams) == side_index)
- break;
- }
- return false;
+ const vconfig::child_list& have_location =
cond.get_children("have_location");
+
+ for(vconfig::child_list::const_iterator v = have_location.begin(); v !=
have_location.end(); ++v) {
+ std::set<gamemap::location> res;
+ wassert(game_map != NULL && units != NULL && status_ptr !=
NULL);
+ game_map->get_locations(res, *v, *status_ptr, *units);
+ if(res.empty()) {
+ return false;
+ }
}
//check against each variable statement to see if the variable
@@ -314,7 +305,7 @@
}
}
- return !have_unit.empty() || !own_village.empty() || !variables.empty()
|| !not_statements.empty() || !and_statements.empty();
+ return !have_unit.empty() || !have_location.empty() ||
!variables.empty() || !not_statements.empty() || !and_statements.empty();
}
} //end namespace game_events
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits