DEADSOFTWARE

gibs and corpses now affected by mplats
[d2df-sdl.git] / src / game / g_panel.pas
index 041a142b3865f54926ca6b81ba14877e1b249f06..bcd1c4c1d4040d2dc820e8c2747a663dd237b82b 100644 (file)
@@ -167,6 +167,11 @@ 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
@@ -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);
@@ -562,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,7 +583,7 @@ var
         plr.GameY := plr.GameY+dy;
         plr.positionChanged();
         // check if we're squashed
-        if plr.live then
+        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
@@ -591,6 +601,55 @@ var
     plr.positionChanged();
   end;
 
+  procedure gibMove (gib: PGib);
+  var
+    px, py, pw, ph, dx, dy: Integer;
+  begin
+    if (gib = nil) or not gib.alive then exit;
+    gib.getMapBox(px, py, pw, ph);
+    {
+    writeln('gib: p=(', px, ',', py, '); obj=(', gib.Obj.X, ',', gib.Obj.Y, ')');
+    px := gib.Obj.X;
+    py := gib.Obj.Y;
+    }
+    if (py+ph <> Y) then
+    begin
+      // push gib
+      if doPush(px, py, pw, ph, dx, dy) then
+      begin
+        gib.Obj.X += dx;
+        gib.Obj.Y += dy;
+        gib.positionChanged();
+      end;
+      exit;
+    end;
+    if (px+pw <= X) then exit;
+    if (px >= X+Width) then exit;
+    gib.Obj.X += mMovingSpeed.X;
+    gib.Obj.Y += mMovingSpeed.Y;
+    gib.positionChanged();
+  end;
+
+  procedure corpseMove (cor: TCorpse);
+  var
+    px, py, pw, ph, dx, dy: Integer;
+  begin
+    if (cor = nil) then exit;
+    cor.getMapBox(px, py, pw, ph);
+    if (py+ph <> Y) then
+    begin
+      // push gib
+      if doPush(px, py, pw, ph, dx, dy) then
+      begin
+        cor.moveBy(dx, dy); // will call `positionChanged()` for us
+      end;
+      exit;
+    end;
+    if (px+pw <= X) then exit;
+    if (px >= X+Width) then exit;
+    cor.moveBy(mMovingSpeed.X, mMovingSpeed.Y); // will call `positionChanged()` for us
+  end;
+
 var
   f: Integer;
   mon: TMonster;
@@ -606,7 +665,7 @@ 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;
@@ -621,6 +680,10 @@ begin
     g_Mons_ForEachAt(nx, ny, Width, Height, monPush);
     // move and push players
     for f := 0 to High(gPlayers) do plrMove(gPlayers[f]);
+    // move and push gibs
+    for f := 0 to High(gGibs) do gibMove(@gGibs[f]);
+    // move and push corpses
+    for f := 0 to High(gCorpses) do corpseMove(gCorpses[f]);
     // reverse moving direction, if necessary
          if (mMovingSpeed.X < 0) and (nx <= mMovingStart.X) then mMovingSpeed.X := -mMovingSpeed.X
     else if (mMovingSpeed.X > 0) and (nx >= mMovingEnd.X) then mMovingSpeed.X := -mMovingSpeed.X;
@@ -635,7 +698,7 @@ begin
     begin
       mon := monMoveList[f];
       // check if it is squashed
-      if mon.live then
+      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