DEADSOFTWARE

trigger turret: add aim modes
authorbinarymaster <x86corez@gmail.com>
Thu, 2 Mar 2017 22:36:39 +0000 (01:36 +0300)
committerbinarymaster <x86corez@gmail.com>
Thu, 2 Mar 2017 23:45:25 +0000 (02:45 +0300)
src/game/g_triggers.pas
src/shared/MAPDEF.pas
src/shared/mapstructio.inc

index 9ce8c0affc12cd9b8884fa381e40bd8c103ae392..9ca5756b048cd9409686c8f59496c1a7ed522b67 100644 (file)
@@ -924,6 +924,22 @@ begin
   end;
 end;
 
+function tr_ShotAimCheck(var Trigger: TTrigger; Obj: PObj): Boolean;
+begin
+  with Trigger do
+  begin
+    if TriggerType <> TRIGGER_SHOT then
+      Exit;
+    Result := (Data.ShotAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
+              or g_Obj_Collide(X, Y, Width, Height, Obj);
+    if Result and (Data.ShotAim and TRIGGER_SHOT_AIM_TRACE > 0) then
+      Result := g_TraceVector(Data.ShotPos.X,
+                              Data.ShotPos.Y,
+                              Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
+                              Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
+  end;
+end;
+
 function ActivateTrigger(var Trigger: TTrigger; actType: Byte): Boolean;
 var
   animonce: Boolean;
@@ -1844,7 +1860,7 @@ begin
               if gMonsters <> nil then
                 for i := Low(gMonsters) to High(gMonsters) do
                   if (gMonsters[i] <> nil) and gMonsters[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gMonsters[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gMonsters[i].Obj)) then
                   begin
                     xd := gMonsters[i].GameX + gMonsters[i].Obj.Rect.Width div 2;
                     yd := gMonsters[i].GameY + gMonsters[i].Obj.Rect.Height div 2;
@@ -1856,7 +1872,7 @@ begin
               if gPlayers <> nil then
                 for i := Low(gPlayers) to High(gPlayers) do
                   if (gPlayers[i] <> nil) and gPlayers[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gPlayers[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gPlayers[i].Obj)) then
                   begin
                     xd := gPlayers[i].GameX + PLAYER_RECT_CX;
                     yd := gPlayers[i].GameY + PLAYER_RECT_CY;
@@ -1869,7 +1885,7 @@ begin
                 for i := Low(gPlayers) to High(gPlayers) do
                   if (gPlayers[i] <> nil) and gPlayers[i].Live and
                      (gPlayers[i].Team = TEAM_RED) and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gPlayers[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gPlayers[i].Obj)) then
                   begin
                     xd := gPlayers[i].GameX + PLAYER_RECT_CX;
                     yd := gPlayers[i].GameY + PLAYER_RECT_CY;
@@ -1882,7 +1898,7 @@ begin
                 for i := Low(gPlayers) to High(gPlayers) do
                   if (gPlayers[i] <> nil) and gPlayers[i].Live and
                      (gPlayers[i].Team = TEAM_BLUE) and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gPlayers[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gPlayers[i].Obj)) then
                   begin
                     xd := gPlayers[i].GameX + PLAYER_RECT_CX;
                     yd := gPlayers[i].GameY + PLAYER_RECT_CY;
@@ -1895,7 +1911,7 @@ begin
               if gMonsters <> nil then
                 for i := Low(gMonsters) to High(gMonsters) do
                   if (gMonsters[i] <> nil) and gMonsters[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gMonsters[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gMonsters[i].Obj)) then
                   begin
                     xd := gMonsters[i].GameX + gMonsters[i].Obj.Rect.Width div 2;
                     yd := gMonsters[i].GameY + gMonsters[i].Obj.Rect.Height div 2;
@@ -1905,7 +1921,7 @@ begin
               if (TargetUID = 0) and (gPlayers <> nil) then
                 for i := Low(gPlayers) to High(gPlayers) do
                   if (gPlayers[i] <> nil) and gPlayers[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gPlayers[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gPlayers[i].Obj)) then
                   begin
                     xd := gPlayers[i].GameX + PLAYER_RECT_CX;
                     yd := gPlayers[i].GameY + PLAYER_RECT_CY;
