Fix AI thread erroring out when there are no targets
authorWuzzy <Wuzzy2@mail.ru>
Wed, 24 Jun 2020 20:16:02 +0200
changeset 15632 25132742a948
parent 15631 b2ed495a7fb1
child 15633 0bf5dda8fa43
Fix AI thread erroring out when there are no targets
ChangeLog.txt
hedgewars/uAI.pas
--- a/ChangeLog.txt	Wed Jun 24 20:24:12 2020 +0300
+++ b/ChangeLog.txt	Wed Jun 24 20:16:02 2020 +0200
@@ -15,6 +15,7 @@
  + New taunt chat commands: /bubble, /happy
  * Fix many projectiles not being affected by Heavy Wind after turn end
  * Fix hog getting stuck when opening parachute right after a shoryuken digging through land
+ * Fix game hanging if computer hog has nothing to attack
 
 Campaigns:
  + A Space Adventure: Spacetrip: Meteorite appears blown-up after victory
--- a/hedgewars/uAI.pas	Wed Jun 24 20:24:12 2020 +0300
+++ b/hedgewars/uAI.pas	Wed Jun 24 20:16:02 2020 +0200
@@ -506,7 +506,14 @@
             Me^.AIHints := ME^.AIHints and (not aihAmmosChanged);
             end;
 
-        end else SDL_Delay(100)
+        end
+    else
+        begin
+        // No target found, skip turn
+        BestActions.Count:= 0;
+        AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
+        Me^.AIHints := ME^.AIHints and (not aihAmmosChanged);
+        end
 else
     begin
     BackMe:= Me^;
@@ -559,11 +566,6 @@
 ThinkingHH:= Me;
 
 FillTargets;
-if Targets.Count = 0 then
-    begin
-    OutError('AI: no targets!?', false);
-    exit
-    end;
 
 FillBonuses(((Me^.State and gstAttacked) <> 0) and (not isInMultiShoot) and ((GameFlags and gfInfAttack) = 0));