Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
authornemo
Sat, 14 Feb 2015 17:34:12 -0500
changeset 10818 f642a28cab0c
parent 10816 37410518628e
child 10820 e86ba0e821a6
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
gameServer/hedgewars-server.hs
hedgewars/uAmmos.pas
hedgewars/uCollisions.pas
hedgewars/uCommandHandlers.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uGearsRender.pas
hedgewars/uIO.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
--- a/gameServer/hedgewars-server.hs	Sat Feb 07 23:25:33 2015 +0300
+++ b/gameServer/hedgewars-server.hs	Sat Feb 14 17:34:12 2015 -0500
@@ -40,7 +40,7 @@
 
 setupLoggers :: IO ()
 setupLoggers = do
-    updateGlobalLogger "Clients" (setLevel NOTICE)
+    updateGlobalLogger "Clients" (setLevel DEBUG)
     updateGlobalLogger "Core" (setLevel NOTICE)
     updateGlobalLogger "REPLAYS" (setLevel NOTICE)
 
--- a/hedgewars/uAmmos.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uAmmos.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -400,12 +400,12 @@
         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
         if (Propz and ammoprop_NeedTarget) <> 0 then
             begin
-            if Gear <> nil then Gear^.State:= Gear^.State or      gstHHChooseTarget;
+            if Gear <> nil then Gear^.State:= Gear^.State or      gstChooseTarget;
             isCursorVisible:= true
             end
         else
             begin
-            if Gear <> nil then Gear^.State:= Gear^.State and (not gstHHChooseTarget);
+            if Gear <> nil then Gear^.State:= Gear^.State and (not gstChooseTarget);
             isCursorVisible:= false
             end;
         end
--- a/hedgewars/uCollisions.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uCollisions.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -52,7 +52,7 @@
 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline;
 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word;
 
-function  TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+function  TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
 
 function  CheckCoordInWater(X, Y: LongInt): boolean; inline;
 
@@ -398,11 +398,11 @@
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
 
-function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
 var x, y: LongInt;
     TestWord: LongWord;
 begin
-TestRectancleForObstacle:= true;
+TestRectangleForObstacle:= true;
 
 if landOnly then
     TestWord:= 255
@@ -431,7 +431,7 @@
         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > TestWord) then
             exit;
 
-TestRectancleForObstacle:= false
+TestRectangleForObstacle:= false
 end;
 
 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
--- a/hedgewars/uCommandHandlers.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uCommandHandlers.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -748,6 +748,11 @@
 cLandMines:= StrToInt(s)
 end;
 
+procedure chAirMines(var s: shortstring);
+begin
+cAirMines:= StrToInt(s)
+end;
+
 procedure chExplosives(var s: shortstring);
 begin
 cExplosives:= StrToInt(s)
--- a/hedgewars/uConsts.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uConsts.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -215,7 +215,7 @@
     gstAttacked       = $00000008;
     gstAttacking      = $00000010;
     gstCollision      = $00000020;
-    gstHHChooseTarget = $00000040;
+    gstChooseTarget   = $00000040;
     gstHHJumping      = $00000100;
     gsttmpFlag        = $00000200;
     gstHHThinking     = $00000800;
--- a/hedgewars/uGears.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uGears.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -33,7 +33,7 @@
  *       effects are called "Visual Gears" and defined in the respective unit!
  *)
 interface
-uses uConsts, uFloat, uTypes, uChat;
+uses uConsts, uFloat, uTypes, uChat, uCollisions;
 
 procedure initModule;
 procedure freeModule;
@@ -394,7 +394,7 @@
             if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0)
             and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
                 begin
-                CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget;
+                CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstChooseTarget;
                 isCursorVisible := true
                 end;
             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacked);
@@ -567,7 +567,7 @@
 end;
 
 procedure AddMiscGears;
-var p,i,j, unplaced: Longword;
+var p,i,j,t,h,unplaced: Longword;
     rx, ry: LongInt;
     rdx, rdy: hwFloat;
     Gear: PGear;
@@ -604,6 +604,70 @@
     inc(i)
     end;
 
+i:= 0;
+j:= 0;
+p:= 0; // 0 searching, 1 bad position, 2 added.
+unplaced:= 0;
+if cAirMines > 0 then
+    Gear:= AddGear(0, 0, gtAirMine, 0, _0, _0, 0);
+while (i < cAirMines) and (j < 1000*cAirMines) do
+    begin
+    p:= 0;
+    if hasBorder then
+        begin
+        rx:= leftX+GetRandom(rightX-leftX-16)+8;
+        ry:= topY+GetRandom(LAND_HEIGHT-topY-16)+8
+        end
+    else
+        begin
+        rx:= leftX+GetRandom(rightX-leftX+400)-200;
+        ry:= topY+GetRandom(LAND_HEIGHT-topY+400)-200
+        end;
+    Gear^.X:= int2hwFloat(rx);
+    Gear^.Y:= int2hwFloat(ry);
+    if CheckLandValue(rx, ry, $FFFF) and
+       (TestCollisionYwithGear(Gear,-1) = 0) and
+       (TestCollisionXwithGear(Gear, 1) = 0) and
+       (TestCollisionXwithGear(Gear,-1) = 0) and
+       (TestCollisionYwithGear(Gear, 1) = 0) then
+        begin
+        t:= 0;
+        h:= 0;
+        while (t < TeamsCount) and (p = 0) do
+            begin
+            with TeamsArray[t]^ do
+                while (h < cMaxHHIndex) and (p = 0) do
+                    begin
+                    if (Hedgehogs[h].Gear <> nil) then
+                        begin
+                        rdx:=Gear^.X-Hedgehogs[h].Gear^.X;
+                        rdy:=Gear^.Y-Hedgehogs[h].Gear^.Y;
+                        if (Gear^.Angle < $FFFFFFFF) and
+                            ((rdx.Round+rdy.Round < Gear^.Angle) and
+                            (hwRound(hwSqr(rdx) + hwSqr(rdy)) < sqr(Gear^.Angle))) then
+                            begin
+// Debug line. Remove later
+AddFileLog('Too Close to Hog @ (' + inttostr(rx) + ',' + inttostr(ry) + ')');
+
+                            p:= 1
+                            end
+                        end;
+                    inc(h)
+                    end;
+            inc(t)
+            end;
+        if p = 0 then
+            begin
+            inc(i);
+            AddFileLog('Placed Air Mine @ (' + inttostr(rx) + ',' + inttostr(ry) + ')');
+            if i < cAirMines then
+                Gear:= AddGear(0, 0, gtAirMine, 0, _0, _0, 0)
+            end
+        end;
+    inc(j)
+    end;
+if p <> 0 then DeleteGear(Gear);
+
 if (GameFlags and gfLowGravity) <> 0 then
     begin
     cGravity:= cMaxWindSpeed;
--- a/hedgewars/uGearsHandlersMess.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -1799,14 +1799,14 @@
         ((TurnTimeLeft < cHedgehogTurnTime) and (cHedgehogTurnTime-TurnTimeLeft < 5000)) or
         (Gear^.State and gsttmpFlag = 0) or
         (Gear^.Angle = 0) then
-        gear^.State:= gear^.State and (not gstHHChooseTarget)
+        gear^.State:= gear^.State and (not gstChooseTarget)
     else if
     // todo, allow not finding new target, set timeout on target retention
         (Gear^.State and gstAttacking = 0) and
         ((GameTicks and $FF) = 17) and
         (GameTicks > Gear^.FlightTime) then // recheck hunted hog
         begin
-        gear^.State:= gear^.State or gstHHChooseTarget;
+        gear^.State:= gear^.State or gstChooseTarget;
         if targ <> nil then
              targDist:= Distance(Gear^.X-targ^.X,Gear^.Y-targ^.Y).Round
         else targDist:= 0;
@@ -2747,7 +2747,7 @@
             end;
         HHGear^.Message := HHGear^.Message and (not gmAttack);
         HHGear^.State := HHGear^.State and (not gstAttacking);
-        HHGear^.State := HHGear^.State or gstHHChooseTarget;
+        HHGear^.State := HHGear^.State or gstChooseTarget;
         isCursorVisible := true;
         DeleteGear(Gear)
         end
@@ -2832,7 +2832,7 @@
         begin
         HHGear^.Message := HHGear^.Message and (not gmAttack);
         HHGear^.State := HHGear^.State and (not gstAttacking);
-        HHGear^.State := HHGear^.State or gstHHChooseTarget;
+        HHGear^.State := HHGear^.State or gstChooseTarget;
         isCursorVisible := true;
         warn:= AddVisualGear(Gear^.Target.X, oy, vgtNoPlaceWarn, 0, true);
         if warn <> nil then
--- a/hedgewars/uGearsHedgehog.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uGearsHedgehog.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -222,7 +222,7 @@
 with Gear^,
     Gear^.Hedgehog^ do
         begin
