- Cut actions array instead of performing full copy, when it is possible
- Fix use of uninitialized attack parameters struct (existed for years, and could maybe explain some weird ai behavior)
--- a/hedgewars/uAI.pas Mon Feb 03 13:32:09 2014 +0400
+++ b/hedgewars/uAI.pas Mon Feb 03 13:52:47 2014 +0400
@@ -108,9 +108,11 @@
ap: TAttackParams;
Score, i, t, n, dAngle: LongInt;
a, aa: TAmmoType;
+ useThisActions: boolean;
begin
BotLevel:= Me^.Hedgehog^.BotLevel;
windSpeed:= hwFloat2Float(cWindSpeed);
+useThisActions:= false;
for i:= 0 to Pred(Targets.Count) do
if (Targets.ar[i].Score >= 0) and (not StopThinking) then
@@ -128,12 +130,21 @@
{$HINTS OFF}
Score:= AmmoTests[a].proc(Me, Targets.ar[i], BotLevel, ap);
{$HINTS ON}
- if Actions.Score + Score > BestActions.Score then
+ if (Score > BadTurn) and (Actions.Score + Score > BestActions.Score) then
if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel - 1) * 2048) then
begin
- BestActions:= Actions;
- inc(BestActions.Score, Score);
- BestActions.isWalkingToABetterPlace:= false;
+ if useThisActions then
+ begin
+ BestActions.Count:= Actions.Count
+ end
+ else
+ begin
+ BestActions:= Actions;
+ BestActions.isWalkingToABetterPlace:= false;
+ useThisActions:= true
+ end;
+
+ BestActions.Score:= Actions.Score + Score;
if HHHasAmmo(Me^.Hedgehog^, amInvulnerable) > 0 then
begin