AI works properly
authorunc0rr
Sun, 28 Jan 2007 20:58:06 +0000
changeset 375 18012da67681
parent 374 95169697cc38
child 376 b5175878dc11
AI works properly
hedgewars/CCHandlers.inc
hedgewars/uAI.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/CCHandlers.inc	Sun Jan 28 16:40:04 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Sun Jan 28 20:58:06 2007 +0000
@@ -100,7 +100,8 @@
 var c: LongInt;
 begin
 if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/color"', true);
-val(id, CurrentTeam^.Color, c);
+//val(id, CurrentTeam^.Color, c);
+CurrentTeam^.Color:= random($FFFFFF);
 CurrentTeam^.AdjColor:= CurrentTeam^.Color;
 AdjustColor(CurrentTeam^.AdjColor)
 end;
--- a/hedgewars/uAI.pas	Sun Jan 28 16:40:04 2007 +0000
+++ b/hedgewars/uAI.pas	Sun Jan 28 20:58:06 2007 +0000
@@ -134,7 +134,7 @@
                   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);
+                                  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
@@ -142,7 +142,7 @@
                   begin
                   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);
+                                  else AddAction(MadeActions, aia_WaitXR, hwRound(AltMe.X), 0, 0, 0);
                   end;
        if not CanGo then break;
        inc(steps);
@@ -162,13 +162,13 @@
        if ((Me^.State and gstAttacked) = 0)
            and ((steps mod 4) = 0) then
            begin
-           if SDL_GetTicks - AIThinkStart > 3 then
+           TestAmmos(Actions, Me);
+           if SDL_GetTicks - AIThinkStart >= cTimerInterval then
               begin
               dec(Actions.Count, 3);
               Push(ticks, Actions, Me^, Me^.Message);
               exit
-              end;
-           TestAmmos(Actions, Me)
+              end
            end
        end;
 until false
--- a/hedgewars/uAIAmmoTests.pas	Sun Jan 28 16:40:04 2007 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Sun Jan 28 20:58:06 2007 +0000
@@ -22,8 +22,8 @@
 
 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
-(*function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
-function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
+function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
+(*function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 *)
@@ -34,7 +34,7 @@
 {amClusterBomb}   nil,
 {amBazooka}       @TestBazooka,
 {amUFO}           nil,
-{amShotgun}       nil,//TestShotgun,
+{amShotgun}       @TestShotgun,
 {amPickHammer}    nil,
 {amSkip}          nil,
 {amRope}          nil,
@@ -92,11 +92,11 @@
 
 begin
 Time:= 0;
-rTime:= 50;
+rTime:= 350;
 ExplR:= 0;
 Result:= BadTurn;
 repeat
-  rTime:= rTime + 300 + Level * 50 + random(200);
+  rTime:= rTime + 300 + Level * 50 + random(300);
   Vx:= - cWindSpeed * rTime * _0_5 + (Targ.X - hwRound(Me^.X)) / rTime;
   Vy:= cGravity * rTime * _0_5 - (Targ.Y - hwRound(Me^.Y)) / rTime;
   r:= Distance(Vx, Vy);
@@ -113,7 +113,7 @@
         Result:= Score
         end;
      end
-until (rTime > 4500);
+until (rTime > 4250);
 TestBazooka:= Result
 end;
 
@@ -169,37 +169,40 @@
 until (TestTime = 5000);
 TestGrenade:= Result
 end;
-{
+
 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 var Vx, Vy, x, y: hwFloat;
-begin       
+    rx, ry, Result: LongInt;
+begin
 ExplR:= 0;
-if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then
+if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
    begin
    Result:= BadTurn;
    exit
    end;
 Time:= 0;
 Power:= 1;
-Vx:= (Targ.X - Me.X)/1024;
-Vy:= (Targ.Y - Me.Y)/1024;
-x:= Me.X;
-y:= Me.Y;
+Vx:= (Targ.X - Me^.X) * _1div1024;
+Vy:= (Targ.Y - Me^.Y) * _1div1024;
+x:= Me^.X;
+y:= Me^.Y;
 Angle:= DxDy2AttackAngle(Vx, -Vy);
 repeat
   x:= x + vX;
   y:= y + vY;
-  if TestColl(round(x), round(y), 2) then
+  rx:= hwRound(x);
+  ry:= hwRound(y);
+  if TestColl(rx, ry, 2) then
      begin
-     Result:= RateShove(Me, round(x), round(y), 25, 25) * 2;
-     if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64
+     Result:= RateShove(Me, rx, ry, 25, 25) * 2;
+     if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
                    else dec(Result, Level * 4000);
-     exit
+     exit(Result)
      end
-until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
-Result:= BadTurn
+until (hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
+TestShotgun:= BadTurn
 end;
-
+{
 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
 var Vx, Vy, x, y, t: hwFloat;
     d: Longword;
--- a/hedgewars/uAIMisc.pas	Sun Jan 28 16:40:04 2007 +0000
+++ b/hedgewars/uAIMisc.pas	Sun Jan 28 20:58:06 2007 +0000
@@ -302,7 +302,7 @@
 repeat
 pX:= hwRound(Gear^.X);
 pY:= hwRound(Gear^.Y);
-if pY + cHHRadius >= cWaterLine then exit;
+if pY + cHHRadius >= cWaterLine then exit(false);
 if (Gear^.State and gstFalling) <> 0 then
    begin
    inc(GoInfo.Ticks);
@@ -380,12 +380,10 @@
    end
    end;
 if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstFalling) = 0) then
-   begin
-   Result:= true;
-   exit(Result)
-   end
+   exit(true);
 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstFalling) = 0);
-HHJump(AltGear, jmpHJump, GoInfo)
+HHJump(AltGear, jmpHJump, GoInfo);
+HHGo:= Result
 end;
 
 function AIrndSign(num: LongInt): LongInt;