mail[Wesnoth-commits] r34225 - /trunk/src/formula_ai.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by df on March 29, 2009 - 09:21:
Author: dfranke
Date: Sun Mar 29 09:21:02 2009
New Revision: 34225

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34225&view=rev
Log:
Validate attacker and defender arguments to calculate_outcome().  Fixes bug 
#13280.

Modified:
    trunk/src/formula_ai.cpp

Modified: trunk/src/formula_ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.cpp?rev=34225&r1=34224&r2=34225&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Sun Mar 29 09:21:02 2009
@@ -414,10 +414,26 @@
                int weapon;
                if (args().size() > 3) weapon = 
args()[3]->evaluate(variables).as_int();
                else weapon = -1;
+
+               map_location attacker_location = 
+                       
convert_variant<location_callable>(args()[0]->evaluate(variables))->loc();
+               if(ai_.get_info().units.count(attacker_location) == 0) {
+                       ERR_AI << "Performing calculate_outcome() with 
non-existent attacker at (" <<
+                               attacker_location.x+1 << "," << 
attacker_location.y+1 << ")\n";
+                       return variant();
+               }
+
+               map_location defender_location = 
+                       
convert_variant<location_callable>(args()[2]->evaluate(variables))->loc();
+               if(ai_.get_info().units.count(defender_location) == 0) {
+                       ERR_AI << "Performing calculate_outcome() with 
non-existent defender at (" <<
+                               defender_location.x+1 << "," << 
defender_location.y+1 << ")\n";
+                       return variant();
+               }
+
                battle_context bc(ai_.get_info().map, ai_.get_info().teams, 
ai_.get_info().units,
                        ai_.get_info().state, 
convert_variant<location_callable>(args()[1]->evaluate(variables))->loc(),
-                       
convert_variant<location_callable>(args()[2]->evaluate(variables))->loc(), 
weapon, -1, 1.0, NULL,
-                       
&ai_.get_info().units.find(convert_variant<location_callable>(args()[0]->evaluate(variables))->loc())->second);
+                       defender_location, weapon, -1, 1.0, NULL, 
&ai_.get_info().units.find(attacker_location)->second);
                std::vector<double> hp_dist = 
bc.get_attacker_combatant().hp_dist;
                std::vector<double>::iterator it = hp_dist.begin();
                int i = 0;




Related Messages


Powered by MHonArc, Updated Sun Mar 29 09:40:27 2009