@@ -1919,7 +1935,7 @@ begin
               if gPlayers <> nil then
                 for i := Low(gPlayers) to High(gPlayers) do
                   if (gPlayers[i] <> nil) and gPlayers[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gPlayers[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gPlayers[i].Obj)) then
                   begin
                     xd := gPlayers[i].GameX + PLAYER_RECT_CX;
                     yd := gPlayers[i].GameY + PLAYER_RECT_CY;
@@ -1929,7 +1945,7 @@ begin
               if (TargetUID = 0) and (gMonsters <> nil) then
                 for i := Low(gMonsters) to High(gMonsters) do
                   if (gMonsters[i] <> nil) and gMonsters[i].Live and
-                     (Data.ShotAllMap or g_Obj_Collide(X, Y, Width, Height, @(gMonsters[i].Obj))) then
+                     tr_ShotAimCheck(Trigger, @(gMonsters[i].Obj)) then
                   begin
                     xd := gMonsters[i].GameX + gMonsters[i].Obj.Rect.Width div 2;
                     yd := gMonsters[i].GameY + gMonsters[i].Obj.Rect.Height div 2;
@@ -1945,7 +1961,8 @@ begin
             end;
           end;
 
-          if (Data.ShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) then
+          if (Data.ShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
+            ((Data.ShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
           begin
             Result := True;
             if (Data.ShotIntSight = 0) or
index 3f843872a2f3cdd8825b9268e254232d35a251a5..15203525aaa81bfdbda94270df10e0e77541961a 100644 (file)
@@ -188,6 +188,11 @@ const
   TRIGGER_SHOT_TARGET_MONPLR = 5;
   TRIGGER_SHOT_TARGET_PLRMON = 6;
 
+  TRIGGER_SHOT_AIM_DEFAULT   = 0;
+  TRIGGER_SHOT_AIM_ALLMAP    = 1;
+  TRIGGER_SHOT_AIM_TRACE     = 2;
+  TRIGGER_SHOT_AIM_TRACEALL  = 3;
+
   TRIGGER_EFFECT_PARTICLE  = 0;
   TRIGGER_EFFECT_ANIMATION = 1;
 
@@ -309,7 +314,7 @@ type
                              ShotType: Byte;
                              ShotTarget: Byte;
                              ShotSound: Boolean;
-                             ShotAllMap: Boolean;
+                             ShotAim: Byte;
                              ShotPanelID: Integer;
                              ShotIntSight: Word;
                              ShotAngle: Word;
index ae432b9614f0a857f524af2fa522be8b06d8d2fa..68b46ac4167c27397b905466224f752413d66396 100644 (file)
@@ -201,7 +201,7 @@ procedure mb_Read_TriggerData (var tr: TTriggerData; ttype: Integer; const buf;
     getBytesAt(tr.ShotType, buf, 8, 1);
     getBytesAt(tr.ShotTarget, buf, 9, 1);
     getBytesAt(tr.ShotSound, buf, 10, 1);
-    getBytesAt(tr.ShotAllMap, buf, 11, 1);
+    getBytesAt(tr.ShotAim, buf, 11, 1);
     getIntAt(tr.ShotPanelID, buf, 12);
     getWordAt(tr.ShotIntSight, buf, 16);
     getWordAt(tr.ShotAngle, buf, 18);
@@ -512,7 +512,7 @@ procedure mb_Write_TriggerData (var buf; bufsize: Integer; ttype: Integer; var t
     putBytesAt(buf, 8, tr.ShotType, 1);
     putBytesAt(buf, 9, tr.ShotTarget, 1);
     putBytesAt(buf, 10, tr.ShotSound, 1);
-    putBytesAt(buf, 11, tr.ShotAllMap, 1);
+    putBytesAt(buf, 11, tr.ShotAim, 1);
     putIntAt(buf, 12, tr.ShotPanelID);
     putWordAt(buf, 16, tr.ShotIntSight);
     putWordAt(buf, 18, tr.ShotAngle);