DEADSOFTWARE

slightly better `traceBox()`
[d2df-sdl.git] / src / game / g_triggers.pas
index 437d1f6462c98f8c1c9973dfd3c099c5a4d906cf..97648af9e91d01cbbf3bdec3123aa363864d80fc 100644 (file)
@@ -89,20 +89,6 @@ procedure g_Triggers_Free();
 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
 
-function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
-
-{
-function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
-function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
-procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
-function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
-
-function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
-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): Integer;
-}
 
 var
   gTriggerClientID: Integer = 0;
@@ -110,6 +96,7 @@ var
   gSecretsCount: Integer = 0;
   gMonstersSpawned: array of LongInt = nil;
 
+
 implementation
 
 uses
@@ -251,6 +238,16 @@ var
 
 begin
   pan := g_Map_PanelByGUID(PanelGUID);
+  {
+  if (pan = nil) then
+  begin
+    e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
+  end
+  else
+  begin
+    e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
+  end;
+  }
   if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
   PanelID := pan.arrIdx;
 
@@ -276,7 +273,7 @@ begin
       begin
         for a := 0 to High(gPlayers) do
         begin
-          if (gPlayers[a] <> nil) and gPlayers[a].Live and gPlayers[a].Collide(X, Y, Width, Height) then
+          if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
           begin
             gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
           end;
@@ -337,7 +334,7 @@ begin
         begin
           for a := 0 to High(gPlayers) do
           begin
-            if (gPlayers[a] <> nil) and gPlayers[a].Live and gPlayers[a].Collide(X, Y, Width, Height) then
+            if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
             begin
               gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
             end;
@@ -349,7 +346,7 @@ begin
         (*
         if gMonsters <> nil then
           for a := 0 to High(gMonsters) do
-            if (gMonsters[a] <> nil) and gMonsters[a].Live and
+            if (gMonsters[a] <> nil) and gMonsters[a].alive and
             g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
               gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
         *)
@@ -1036,7 +1033,7 @@ var
   function monsShotTarget (mon: TMonster): Boolean;
   begin
     result := false; // don't stop
-    if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+    if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
     begin
       xd := mon.GameX + mon.Obj.Rect.Width div 2;
       yd := mon.GameY + mon.Obj.Rect.Height div 2;
@@ -1048,7 +1045,7 @@ var
   function monsShotTargetMonPlr (mon: TMonster): Boolean;
   begin
     result := false; // don't stop
-    if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+    if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
     begin
       xd := mon.GameX + mon.Obj.Rect.Width div 2;
       yd := mon.GameY + mon.Obj.Rect.Height div 2;
@@ -1060,7 +1057,7 @@ var
   function monShotTargetPlrMon (mon: TMonster): Boolean;
   begin
     result := false; // don't stop
-    if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+    if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
     begin
       xd := mon.GameX + mon.Obj.Rect.Width div 2;
       yd := mon.GameY + mon.Obj.Rect.Height div 2;
@@ -1973,7 +1970,7 @@ begin
             TRIGGER_SHOT_TARGET_PLR: // players
               if gPlayers <> nil then
                 for idx := Low(gPlayers) to High(gPlayers) do
-                  if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
+                  if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
                      tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
                   begin
                     xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
@@ -1985,7 +1982,7 @@ begin
             TRIGGER_SHOT_TARGET_RED: // red team
               if gPlayers <> nil then
                 for idx := Low(gPlayers) to High(gPlayers) do
-                  if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
+                  if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
                      (gPlayers[idx].Team = TEAM_RED) and
                      tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
                   begin
@@ -1998,7 +1995,7 @@ begin
             TRIGGER_SHOT_TARGET_BLUE: // blue team
               if gPlayers <> nil then
                 for idx := Low(gPlayers) to High(gPlayers) do
-                  if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
+                  if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
                      (gPlayers[idx].Team = TEAM_BLUE) and
                      tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
                   begin
@@ -2015,7 +2012,7 @@ begin
 
               if (TargetUID = 0) and (gPlayers <> nil) then
                 for idx := Low(gPlayers) to High(gPlayers) do
-                  if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
+                  if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
                      tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
                   begin
                     xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
@@ -2029,7 +2026,7 @@ begin
             begin
               if gPlayers <> nil then
                 for idx := Low(gPlayers) to High(gPlayers) do
-                  if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
+                  if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
                      tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
                   begin
                     xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
@@ -2131,7 +2128,7 @@ begin
   Trigger.mapIndex := mapidx;
   if (Trigger.trigData.trigRec <> nil) then
   begin
-    Trigger.trigData := Trigger.trigData.trigRec.clone();
+    Trigger.trigData := Trigger.trigData.trigRec.clone({Trigger.trigData.headerRec}nil);
   end
   else
   begin
@@ -2468,9 +2465,17 @@ begin
             end;
           end;
 
+          //HACK!
           // if we have panelid, assume that it will switch the moving platform
-          if (trigPanelGUID >= 0) then
+          pan := g_Map_PanelByGUID(trigPanelGUID);
+          if (pan <> nil) then
           begin
+            case TriggerType of
+              TRIGGER_PRESS: pan.movingActive := true; // what to do here?
+              TRIGGER_ON: pan.movingActive := true;
+              TRIGGER_OFF: pan.movingActive := false;
+              TRIGGER_ONOFF: pan.movingActive := not pan.movingActive;
+            end;
           end;
 
           // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
@@ -2546,7 +2551,7 @@ begin
               if gPlayers[b] <> nil then
                 with gPlayers[b] do
                 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
-                  if Live and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
+                  if alive and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
                      Collide(X, Y, Width, Height) then
                   begin
                     gTriggers[a].ActivateUID := UID;
@@ -2603,6 +2608,7 @@ end;
 
 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
 begin
+  if (ID >= Length(gTriggers)) then exit;
   gTriggers[ID].ActivateUID := ActivateUID;
   ActivateTrigger(gTriggers[ID], ActivateType);
 end;