DEADSOFTWARE

no more old mapreader: use textmap reader both for text and for binary maps
[d2df-sdl.git] / src / game / g_game.pas
index b198947e145dffab6b26a56ae1591635a59cfb39..1cf480864080a2c4115db2cae221b07de7e16299 100644 (file)
@@ -20,7 +20,7 @@ interface
 
 uses
   g_basic, g_player, e_graphics, Classes, g_res_downloader,
-  SysUtils, g_sound, g_gui, MAPSTRUCT, wadreader, md5, xprofiler;
+  SysUtils, g_sound, g_gui, MAPDEF, wadreader, md5, xprofiler;
 
 type
   TGameSettings = record
@@ -63,7 +63,7 @@ type
 
   THearPoint = record
     Active: Boolean;
-    Coords: TPoint;
+    Coords: TDFPoint;
   end;
 
 function  g_Game_IsNet(): Boolean;
@@ -209,9 +209,9 @@ var
   gPlayer1Settings: TPlayerSettings;
   gPlayer2Settings: TPlayerSettings;
   gGameOn: Boolean;
-  gPlayerScreenSize: TPoint;
-  gPlayer1ScreenCoord: TPoint;
-  gPlayer2ScreenCoord: TPoint;
+  gPlayerScreenSize: TDFPoint;
+  gPlayer1ScreenCoord: TDFPoint;
+  gPlayer2ScreenCoord: TDFPoint;
   gPlayer1: TPlayer = nil;
   gPlayer2: TPlayer = nil;
   gPlayerDrawn: TPlayer = nil;
@@ -315,6 +315,15 @@ var
   g_profile_los: Boolean = false;
   g_profile_history_size: Integer = 1000;
 
+  g_rlayer_back: Boolean = true;
+  g_rlayer_step: Boolean = true;
+  g_rlayer_wall: Boolean = true;
+  g_rlayer_door: Boolean = true;
+  g_rlayer_acid1: Boolean = true;
+  g_rlayer_acid2: Boolean = true;
+  g_rlayer_water: Boolean = true;
+  g_rlayer_fore: Boolean = true;
+
 
 procedure g_ResetDynlights ();
 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
@@ -329,7 +338,7 @@ uses
   g_textures, g_main, g_window, g_menu,
   e_input, e_log, g_console, g_items, g_map, g_panel,
   g_playermodel, g_gfx, g_options, g_weapons, Math,
-  g_triggers, MAPDEF, g_monsters, e_sound, CONFIG,
+  g_triggers, g_monsters, e_sound, CONFIG,
   BinEditor, g_language, g_net, SDL,
   ENet, e_msg, g_netmsg, g_netmaster, GL, GLExt,
   utils, sfs, g_holmes;
@@ -451,7 +460,8 @@ begin
   if (y < 0) then y := gScreenHeight-(hgt-1)+y;
   // background
   //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
-  e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
+  //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
+  e_DarkenQuadWH(x, y, wdt, hgt, 150);
   // title
   yy := y+2;
   for ii := 0 to High(prof.bars) do
@@ -1980,7 +1990,11 @@ begin
     UPSTime := Time;
   end;
 
-  if gGameOn then g_Weapon_AddDynLights();
+  if gGameOn then
+  begin
+    g_Weapon_AddDynLights();
+    g_Items_AddDynLights();
+  end;
 end;
 
 procedure g_Game_LoadData();
@@ -2700,6 +2714,7 @@ begin
     if ly-sY-lrad >= gPlayerScreenSize.Y then continue;
 
     // set scissor to optimize drawing
+    //FIXME: broken for splitscreen mode
     glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
     // no need to clear stencil buffer, light blitting will do it for us
     glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
