# HG changeset patch # User unc0rr # Date 1391421167 -14400 # Node ID f00dee04b5d725bf53fc747ba7343f6b37a966a9 # Parent acef073e190f47a46b343b4004ebccdd1b3cacad - 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) diff -r acef073e190f -r f00dee04b5d7 hedgewars/uAI.pas --- 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