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


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

Header


Content

Posted by dragonking on March 21, 2008 - 21:02:
Author: dragonking
Date: Fri Mar 21 20:36:03 2008
New Revision: 24953

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24953&view=rev
Log:
Small fix to unit formulas, and making move_unit work correctly for formulas 
which attempt to move unit to a place where it is already standing

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=24953&r1=24952&r2=24953&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Fri Mar 21 20:36:03 2008
@@ -537,15 +537,25 @@
        move_formula_ = 
game_logic::formula::create_optional_formula(current_team().ai_parameters()["move"],
 &function_table);
 
        //execute units formulas first
+       std::vector<gamemap::location> formula_unit_loc;
        for(unit_map::const_iterator i = units_.begin(); i != units_.end(); 
++i) {
-               if( (i->second.side() == get_info().team_num) && 
i->second.has_formula()) 
+               if( (i->second.side() == get_info().team_num) && 
i->second.has_formula() ) 
                {
-                       game_logic::const_formula_ptr formula(new 
game_logic::formula(i->second.get_formula(), &function_table));
-                       game_logic::map_formula_callable callable(this);
-                       callable.add_ref();
-                       callable.add("me", variant(new unit_callable(*i, 
current_team(), get_info().team_num)));
-                       make_move(formula, callable);
-               }
+                       formula_unit_loc.push_back(i->first);
+               }
+       }
+
+       for(std::vector<gamemap::location>::const_iterator i = 
formula_unit_loc.begin() ; i != formula_unit_loc.end() ; ++i)
+       {
+                       unit_map::const_iterator unit_it = units_.find(*i);
+                       if ( unit_it != units_.end() )
+                       {
+                               game_logic::const_formula_ptr formula(new 
game_logic::formula(unit_it->second.get_formula(), &function_table));
+                               game_logic::map_formula_callable 
callable(this);
+                               callable.add_ref();
+                               callable.add("me", variant(new 
unit_callable(*unit_it, current_team(), get_info().team_num)));
+                               make_move(formula, callable);
+                       }
        }
 
        game_logic::map_formula_callable callable(this);
@@ -650,7 +660,8 @@
                prepare_move();
                if(move) {
                        std::cerr << "moving " << move->src().x << "," << 
move->src().y << " -> " << move->dst().x << "," << move->dst().y << "\n";
-                       if(possible_moves_.count(move->src()) > 0) {
+                       unit_map::iterator i = units_.find(move->src());
+                       if( (possible_moves_.count(move->src()) > 0) && 
(i->second.movement_left() != 0) ) {
                                move_unit(move->src(), move->dst(), 
possible_moves_);
                                made_move = true;
                        }




Related Messages


Powered by MHonArc, Updated Fri Mar 21 21:21:25 2008