--- a/hedgewars/HHHandlers.inc Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/HHHandlers.inc Fri Jan 26 22:36:21 2007 +0000
@@ -280,7 +280,7 @@
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
Gear^.X:= Gear^.X + Gear^.dX;
Gear^.dY:= Gear^.dY + cGravity;
- if (Gear^.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= 0;
+ if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= 0;
Gear^.Y:= Gear^.Y + Gear^.dY;
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then
begin
--- a/hedgewars/uAI.pas Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/uAI.pas Fri Jan 26 22:36:21 2007 +0000
@@ -24,7 +24,7 @@
procedure FreeActionsList;
implementation
-{uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc,
+uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc,
uAIThinkStack, uAmmos;
var BestActions: TActions;
@@ -32,26 +32,26 @@
AIThinkStart: Longword;
isThinking: boolean = false;
-}procedure FreeActionsList;
+procedure FreeActionsList;
begin
-{isThinking:= false;
+isThinking:= false;
BestActions.Count:= 0;
BestActions.Pos:= 0
-}end;
-{
+end;
+
procedure TestAmmos(var Actions: TActions; Me: PGear);
var Time, BotLevel: Longword;
Angle, Power, Score, ExplX, ExplY, ExplR: integer;
i: integer;
a, aa: TAmmoType;
begin
-BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
+BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel;
for i:= 0 to Pred(Targets.Count) do
if (Targets.ar[i].Score >= 0) then
begin
- with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
- a:= Ammo[CurSlot, CurAmmo].AmmoType;
+ with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+ a:= Ammo^[CurSlot, CurAmmo].AmmoType;
aa:= a;
repeat
if CanUseAmmo[a] then
@@ -62,32 +62,32 @@
BestActions:= Actions;
inc(BestActions.Score, Score);
- AddAction(BestActions, aia_Weapon, Longword(a), 500);
- if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
- if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
- else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
+ AddAction(BestActions, aia_Weapon, Longword(a), 500, 0, 0);
+ if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400, 0, 0);
+ if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
+ else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
begin
- Angle:= integer(Me.Angle) - Abs(Angle);
+ Angle:= integer(Me^.Angle) - Abs(Angle);
if Angle > 0 then
begin
- AddAction(BestActions, aia_Up, aim_push, 500);
- AddAction(BestActions, aia_Up, aim_release, Angle)
+ AddAction(BestActions, aia_Up, aim_push, 500, 0, 0);
+ AddAction(BestActions, aia_Up, aim_release, Angle, 0, 0)
end else if Angle < 0 then
begin
- AddAction(BestActions, aia_Down, aim_push, 500);
- AddAction(BestActions, aia_Down, aim_release, -Angle)
+ AddAction(BestActions, aia_Down, aim_push, 500, 0, 0);
+ AddAction(BestActions, aia_Down, aim_release, -Angle, 0, 0)
end
end;
- AddAction(BestActions, aia_attack, aim_push, 800);
- AddAction(BestActions, aia_attack, aim_release, Power);
+ AddAction(BestActions, aia_attack, aim_push, 800, 0, 0);
+ AddAction(BestActions, aia_attack, aim_release, Power, 0, 0);
if ExplR > 0 then
AddAction(BestActions, aia_AwareExpl, ExplR, 10, ExplX, ExplY);
end
end;
if a = High(TAmmoType) then a:= Low(TAmmoType)
else inc(a)
- until (a = aa) or (PHedgehog(Me.Hedgehog).AttacksNum > 0)
+ until (a = aa) or (PHedgehog(Me^.Hedgehog)^.AttacksNum > 0)
end
end;
@@ -101,9 +101,9 @@
CanGo: boolean;
AltMe: TGear;
begin
-BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
+BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel;
-if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
+if (Me^.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
else maxticks:= TurnTimeLeft;
BaseRate:= RatePlace(Me);
@@ -115,12 +115,12 @@
exit
end;
- AddAction(Actions, Me.Message, aim_push, 10);
- if (Me.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, round(Me.X), 0)
- else AddAction(Actions, aia_WaitXR, round(Me.X), 0);
- AddAction(Actions, Me.Message, aim_release, 0);
+ AddAction(Actions, Me^.Message, aim_push, 10, 0, 0);
+ if (Me^.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
+ else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
+ AddAction(Actions, Me^.Message, aim_release, 0, 0, 0);
steps:= 0;
- if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
+ if ((Me^.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
while not PosInThinkStack(Me) do
begin
@@ -132,23 +132,23 @@
if Push(ticks, Actions, AltMe, Me^.Message) then
with ThinkStack.States[Pred(ThinkStack.Count)] do
begin
- AddAction(MadeActions, aia_HJump, 0, 305);
- AddAction(MadeActions, aia_HJump, 0, 350);
- if (Me.dX < 0) then AddAction(MadeActions, aia_WaitXL, round(AltMe.X), 0)
- else AddAction(MadeActions, aia_WaitXR, round(AltMe.X), 0);
+ AddAction(MadeActions, aia_HJump, 0, 305, 0, 0);
+ AddAction(MadeActions, aia_HJump, 0, 350, 0, 0);
+ if (Me^.dX < 0) then AddAction(MadeActions, aia_WaitXL, hwRound(AltMe.X), 0, 0, 0)
+ else AddAction(MadeActions, aia_WaitXR, hwRound(AltMe.X), 0, 0, 0);
end;
if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
if Push(ticks, Actions, AltMe, Me^.Message) then
with ThinkStack.States[Pred(ThinkStack.Count)] do
begin
- AddAction(MadeActions, aia_LJump, 0, 305);
- if (Me.dX < 0) then AddAction(MadeActions, aia_WaitXL, round(AltMe.X), 0)
- else AddAction(MadeActions, aia_WaitXR, round(AltMe.X), 0);
+ AddAction(MadeActions, aia_LJump, 0, 305, 0, 0);
+ if (Me^.dX < 0) then AddAction(MadeActions, aia_WaitXL, hwRound(AltMe.X), 0, 0, 0)
+ else AddAction(MadeActions, aia_WaitXR, hwRound(AltMe.X), 0, 0, 0);
end;
if not CanGo then break;
inc(steps);
- Actions.actions[Actions.Count - 2].Param:= round(Me.X);
+ Actions.actions[Actions.Count - 2].Param:= hwRound(Me^.X);
Rate:= RatePlace(Me);
if Rate > BaseRate then
begin
@@ -161,7 +161,7 @@
if GoInfo.FallPix >= FallPixForBranching then
Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
- if ((Me.State and gstAttacked) = 0)
+ if ((Me^.State and gstAttacked) = 0)
and ((steps mod 4) = 0) then
begin
if SDL_GetTicks - AIThinkStart > 3 then
@@ -182,7 +182,7 @@
AIThinkStart:= SDL_GetTicks;
BackMe:= Me^;
WalkMe:= BackMe;
-if (Me.State and gstAttacked) = 0 then
+if (Me^.State and gstAttacked) = 0 then
if Targets.Count > 0 then
begin
Walk(@WalkMe);
@@ -191,15 +191,15 @@
if BestActions.Score < -1023 then
begin
BestActions.Count:= 0;
- AddAction(BestActions, aia_Skip, 0, 250);
+ AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
end;
- Me.State:= Me.State and not gstHHThinking
+ Me^.State:= Me^.State and not gstHHThinking
end
end else
else begin
FillBonuses(true);
Walk(@WalkMe);
- AddAction(BestActions, aia_Wait, GameTicks + 100, 100);
+ AddAction(BestActions, aia_Wait, GameTicks + 100, 100, 0, 0);
end
end;
@@ -207,25 +207,25 @@
var a: TAmmoType;
tmp: integer;
begin
-if ((Me.State and gstAttacking) <> 0) or isInMultiShoot then exit;
+if ((Me^.State and gstAttacking) <> 0) or isInMultiShoot then exit;
ThinkingHH:= Me;
isThinking:= true;
ClearThinkStack;
-Me.State:= Me.State or gstHHThinking;
-Me.Message:= 0;
+Me^.State:= Me^.State or gstHHThinking;
+Me^.Message:= 0;
FillTargets;
if Targets.Count = 0 then
begin
- OutError('AI: no targets!?');
+ OutError('AI: no targets!?', false);
exit
end;
-FillBonuses((Me.State and gstAttacked) <> 0);
+FillBonuses((Me^.State and gstAttacked) <> 0);
for a:= Low(TAmmoType) to High(TAmmoType) do
- CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me.Hedgehog), a);
+ CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me^.Hedgehog), a);
BestActions.Count:= 0;
BestActions.Pos:= 0;
@@ -236,14 +236,14 @@
BestActions.Score:= Low(integer);
Think(Me)
-end; }
+end;
procedure ProcessBot(FrameNo: Longword);
-//const LastFrameNo: Longword = 0;
+const LastFrameNo: Longword = 0;
begin
-{with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
+with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
if (Gear <> nil)
- and ((Gear.State and gstHHDriven) <> 0)
+ and ((Gear^.State and gstHHDriven) <> 0)
and (TurnTimeLeft < cHedgehogTurnTime - 50) then
if not isThinking then
if (BestActions.Pos >= BestActions.Count) then StartThink(Gear)
@@ -253,6 +253,6 @@
LastFrameNo:= FrameNo;
Think(Gear)
end;
-}end;
+end;
end.
--- a/hedgewars/uAIActions.pas Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/uAIActions.pas Fri Jan 26 22:36:21 2007 +0000
@@ -20,7 +20,7 @@
interface
uses uGears, uFloat;
{$INCLUDE options.inc}
-(*const MAXACTIONS = 96;
+const MAXACTIONS = 96;
aia_none = 0;
aia_Left = 1;
aia_Right = 2;
@@ -55,11 +55,11 @@
Score: integer;
end;
-procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0);
+procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; X, Y: integer);
procedure ProcessAction(var Actions: TActions; Me: PGear);
-*)
+
implementation
-(*uses uMisc, uTeams, uConsts, uConsole, uAIMisc;
+uses uMisc, uTeams, uConsts, uConsole, uAIMisc;
const ActionIdToStr: array[0..6] of string[16] = (
{aia_none} '',
@@ -97,7 +97,7 @@
end;
{$ENDIF}
-procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0);
+procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; X, Y: integer);
begin
with Actions do
begin
@@ -119,9 +119,9 @@
const PrevX: integer = 0;
timedelta: Longword = 0;
begin
- if Round(Me.X) <> PrevX then
+ if hwRound(Me^.X) <> PrevX then
begin
- PrevX:= Round(Me.X);
+ PrevX:= hwRound(Me^.X);
timedelta:= 0
end else
begin
@@ -146,34 +146,34 @@
if (Action and ai_specmask) <> 0 then
case Action of
aia_Weapon: SetWeapon(TAmmoType(Param));
- aia_WaitXL: if round(Me.X) = Param then Time:= GameTicks
- else if Round(Me.X) < Param then
+ aia_WaitXL: if hwRound(Me^.X) = Param then Time:= GameTicks
+ else if hwRound(Me^.X) < Param then
begin
- OutError('AI: WaitXL assert');
+ OutError('AI: WaitXL assert', false);
Actions.Count:= 0
end
else begin CheckHang; exit end;
- aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
- else if Round(Me.X) > Param then
+ aia_WaitXR: if hwRound(Me^.X) = Param then Time:= GameTicks
+ else if hwRound(Me^.X) > Param then
begin
- OutError('AI: WaitXR assert');
+ OutError('AI: WaitXR assert', false);
Actions.Count:= 0
end
else begin CheckHang; exit end;
- aia_LookLeft: if Me.dX >= 0 then
+ aia_LookLeft: if not Me^.dX.isNegative then
begin
- ParseCommand('+left');
+ ParseCommand('+left', true);
exit
- end else ParseCommand('-left');
- aia_LookRight: if Me.dX < 0 then
+ end else ParseCommand('-left', true);
+ aia_LookRight: if Me^.dX.isNegative then
begin
- ParseCommand('+right');
+ ParseCommand('+right', true);
exit
- end else ParseCommand('-right');
+ end else ParseCommand('-right', true);
aia_AwareExpl: AwareOfExplosion(X, Y, Param);
- aia_HJump: ParseCommand('hjump');
- aia_LJump: ParseCommand('ljump');
- aia_Skip: ParseCommand('skip');
+ aia_HJump: ParseCommand('hjump', true);
+ aia_LJump: ParseCommand('ljump', true);
+ aia_Skip: ParseCommand('skip', true);
end else
begin
s:= ActionIdToStr[Action];
@@ -183,7 +183,7 @@
aim_release: s:= '-' + s;
end
else if Param <> 0 then s:= s + ' ' + inttostr(Param);
- ParseCommand(s)
+ ParseCommand(s, true)
end
end;
inc(Actions.Pos);
@@ -191,5 +191,5 @@
inc(Actions.actions[Actions.Pos].Time, GameTicks);
until false
end;
-*)
+
end.
--- a/hedgewars/uAIAmmoTests.pas Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/uAIAmmoTests.pas Fri Jan 26 22:36:21 2007 +0000
@@ -26,23 +26,23 @@
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
-
-type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
+*)
+type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
const AmmoTests: array[TAmmoType] of TAmmoTestProc =
(
-{amGrenade} TestGrenade,
+{amGrenade} nil,//TestGrenade,
{amClusterBomb} nil,
-{amBazooka} TestBazooka,
+{amBazooka} nil,//TestBazooka,
{amUFO} nil,
-{amShotgun} TestShotgun,
+{amShotgun} nil,//TestShotgun,
{amPickHammer} nil,
{amSkip} nil,
{amRope} nil,
{amMine} nil,
-{amDEagle} TestDesertEagle,
+{amDEagle} nil,//TestDesertEagle,
{amDynamite} nil,
-{amFirePunch} TestFirePunch,
-{amBaseballBat} TestBaseballBat,
+{amFirePunch} nil,//TestFirePunch,
+{amBaseballBat} nil,//TestBaseballBat,
{amParachute} nil,
{amAirAttack} nil,
{amMineStrike} nil,
@@ -50,7 +50,7 @@
);
const BadTurn = Low(integer);
-*)
+
implementation
uses uMisc, uAIMisc, uLand;
--- a/hedgewars/uAIMisc.pas Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/uAIMisc.pas Fri Jan 26 22:36:21 2007 +0000
@@ -20,7 +20,7 @@
interface
uses SDLh, uConsts, uGears, uFloat;
{$INCLUDE options.inc}
- {
+
type TTarget = record
Point: TPoint;
Score: integer;
@@ -43,17 +43,17 @@
function TestColl(x, y, r: integer): boolean;
function RateExplosion(Me: PGear; x, y, r: integer): integer;
function RateShove(Me: PGear; x, y, r, power: integer): integer;
-function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean;
-function rndSign(num: integer): integer;
+function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
+//function rndSign(num: integer): integer;
var ThinkingHH: PGear;
Targets: TTargets;
- }
+
implementation
-{uses uTeams, uMisc, uLand, uCollisions;
+uses uTeams, uMisc, uLand, uCollisions;
const KillScore = 200;
MAXBONUS = 1024;
-
+
type TBonus = record
X, Y: integer;
Radius: integer;
@@ -76,19 +76,19 @@
while t <> nil do
begin
for i:= 0 to cMaxHHIndex do
- if (t.Hedgehogs[i].Gear <> nil)
- and (t.Hedgehogs[i].Gear <> ThinkingHH) then
+ if (t^.Hedgehogs[i].Gear <> nil)
+ and (t^.Hedgehogs[i].Gear <> ThinkingHH) then
begin
- with Targets.ar[Targets.Count], t.Hedgehogs[i] do
+ with Targets.ar[Targets.Count], t^.Hedgehogs[i] do
begin
- Point.X:= Round(Gear.X);
- Point.Y:= Round(Gear.Y);
- if t.Color <> CurrentTeam.Color then Score:= Gear.Health
- else Score:= -Gear.Health
+ Point.X:= hwRound(Gear^.X);
+ Point.Y:= hwRound(Gear^.Y);
+ if t^.Color <> CurrentTeam^.Color then Score:= Gear^.Health
+ else Score:= -Gear^.Health
end;
inc(Targets.Count)
end;
- t:= t.Next
+ t:= t^.Next
end
end;
@@ -108,23 +108,23 @@
begin
bonuses.Count:= 0;
-MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color;
+MyColor:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Color;
Gear:= GearsList;
while Gear <> nil do
begin
- case Gear.Kind of
- gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25);
- gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50)
- else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on
- gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75);
+ case Gear^.Kind of
+ gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
+ gtMine: if (Gear^.State and gstAttacking) = 0 then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
+ else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
+ gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
gtHedgehog: begin
- if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else
- if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then
- if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend
- else AddBonus(round(Gear.X), round(Gear.Y), 100, 3)
+ if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else
+ if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
+ if (MyColor = PHedgehog(Gear^.Hedgehog)^.Team^.Color) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
+ else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
end;
end;
- Gear:= Gear.NextGear
+ Gear:= Gear^.NextGear
end;
if isAfterAttack and (KnownExplosion.Radius > 0) then
with KnownExplosion do
@@ -140,44 +140,47 @@
function RatePlace(Gear: PGear): integer;
var i, r: integer;
+ Result: integer;
begin
Result:= 0;
for i:= 0 to Pred(bonuses.Count) do
with bonuses.ar[i] do
begin
- r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)));
+ r:= hwRound(Distance(Gear^.X - X, Gear^.Y - y));
if r < Radius then
inc(Result, Score * (Radius - r))
end;
+ RatePlace:= Result
end;
function TestColl(x, y, r: integer): boolean;
+var b: boolean;
begin
-Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0);
-if Result then exit;
-Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0);
-if Result then exit;
-Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0);
-if Result then exit;
-Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0);
+b:= (((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0);
+if b then exit(true);
+b:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0);
+if b then exit(true);
+b:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0);
+if b then exit(true);
+TestColl:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0)
end;
function RateExplosion(Me: PGear; x, y, r: integer): integer;
-var i, dmg: integer;
+var i, dmg, Result: integer;
begin
Result:= 0;
// add our virtual position
with Targets.ar[Targets.Count] do
begin
- Point.x:= round(Me.X);
- Point.y:= round(Me.Y);
- Score:= - ThinkingHH.Health
+ Point.x:= hwRound(Me^.X);
+ Point.y:= hwRound(Me^.Y);
+ Score:= - ThinkingHH^.Health
end;
// rate explosion
for i:= 0 to Targets.Count do
with Targets.ar[i] do
begin
- dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y)));
+ dmg:= r - hwRound(Distance(Point.x - x, Point.y - y));
if dmg > 0 then
begin
dmg:= dmg shr 1;
@@ -189,17 +192,17 @@
else dec(Result, dmg * 3)
end;
end;
-Result:= Result * 1024
+RateExplosion:= Result * 1024
end;
function RateShove(Me: PGear; x, y, r, power: integer): integer;
-var i, dmg: integer;
+var i, dmg, Result: integer;
begin
Result:= 0;
for i:= 0 to Targets.Count do
with Targets.ar[i] do
begin
- dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y)));
+ dmg:= r - hwRound(Distance(Point.x - x, Point.y - y));
if dmg > 0 then
begin
if power > abs(Score) then
@@ -210,84 +213,85 @@
else dec(Result, power * 3)
end;
end;
-Result:= Result * 1024
+RateShove:= Result * 1024
end;
-function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean;
+function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean;
var bX, bY: integer;
+ Result: boolean;
begin
Result:= false;
GoInfo.Ticks:= 0;
GoInfo.FallPix:= 0;
GoInfo.JumpType:= jmpNone;
-bX:= round(Gear.X);
-bY:= round(Gear.Y);
+bX:= hwRound(Gear^.X);
+bY:= hwRound(Gear^.Y);
case JumpType of
- jmpNone: exit;
+ jmpNone: exit(Result);
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then
begin
- Gear.dY:= -0.20;
- Gear.dX:= 0.0000001 * hwSign(Gear.dX);
- Gear.X:= Gear.X - hwSign(Gear.dX)*0.00008; // shift compensation
- Gear.State:= Gear.State or gstFalling or gstHHJumping;
- end else exit;
+ Gear^.dY:= -_0_2;
+ SetLittle(Gear^.dX);
+ Gear^.State:= Gear^.State or gstFalling or gstHHJumping;
+ end else exit(Result);
jmpLJump: begin
if not TestCollisionYwithGear(Gear, -1) then
- if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
- if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithGear(Gear, hwSign(Gear.dX))
+ if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - 2 else
+ if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
or TestCollisionYwithGear(Gear, -1)) then
begin
- Gear.dY:= -0.15;
- Gear.dX:= hwSign(Gear.dX) * 0.15;
- Gear.State:= Gear.State or gstFalling or gstHHJumping
- end else exit
+ Gear^.dY:= _0_15;
+ Gear^.dX:= hwSign(Gear^.dX) * _0_15;
+ Gear^.State:= Gear^.State or gstFalling or gstHHJumping
+ end else exit(Result)
end
end;
repeat
-if Gear.Y + cHHRadius >= cWaterLine then exit;
-if (Gear.State and gstFalling) <> 0 then
+if not (Gear^.Y + cHHRadius < cWaterLine) then exit(Result);
+if (Gear^.State and gstFalling) <> 0 then
begin
if (GoInfo.Ticks = 350) then
- if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then
+ if (hwAbs(Gear^.dX) < cLittle + cLittle) and (Gear^.dY < -_0_02) then
begin
- Gear.dY:= -0.25;
- Gear.dX:= hwSign(Gear.dX) * 0.02
+ Gear^.dY:= -_0_25;
+ Gear^.dX:= hwSign(Gear^.dX) * _0_02
end;
- if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then Gear.dX:= 0.0000001 * hwSign(Gear.dX);
- Gear.X:= Gear.X + Gear.dX;
+ if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
+ Gear^.X:= Gear^.X + Gear^.dX;
inc(GoInfo.Ticks);
- Gear.dY:= Gear.dY + cGravity;
- if Gear.dY > 0.40 then exit;
- if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0;
- Gear.Y:= Gear.Y + Gear.dY;
- if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then
+ Gear^.dY:= Gear^.dY + cGravity;
+ if Gear^.dY > _0_4 then exit(Result);
+ if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= 0;
+ Gear^.Y:= Gear^.Y + Gear^.dY;
+ if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then
begin
- Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
- Gear.dY:= 0;
+ Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping);
+ Gear^.dY:= 0;
case JumpType of
- jmpHJump: if (bY - Gear.Y > 5) then
+ jmpHJump: if (bY - Gear^.Y > 5) then
begin
Result:= true;
GoInfo.JumpType:= jmpHJump;
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
end;
- jmpLJump: if abs(bX - Gear.X) > 30 then
+ jmpLJump: if hwAbs(bX - Gear^.X) > 30 then
begin
Result:= true;
GoInfo.JumpType:= jmpLJump;
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
end;
end;
- exit
+ exit(Result)
end;
end;
-until false;
+until false
end;
-function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean;
+function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
var pX, pY: integer;
+ Result: boolean;
begin
Result:= false;
AltGear^:= Gear^;
@@ -296,79 +300,78 @@
GoInfo.FallPix:= 0;
GoInfo.JumpType:= jmpNone;
repeat
-pX:= round(Gear.X);
-pY:= round(Gear.Y);
+pX:= hwRound(Gear^.X);
+pY:= hwRound(Gear^.Y);
if pY + cHHRadius >= cWaterLine then exit;
-if (Gear.State and gstFalling) <> 0 then
+if (Gear^.State and gstFalling) <> 0 then
begin
inc(GoInfo.Ticks);
- Gear.dY:= Gear.dY + cGravity;
- if Gear.dY > 0.40 then
+ Gear^.dY:= Gear^.dY + cGravity;
+ if Gear^.dY > _0_4 then
begin
Goinfo.FallPix:= 0;
HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage
- exit
+ exit(Result)
end;
- Gear.Y:= Gear.Y + Gear.dY;
- if round(Gear.Y) > pY then inc(GoInfo.FallPix);
+ Gear^.Y:= Gear^.Y + Gear^.dY;
+ if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix);
if TestCollisionYwithGear(Gear, 1) then
begin
inc(GoInfo.Ticks, 300);
- Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
- Gear.dY:= 0;
+ Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping);
+ Gear^.dY:= 0;
Result:= true;
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
- exit
+ exit(Result)
end;
continue
end;
- if (Gear.Message and gm_Left )<>0 then Gear.dX:= -1.0 else
- if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit;
- if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then
+ if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= -cLittle else
+ if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit(Result);
+ if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
begin
- if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
- if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX))
- or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
+ if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear^.dX))
+ or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1;
end;
- if not TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then
+ if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
begin
- Gear.X:= Gear.X + Gear.dX;
+ Gear^.X:= Gear^.X + Gear^.dX;
inc(GoInfo.Ticks, cHHStepTicks)
end;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y + 1;
+ Gear^.Y:= Gear^.Y + 1;
if not TestCollisionYwithGear(Gear, 1) then
begin
- Gear.Y:= Gear.Y - 6;
- Gear.dY:= 0;
- Gear.dX:= 0.0000001 * hwSign(Gear.dX);
- Gear.State:= Gear.State or gstFalling
+ Gear^.Y:= Gear^.Y - 6;
+ Gear^.dY:= 0;
+ Gear^.State:= Gear^.State or gstFalling
end
end
end
@@ -376,16 +379,16 @@
end
end
end;
-if (pX <> round(Gear.X)) and ((Gear.State and gstFalling) = 0) then
+if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstFalling) = 0) then
begin
Result:= true;
- exit
+ exit(Result)
end
-until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
+until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstFalling) = 0);
HHJump(AltGear, jmpHJump, GoInfo)
end;
-function rndSign(num: integer): integer;
+{function rndSign(num: integer): integer;
begin
if random(2) = 0 then Result:= num
else Result:= - num
--- a/hedgewars/uAIThinkStack.pas Fri Jan 26 18:39:40 2007 +0000
+++ b/hedgewars/uAIThinkStack.pas Fri Jan 26 22:36:21 2007 +0000
@@ -18,7 +18,7 @@
unit uAIThinkStack;
interface
-uses uAIActions, uGears;
+uses uAIActions, uGears, uFloat;
{$INCLUDE options.inc}
const cBranchStackSize = 12;
type TStackEntry = record
@@ -33,13 +33,14 @@
end;
function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean;
-function Pop(out Ticks: Longword; out Actions: TActions; out Me: TGear): boolean;
+function Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear): boolean;
function PosInThinkStack(Me: PGear): boolean;
procedure ClearThinkStack;
implementation
function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean;
+var Result: boolean;
begin
Result:= (ThinkStack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5);
if Result then
@@ -50,10 +51,12 @@
Hedgehog:= Me;
Hedgehog.Message:= Dir;
inc(ThinkStack.Count)
- end
+ end;
+Push:= Result
end;
-function Pop(out Ticks: Longword; out Actions: TActions; out Me: TGear): boolean;
+function Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear): boolean;
+var Result: boolean;
begin
Result:= ThinkStack.Count > 0;
if Result then
@@ -65,21 +68,22 @@
Actions:= MadeActions;
Me:= Hedgehog
end
- end
+ end;
+Pop:= Result
end;
function PosInThinkStack(Me: PGear): boolean;
var i: Longword;
begin
i:= 0;
-Result:= false;
-while (i < ThinkStack.Count) and not Result do
+while (i < ThinkStack.Count) do
begin
- Result:= (abs(ThinkStack.States[i].Hedgehog.X - Me.X) +
- abs(ThinkStack.States[i].Hedgehog.Y - Me.Y) <= 2)
- and (ThinkStack.States[i].Hedgehog.Message = Me.Message);
+ if (not (2 < hwAbs(ThinkStack.States[i].Hedgehog.X - Me^.X) +
+ hwAbs(ThinkStack.States[i].Hedgehog.Y - Me^.Y)))
+ and (ThinkStack.States[i].Hedgehog.Message = Me^.Message) then exit(true);
inc(i)
- end
+ end;
+PosInThinkStack:= false
end;
procedure ClearThinkStack;