-        if ((State and gstHHDriven) <> 0) and ((State and (gstAttacked or gstHHChooseTarget)) = 0) and (((State and gstMoving) = 0)
+        if ((State and gstHHDriven) <> 0) and ((State and (gstAttacked or gstChooseTarget)) = 0) and (((State and gstMoving) = 0)
         or (Power > 0)
         or (CurAmmoType = amTeleport)
         or
@@ -1318,7 +1318,7 @@
     begin
     if Gear^.Timer = 0 then
         begin
-        Gear^.State:= Gear^.State and (not (gstWait or gstLoser or gstWinner or gstAttacked or gstNotKickable or gstHHChooseTarget));
+        Gear^.State:= Gear^.State and (not (gstWait or gstLoser or gstWinner or gstAttacked or gstNotKickable or gstChooseTarget));
         if Gear^.Hedgehog^.Effects[heFrozen] = 0 then Gear^.Active:= false;
         AddCI(Gear);
         exit
--- a/hedgewars/uGearsRender.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uGearsRender.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -1128,7 +1128,7 @@
                         end
                     else if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then  // mine is chasing a hog
                          DrawSprite(sprAirMine, x-16, y-16, (RealTicks div 25) mod 16)
-                    else if Gear^.State and gstHHChooseTarget <> 0 then   // mine is seeking for hogs
+                    else if Gear^.State and gstChooseTarget <> 0 then   // mine is seeking for hogs
                          DrawSprite(sprAirMine, x-16, y-16, (RealTicks div 125) mod 16)
                     else
                          DrawSprite(sprAirMine, x-16, y-16, 4);           // mine is active but not seeking
--- a/hedgewars/uIO.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uIO.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -462,7 +462,7 @@
 
 with CurrentHedgehog^.Gear^,
     CurrentHedgehog^ do
-    if (State and gstHHChooseTarget) <> 0 then
+    if (State and gstChooseTarget) <> 0 then
         begin
         isCursorVisible:= false;
         if not CurrentTeam^.ExtDriven then
@@ -485,7 +485,7 @@
             TargetPoint.Y:= putY
             end;
         AddFileLog('put: ' + inttostr(TargetPoint.X) + ', ' + inttostr(TargetPoint.Y));
-        State:= State and (not gstHHChooseTarget);
+        State:= State and (not gstChooseTarget);
         if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackingPut) <> 0 then
             Message:= Message or (gmAttack and InputMask);
         end
--- a/hedgewars/uScript.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uScript.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -2309,7 +2309,7 @@
 begin
     if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
         begin
-        rtn:= TestRectancleForObstacle(
+        rtn:= TestRectangleForObstacle(
                     lua_tointeger(L, 1),
                     lua_tointeger(L, 2),
                     lua_tointeger(L, 3),
@@ -3027,7 +3027,7 @@
 ScriptSetInteger('gstAttacked'      , gstAttacked);
 ScriptSetInteger('gstAttacking'     , gstAttacking);
 ScriptSetInteger('gstCollision'     , gstCollision);
-ScriptSetInteger('gstHHChooseTarget', gstHHChooseTarget);
+ScriptSetInteger('gstChooseTarget', gstChooseTarget);
 ScriptSetInteger('gstHHJumping'     , gstHHJumping);
 ScriptSetInteger('gsttmpFlag'       , gsttmpFlag);
 ScriptSetInteger('gstHHThinking'    , gstHHThinking);
--- a/hedgewars/uVariables.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uVariables.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -149,6 +149,7 @@
 
     cCaseFactor     : Longword;
     cLandMines      : Longword;
+    cAirMines       : Longword;
     cExplosives     : Longword;
 
     cScriptName     : shortstring;
@@ -2607,6 +2608,7 @@
     AttackBar       := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - from weapon
     cCaseFactor     := 5;  {0..9}
     cLandMines      := 4;
+    cAirMines       := 1000;
     cExplosives     := 2;
 
     GameState       := Low(TGameState);
--- a/hedgewars/uWorld.pas	Sat Feb 07 23:25:33 2015 +0300
+++ b/hedgewars/uWorld.pas	Sat Feb 14 17:34:12 2015 -0500
@@ -1808,7 +1808,7 @@
         begin
         if not CurrentTeam^.ExtDriven then TargetCursorPoint:= CursorPoint;
         with CurrentHedgehog^ do
-            if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then
+            if (Gear <> nil) and ((Gear^.State and gstChooseTarget) <> 0) then
                 begin
             if (CurAmmoType = amNapalm) or (CurAmmoType = amMineStrike) or (((GameFlags and gfMoreWind) <> 0) and ((CurAmmoType = amDrillStrike) or (CurAmmoType = amAirAttack))) then
                 DrawLine(-3000, topY-300, 7000, topY-300, 3.0, (Team^.Clan^.Color shr 16), (Team^.Clan^.Color shr 8) and $FF, Team^.Clan^.Color and $FF, $FF);