make domesticated sentries not target their owners
authoralfadur
Sat, 16 Oct 2021 02:20:15 +0300
changeset 15821 4a1e3d824c34
parent 15820 b6379a7ed674
child 15822 4ede5e84278a
make domesticated sentries not target their owners
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uGearsHandlersMess.pas	Sat Oct 16 01:21:26 2021 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Sat Oct 16 02:20:15 2021 +0300
@@ -7359,19 +7359,24 @@
     PlaySound(sndGun);
 end;
 
-function GetSentryTarget(): PGear;
+function GetSentryTarget(sentry: PGear): PGear;
 var HHGear: PGear;
+    friendlyTarget: boolean;
 begin
     GetSentryTarget := nil;
-    if (CurrentHedgehog <> nil) then
+    friendlyTarget := false;
+
+    if CurrentHedgehog <> nil then
     begin
         HHGear := CurrentHedgehog^.Gear;
         if HHGear <> nil then
-        begin
-            if ((HHGear^.State and gstHHDriven) <> 0)
-                and (HHGear^.CollisionIndex < 0) then
-                GetSentryTarget := HHGear;
-        end
+            if ((HHGear^.State and gstHHDriven) <> 0) and (HHGear^.CollisionIndex < 0) then
+            begin
+                if sentry^.Hedgehog <> nil then
+                    friendlyTarget := sentry^.Hedgehog^.Team = CurrentHedgehog^.Team;
+                if not friendlyTarget then
+                    GetSentryTarget := HHGear;
+            end
     end
 end;
 
@@ -7500,7 +7505,7 @@
     if ((GameTicks and $FF) = 0)
         and (Gear^.Tag in [sentry_Idle, sentry_Walking]) then
     begin
-        HHGear := GetSentryTarget();
+        HHGear := GetSentryTarget(Gear);
         if HHGear <> nil then
             if CheckSentryAttackRange(Gear, HHGear^.X, HHGear^.Y) then
             begin
@@ -7602,7 +7607,7 @@
     if ((GameTicks and $FF) = 0)
         and (Gear^.Tag in [sentry_Idle, sentry_Walking]) then
     begin
-        HHGear := GetSentryTarget();
+        HHGear := GetSentryTarget(Gear);
         if HHGear <> nil then
             if CheckSentryAttackRange(Gear, HHGear^.X, HHGear^.Y) then
             begin