@@ -2740,7 +2755,7 @@ procedure renderMapInternal (backXOfs, backYOfs: Integer; transX, transY: Intege
 type
   TDrawCB = procedure ();
 
-  procedure drawPanelType (profname: AnsiString; panType: DWord);
+  procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
   var
     tagmask: Integer;
     pan: TPanel;
@@ -2749,28 +2764,17 @@ type
     if gdbg_map_use_accel_render then
     begin
       tagmask := panelTypeToTag(panType);
-      {$IF TRUE}
       while (gDrawPanelList.count > 0) do
       begin
         pan := TPanel(gDrawPanelList.front());
         if ((pan.tag and tagmask) = 0) then break;
-        pan.Draw();
-        gDrawPanelList.popFront();
-      end;
-      {$ELSE}
-      e_WriteLog(Format('=== PANELS: %d ===', [gDrawPanelList.count]), MSG_NOTIFY);
-      while (gDrawPanelList.count > 0) do
-      begin
-        pan := TPanel(gDrawPanelList.front());
-        e_WriteLog(Format('tagmask: 0x%04x; pan.tag: 0x%04x; pan.arrIdx: %d', [tagmask, pan.tag, pan.arrIdx]), MSG_NOTIFY);
-        pan.Draw();
+        if doDraw then pan.Draw();
         gDrawPanelList.popFront();
       end;
-      {$ENDIF}
     end
     else
     begin
-      g_Map_DrawPanels(panType);
+      if doDraw then g_Map_DrawPanels(panType);
     end;
     profileFrameDraw.sectionEnd();
   end;
@@ -2800,23 +2804,23 @@ begin
 
   if (setTransMatrix) then glTranslatef(transX, transY, 0);
 
-  drawPanelType('*back', PANEL_BACK);
-  drawPanelType('*step', PANEL_STEP);
+  drawPanelType('*back', PANEL_BACK, g_rlayer_back);
+  drawPanelType('*step', PANEL_STEP, g_rlayer_step);
   drawOther('items', @g_Items_Draw);
   drawOther('weapons', @g_Weapon_Draw);
   drawOther('shells', @g_Player_DrawShells);
   drawOther('drawall', @g_Player_DrawAll);
   drawOther('corpses', @g_Player_DrawCorpses);
-  drawPanelType('*wall', PANEL_WALL);
+  drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
   drawOther('monsters', @g_Monsters_Draw);
-  drawPanelType('*door', PANEL_CLOSEDOOR);
+  drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
   drawOther('gfx', @g_GFX_Draw);
   drawOther('flags', @g_Map_DrawFlags);
-  drawPanelType('*acid1', PANEL_ACID1);
-  drawPanelType('*acid2', PANEL_ACID2);
-  drawPanelType('*water', PANEL_WATER);
+  drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
+  drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
+  drawPanelType('*water', PANEL_WATER, g_rlayer_water);
   drawOther('dynlights', @renderDynLightsInternal);
-  drawPanelType('*fore', PANEL_FORE);
+  drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
 
   if g_debug_HealthBar then
   begin
@@ -3195,7 +3199,8 @@ begin
 
   if gPause and gGameOn and (g_ActiveWindow = nil) then
   begin
-    e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+    //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+    e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
 
     e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
     e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
@@ -3213,11 +3218,16 @@ begin
         else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
       end;
       if g_ActiveWindow <> nil then
-        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+      begin
+        //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
+      end;
     end;
 
     if gState = STATE_FOLD then
+    begin
       e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
+    end;
 
     if gState = STATE_INTERCUSTOM then
     begin
@@ -3238,13 +3248,18 @@ begin
       DrawCustomStat();
 
       if g_ActiveWindow <> nil then
-        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+      begin
+        //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
+      end;
     end;
 
     if gState = STATE_INTERSINGLE then
     begin
       if EndingGameCounter > 0 then
-        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter)
+      begin
+        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
+      end
       else
       begin
         back := 'INTER';
@@ -3257,7 +3272,10 @@ begin
         DrawSingleStat();
 
         if g_ActiveWindow <> nil then
-          e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        begin
+          //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+          e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
+        end;
       end;
     end;
 
@@ -3273,7 +3291,10 @@ begin
         e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
 
       if g_ActiveWindow <> nil then
-        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+      begin
+        //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
+      end;
     end;
 
     if gState = STATE_SLIST then
@@ -3281,7 +3302,8 @@ begin
       if g_Texture_Get('MENU_BACKGROUND', ID) then
       begin
         e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
-        e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+        e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
       end;
       g_Serverlist_Draw(slCurrent);
     end;
@@ -3290,7 +3312,10 @@ begin
   if g_ActiveWindow <> nil then
   begin
     if gGameOn then
-      e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+    begin
+      //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
+      e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
+    end;
     g_ActiveWindow.Draw();
   end;
 
@@ -3316,6 +3341,8 @@ begin
     drawTime(gScreenWidth-72, gScreenHeight-16);
 
   if gGameOn then drawProfilers();
+
+  g_Holmes_DrawUI();
 end;
 
 procedure g_Game_Quit();
@@ -4990,7 +5017,7 @@ procedure DebugCommands(P: SArray);
 var
   a, b: Integer;
   cmd: string;
-  //pt: TPoint;
+  //pt: TDFPoint;
   mon: TMonster;
 begin
 // Êîìàíäû îòëàäî÷íîãî ðåæèìà: