DEADSOFTWARE

Refactor: Define constants for LiftType
[d2df-sdl.git] / src / game / g_panel.pas
index f5a6bddcc70c0b38640f1e1153679eb815ca3519..bcf0883385f89309450a420e89616af331eadbc7 100644 (file)
@@ -1,4 +1,4 @@
-(* Copyright (C)  DooM 2D:Forever Developers
+(* Copyright (C)  Doom 2D: Forever Developers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@ type
       Anim: Boolean;
     end;
 
+  PPanel = ^TPanel;
   TPanel = Class (TObject)
   private
     const
@@ -109,6 +110,7 @@ type
     tag:              Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
     proxyId:          Integer; // proxy id in map grid (DO NOT USE!)
     mapId:            AnsiString; // taken directly from map file; dunno why it is here
+    hasTexTrigger:    Boolean; // HACK: true when there's a trigger than can change my texture
 
     constructor Create(PanelRec: TDynRecord;
                        AddTextures: TAddTextureArray;
@@ -124,6 +126,7 @@ type
     procedure   SetTexture(ID: Integer; AnimLoop: Byte = 0);
     function    GetTextureID(): Cardinal;
     function    GetTextureCount(): Integer;
+    function    CanChangeTexture(): Boolean;
 
     procedure   SaveState (st: TStream);
     procedure   LoadState (st: TStream);
@@ -201,6 +204,12 @@ type
 
   TPanelArray = Array of TPanel;
 
+const
+  LIFTTYPE_UP = 0;
+  LIFTTYPE_DOWN = 1;
+  LIFTTYPE_LEFT = 2;
+  LIFTTYPE_RIGHT = 3;
+
 var
   g_dbgpan_mplat_active: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}true{$ENDIF};
   g_dbgpan_mplat_step: Boolean = false; // one step, and stop
@@ -209,8 +218,9 @@ var
 implementation
 
 uses
+  {$INCLUDE ../nogl/noGLuses.inc}
   e_texture, g_basic, g_map, g_game, g_gfx, e_graphics, g_weapons, g_triggers,
-  g_console, g_language, g_monsters, g_player, g_grid, e_log, GL, geom, utils, xstreams;
+  g_console, g_language, g_monsters, g_player, g_grid, e_log, geom, utils, xstreams;
 
 const
   PANEL_SIGNATURE = $4C4E4150; // 'PANL'
@@ -223,6 +233,7 @@ constructor TPanel.Create(PanelRec: TDynRecord;
                           var Textures: TLevelTextureArray; aguid: Integer);
 var
   i: Integer;
+  tnum: Integer;
 begin
   X := PanelRec.X;
   Y := PanelRec.Y;
@@ -256,15 +267,16 @@ begin
   PanelType := PanelRec.PanelType;
   Enabled := True;
   Door := False;
-  LiftType := 0;
+  LiftType := LIFTTYPE_UP;
+  hasTexTrigger := False;
 
   case PanelType of
     PANEL_OPENDOOR: begin Enabled := False; Door := True; end;
     PANEL_CLOSEDOOR: Door := True;
-    PANEL_LIFTUP: LiftType := 0; //???
-    PANEL_LIFTDOWN: LiftType := 1;
-    PANEL_LIFTLEFT: LiftType := 2;
-    PANEL_LIFTRIGHT: LiftType := 3;
+    PANEL_LIFTUP: LiftType := LIFTTYPE_UP; //???
+    PANEL_LIFTDOWN: LiftType := LIFTTYPE_DOWN;
+    PANEL_LIFTLEFT: LiftType := LIFTTYPE_LEFT;
+    PANEL_LIFTRIGHT: LiftType := LIFTTYPE_RIGHT;
   end;
 
 // Íåâèäèìàÿ:
@@ -337,19 +349,22 @@ begin
 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
   //if Length(FTextureIDs) > 1 then SaveIt := True;
 
+  if (PanelRec.TextureRec = nil) then tnum := -1 else tnum := PanelRec.tagInt;
+  if (tnum < 0) then tnum := Length(Textures);
+
 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
-  if PanelRec.TextureNum > High(Textures) then
+  if ({PanelRec.TextureNum}tnum > High(Textures)) then
   begin
-    e_WriteLog(Format('WTF?! PanelRec.TextureNum is out of limits! (%d : %d)', [PanelRec.TextureNum, High(Textures)]), TMsgType.Fatal);
+    e_WriteLog(Format('WTF?! tnum is out of limits! (%d : %d)', [tnum, High(Textures)]), TMsgType.Warning);
     FTextureWidth := 2;
     FTextureHeight := 2;
     FAlpha := 0;
     FBlending := ByteBool(0);
   end
-  else if not g_Map_IsSpecialTexture(Textures[PanelRec.TextureNum].TextureName) then
+  else if not g_Map_IsSpecialTexture(Textures[{PanelRec.TextureNum}tnum].TextureName) then
   begin
-    FTextureWidth := Textures[PanelRec.TextureNum].Width;
-    FTextureHeight := Textures[PanelRec.TextureNum].Height;
+    FTextureWidth := Textures[{PanelRec.TextureNum}tnum].Width;
+    FTextureHeight := Textures[{PanelRec.TextureNum}tnum].Height;
     FAlpha := PanelRec.Alpha;
     FBlending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING);
   end;
@@ -581,7 +596,7 @@ var
     begin
       if (ontop <> nil) then ontop^ := true;
       // yes, move with it; but skip steps (no need to process size change here, 'cause platform top cannot be changed with it)
-      mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, (GridTagWall or GridTagDoor));
+      mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, (GridTagWall or GridTagDoor));
     end
     else
     begin
