Don't make unnecessary calls to TestWhip, TestFirePunch, TestBaseballBat and TestHammer functions as they have no need to take Targ parameter into account and thus may only be called once per position
--- a/hedgewars/uAI.pas Mon Jun 04 08:11:47 2012 -0400
+++ b/hedgewars/uAI.pas Mon Jun 04 22:43:56 2012 +0400
@@ -129,8 +129,10 @@
ThreadSwitch();
{$ENDIF}
repeat
- if (CanUseAmmo[a]) and
- ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
+ if (CanUseAmmo[a])
+ and ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0))
+ and ((i = 0) or ((AmmoTests[a].flags and amtest_NoTarget) = 0))
+ then
begin
{$HINTS OFF}
Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap);
@@ -181,8 +183,8 @@
if a = High(TAmmoType) then
a:= Low(TAmmoType)
else inc(a)
- until (a = aa) or (CurrentHedgehog^.MultiShootAttacks > 0) or // shooting same weapon
- StopThinking
+ until (a = aa) or (CurrentHedgehog^.MultiShootAttacks > 0) {shooting same weapon}
+ or StopThinking
end
end;
--- a/hedgewars/uAIAmmoTests.pas Mon Jun 04 08:11:47 2012 -0400
+++ b/hedgewars/uAIAmmoTests.pas Mon Jun 04 22:43:56 2012 +0400
@@ -21,7 +21,9 @@
unit uAIAmmoTests;
interface
uses SDLh, uConsts, uFloat, uTypes;
-const amtest_OnTurn = $00000001;
+const
+ amtest_OnTurn = $00000001; // from one position
+ amtest_NoTarget = $00000002; // each pos, but no targetting
var windSpeed: real;
@@ -68,9 +70,9 @@
(proc: nil; flags: 0), // amMine
(proc: @TestDesertEagle; flags: 0), // amDEagle
(proc: nil; flags: 0), // amDynamite
- (proc: @TestFirePunch; flags: 0), // amFirePunch
- (proc: @TestWhip; flags: 0), // amWhip
- (proc: @TestBaseballBat; flags: 0), // amBaseballBat
+ (proc: @TestFirePunch; flags: amtest_NoTarget), // amFirePunch
+ (proc: @TestWhip; flags: amtest_NoTarget), // amWhip
+ (proc: @TestBaseballBat; flags: amtest_NoTarget), // amBaseballBat
(proc: nil; flags: 0), // amParachute
(proc: @TestAirAttack; flags: amtest_OnTurn), // amAirAttack
(proc: nil; flags: 0), // amMineStrike
@@ -105,7 +107,7 @@
(proc: @TestShotgun; flags: 0), // amSineGun
(proc: nil; flags: 0), // amFlamethrower
(proc: @TestGrenade; flags: 0), // amSMine
- (proc: @TestHammer; flags: 0), // amHammer
+ (proc: @TestHammer; flags: amtest_NoTarget), // amHammer
(proc: nil; flags: 0), // amResurrector
(proc: nil; flags: 0), // amDrillStrike
(proc: nil; flags: 0), // amSnowball
@@ -640,7 +642,7 @@
ap.ExplR:= 0;
x:= hwFloat2Float(Me^.X);
y:= hwFloat2Float(Me^.Y);
-if (Level > 2) or (Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) > 25) then
+if (Level > 2) then
exit(BadTurn);
ap.Time:= 0;
@@ -710,8 +712,7 @@
else TestFirePunch:= BadTurn;
end;
-// TODO: TestWhip, TestFirepunch and TestBaseballBat could be called only once at each position
-// (now they're called for each possible target in each position)
+
function TestWhip(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
var valueResult, v1, v2: LongInt;
x, y: real;
@@ -723,9 +724,6 @@
x:= hwFloat2Float(Me^.X);
y:= hwFloat2Float(Me^.Y);
-if(abs(Targ.X - x) > 50) or (abs(Targ.Y - y) > 30) then // we're way too far from our target
- exit(BadTurn);
-
// check left direction
{first RateShove checks fartherest of two whip's AmmoShove attacks
to encourage distant attacks (damaged hog is excluded from view of second
@@ -775,10 +773,7 @@
ap.Power:= 1;
ap.Angle:= 0;
-if (Abs(hwRound(Me^.X) + hwSign(Me^.dX) * 10 - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) > 20) then
- rate:= 0
-else
- rate:= RateHammer(Me);
+rate:= RateHammer(Me);
if rate = 0 then
rate:= BadTurn;
TestHammer:= rate;