DEADSOFTWARE

field namefix: `FLive` -> `FAlive`; `live` -> `alive`
[d2df-sdl.git] / src / game / g_panel.pas
index d104593da3eeb95a875366263c08c5c78b2554f7..0a3f8f7900c6f417115570d89c89a581ecb035e5 100644 (file)
@@ -167,10 +167,15 @@ type
 
   TPanelArray = Array of TPanel;
 
+var
+  g_dbgpan_mplat_active: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}true{$ENDIF};
+  g_dbgpan_mplat_step: Boolean = false; // one step, and stop
+
+
 implementation
 
 uses
-  SysUtils, g_basic, g_map, g_game, g_gfx, e_graphics,
+  SysUtils, g_basic, g_map, g_game, g_gfx, e_graphics, g_weapons,
   g_console, g_language, g_monsters, g_player, e_log, GL;
 
 const
@@ -490,9 +495,13 @@ var
 begin
   if (proxyId >= 0) then
   begin
-    monsGrid.getBodyDims(proxyId, px, py, pw, ph);
+    mapGrid.getBodyDims(proxyId, px, py, pw, ph);
     if (px <> x) or (py <> y) or (pw <> Width) or (ph <> Height) then
     begin
+      {
+      e_LogWritefln('panel moved: arridx=%s; guid=%s; proxyid=%s; old:(%s,%s)-(%sx%s); new:(%s,%s)-(%sx%s)',
+        [arrIdx, mGUID, proxyId, px, py, pw, ph, x, y, width, height]);
+      }
       g_Mark(px, py, pw, ph, MARK_WALL, false);
       if (pw <> Width) or (ph <> Height) then mapGrid.moveResizeBody(proxyId, X, Y, Width, Height)
       else mapGrid.moveBody(proxyId, X, Y);
@@ -509,7 +518,6 @@ var
 procedure TPanel.Update();
 var
   nx, ny: Integer;
-  f: Integer;
 
   function doPush (px, py, pw, ph: Integer; out dx, dy: Integer): Boolean;
   begin
@@ -563,7 +571,8 @@ var
   var
     px, py, pw, ph, dx, dy: Integer;
   begin
-    if (plr = nil) then exit;
+    // dead players leaves separate body entities, so don't move 'em
+    if (plr = nil) or not plr.alive then exit;
     plr.getMapBox(px, py, pw, ph);
     if (py+ph <> Y) then
     begin
@@ -573,6 +582,15 @@ var
         plr.GameX := plr.GameX+dx;
         plr.GameY := plr.GameY+dy;
         plr.positionChanged();
+        // check if we're squashed
+        if plr.alive then
+        begin
+          plr.getMapBox(px, py, pw, ph);
+          if g_Map_CollidePanel(px, py, pw, ph, (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
+          begin
+            plr.Damage(15000, 0, 0, 0, HIT_TRAP);
+          end;
+        end;
       end;
       exit;
     end;
@@ -583,6 +601,10 @@ var
     plr.positionChanged();
   end;
 
+var
+  f: Integer;
+  mon: TMonster;
+  px, py, pw, ph: Integer;
 begin
   if Enabled and (FCurTexture >= 0) and
     (FTextureIDs[FCurTexture].Anim) and
@@ -594,13 +616,17 @@ begin
     FCurFrameCount := FTextureIDs[FCurTexture].AnTex.CurrentCounter;
   end;
 
-  if mMovingActive and (not mMovingSpeed.isZero) then
+  if mMovingActive and (not mMovingSpeed.isZero) and g_dbgpan_mplat_active then
   begin
     monMoveListUsed := 0;
     nx := X+mMovingSpeed.X;
     ny := Y+mMovingSpeed.Y;
     // move monsters on lifts
     g_Mons_ForEachAt(X, Y-1, Width, 1, monMove);
+    X := nx;
+    Y := ny;
+    // fix grid
+    positionChanged();
     // push monsters
     g_Mons_ForEachAt(nx, ny, Width, Height, monPush);
     // move and push players
@@ -610,15 +636,24 @@ begin
     else if (mMovingSpeed.X > 0) and (nx >= mMovingEnd.X) then mMovingSpeed.X := -mMovingSpeed.X;
          if (mMovingSpeed.Y < 0) and (ny <= mMovingStart.Y) then mMovingSpeed.Y := -mMovingSpeed.Y
     else if (mMovingSpeed.Y > 0) and (ny >= mMovingEnd.Y) then mMovingSpeed.Y := -mMovingSpeed.Y;
-    // awake particles
-    //g_Mark(X, Y, Width, Height, MARK_WALL, false);
-    X := nx;
-    Y := ny;
-    //g_Mark(nx, ny, Width, Height, MARK_WALL);
-    // fix grid
-    positionChanged();
     // notify moved monsters about their movement
-    for f := 0 to monMoveListUsed-1 do monMoveList[f].positionChanged();
+    for f := 0 to monMoveListUsed-1 do
+    begin
+      monMoveList[f].positionChanged();
+    end;
+    for f := 0 to monMoveListUsed-1 do
+    begin
+      mon := monMoveList[f];
+      // check if it is squashed
+      if mon.alive then
+      begin
+        mon.getMapBox(px, py, pw, ph);
+        if g_Map_CollidePanel(px, py, pw, ph, (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) then
+        begin
+          mon.Damage(15000, 0, 0, 0, HIT_TRAP);
+        end;
+      end;
+    end;
   end;
 end;