DEADSOFTWARE

some new code for moving platforms: only for players yet
[d2df-sdl.git] / src / game / g_holmes.pas
index 23c4b13d16ee07817d48508006086f0d16661c82..1f548e4c2058b560b06054513333e175df7ee7bc 100644 (file)
@@ -21,7 +21,7 @@ interface
 uses
   e_log, e_input,
   g_textures, g_basic, e_graphics, g_phys, g_grid, g_player, g_monsters,
-  g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console,
+  g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console, g_gfx,
   xprofiler;
 
 
@@ -96,6 +96,7 @@ operator = (const s: AnsiString; constref ev: THMouseEvent): Boolean;
 
 var
   g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
+  g_holmes_ui_scale: Single = 1.0;
 
 
 implementation
@@ -113,14 +114,15 @@ var
   msY: Integer = -666;
   msB: Word = 0; // button state
   kbS: Word = 0; // keyboard modifiers state
-  showGrid: Boolean = true;
+  showGrid: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
   showMonsInfo: Boolean = false;
   showMonsLOS2Plr: Boolean = false;
   showAllMonsCells: Boolean = false;
   showMapCurPos: Boolean = false;
   showLayersWindow: Boolean = false;
   showOutlineWindow: Boolean = false;
-  showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
+  showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
+
 
 // ////////////////////////////////////////////////////////////////////////// //
 {$INCLUDE g_holmes.inc}
@@ -650,6 +652,7 @@ var
   laserSet: Boolean = false;
   laserX0, laserY0, laserX1, laserY1: Integer;
   monMarkedUID: Integer = -1;
+  platMarkedGUID: Integer = -1;
 
 
 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
@@ -905,6 +908,22 @@ procedure plrDebugDraw ();
     end;
   end;
 
+  procedure drawAwakeCells ();
+  var
+    x, y: Integer;
+  begin
+    for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
+    begin
+      for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
+      begin
+        if awmIsSetHolmes(x*mapGrid.tileSize+mapGrid.gridX0+1, y*mapGrid.tileSize++mapGrid.gridY0+1) then
+        begin
+          fillRect(x*mapGrid.tileSize++mapGrid.gridX0, y*mapGrid.tileSize++mapGrid.gridY0, monsGrid.tileSize, monsGrid.tileSize, 128, 0, 128, 64);
+        end;
+      end;
+    end;
+  end;
+
   procedure hilightCell (cx, cy: Integer);
   begin
     fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
@@ -1039,14 +1058,25 @@ procedure plrDebugDraw ();
     monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
   end;
 
+  procedure drawSelectedPlatformCells ();
+  var
+    pan: TPanel;
+  begin
+    if not showGrid then exit;
+    pan := g_Map_PanelByGUID(platMarkedGUID);
+    if (pan = nil) then exit;
+    mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
+    drawRect(pan.x, pan.y, pan.width, pan.height, 0, 200, 0, 200);
+  end;
+
   procedure drawTrigger (var trig: TTrigger);
 
-    procedure drawPanelDest (var parr: TPanelArray; idx: Integer);
+    procedure drawPanelDest (pguid: Integer);
     var
       pan: TPanel;
     begin
-      if (idx < 0) or (idx >= Length(parr)) then exit;
-      pan := parr[idx];
+      pan := g_Map_PanelByGUID(pguid);
+      if (pan = nil) then exit;
       drawLine(
         trig.trigCenter.x, trig.trigCenter.y,
         pan.x+pan.width div 2, pan.y+pan.height div 2,
@@ -1065,32 +1095,36 @@ procedure plrDebugDraw ();
     tx := trig.x+(trig.width-Length(trig.mapId)*6) div 2;
     darkenRect(tx-2, trig.y-20, Length(trig.mapId)*6+4, 10, 64);
     drawText6(tx, trig.y-19, trig.mapId, 255, 255, 0);
+    drawPanelDest(trig.trigPanelGUID);
     case trig.TriggerType of
       TRIGGER_NONE: begin end;
       TRIGGER_EXIT: begin end;
       TRIGGER_TELEPORT: begin end;
-      TRIGGER_OPENDOOR: begin drawPanelDest(gWalls, trig.trigPanelId); end;
-      TRIGGER_CLOSEDOOR: begin drawPanelDest(gWalls, trig.trigPanelId); end;
-      TRIGGER_DOOR: begin drawPanelDest(gWalls, trig.trigPanelId); end;
-      TRIGGER_DOOR5: begin drawPanelDest(gWalls, trig.trigPanelId); end;
-      TRIGGER_CLOSETRAP: begin drawPanelDest(gWalls, trig.trigPanelId); end;
-      TRIGGER_TRAP: begin drawPanelDest(gWalls, trig.trigPanelId); end;
+      TRIGGER_OPENDOOR: begin end;
+      TRIGGER_CLOSEDOOR: begin end;
+      TRIGGER_DOOR: begin end;
+      TRIGGER_DOOR5: begin end;
+      TRIGGER_CLOSETRAP: begin end;
+      TRIGGER_TRAP: begin end;
       TRIGGER_SECRET: begin end;
-      TRIGGER_LIFTUP: begin drawPanelDest(gLifts, trig.trigPanelId); end;
-      TRIGGER_LIFTDOWN: begin drawPanelDest(gLifts, trig.trigPanelId); end;
-      TRIGGER_LIFT: begin drawPanelDest(gLifts, trig.trigPanelId); end;
+      TRIGGER_LIFTUP: begin end;
+      TRIGGER_LIFTDOWN: begin end;
+      TRIGGER_LIFT: begin end;
       TRIGGER_TEXTURE: begin end;
       TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF, TRIGGER_PRESS:
         begin
-        fillRect(
-          trig.trigData.trigTX, trig.trigData.trigTY,
-          trig.trigData.trigTWidth, trig.trigData.trigTHeight,
-          0, 255, 255, 42);
-        drawLine(
-          trig.trigCenter.x, trig.trigCenter.y,
-          trig.trigData.trigTX+trig.trigData.trigTWidth div 2,
-          trig.trigData.trigTY+trig.trigData.trigTHeight div 2,
-          255, 0, 255, 220);
+          if (trig.trigData.trigTWidth > 0) and (trig.trigData.trigTHeight > 0) then
+          begin
+            fillRect(
+              trig.trigData.trigTX, trig.trigData.trigTY,
+              trig.trigData.trigTWidth, trig.trigData.trigTHeight,
+              0, 255, 255, 42);
+            drawLine(
+              trig.trigCenter.x, trig.trigCenter.y,
+              trig.trigData.trigTX+trig.trigData.trigTWidth div 2,
+              trig.trigData.trigTY+trig.trigData.trigTHeight div 2,
+              255, 0, 255, 220);
+          end;
         end;
       TRIGGER_SOUND: begin end;
       TRIGGER_SPAWNMONSTER: begin end;
@@ -1116,6 +1150,23 @@ procedure plrDebugDraw ();
     for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
   end;
 
+  procedure drawGibsBoxes ();
+  var
+    f: Integer;
+    px, py, pw, ph: Integer;
+    gib: PGib;
+  begin
+    for f := 0 to High(gGibs) do
+    begin
+      gib := @gGibs[f];
+      if gib.alive then
+      begin
+        gib.getMapBox(px, py, pw, ph);
+        drawRect(px, py, pw, ph, 255, 0, 255);
+      end;
+    end;
+  end;
+
 var
   mon: TMonster;
   mx, my, mw, mh: Integer;
@@ -1145,8 +1196,13 @@ begin
     end;
   end;
 
-  if showAllMonsCells then g_Mons_ForEach(highlightAllMonsterCells);
+  if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells);
   if showTriggers then drawTriggers();
+  if showGrid then drawSelectedPlatformCells();
+
+  drawAwakeCells();
+
+  //drawGibsBoxes();
 
   glPopMatrix();
 
@@ -1158,16 +1214,21 @@ end;
 
 // ////////////////////////////////////////////////////////////////////////// //
 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean;
+var
+  he: THMouseEvent;
 begin
   holmesInitCommands();
   holmesInitBinds();
   result := true;
-  msX := ev.x;
-  msY := ev.y;
+  msX := trunc(ev.x/g_holmes_ui_scale);
+  msY := trunc(ev.y/g_holmes_ui_scale);
   msB := ev.bstate;
   kbS := ev.kstate;
   msB := msB;
-  if not uiMouseEvent(ev) then plrDebugMouse(ev);
+  he := ev;
+  he.x := trunc(he.x/g_holmes_ui_scale);
+  he.y := trunc(he.y/g_holmes_ui_scale);
+  if not uiMouseEvent(he) then plrDebugMouse(he);
 end;
 
 
@@ -1258,14 +1319,20 @@ end;
 procedure g_Holmes_DrawUI ();
 begin
   {$IF not DEFINED(HEADLESS)}
+  glPushMatrix();
+  glScalef(g_holmes_ui_scale, g_holmes_ui_scale, 1.0);
   uiDraw();
   drawCursor();
