mail[Wesnoth-commits] r33190 - /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 01, 2009 - 00:11:
Author: dragonking
Date: Sun Mar  1 00:11:39 2009
New Revision: 33190

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33190&view=rev
Log:
Fix for atack() function

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=33190&r1=33189&r2=33190&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Sun Mar  1 00:11:39 2009
@@ -14,6 +14,8 @@
 
 #include <boost/lexical_cast.hpp>
 #include <vector>
+
+#include "unit.hpp"
 
 #include "menu_events.hpp"
 #include "formula_ai.hpp"
@@ -1680,6 +1682,8 @@
                                 }
                        }
                } else if(attack) {
+                        LOG_AI << "ATTACK: " << attack->src() << " -> " << 
attack->dst() << " " << attack->weapon() << "\n";
+
                        if(get_info().units.count(attack->dst()) == 0) {
                                //this is a legitimate situation; someone 
might send a series of units in
                                //to attack, but if the defender dies in the 
middle, we'll save the unit
@@ -1687,11 +1691,25 @@
                                continue;
                        }
 
-                       if(attack->move_from() != attack->src()) {
+                        std::map<map_location,paths>::iterator path = 
possible_moves_.find(attack->move_from());
+
+                        if( path->second.routes.count(attack->src()) == 0) {
+                            made_move = true;
+                            continue;
+                        }
+
+                        unit_map::iterator unit_it = 
units_.find(attack->move_from());
+
+                       if(attack->move_from() != attack->src() && 
(unit_it->second.movement_left() != 0) && 
get_info().map.on_board(attack->src() )) {
                                move_unit(attack->move_from(), attack->src(), 
possible_moves_);
-                       }
-                       LOG_AI << "ATTACK: " << attack->src() << " -> " << 
attack->dst() << " " << attack->weapon() << "\n";
-                       attack_enemy(attack->src(), attack->dst(), 
attack->weapon(), attack->defender_weapon());
+                       } else {
+                            made_move = true;
+                            continue;
+                        }
+
+                        if(unit_it->second.attacks_left() != 0) {
+                            attack_enemy(attack->src(), attack->dst(), 
attack->weapon(), attack->defender_weapon());
+                        }
                        made_move = true;
                } else if(attack_analysis) {
                        //If we get an attack analysis back we will do the 
first attack.




Related Messages


Powered by MHonArc, Updated Sun Mar 01 00:40:22 2009