DEADSOFTWARE

remove scripts
[d2df-sdl.git] / src / game / g_triggers.pas
index 40de5b4d42199ffe0cca71090bec55d38848841a..8c1c1b895de8c7b08df419df0d85e43204ee449f 100644 (file)
@@ -87,7 +87,7 @@ function tr_Teleport(ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silen
 function tr_Push(ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
 
 procedure tr_MakeEffect(X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
-function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word; TID: DWORD): Integer;
+function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
 
 var
   gTriggerClientID: Integer = 0;
@@ -101,7 +101,7 @@ uses
   g_player, g_map, Math, g_gfx, g_game, g_textures,
   g_console, g_monsters, g_items, g_phys, g_weapons,
   wadreader, g_main, SysUtils, e_log, g_language,
-  g_options, g_net, g_netmsg, g_scripts;
+  g_options, g_net, g_netmsg;
 
 const
   TRIGGER_SIGNATURE = $52475254; // 'TRGR'
@@ -427,7 +427,7 @@ begin
   end;
 end;
 
-function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word; TID: DWORD): Integer;
+function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
 var
   snd: string;
   Projectile: Boolean;
@@ -557,7 +557,7 @@ begin
           Anim.Free();
         end;
         Projectile := False;
-        g_Weapon_Explode(wx, wy, 60, 0, TID);
+        g_Weapon_Explode(wx, wy, 60, 0);
         snd := 'SOUND_WEAPON_EXPLODEROCKET';
       end;
 
@@ -620,7 +620,7 @@ begin
       dx := dx + Random(Data.ShotAccuracy) - Random(Data.ShotAccuracy);
       dy := dy + Random(Data.ShotAccuracy) - Random(Data.ShotAccuracy);
       
-      tr_SpawnShot(Data.ShotType, wx, wy, dx, dy, Data.ShotSound, TargetUID, ID);
+      tr_SpawnShot(Data.ShotType, wx, wy, dx, dy, Data.ShotSound, TargetUID);
     end
     else
       if (Data.ShotIntReload > 0) and (ShotReloadTime = 0) then
@@ -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;
@@ -1829,6 +1845,9 @@ begin
           if ShotSightTime > 0 then
             Exit;
 
+          // put this at the beginning so it doesn't trigger itself
+          TimeOut := Data.ShotWait + 1;
+
           wx := Data.ShotPos.X;
           wy := Data.ShotPos.Y;
           pAngle := -DegToRad(Data.ShotAngle);
@@ -1841,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;
@@ -1853,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;
@@ -1866,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;
@@ -1879,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;
@@ -1892,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;
@@ -1902,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;
@@ -1916,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;
@@ -1926,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;
@@ -1935,10 +1954,15 @@ begin
                   end;
             end;
 
-            else TargetUID := ActivateUID;
+            else begin
+              if (Data.ShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
+                 (Data.ShotType <> TRIGGER_SHOT_REV) then
+                TargetUID := ActivateUID;
+            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
@@ -1957,8 +1981,6 @@ begin
               end;
             end;
           end;
-
-          TimeOut := Data.ShotWait + 1;
         end;
 
       TRIGGER_EFFECT:
@@ -1996,13 +2018,6 @@ begin
           end;
           TimeOut := Data.FXWait;
         end;
-
-      TRIGGER_SCRIPT:
-        begin
-          g_Scripts_ProcExec(Data.SCRProc, [ID, ActivateUID, actType, Data.SCRArg], 'map');
-          TimeOut := 0;
-          Result := True;
-        end;
     end;
   end;
 
@@ -2500,7 +2515,7 @@ begin
 
   for a := 0 to High(gTriggers) do
     if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
-          (gTriggers[a].TriggerType <> TRIGGER_NONE) and
+       (gTriggers[a].TriggerType <> TRIGGER_NONE) and
        (gTriggers[a].TimeOut = 0) and
        ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
        ByteBool(gTriggers[a].ActivateType and ActivateType) then