@@ -609,7 +624,7 @@ var
             trtag := (GridTagWall or GridTagDoor);
             // if we're moving down, consider steps too
             if (szdy > 0) then trtag := trtag or GridTagStep;
-            mapGrid.traceBox(tex, tey, px, py, pw, ph, szdx, szdy, nil, trtag);
+            mapGrid.traceBox(tex, tey, px, py, pw, ph, szdx, szdy, trtag);
           end;
         end;
       end;
@@ -628,7 +643,7 @@ var
           trtag := (GridTagWall or GridTagDoor);
           // if we're moving down, consider steps too
           if (pdy > 0) then trtag := trtag or GridTagStep;
-          mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, trtag);
+          mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, trtag);
         end;
       end;
     end;
@@ -893,7 +908,7 @@ begin
     (FTextureIDs[FCurTexture].AnTex <> nil) and
     (Width > 0) and (Height > 0) and (FAlpha < 255) then
   begin
-    FCurFrame := ClampInt(Frame, 0, FTextureIDs[FCurTexture].AnTex.TotalFrames);
+    FCurFrame := ClampInt(Frame, 0, FTextureIDs[FCurTexture].AnTex.TotalFrames - 1);
     FCurFrameCount := Count;
     FTextureIDs[FCurTexture].AnTex.CurrentFrame := FCurFrame;
     FTextureIDs[FCurTexture].AnTex.CurrentCounter := FCurFrameCount;
@@ -949,22 +964,8 @@ end;
 
 procedure TPanel.SetTexture(ID: Integer; AnimLoop: Byte = 0);
 begin
-// Íåò òåêñòóð:
-  if Length(FTextureIDs) = 0 then
-    FCurTexture := -1
-  else
-  // Òîëüêî îäíà òåêñòóðà:
-    if Length(FTextureIDs) = 1 then
-      begin
-        if (ID = 0) or (ID = -1) then
-          FCurTexture := ID;
-      end
-    else
-    // Áîëüøå îäíîé òåêñòóðû:
-      begin
-        if (ID >= -1) and (ID <= High(FTextureIDs)) then
-          FCurTexture := ID;
-      end;
+  if (ID >= -1) and (ID < Length(FTextureIDs)) then
+    FCurTexture := ID;
 
 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
   if (FCurTexture >= 0) and FTextureIDs[FCurTexture].Anim then
@@ -1010,6 +1011,10 @@ begin
        Result := Result + 100;
 end;
 
+function TPanel.CanChangeTexture(): Boolean;
+begin
+  Result := (GetTextureCount() > 1) or hasTexTrigger;
+end;
 
 const
   PAN_SAVE_VERSION = 1;