Author: dragonking
Date: Wed Jun 24 15:29:17 2009
New Revision: 36387
URL: http://svn.gna.org/viewcvs/wesnoth?rev=36387&view=rev
Log:
Commited patch #1170 with some addictional modifications
Modified:
trunk/src/ai/formula/ai.cpp
trunk/src/callable_objects.cpp
trunk/src/map_location.hpp
Modified: trunk/src/ai/formula/ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/formula/ai.cpp?rev=36387&r1=36386&r2=36387&view=diff
==============================================================================
--- trunk/src/ai/formula/ai.cpp (original)
+++ trunk/src/ai/formula/ai.cpp Wed Jun 24 15:29:17 2009
@@ -905,6 +905,38 @@
const map_location& dst() const { return dst_; }
int weapon() const { return bc_.get_attacker_stats().attack_num; }
int defender_weapon() const { return
bc_.get_defender_stats().attack_num; }
+
+ /** Compare two attacks in deterministic way or compare pointers
+ * (nondeterministic in consequent game runs) if method argument is not
+ * move_callable */
+ int do_compare(const game_logic::formula_callable* callable)
+ const {
+ const attack_callable* a_callable = dynamic_cast<const
attack_callable*>(callable);
+ if(a_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ const map_location& other_from = a_callable->move_from();
+
+ if (int cmp = move_from_.do_compare(other_from)) {
+ return cmp;
+ }
+ const map_location& other_src = a_callable->src();
+ if (int cmp = src_.do_compare(other_src)) {
+ return cmp;
+ }
+ const map_location& other_dst = a_callable->dst();
+ if (int cmp = dst_.do_compare(other_dst)) {
+ return cmp;
+ }
+ const int other_weapon = a_callable->weapon();
+ if (int cmp = (this->weapon() - other_weapon)) {
+ return cmp;
+ }
+ const int other_def_weapon = a_callable->defender_weapon();
+ return this->defender_weapon() - other_def_weapon;
+ }
+
};
Modified: trunk/src/callable_objects.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/callable_objects.cpp?rev=36387&r1=36386&r2=36387&view=diff
==============================================================================
--- trunk/src/callable_objects.cpp (original)
+++ trunk/src/callable_objects.cpp Wed Jun 24 15:29:17 2009
@@ -61,11 +61,7 @@
}
const map_location& other_loc = loc_callable->loc();
- if(other_loc.x != loc_.x) {
- return loc_.x - other_loc.x;
- }
-
- return loc_.y - other_loc.y;
+ return loc_.do_compare(other_loc);
}
void location_callable::serialize_to_string(std::string& str) const
@@ -391,11 +387,8 @@
}
const map_location& other_loc = terr_callable->loc_;
- if(other_loc.x != loc_.x) {
- return loc_.x - other_loc.x;
- }
-
- return loc_.y - other_loc.y;
+
+ return loc_.do_compare(other_loc);
}
int move_callable::do_compare(const formula_callable* callable) const
@@ -408,19 +401,11 @@
const map_location& other_src = mv_callable->src_;
const map_location& other_dst = mv_callable->dst_;
- if(other_src.x != src_.x) {
- return src_.x - other_src.x;
- }
-
- if(other_src.y != src_.y) {
- return src_.y - other_src.y;
- }
-
- if(other_dst.x != dst_.x) {
- return dst_.x - other_dst.x;
- }
-
- return dst_.y - other_dst.y;
+ if (int cmp = src_.do_compare(other_src)) {
+ return cmp;
+ }
+
+ return dst_.do_compare(other_dst);
}
int move_partial_callable::do_compare(const formula_callable* callable) const
@@ -433,18 +418,10 @@
const map_location& other_src = mv_callable->src_;
const map_location& other_dst = mv_callable->dst_;
- if(other_src.x != src_.x) {
- return src_.x - other_src.x;
- }
-
- if(other_src.y != src_.y) {
- return src_.y - other_src.y;
- }
-
- if(other_dst.x != dst_.x) {
- return dst_.x - other_dst.x;
- }
-
- return dst_.y - other_dst.y;
-}
-
+ if (int cmp = src_.do_compare(other_src)) {
+ return cmp;
+ }
+
+ return dst_.do_compare(other_dst);
+}
+
Modified: trunk/src/map_location.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map_location.hpp?rev=36387&r1=36386&r2=36387&view=diff
==============================================================================
--- trunk/src/map_location.hpp (original)
+++ trunk/src/map_location.hpp Wed Jun 24 15:29:17 2009
@@ -71,6 +71,9 @@
bool operator==(const map_location& a) const { return x == a.x && y ==
a.y; }
bool operator!=(const map_location& a) const { return !operator==(a); }
+ /** three-way comparator */
+ int do_compare(const map_location& a) const {return x == a.x ? y - a.y
: x - a.x; }
+
// Adds an absolute location to a "delta" location
// This is not the mathematically correct behviour, it is neither
// commutative nor associative. Negative coordinates may give strange
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits