DEADSOFTWARE

moved debug inspector to g_holmes.pas
[d2df-sdl.git] / src / game / g_player.pas
index f277a4e8ab74fa5ce9992b49c8af0b215c4e5e27..e72a75689012b6f2e44462e0cfd5e327f0fa2c55 100644 (file)
@@ -21,7 +21,7 @@ interface
 uses
   e_graphics, g_playermodel, g_basic, g_textures,
   g_weapons, g_phys, g_sound, g_saveload, MAPSTRUCT,
-  BinEditor, g_panel, z_aabbtree;
+  BinEditor, g_panel;
 
 const
   KEY_LEFT       = 1;
@@ -222,8 +222,6 @@ type
     procedure resetWeaponQueue ();
     function hasAmmoForWeapon (weapon: Byte): Boolean;
 
-    function getMapAABB (): AABB2D;
-
   public
     FDamageBuffer:   Integer;
 
@@ -251,6 +249,11 @@ type
     FDummy:     Boolean;
     FFireTime:  Integer;
 
+    // debug: viewport offset
+    viewPortX, viewPortY, viewPortW, viewPortH: Integer;
+
+    function isValidViewPort (): Boolean; inline;
+
     constructor Create(); virtual;
     destructor  Destroy(); override;
     procedure   Respawn(Silent: Boolean; Force: Boolean = False); virtual;
@@ -316,6 +319,8 @@ type
     //WARNING! this does nothing for now, but still call it!
     procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
 
+    procedure getMapBox (out x, y, w, h: Integer); inline;
+
     property    Name: String read FName write FName;
     property    Model: TPlayerModel read FModel;
     property    Health: Integer read FHealth write FHealth;
@@ -348,8 +353,6 @@ type
     property    UID: Word read FUID write FUID;
     property    JustTeleported: Boolean read FJustTeleported write FJustTeleported;
     property    NetTime: LongWord read FNetTime write FNetTime;
-
-    property mapAABB: AABB2D read getMapAABB;
   end;
 
   TDifficult = record
@@ -521,8 +524,9 @@ implementation
 
 uses
   e_log, g_map, g_items, g_console, SysUtils, g_gfx, Math,
-  g_options, g_triggers, g_menu, MAPDEF, g_game,
-  wadreader, g_main, g_monsters, CONFIG, g_language, g_net, g_netmsg;
+  g_options, g_triggers, g_menu, MAPDEF, g_game, g_grid,
+  wadreader, g_main, g_monsters, CONFIG, g_language,
+  g_net, g_netmsg, g_window, GL, g_holmes;
 
 type
   TBotProfile = record
@@ -1846,6 +1850,8 @@ end;
 
 { T P l a y e r : }
 
+function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
+
 procedure TPlayer.BFGHit();
 begin
   g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
@@ -1989,6 +1995,11 @@ end;
 
 constructor TPlayer.Create();
 begin
+  viewPortX := 0;
+  viewPortY := 0;
+  viewPortW := 0;
+  viewPortH := 0;
+
   FIamBot := False;
   FDummy := False;
   FSpawned := False;
@@ -2304,7 +2315,53 @@ begin
     DrawAim();
 end;
 
+
 procedure TPlayer.DrawAim();
+  procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
+
+    procedure drawTileGrid ();
+    var
+      x, y: Integer;
+    begin
+      y := mapGrid.gridY0;
+      while (y < mapGrid.gridY0+mapGrid.gridHeight) do
+      begin
+        x := mapGrid.gridX0;
+        while (x < mapGrid.gridX0+mapGrid.gridWidth) do
+        begin
+          if (x+mapGrid.tileSize > viewPortX) and (y+mapGrid.tileSize > viewPortY) and
+             (x < viewPortX+viewPortW) and (y < viewPortY+viewPortH) then
+          begin
+            e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
+          end;
+          Inc(x, mapGrid.tileSize);
+        end;
+        Inc(y, mapGrid.tileSize);
+      end;
+    end;
+
+  var
+    ex, ey: Integer;
+  begin
+    if isValidViewPort and (self = gPlayer1) then
+    begin
+      g_Holmes_plrView(viewPortX, viewPortY, viewPortW, viewPortH);
+      g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
+    end;
+
+    e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
+    if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
+    begin
+      e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
+    end
+    else
+    begin
+      e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
+    end;
+
+    drawTileGrid();
+  end;
+
 var
   wx, wy, xx, yy: Integer;
   angle: SmallInt;
@@ -2391,7 +2448,11 @@ begin
   end;
   xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
   yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
+  {$IF DEFINED(D2F_DEBUG)}
+  drawCast(sz, wx, wy, xx, yy);
+  {$ELSE}
   e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
+  {$ENDIF}
 end;
 
 procedure TPlayer.DrawGUI();
@@ -4817,7 +4878,7 @@ begin
   DecMin(FPain, 5, 0);
   DecMin(FPickup, 1, 0);
 
-  if FLive and (FObj.Y > gMapInfo.Height+128) and AnyServer then
+  if FLive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
   begin
     // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
     FMegaRulez[MR_SUIT] := 0;
@@ -5002,9 +5063,12 @@ begin
     if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
 end;
 
-function TPlayer.getMapAABB (): AABB2D; inline;
+procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
 begin
-  result := AABB2D.CreateWH(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
+  x := FObj.X+PLAYER_RECT.X;
+  y := FObj.Y+PLAYER_RECT.Y;
+  w := PLAYER_RECT.Width;
+  h := PLAYER_RECT.Height;
 end;
 
 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;