downgrade sentries to miniguns
authoralfadur
Tue, 30 Jun 2020 02:18:54 +0300
changeset 15656 c34cad72cd85
parent 15655 116307c752f6
child 15657 72173f800dc4
downgrade sentries to miniguns
hedgewars/uCollisions.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uGearsUtils.pas
--- a/hedgewars/uCollisions.pas	Tue Jun 30 00:58:24 2020 +0300
+++ b/hedgewars/uCollisions.pas	Tue Jun 30 02:18:54 2020 +0300
@@ -71,6 +71,7 @@
 function  CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray;
 
 function  UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; inline;
+function  UpdateHitOrder(Gear: PGear; Order: LongInt; Global: boolean): boolean; inline;
 function  UpdateGlobalHitOrder(Gear: PGear; Order: LongInt): boolean; inline;
 procedure ClearHitOrderLeq(MinOrder: LongInt); inline;
 procedure ClearGlobalHitOrderLeq(MinOrder: LongInt); inline;
@@ -371,6 +372,14 @@
     UpdateHitOrder := UpdateHitOrderImpl(@ordera, Gear, Order);
 end;
 
+function UpdateHitOrder(Gear: PGear; Order: LongInt; Global: boolean): boolean; inline;
+begin
+    if Global then
+        UpdateHitOrder := UpdateHitOrderImpl(@ordera, Gear, Order)
+    else
+        UpdateHitOrder := UpdateHitOrderImpl(@globalordera, Gear, Order)
+end;
+
 function UpdateGlobalHitOrder(Gear: PGear; Order: LongInt): boolean; inline;
 begin
     UpdateGlobalHitOrder := UpdateHitOrderImpl(@globalordera, Gear, Order);
@@ -382,7 +391,7 @@
     freeIndex:= 0;
     i:= 0;
 
-    while i < ordera.Count do
+    while i < HitOrder^.Count do
     begin
         if HitOrder^.order[i] <= MinOrder then
             Dec(HitOrder^.Count)
--- a/hedgewars/uGearsHandlersMess.pas	Tue Jun 30 00:58:24 2020 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Tue Jun 30 02:18:54 2020 +0300
@@ -1564,7 +1564,7 @@
             begin
             if Gear^.Kind = gtMinigunBullet then
                 begin
-                doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 5,
+                doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Karma,
                                 Gear^.Hedgehog, (EXPLNoDamage or EXPLDoNotTouchHH){ or EXPLDontDraw or EXPLNoGfx});
                 VGear := AddVisualGear(hwRound(Gear^.X + Gear^.dX * 5), hwRound(Gear^.Y + Gear^.dY * 5), vgtBulletHit);
                 end
@@ -1607,7 +1607,6 @@
 
 procedure doStepDEagleShot(Gear: PGear);
 begin
-
     if Gear^.Data = nil then
         // remember who fired this
         if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then
@@ -7161,10 +7160,10 @@
 
 procedure doStepMinigunBullet(Gear: PGear);
 begin
-    Gear^.Data:= nil;
-    // remember who fired this
-    if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then
-        Gear^.Data:= Pointer(Gear^.Hedgehog^.Gear);
+    if Gear^.Data = nil then
+        // remember who fired this
+        if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then
+            Gear^.Data:= Pointer(Gear^.Hedgehog^.Gear);
 
     Gear^.X := Gear^.X + Gear^.dX * 2;
     Gear^.Y := Gear^.Y + Gear^.dY * 2;
@@ -7244,10 +7243,18 @@
     if TestCollisionY(Gear, 1) = 0 then
     begin
         doStepFallingGear(Gear);
-        Gear^.Timer := 0;
-        Gear^.Tag := sentry_Idle;
-        Gear^.Target.X := 0;
-        Gear^.Target.Y := 0;
+        if Gear^.Tag <> sentry_Idle then
+        begin
+            Gear^.Timer := 0;
+            Gear^.Tag := sentry_Idle;
+            Gear^.Target.X := 0;
+            Gear^.Target.Y := 0;
+            if Gear^.Karma <> 0 then
+            begin
+                ClearGlobalHitOrderLeq(Gear^.Karma);
+                Gear^.Karma := 0;
+            end;
+        end;
         exit;
     end;
 
@@ -7270,7 +7277,7 @@
         begin
             Gear^.WDTimer := 5 + GetRandom(3);
             Gear^.Tag := sentry_Attacking;
-            Gear^.Timer := 200;
+            Gear^.Timer := 100;
         end
         else if Gear^.Tag = sentry_Attacking then
         begin
@@ -7282,29 +7289,35 @@
 
             bullet := AddGear(
                 hwRound(Gear^.X), hwRound(Gear^.Y),
-                gtDEagleShot, 0,
-                distX, distY, 0);
-
-            bullet^.Boom := 4;
-            bullet^.Health := 15;
+                gtMinigunBullet, 0,
+                distX * _0_9 + rndSign(getRandomf * _0_1),
+                distY * _0_9 + rndSign(getRandomf * _0_1),
+                0);
+
+            bullet^.Karma := 12;
+            bullet^.Pos := 1;
+            bullet^.WDTimer := GameTicks;
             bullet^.PortalCounter := 1;
             bullet^.Elasticity := Gear^.X;
             bullet^.Friction := Gear^.Y;
             bullet^.Data := Pointer(Gear);
 
             CreateShellForGear(Gear, Gear^.WDTimer and 1);
+            PlaySound(sndGun);
 
             if Gear^.WDTimer = 0 then
             begin
                 Gear^.Target.X := 0;
                 Gear^.Target.Y := 0;
+                ClearGlobalHitOrderLeq(Gear^.Karma);
+                Gear^.Karma := 0;
                 Gear^.Tag := sentry_Reloading;
                 Gear^.Timer := 6000 + GetRandom(2000);
             end
             else
             begin
                 dec(Gear^.WDTimer);
-                Gear^.Timer := 200;
+                Gear^.Timer := 100;
             end
         end;
     end;
@@ -7332,6 +7345,7 @@
         begin
             Gear^.Target.X := hwRound(HHGear^.X);
             Gear^.Target.Y := hwRound(HHGear^.Y);
+            Gear^.Karma := GameTicks;
             Gear^.Tag := sentry_Aiming;
             Gear^.Timer := 1800 + GetRandom(400);
         end
--- a/hedgewars/uGearsList.pas	Tue Jun 30 00:58:24 2020 +0300
+++ b/hedgewars/uGearsList.pas	Tue Jun 30 02:18:54 2020 +0300
@@ -832,6 +832,9 @@
  gtMinigunBullet: begin
                 gear^.Radius:= 1;
                 gear^.Health:= 2;
+                gear^.Karma:= 5; //impact radius
+                gear^.Pos:= 0; //uses non-global hit order
+                gear^.Data:= nil;
                 end;
         gtSentry: begin
                 gear^.Radius:= cHHRadius;
--- a/hedgewars/uGearsUtils.pas	Tue Jun 30 00:58:24 2020 +0300
+++ b/hedgewars/uGearsUtils.pas	Tue Jun 30 02:18:54 2020 +0300
@@ -1377,7 +1377,10 @@
     if (Ammo^.Kind in [gtDEagleShot, gtSniperRifleShot, gtMinigunBullet,
                        gtFirePunch, gtKamikaze, gtWhip, gtShover])
         and (((Ammo^.Data <> nil) and (PGear(Ammo^.Data) = Gear))
-             or (not UpdateHitOrder(Gear, Ammo^.WDTimer))) then
+            or (not UpdateHitOrder(
+                    Gear, 
+                    Ammo^.WDTimer, 
+                    (Ammo^.Kind = gtMinigunBullet) and (Gear^.Pos <> 0)))) then
         continue;
 
     if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and