# HG changeset patch # User unc0rr # Date 1336676113 -14400 # Node ID 76a9274f280f11d0e3a239e296b627b8d0c99958 # Parent 4aff2da0d0b339b05839742723fbb6a0daa7a604 More definitions and mess with pascal code diff -r 4aff2da0d0b3 -r 76a9274f280f hedgewars/pas2c.h --- a/hedgewars/pas2c.h Thu May 10 13:45:47 2012 +0400 +++ b/hedgewars/pas2c.h Thu May 10 22:55:13 2012 +0400 @@ -105,3 +105,6 @@ int random(int max); int abs(int i); +double sqr(double n); +double sqrt(double n); +int trunc(double n); diff -r 4aff2da0d0b3 -r 76a9274f280f hedgewars/pas2cSystem.pas --- a/hedgewars/pas2cSystem.pas Thu May 10 13:45:47 2012 +0400 +++ b/hedgewars/pas2cSystem.pas Thu May 10 22:55:13 2012 +0400 @@ -63,7 +63,7 @@ new, dispose, FillChar, Move : procedure; trunc, round : function : integer; - abs, Sqr : function : integer; + abs, sqr : function : integer; StrPas, FormatDateTime, copy, delete, str, pos, trim, LowerCase : function : shortstring; Length, StrToInt : function : integer; diff -r 4aff2da0d0b3 -r 76a9274f280f hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Thu May 10 13:45:47 2012 +0400 +++ b/hedgewars/uAIAmmoTests.pas Thu May 10 22:55:13 2012 +0400 @@ -479,18 +479,18 @@ TestTime: Longword; x, y, dY, meX, meY: real; begin -TestMortar:= BadTurn; -ap.ExplR:= 0; -meX:= hwFloat2Float(Me^.X); -meY:= hwFloat2Float(Me^.Y); + TestMortar:= BadTurn; + ap.ExplR:= 0; + meX:= hwFloat2Float(Me^.X); + meY:= hwFloat2Float(Me^.Y); -if (Level > 2) then - exit; + if (Level > 2) then + exit(BadTurn); -TestTime:= Solve(Targ.X, Targ.Y, trunc(meX), trunc(meY)); + TestTime:= Solve(Targ.X, Targ.Y, trunc(meX), trunc(meY)); -if TestTime = 0 then - exit; + if TestTime = 0 then + exit(BadTurn); Vx:= (Targ.X - meX) / TestTime; Vy:= cGravityf * (TestTime div 2) - (Targ.Y - meY) / TestTime; @@ -548,7 +548,8 @@ y:= hwFloat2Float(Me^.Y); range:= Metric(trunc(x), trunc(y), Targ.X, Targ.Y); if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then - exit; + exit(BadTurn); + Vx:= (Targ.X - x) * 1 / 1024; Vy:= (Targ.Y - y) * 1 / 1024; ap.Angle:= DxDy2AttackAnglef(Vx, -Vy); @@ -568,8 +569,7 @@ else dec(valueResult, Level * 4000); // 27/20 is reuse bonus - TestShotgun:= valueResult * 27 div 20; - exit + exit(valueResult * 27 div 20) end until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4) or (x < 0) @@ -593,10 +593,10 @@ x:= hwFloat2Float(Me^.X); y:= hwFloat2Float(Me^.Y); if Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) < 40 then -begin + begin TestDesertEagle:= BadTurn; - exit; -end; + exit(BadTurn); + end; t:= 0.5 / sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y)); Vx:= (Targ.X - x) * t; Vy:= (Targ.Y - y) * t; @@ -638,7 +638,7 @@ x:= hwFloat2Float(Me^.X); y:= hwFloat2Float(Me^.Y); if (Level > 2) or (Abs(trunc(x) - Targ.X) + Abs(trunc(y) - Targ.Y) > 25) then - exit; + exit(BadTurn); ap.Time:= 0; ap.Power:= 1; @@ -676,8 +676,7 @@ val1:= Succ(BadTurn) else val1:= BadTurn; - TestFirePunch:= val1; - exit; + exit(val1); end; (* For some silly reason, having this enabled w/ the AI @@ -725,8 +724,7 @@ valueResult:= Succ(BadTurn) else valueResult:= BadTurn; - TestWhip:= valueResult; - exit; + exit(valueResult); end; valueResult:= 0; @@ -770,10 +768,7 @@ ap.ExplR:= 0; ap.Time:= 0; if (Level > 3) then -begin - TestAirAttack:= BadTurn; - exit; -end; + exit(BadTurn); ap.AttackPutX:= Targ.X; ap.AttackPutY:= Targ.Y; @@ -837,7 +832,7 @@ maxTop: longword; begin TestTeleport := BadTurn; - exit; + exit(BadTurn); Level:= Level; // avoid compiler hint //FillBonuses(true, [gtCase]); if bonuses.Count = 0 then diff -r 4aff2da0d0b3 -r 76a9274f280f hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Thu May 10 13:45:47 2012 +0400 +++ b/hedgewars/uAIMisc.pas Thu May 10 22:55:13 2012 +0400 @@ -216,14 +216,13 @@ function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline; var MeX, MeY: LongInt; begin - TestCollExcludingMe:= false; if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then begin MeX:= hwRound(Me^.X); MeY:= hwRound(Me^.Y); // We are still inside the hog. Skip radius test if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and ((Land[y, x] and $FF00) = 0) then - exit; + exit(false); end; TestCollExcludingMe:= TestColl(x, y, r) end; @@ -231,23 +230,21 @@ function TestColl(x, y, r: LongInt): boolean; inline; var b: boolean; begin - TestColl:= true; - b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0); if b then - exit; + exit(true); b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] <> 0); if b then - exit; + exit(true); b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] <> 0); if b then - exit; + exit(true); b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] <> 0); if b then - exit; + exit(true); TestColl:= false; end; @@ -255,23 +252,21 @@ function TestCollWithLand(x, y, r: LongInt): boolean; inline; var b: boolean; begin - TestCollWithLand:= true; - b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] > 255); if b then - exit; + exit(true); b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] > 255); if b then - exit; + exit(true); b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] > 255); if b then - exit; + exit(true); b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] > 255); if b then - exit; + exit(true); TestCollWithLand:= false; end; @@ -298,20 +293,12 @@ begin dmg := 1 + trunc((abs(dY) - 0.4) * 70); if dmg >= 1 then - begin - TraceFall:= dmg; - exit - end; + exit(dmg); end; - TraceFall:= 0; - exit + exit(0) end; if (y > cWaterLine) or (x > 4096) or (x < 0) then - begin - // returning -1 for drowning so it can be considered in the Rate routine - TraceFall:= -1; - exit; - end; + exit(-1); end; end; @@ -330,20 +317,13 @@ begin dmg := 1 + trunc((abs(dY) - 0.4) * 70); if dmg >= 1 then - begin - TraceShoveFall:= dmg; - exit - end; + exit(dmg); end; - TraceShoveFall:= 0; - exit + exit(0) end; if (y > cWaterLine) or (x > 4096) or (x < 0) then - begin // returning -1 for drowning so it can be considered in the Rate routine - TraceShoveFall:= -1; - exit; - end; + exit(-1) end; end; @@ -535,7 +515,7 @@ bX:= hwRound(Gear^.X); bY:= hwRound(Gear^.Y); case JumpType of - jmpNone: exit; + jmpNone: exit(false); jmpHJump: if TestCollisionYwithGear(Gear, -1) = 0 then @@ -545,7 +525,7 @@ Gear^.State:= Gear^.State or gstMoving or gstHHJumping; end else - exit; + exit(false); jmpLJump: begin @@ -563,13 +543,13 @@ Gear^.State:= Gear^.State or gstMoving or gstHHJumping end else - exit + exit(false) end end; repeat if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then - exit; + exit(false); if (Gear^.State and gstMoving) <> 0 then begin if (GoInfo.Ticks = 350) then @@ -583,32 +563,32 @@ inc(GoInfo.Ticks); Gear^.dY:= Gear^.dY + cGravity; if Gear^.dY > _0_4 then - exit; + exit(false); if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY:= _0; Gear^.Y:= Gear^.Y + Gear^.dY; if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then - begin + begin Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); Gear^.dY:= _0; case JumpType of jmpHJump: if bY - hwRound(Gear^.Y) > 5 then - begin - HHJump:= true; + begin GoInfo.JumpType:= jmpHJump; - inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after - end; + inc(GoInfo.Ticks, 300 + 300); // 300 before jump, 300 after + exit(true) + end; jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then - begin - HHJump:= true; + begin GoInfo.JumpType:= jmpLJump; - inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after - end + inc(GoInfo.Ticks, 300 + 300); // 300 before jump, 300 after + exit(true) + end + end; + exit(false) end; - exit - end; end; until false end; @@ -626,7 +606,7 @@ pX:= hwRound(Gear^.X); pY:= hwRound(Gear^.Y); if pY + cHHRadius >= cWaterLine then - exit; + exit(false); if (Gear^.State and gstMoving) <> 0 then begin inc(GoInfo.Ticks); @@ -635,7 +615,7 @@ begin Goinfo.FallPix:= 0; HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage - exit + exit(false) end; Gear^.Y:= Gear^.Y + Gear^.dY; if hwRound(Gear^.Y) > pY then @@ -647,7 +627,7 @@ Gear^.dY:= _0; HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall HHGo:= true; - exit + exit(false) end; continue end; @@ -657,7 +637,7 @@ if (Gear^.Message and gmRight )<>0 then Gear^.dX:= cLittle else - exit; + exit(false); if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then begin if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) @@ -728,10 +708,7 @@ end end; if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then -begin - HHGo:= true; - exit; -end; + exit(true) until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); HHJump(AltGear, jmpHJump, GoInfo); end;