Make sure AI doesn't skip after collecting ammo. Fixes bug 796
authorWuzzy <Wuzzy2@mail.ru>
Mon, 07 Oct 2019 14:18:31 +0200
changeset 15466 6031c0cfec89
parent 15465 61a0bd0bb021
child 15467 eb1c407a9e8f
Make sure AI doesn't skip after collecting ammo. Fixes bug #796
hedgewars/uAI.pas
hedgewars/uAmmos.pas
hedgewars/uConsts.pas
hedgewars/uTeams.pas
--- a/hedgewars/uAI.pas	Fri Oct 04 23:23:35 2019 +0300
+++ b/hedgewars/uAI.pas	Mon Oct 07 14:18:31 2019 +0200
@@ -107,6 +107,7 @@
 BotLevel:= Me^.Hedgehog^.BotLevel;
 windSpeed:= hwFloat2Float(cWindSpeed);
 useThisActions:= false;
+Me^.AIHints:= Me^.AIHints and (not aihAmmosChanged);
 
 for i:= 0 to Pred(Targets.Count) do
     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
@@ -432,7 +433,7 @@
     switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch)
 else switchCount:= 0;
 
-if ((Me^.State and gstAttacked) = 0) or isInMultiShoot or bonuses.activity then
+if ((Me^.State and gstAttacked) = 0) or isInMultiShoot or bonuses.activity or ((Me^.AIHints and aihAmmosChanged) <> 0) then
     if Targets.Count > 0 then
         begin
         // iterate over current team hedgehogs
@@ -478,7 +479,7 @@
             FillBonuses(false);
 
             // Hog has no idea what to do. Use tardis or skip
-            if not bonuses.activity then
+            if (not bonuses.activity) and ((Me^.AIHints and aihAmmosChanged) = 0) then
                 if (((GameFlags and gfInfAttack) <> 0) or (CurrentHedgehog^.MultiShootAttacks = 0)) and (HHHasAmmo(Me^.Hedgehog^, amTardis) > 0) and (CanUseTardis(Me^.Hedgehog^.Gear)) and (random(4) < 3) then
                     // Tardis brings hog to a random place. Perfect for clueless AI
                     begin
@@ -488,6 +489,7 @@
                     end
                 else
                     AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
+            Me^.AIHints := ME^.AIHints and (not aihAmmosChanged);
             end;
 
         end else SDL_Delay(100)
--- a/hedgewars/uAmmos.pas	Fri Oct 04 23:23:35 2019 +0300
+++ b/hedgewars/uAmmos.pas	Mon Oct 07 14:18:31 2019 +0200
@@ -265,7 +265,9 @@
         begin
         PackAmmo(Ammo, Ammoz[AmmoType].Slot);
         CurAmmoType:= amNothing
-        end
+        end;
+if Hedgehog.BotLevel <> 0 then
+    Hedgehog.Gear^.AIHints := Hedgehog.Gear^.AIHints or aihAmmosChanged;
 end;
 
 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
--- a/hedgewars/uConsts.pas	Fri Oct 04 23:23:35 2019 +0300
+++ b/hedgewars/uConsts.pas	Mon Oct 07 14:18:31 2019 +0200
@@ -321,6 +321,7 @@
     // AI hints to be set for any gear
     aihUsualProcessing    = $00000000; // treat gear as usual
     aihDoesntMatter       = $00000001; // ignore gear in attack calculations and don't intentionally attack it
+    aihAmmosChanged       = $00000002; // set when ammos were changed within this turn but not processed yet
 
     // ammo properties
     ammoprop_Timerable    = $00000001; // can set timer
--- a/hedgewars/uTeams.pas	Fri Oct 04 23:23:35 2019 +0300
+++ b/hedgewars/uTeams.pas	Mon Oct 07 14:18:31 2019 +0200
@@ -393,6 +393,8 @@
 CurWeapon:= GetCurAmmoEntry(CurrentHedgehog^);
 if CurWeapon^.Count = 0 then
     CurrentHedgehog^.CurAmmoType:= amNothing;
+if CurrentHedgehog^.BotLevel <> 0 then
+    CurrentHedgehog^.Gear^.AIHints:= (CurrentHedgehog^.Gear^.AIHints and (not aihAmmosChanged));
 
 with CurrentHedgehog^ do
     begin