+  glPopMatrix();
   {$ENDIF}
 end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
 procedure bcOneMonsterThinkStep (); begin gmon_debug_think := false; gmon_debug_one_think_step := true; end;
+procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active := false; g_dbgpan_mplat_step := true; end;
+procedure bcMPlatToggle (); begin g_dbgpan_mplat_active := not g_dbgpan_mplat_active; end;
+
 procedure bcToggleMonsterInfo (arg: Integer=-1); begin if (arg < 0) then showMonsInfo := not showMonsInfo else showMonsInfo := (arg > 0); end;
 procedure bcToggleMonsterLOSPlr (arg: Integer=-1); begin if (arg < 0) then showMonsLOS2Plr := not showMonsLOS2Plr else showMonsLOS2Plr := (arg > 0); end;
 procedure bcToggleMonsterCells (arg: Integer=-1); begin if (arg < 0) then showAllMonsCells := not showAllMonsCells else showAllMonsCells := (arg > 0); end;
@@ -1274,6 +1341,20 @@ procedure bcToggleDrawTriggers (arg: Integer=-1); begin if (arg < 0) then showTr
 procedure bcToggleCurPos (arg: Integer=-1); begin if (arg < 0) then showMapCurPos := not showMapCurPos else showMapCurPos := (arg > 0); end;
 procedure bcToggleGrid (arg: Integer=-1); begin if (arg < 0) then showGrid := not showGrid else showGrid := (arg > 0); end;
 
+procedure bcMonsterSpawn (s: AnsiString);
+var
+  mon: TMonster;
+begin
+  if not gGameOn or g_Game_IsClient then
+  begin
+    conwriteln('cannot spawn monster in this mode');
+    exit;
+  end;
+  mon := g_Mons_SpawnAt(s, pmsCurMapX, pmsCurMapY);
+  if (mon = nil) then begin conwritefln('unknown monster id: ''%s''', [s]); exit; end;
+  monMarkedUID := mon.UID;
+end;
+
 procedure bcMonsterWakeup ();
 var
   mon: TMonster;
@@ -1343,6 +1424,7 @@ procedure cbAtcurDumpWalls ();
   function wallToggle (pan: TPanel; tag: Integer): Boolean;
   begin
     result := false; // don't stop
+    if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
     e_LogWritefln('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]);
     dumpPublishedProperties(pan);
   end;
@@ -1351,6 +1433,7 @@ var
   f: Integer;
   trig: PTrigger;
 begin
+  platMarkedGUID := -1;
   e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
   mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
   e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
@@ -1374,7 +1457,7 @@ procedure cbAtcurToggleWalls ();
   begin
     result := false; // don't stop
     //e_WriteLog(Format('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]), MSG_NOTIFY);
-    if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
+    if pan.Enabled then g_Map_DisableWallGUID(pan.guid) else g_Map_EnableWallGUID(pan.guid);
   end;
 begin
   //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
@@ -1398,6 +1481,11 @@ begin
   cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
   cmdAdd('mon_wakeup', bcMonsterWakeup, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
 
+  cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
+
+  cmdAdd('mplat_step', bcOneMPlatThinkStep, 'one mplat think step', 'mplat control');
+  cmdAdd('mplat_toggle', bcMPlatToggle, 'activate/deactivate moving platforms', 'mplat control');
+
   cmdAdd('plr_teleport', bcPlayerTeleport, 'teleport player', 'player control');
 
   cmdAdd('dbg_curpos', bcToggleCurPos, 'toggle "show cursor position on the map"', 'various');
@@ -1434,12 +1522,17 @@ begin
     keybindAdd('M-G', 'mon_cells');
     keybindAdd('M-A', 'mon_wakeup');
 
+    keybindAdd('M-P', 'mplat_step');
+    keybindAdd('M-O', 'mplat_toggle');
+
     keybindAdd('C-T', 'plr_teleport');
 
     keybindAdd('C-P', 'dbg_curpos');
     keybindAdd('C-G', 'dbg_grid');
     keybindAdd('C-X', 'dbg_triggers');
 
+    keybindAdd('C-1', 'mon_spawn zombie');
+
     // mouse
     msbindAdd('LMB', 'atcur_select_monster');
     msbindAdd('M-LMB', 'atcur_dump_monsters');
@@ -1486,4 +1579,6 @@ begin
 end;
 
 
+begin
+  conRegVar('hlm_ui_scale', @g_holmes_ui_scale, 0.01, 5.0, 'Holmes UI scale', '', false);
 end.