remove owner from wild sentries
authoralfadur
Sat, 16 Oct 2021 03:35:48 +0300
changeset 15846 681db3039ad7
parent 15845 744f4d708963
child 15847 e48c3333c404
remove owner from wild sentries
hedgewars/uGears.pas
hedgewars/uGearsUtils.pas
hedgewars/uStats.pas
--- a/hedgewars/uGears.pas	Sat Oct 16 02:52:06 2021 +0300
+++ b/hedgewars/uGears.pas	Sat Oct 16 03:35:48 2021 +0300
@@ -814,7 +814,7 @@
     end;
 
     for i := 0 to min(count, positionsCount) - 1 do
-        AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0);
+        AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0)^.Hedgehog := nil;
 end;
 
 function AddWaterSentries(count: Longword): Longword;
@@ -842,7 +842,7 @@
 
     for i := 0 to min(count, positionsCount) - 1 do
     begin
-        AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0);
+        AddGear(positions[i].X, positions[i].Y - cHHRadius, gtSentry, 0, _0, _0, 0)^.Hedgehog := nil;
         inc(AddWaterSentries);
     end;
 end;
--- a/hedgewars/uGearsUtils.pas	Sat Oct 16 02:52:06 2021 +0300
+++ b/hedgewars/uGearsUtils.pas	Sat Oct 16 03:35:48 2021 +0300
@@ -321,25 +321,25 @@
 
         uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);
 
-    if AprilOne and (Gear^.Hedgehog^.Hat = 'fr_tomato') and (Damage > 2) then
-        for i := 0 to random(min(Damage,20))+5 do
-        begin
-        vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot);
-        if vg <> nil then
-            with vg^ do
+        if AprilOne and (Gear^.Hedgehog^.Hat = 'fr_tomato') and (Damage > 2) then
+            for i := 0 to random(min(Damage,20))+5 do
             begin
-            dx:= 0.001 * (random(100)+10);
-            dy:= 0.001 * (random(100)+10);
-            tdy:= -cGravityf;
-            if random(2) = 0 then
-                dx := -dx;
-            FrameTicks:= random(500) + 1000;
-            State:= ord(sprBubbles);
-            Tint:= $ff0000ff
+            vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot);
+            if vg <> nil then
+                with vg^ do
+                begin
+                dx:= 0.001 * (random(100)+10);
+                dy:= 0.001 * (random(100)+10);
+                tdy:= -cGravityf;
+                if random(2) = 0 then
+                    dx := -dx;
+                FrameTicks:= random(500) + 1000;
+                State:= ord(sprBubbles);
+                Tint:= $ff0000ff
+                end
             end
-    end
-    end else
-        Gear^.Hedgehog:= AttackerHog;
+        end else if AttackerHog <> nil then
+            Gear^.Hedgehog:= AttackerHog;
     inc(Gear^.Damage, Damage);
 
     ScriptCall('onGearDamage', Gear^.UID, Damage);
--- a/hedgewars/uStats.pas	Sat Oct 16 02:52:06 2021 +0300
+++ b/hedgewars/uStats.pas	Sat Oct 16 03:35:48 2021 +0300
@@ -105,15 +105,20 @@
 end;
 
 procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
+var sameClan: Boolean;
 begin
-if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then
+sameClan := false;
+if Attacker <> nil then
+    sameClan := Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan;
+
+if sameClan then
     vpHurtSameClan:= Gear^.Hedgehog^.Team^.voicepack
 else
     begin
     if not FirstBlood then
         StepFirstBlood:= true;
     vpHurtEnemy:= Gear^.Hedgehog^.Team^.voicepack;
-    if (not killed) and (not bDuringWaterRise) then
+    if (Attacker <> nil) and (not killed) and (not bDuringWaterRise) then
         begin
         // Check if victim got attacked by RevengeHog again
         if (Gear^.Hedgehog^.RevengeHog <> nil) and (Gear^.Hedgehog^.RevengeHog = Attacker) and (Gear^.Hedgehog^.stats.StepRevenge = false) then
@@ -141,7 +146,8 @@
 
 if (not bDuringWaterRise) then
     begin
-    inc(Attacker^.stats.StepDamageGiven, Damage);
+    if Attacker <> nil then
+        inc(Attacker^.stats.StepDamageGiven, Damage);
     inc(Gear^.Hedgehog^.stats.StepDamageRecv, Damage);
     end;
 
@@ -157,7 +163,7 @@
 
     if bDuringWaterRise then
         inc(KillsSD)
-    else
+    else if Attacker <> nil then
         begin
         inc(Attacker^.stats.StepKills);
         inc(Attacker^.Team^.stats.Kills);