Tell AI to avoid edges, especially ones over water (this does not include checking whether a knock could drown yet). Also make flakes pick a new random dx/dy on respawn to further reduce patterns. Also disable a couple of weapons for the particularly dumb AI levels, and disable switching for the dumbest.
authornemo
Wed, 11 Jul 2012 22:18:43 -0400
changeset 7375 16ae2e1c9005
parent 7372 fcc002658832
child 7378 ac9ce7f033df
Tell AI to avoid edges, especially ones over water (this does not include checking whether a knock could drown yet). Also make flakes pick a new random dx/dy on respawn to further reduce patterns. Also disable a couple of weapons for the particularly dumb AI levels, and disable switching for the dumbest.
hedgewars/VGSHandlers.inc
hedgewars/uAI.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
hedgewars/uGearsHedgehog.pas
--- a/hedgewars/VGSHandlers.inc	Mon Jul 09 23:28:02 2012 -0400
+++ b/hedgewars/VGSHandlers.inc	Wed Jul 11 22:18:43 2012 -0400
@@ -27,6 +27,7 @@
 
 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
 var sign: real;
+    moved: boolean;
 begin
 if vobCount = 0 then exit;
 
@@ -84,21 +85,37 @@
         end
     else
         begin
+        moved:= false;
         if round(X) < cLeftScreenBorder then
-            X:= X + cScreenSpace
+            begin
+            X:= X + cScreenSpace;
+            moved:= true
+            end
         else
             if round(X) > cRightScreenBorder then
+                begin
                 X:= X - cScreenSpace;
+                moved:= true
+                end;
             // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards?
         if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then
             begin
             X:= cLeftScreenBorder + random(cScreenSpace);
-            Y:= Y - (1024 + 250 + random(50)) // TODO - configure in theme (jellies for example could use limited range)
+            Y:= Y - (1024 + 250 + random(50)); // TODO - configure in theme (jellies for example could use limited range)
+            moved:= true
             end
         else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then
             begin
             X:= cLeftScreenBorder + random(cScreenSpace);
-            Y:= Y - (1024 + random(25))
+            Y:= Y - (1024 + random(25));
+            moved:= true
+            end;
+        if moved then
+            begin
+            Angle:= random(360);
+            dx:= 0.0000038654705 * random(10000);
+            dy:= 0.000003506096 * random(7000);
+            if random(2) = 0 then dx := -dx
             end;
         Timer:= 0;
         tdX:= 0;
--- a/hedgewars/uAI.pas	Mon Jul 09 23:28:02 2012 -0400
+++ b/hedgewars/uAI.pas	Wed Jul 11 22:18:43 2012 -0400
@@ -336,7 +336,9 @@
 switchesNum:= 0;
 
 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
-switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch);
+if PGear(Me)^.Hedgehog^.BotLevel <> 5 then
+    switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch)
+else switchCount:= 0;
 
 if (PGear(Me)^.State and gstAttacked) = 0 then
     if Targets.Count > 0 then
@@ -390,6 +392,11 @@
     BackMe:= PGear(Me)^;
     while (not StopThinking) and (BestActions.Count = 0) do
         begin
+(*
+        // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
+        if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
+            AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
+*)
         FillBonuses(true);
         WalkMe:= BackMe;
         Actions.Count:= 0;
--- a/hedgewars/uAIAmmoTests.pas	Mon Jul 09 23:28:02 2012 -0400
+++ b/hedgewars/uAIAmmoTests.pas	Wed Jul 11 22:18:43 2012 -0400
@@ -599,6 +599,7 @@
     d: Longword;
     fallDmg, valueResult: LongInt;
 begin
+if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 Level:= Level; // avoid compiler hint
 ap.ExplR:= 0;
@@ -648,6 +649,7 @@
     d: Longword;
     fallDmg, valueResult: LongInt;
 begin
+if Me^.Hedgehog^.BotLevel > 3 then exit(BadTurn);
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 Level:= Level; // avoid compiler hint
 ap.ExplR:= 0;
--- a/hedgewars/uAIMisc.pas	Mon Jul 09 23:28:02 2012 -0400
+++ b/hedgewars/uAIMisc.pas	Wed Jul 11 22:18:43 2012 -0400
@@ -54,6 +54,7 @@
 procedure freeModule;
 
 procedure FillTargets;
+procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt); inline;
 procedure FillBonuses(isAfterAttack: boolean);
 procedure AwareOfExplosion(x, y, r: LongInt); inline;
 
@@ -80,6 +81,11 @@
         ar: array[0..Pred(MAXBONUS)] of TBonus;
         end;
 
+    walkbonuses: record
+        Count: Longword;
+        ar: array[0..Pred(MAXBONUS div 4)] of TBonus;  // don't use too many
+        end;
+
 implementation
 uses uCollisions, uVariables, uUtils, uDebug, uLandTexture;
 
@@ -140,9 +146,22 @@
     end;
 end;
 
+procedure AddWalkBonus(x, y: LongInt; r: Longword; s: LongInt); inline;
+begin
+if(walkbonuses.Count < MAXBONUS div 4) then
+    begin
+    walkbonuses.ar[walkbonuses.Count].x:= x;
+    walkbonuses.ar[walkbonuses.Count].y:= y;
+    walkbonuses.ar[walkbonuses.Count].Radius:= r;
+    walkbonuses.ar[walkbonuses.Count].Score:= s;
+    inc(walkbonuses.Count);
+    end;
+end;
+
 procedure FillBonuses(isAfterAttack: boolean);
 var Gear: PGear;
     MyClan: PClan;
+    i: Longint;
 begin
 bonuses.Count:= 0;
 MyClan:= ThinkingHH^.Hedgehog^.Team^.Clan;
@@ -190,6 +209,11 @@
 if isAfterAttack and (KnownExplosion.Radius > 0) then
     with KnownExplosion do
         AddBonus(X, Y, Radius + 10, -Radius);
+if isAfterAttack then
+    for i:= 0 to Pred(walkbonuses.Count) do
+        with walkbonuses.ar[i] do
+            AddBonus(X, Y, Radius, Score);
+walkbonuses.Count:= 0
 end;
 
 procedure AwareOfExplosion(x, y, r: LongInt); inline;
@@ -642,7 +666,7 @@
 end;
 
 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
-var pX, pY: LongInt;
+var pX, pY, tY: LongInt;
 begin
 HHGo:= false;
 AltGear^:= Gear^;
@@ -650,12 +674,16 @@
 GoInfo.Ticks:= 0;
 GoInfo.FallPix:= 0;
 GoInfo.JumpType:= jmpNone;
-
+tY:= hwRound(Gear^.Y);
 repeat
     pX:= hwRound(Gear^.X);
     pY:= hwRound(Gear^.Y);
     if pY + cHHRadius >= cWaterLine then
-        exit(false);
+        begin
+        if AltGear^.Hedgehog^.BotLevel < 4 then
+            AddWalkBonus(pX, tY, 250, -40);
+        exit(false)
+        end;
         
     // hog is falling    
     if (Gear^.State and gstMoving) <> 0 then
@@ -667,6 +695,8 @@
             Goinfo.FallPix:= 0;
             // try ljump instead of fall with damage
             HHJump(AltGear, jmpLJump, GoInfo); 
+            if AltGear^.Hedgehog^.BotLevel < 4 then
+                AddWalkBonus(pX, tY, 175, -20);
             exit(false)
             end;
         Gear^.Y:= Gear^.Y + Gear^.dY;
--- a/hedgewars/uGearsHedgehog.pas	Mon Jul 09 23:28:02 2012 -0400
+++ b/hedgewars/uGearsHedgehog.pas	Wed Jul 11 22:18:43 2012 -0400
@@ -355,7 +355,6 @@
                                  newGear:= AddGear(hwRound(lx), hwRound(ly), gtResurrector, 0, _0, _0, 0);
                                  newGear^.SoundChannel := LoopSound(sndResurrector);
                                  end;
-                                 //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
                     amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);