Author: dragonking
Date: Sun Apr 12 11:38:14 2009
New Revision: 34762

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34762&view=rev
Log:
Fixed bug that made 'attack' candidate move attack and kill allied units.

Modified:
    branches/1.6/src/formula_ai.cpp
    branches/1.6/src/formula_ai.hpp

Modified: branches/1.6/src/formula_ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/formula_ai.cpp?rev=34762&r1=34761&r2=34762&view=diff
==============================================================================
--- branches/1.6/src/formula_ai.cpp (original)
+++ branches/1.6/src/formula_ai.cpp Sun Apr 12 11:38:14 2009
@@ -2413,16 +2413,19 @@
        return keeps_cache_;
 }
 
-bool formula_ai::can_attack(const map_location unit_loc,
-               const map_location enemy_loc) const {
+bool formula_ai::can_attack(const unit_map::unit_iterator unit,
+               const unit_map::unit_iterator enemy) const {
+       if( !current_team().is_enemy(enemy->second.side()) )
+               return false;
+
         prepare_move();
        move_map::iterator i;
        std::pair<move_map::iterator,
                          move_map::iterator> unit_moves;
 
-       unit_moves = srcdst_.equal_range(unit_loc);
+       unit_moves = srcdst_.equal_range(unit->first);
        for(i = unit_moves.first; i != unit_moves.second; ++i) {
-               map_location diff(((*i).second).vector_difference(enemy_loc));
+               map_location 
diff(((*i).second).vector_difference(enemy->first));
                if((abs(diff.x) <= 1) && (abs(diff.y) <= 1)) {
                        return true;
                }
@@ -2441,7 +2444,7 @@
                                        (me->second.has_moved() == false) ) {
                                for(unit_map::unit_iterator target = 
units.begin() ; target != units.end() ; ++target) {
                                        if( (target->second.side() != team_num) 
&&
-                                                       
(ai->can_attack(me->first, target->first)) ) {
+                                                       (ai->can_attack(me, 
target)) ) {
                                                 int res = -1000;
 
                                                
game_logic::map_formula_callable callable((formula_callable*) ai);

Modified: branches/1.6/src/formula_ai.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/formula_ai.hpp?rev=34762&r1=34761&r2=34762&view=diff
==============================================================================
--- branches/1.6/src/formula_ai.hpp (original)
+++ branches/1.6/src/formula_ai.hpp Sun Apr 12 11:38:14 2009
@@ -158,8 +158,9 @@
 
        void store_outcome_position(const variant& var);
 
-       // Check if given unit loc can reach attack range of enemy loc
-       bool can_attack (const map_location, const map_location) const;
+       // Check if given unit can reach and attack enemy
+       bool can_attack (const unit_map::unit_iterator unit,
+                               const unit_map::unit_iterator enemy) const;
 
        const std::map<location,paths>& get_possible_moves() const { 
prepare_move(); return possible_moves_; }
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to