Author: ai0867
Date: Sun Oct 12 02:33:55 2008
New Revision: 30067

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30067&view=rev
Log:
* Add (un)consider events to AIs. (bug #12375)

Modified:
    trunk/data/scenario-test.cfg
    trunk/src/ai.cpp
    trunk/src/ai_python.cpp
    trunk/src/formula_ai.cpp

Modified: trunk/data/scenario-test.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/scenario-test.cfg?rev=30067&r1=30066&r2=30067&view=diff
==============================================================================
--- trunk/data/scenario-test.cfg (original)
+++ trunk/data/scenario-test.cfg Sun Oct 12 02:33:55 2008
@@ -300,6 +300,82 @@
     [/event]
 
     [label]
+        x,y=2,5
+        text="Arm your enemy"
+    [/label]
+    [event]
+        name=moveto
+        [filter]
+            side=1
+            x,y=2,5
+        [/filter]
+        [message]
+            side=2
+            message="We have dastone and we are not afraid to use it!"
+        [/message]
+        [event]
+            name=consider attack
+            first_time_only=no
+            [filter]
+                side=2
+            [/filter]
+            [object]
+                name="I will kill you with dastone!"
+                [filter]
+                    x,y=$x1,$y1
+                [/filter]
+                [effect]
+                    apply_to=new_attack
+                    name=ruby of fire
+                    description="ruby of fire"
+                    icon=attacks/fireball.png
+                    type=fire
+                    range=ranged
+                    [specials]
+                        {WEAPON_SPECIAL_MAGICAL}
+                    [/specials]
+                    damage=14
+                    number=4
+                [/effect]
+            [/object]
+        [/event]
+        [event]
+            name=unconsider attack
+            first_time_only=no
+            [filter]
+                side=2
+            [/filter]
+            [object]
+                silent=yes
+                [filter]
+                    x,y=$x1,$y1
+                [/filter]
+                [effect]
+                    apply_to=remove_attacks
+                    name=ruby of fire
+                [/effect]
+            [/object]
+        [/event]
+        [event]
+            name=attack_end
+            first_time_only=no
+            [filter]
+                side=2
+            [/filter]
+            [object]
+                silent=yes
+                [filter]
+                    x,y=$x1,$y1
+                [/filter]
+                [effect]
+                    apply_to=remove_attacks
+                    name=ruby of fire
+                [/effect]
+            [/object]
+        [/event]
+    [/event]
+
+    [label]
         x,y=17,7
         text="Open the hell"
     [/label]

Modified: trunk/src/ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=30067&r1=30066&r2=30067&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Sun Oct 12 02:33:55 2008
@@ -114,6 +114,7 @@
 
                                if(best_defense != -1) {
                                        
move_unit(best_movement.second,best_movement.first,possible_moves);
+                                       game_events::fire("consider attack", 
best_movement.first, i->first);
                                        battle_context bc(get_info().map, 
get_info().teams,
                                                                          
get_info().units, get_info().state,
                                                                          
best_movement.first,
@@ -743,6 +744,7 @@
                                const unit_map::const_iterator itor = 
units_.find(*adj_i);
                                if(itor != units_.end() && 
current_team().is_enemy(itor->second.side()) &&
                                   !itor->second.incapacitated()) {
+                                       game_events::fire("consider attack", 
res, itor->first);
                                        battle_context bc(map_, teams_, units_, 
state_,
                                                                          res, 
*adj_i, -1, -1, current_team().aggression());
                                        
attack_enemy(res,itor->first,bc.get_attacker_stats().attack_num,bc.get_defender_stats().attack_num);
@@ -1191,6 +1193,7 @@
                }
 
                // Recalc appropriate weapons here: AI uses approximations.
+               game_events::fire("consider attack", to, target_loc);
                battle_context bc(map_, teams_, units_, state_,
                                                  to, target_loc, -1, -1,
                                                  current_team().aggression());
@@ -1507,14 +1510,16 @@
                                                                                
                                                   teams_,current_team());
 
                                if(enemy != units_.end() &&
-                                  
current_team().is_enemy(enemy->second.side()) && 
!enemy->second.incapacitated()) {
+                                       
current_team().is_enemy(enemy->second.side()) && 
!enemy->second.incapacitated()) {
                                        // Current behavior is to only make 
risk-free attacks.
+                                       game_events::fire("consider attack", 
arrived_at, adj[n]);
                                        battle_context bc(map_, teams_, units_, 
state_, arrived_at, adj[n], -1, -1, 100.0);
                                        if (bc.get_defender_stats().damage == 
0) {
                                                attack_enemy(arrived_at, 
adj[n], bc.get_attacker_stats().attack_num,
                                                                
bc.get_defender_stats().attack_num);
                                                break;
                                        }
+                                       game_events::fire("unconsider attack", 
arrived_at, adj[n]);
                                }
                        }
                }

Modified: trunk/src/ai_python.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_python.cpp?rev=30067&r1=30066&r2=30067&view=diff
==============================================================================
--- trunk/src/ai_python.cpp (original)
+++ trunk/src/ai_python.cpp Sun Oct 12 02:33:55 2008
@@ -1562,6 +1562,7 @@
 
        info& inf = running_instance->get_info();
 
+       game_events::fire("consider attack", *from->location_, *to->location_);
        battle_context bc(
                inf.map,
                inf.teams,

Modified: trunk/src/formula_ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.cpp?rev=30067&r1=30066&r2=30067&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Sun Oct 12 02:33:55 2008
@@ -16,6 +16,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include "actions.hpp"
+#include "game_events.hpp"
 #include "menu_events.hpp"
 #include "formula_ai.hpp"
 #include "pathutils.hpp"
@@ -1539,6 +1540,7 @@
                                move_unit(attack->move_from(), attack->src(), 
possible_moves_);
                        }
                        std::cerr << "ATTACK: " << attack->src() << " -> " << 
attack->dst() << " " << attack->weapon() << "\n";
+                       game_events::fire("consider attack", attack->src(), 
attack->dst());
                        attack_enemy(attack->src(), attack->dst(), 
attack->weapon(), attack->defender_weapon());
                        made_move = true;
                } else if(attack_analysis) {
@@ -1564,17 +1566,18 @@
                        if ( unit == units_.end() )
                                continue;
 
-                       move_unit(attack_analysis->movements.front().first,
-                                 attack_analysis->movements.front().second,
+                       move_unit(src,
+                                         dst,
                                          possible_moves_);
 
                        if(get_info().units.count(src)) {
+                               game_events::fire("consider attack", src, dst);
                                battle_context bc(get_info().map, 
get_info().teams,
-                                                 get_info().units, 
get_info().state,
-                                                 src, dst, -1, -1, 1.0, NULL,
+                                                                 
get_info().units, get_info().state,
+                                                                 src, dst, -1, 
-1, 1.0, NULL,
                                                                  
&get_info().units.find(src)->second);
-                               
attack_enemy(attack_analysis->movements.front().second,
-                                            attack_analysis->target,
+                               attack_enemy(src,
+                                                        dst,
                                                         
bc.get_attacker_stats().attack_num,
                                                         
bc.get_defender_stats().attack_num);
                        }


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

Reply via email to