DEADSOFTWARE

game should write stack trace on exceptions now
[d2df-sdl.git] / src / game / g_player.pas
index 69cc9021fc74547423ced6a82f1c626c4155cb93..04719fccc88dca671b0e98a9838a388f55d7170f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *)
 {$INCLUDE ../shared/a_modes.inc}
+{$M+}
 unit g_player;
 
 interface
 
 uses
   e_graphics, g_playermodel, g_basic, g_textures,
-  g_weapons, g_phys, g_sound, g_saveload, MAPSTRUCT,
+  g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
   BinEditor, g_panel;
 
 const
@@ -321,6 +322,11 @@ type
 
     procedure getMapBox (out x, y, w, h: Integer); inline;
 
+  public
+    property    Vel: TPoint2i read FObj.Vel;
+    property    Obj: TObj read FObj;
+
+  published
     property    Name: String read FName write FName;
     property    Model: TPlayerModel read FModel;
     property    Health: Integer read FHealth write FHealth;
@@ -347,8 +353,6 @@ type
     property    GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
     property    GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
     property    GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
-    property    Vel: TPoint2i read FObj.Vel;
-    property    Obj: TObj read FObj;
     property    IncCam: Integer read FIncCam write FIncCam;
     property    UID: Word read FUID write FUID;
     property    JustTeleported: Boolean read FJustTeleported write FJustTeleported;
@@ -524,9 +528,9 @@ implementation
 
 uses
   e_log, g_map, g_items, g_console, SysUtils, g_gfx, Math,
-  g_options, g_triggers, g_menu, MAPDEF, g_game, g_grid,
+  g_options, g_triggers, g_menu, g_game, g_grid,
   wadreader, g_main, g_monsters, CONFIG, g_language,
-  g_net, g_netmsg, g_window, GL;
+  g_net, g_netmsg, g_window, GL, g_holmes;
 
 type
   TBotProfile = record
@@ -563,7 +567,7 @@ const
   ANGLE_LEFTUP    = 125;
   ANGLE_LEFTDOWN  = -145;
   PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
-  WEAPONPOINT: Array [TDirection] of TPoint = ((X:16; Y:32), (X:47; Y:32));
+  WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
   BOT_MAXJUMP = 84;
   BOT_LONGDIST   = 300;
   BOT_UNSAFEDIST = 128;
@@ -1711,7 +1715,7 @@ end;
 procedure g_Player_DrawCorpses();
 var
   i: Integer;
-  a: TPoint;
+  a: TDFPoint;
 begin
   if gGibs <> nil then
     for i := 0 to High(gGibs) do
@@ -1742,7 +1746,7 @@ end;
 procedure g_Player_DrawShells();
 var
   i: Integer;
-  a: TPoint;
+  a: TDFPoint;
 begin
   if gShells <> nil then
     for i := 0 to High(gShells) do
@@ -2271,10 +2275,10 @@ begin
         e_GetTextureSize(ID, @w, @h);
         if FDirection = D_LEFT then
           e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
-                     FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False)
+                     FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False)
         else
           e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
-                     FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False);
+                     FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False);
       end;
 
     if FMegaRulez[MR_INVIS] > gTime then
@@ -2287,15 +2291,15 @@ begin
         else
           dr := True;
         if dr then
-          FModel.Draw(FObj.X, FObj.Y, 200)
+          FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 200)
         else
-          FModel.Draw(FObj.X, FObj.Y);
+          FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
       end
       else
-        FModel.Draw(FObj.X, FObj.Y, 254);
+        FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 254);
     end
     else
-      FModel.Draw(FObj.X, FObj.Y);
+      FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
   end;
 
   if g_debug_Frames then
@@ -2316,146 +2320,16 @@ begin
 end;
 
 
-var
-  plrMouseX: Integer = -666;
-  plrMouseY: Integer = -666;
-  vpx, vpy: Integer;
-  //vpw, vph: Integer;
-  laserX0, laserY0, laserX1, laserY1: Integer;
-  monMarkedUID: Integer = -1;
-
-function pmsCurMapX (): Integer; inline; begin result := plrMouseX+vpx; end;
-function pmsCurMapY (): Integer; inline; begin result := plrMouseY+vpy; end;
-
-procedure plrDebugMouse (msx, msy, but: Integer; bstate: Integer);
-
-  function wallToggle (pan: TPanel; tag: Integer): Boolean;
-  begin
-    result := false; // don't stop
-    if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
-  end;
-
-  function monsAtDump (mon: TMonster; tag: Integer): Boolean;
-  begin
-    result := false; // don't stop
-    e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
-    monMarkedUID := mon.UID;
-    //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
-  end;
-
-begin
-  plrMouseX := msx;
-  plrMouseY := msy;
-  //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
-  if (gPlayer1 = nil) then exit;
-
-  if (but = MouseLeft) then
-  begin
-    mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
-    exit;
-  end;
-
-  if (but = MouseRight) then
-  begin
-    monMarkedUID := -1;
-    e_WriteLog('===========================', MSG_NOTIFY);
-    monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
-    e_WriteLog('---------------------------', MSG_NOTIFY);
-    exit;
-  end;
-end;
-
-
-procedure plrDebugDrawMouse ();
-
-  function monsCollector (mon: TMonster; tag: Integer): Boolean;
-  var
-    ex, ey: Integer;
-    mx, my, mw, mh: Integer;
-  begin
-    result := false;
-    mon.getMapBox(mx, my, mw, mh);
-    e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
-    if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
-    begin
-      e_DrawPoint(8, ex, ey, 0, 255, 0);
-    end;
-  end;
-
-var
-  mon: TMonster;
-  mx, my, mw, mh: Integer;
-begin
-  e_DrawPoint(4, plrMouseX, plrMouseY, 255, 0, 255);
-  if (gPlayer1 = nil) then exit;
-
-  //e_WriteLog(Format('(%d,%d)-(%d,%d)', [laserX0, laserY0, laserX1, laserY1]), MSG_NOTIFY);
-
-  glPushMatrix();
-  glTranslatef(-vpx, -vpy, 0);
-
-  g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
-
-  if (monMarkedUID <> -1) then
-  begin
-    mon := g_Monsters_ByUID(monMarkedUID);
-    if (mon <> nil) then
-    begin
-      mon.getMapBox(mx, my, mw, mh);
-      e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
-    end;
-  end;
-
-  //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
-
-  glPopMatrix();
-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;
-    //mon: TMonster;
-    //mx, my, mw, mh: Integer;
   begin
     if isValidViewPort and (self = gPlayer1) then
     begin
-      vpx := viewPortX;
-      vpy := viewPortY;
-      //vpw := viewPortW;
-      //vpy := viewPortH;
-      evMouseCB := plrDebugMouse;
-      postdrawMouse := plrDebugDrawMouse;
+      g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
     end;
 
-    laserX0 := ax0;
-    laserY0 := ay0;
-    laserX1 := ax1;
-    laserY1 := ay1;
-
     e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
     if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
     begin
@@ -2465,25 +2339,6 @@ procedure TPlayer.DrawAim();
     begin
       e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
     end;
-
-    {
-    mon := g_Mons_ByIdx(0);
-    mon.getMapBox(mx, my, mw, mh);
-    ax1 := mx+mw div 2;
-    ay1 := my+mh div 2;
-    e_DrawLine(2, ax0, ay0, ax1, ay1, 0, 96, 96, 96);
-
-    if lineAABBIntersects(ax0, ay0, ax1, ay1, mx, my, mw, mh, ex, ey) then
-    begin
-      e_DrawLine(2, ax0, ay0, ex, ey, 255, 255, 0, 96);
-    end
-    else
-    begin
-      e_DrawLine(2, ax0, ay0, ex, ey, 255, 127, 0, 96);
-    end;
-    }
-
-    drawTileGrid();
   end;
 
 var