DEADSOFTWARE

fixed error message if default megawad map failed to load
[d2df-sdl.git] / src / game / g_game.pas
index f696accdf385baf3a40b56daa97ac22f6f8e678a..78c8dba234975e1ead9c75585d60eedb1171eced 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
@@ -1538,8 +1538,8 @@ begin
       Exit;
   end;
 
-// ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
-  e_PollInput();
+  // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
+  // no need to, as we'll do it in event handler
 
 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
   g_Console_Update();
@@ -2054,12 +2054,12 @@ begin
   g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_RB', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_RS', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_RD', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_BB', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_BS', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_BD', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
   g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
@@ -2182,7 +2182,8 @@ var
 begin
   e_TextureFontGetSize(gStdFont, ww2, hh2);
 
-  e_PollInput();
+  g_ProcessMessages();
+
   if e_KeyPressed(IK_TAB) then
   begin
     if not gStatsPressed then
@@ -2503,13 +2504,60 @@ begin
 end;
 
 procedure DrawLoadingStat();
+  procedure drawRect (x, y, w, h: Integer);
+  begin
+    if (w < 1) or (h < 1) then exit;
+    glBegin(GL_QUADS);
+      glVertex2f(x+0.375, y+0.375);
+      glVertex2f(x+w+0.375, y+0.375);
+      glVertex2f(x+w+0.375, y+h+0.375);
+      glVertex2f(x+0.375, y+h+0.375);
+    glEnd();
+  end;
+
+  procedure drawPBar (cur, total: Integer);
+  var
+    rectW, rectH: Integer;
+    x0, y0: Integer;
+    wdt: Integer;
+  begin
+    if (total < 1) then exit;
+    if (cur < 1) then exit; // don't blink
+    if (cur >= total) then exit; // don't blink
+    //if (cur < 0) then cur := 0;
+    //if (cur > total) then cur := total;
+
+    rectW := gScreenWidth-64;
+    rectH := 16;
+
+    x0 := (gScreenWidth-rectW) div 2;
+    y0 := gScreenHeight-rectH-64;
+    if (y0 < 2) then y0 := 2;
+
+    glDisable(GL_BLEND);
+    glDisable(GL_TEXTURE_2D);
+
+    //glClearColor(0, 0, 0, 0);
+    //glClear(GL_COLOR_BUFFER_BIT);
+
+    glColor4ub(127, 127, 127, 255);
+    drawRect(x0-2, y0-2, rectW+4, rectH+4);
+
+    glColor4ub(0, 0, 0, 255);
+    drawRect(x0-1, y0-1, rectW+2, rectH+2);
+
+    glColor4ub(127, 127, 127, 255);
+    wdt := rectW*cur div total;
+    if (wdt > rectW) then wdt := rectW;
+    drawRect(x0, y0, wdt, rectH);
+  end;
+
 var
   ww, hh: Word;
   xx, yy, i: Integer;
   s: String;
 begin
-  if Length(LoadingStat.Msgs) = 0 then
-    Exit;
+  if (Length(LoadingStat.Msgs) = 0) then exit;
 
   e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
   yy := (gScreenHeight div 3);
@@ -2517,16 +2565,19 @@ begin
   xx := (gScreenWidth div 3);
 
   with LoadingStat do
+  begin
     for i := 0 to NextMsg-1 do
-      begin
-        if (i = (NextMsg-1)) and (MaxValue > 0) then
-          s := Format('%s:  %d/%d', [Msgs[i], CurValue, MaxValue])
-        else
-          s := Msgs[i];
+    begin
+      if (i = (NextMsg-1)) and (MaxValue > 0) then
+        s := Format('%s:  %d/%d', [Msgs[i], CurValue, MaxValue])
+      else
+        s := Msgs[i];
 
-        e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
-        yy := yy + LOADING_INTERLINE;
-      end;
+      e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
+      yy := yy + LOADING_INTERLINE;
+      drawPBar(CurValue, MaxValue);
+    end;
+  end;
 end;
 
 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
@@ -3734,6 +3785,7 @@ end;
 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
 var
   i, nPl: Integer;
+  tmps: AnsiString;
 begin
   g_Game_Free();
 
@@ -3789,7 +3841,8 @@ begin
 // Çàãðóçêà è çàïóñê êàðòû:
   if not g_Game_StartMap(MAP, True) then
   begin
-    g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + MAP]));
+    if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
+    g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
     Exit;
   end;
 
@@ -4136,6 +4189,7 @@ begin
           enet_packet_destroy(NetEvent.packet);
       end
       else
+      begin
         if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
         begin
           State := 0;
@@ -4145,12 +4199,11 @@ begin
           OuterLoop := False;
           Break;
         end;
+      end;
     end;
 
     ProcessLoading(true);
 
-    e_PollInput();
-
     if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
     begin
       State := 0;
@@ -6008,7 +6061,7 @@ begin
         if P[2] = '' then
           g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
         else
-          g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
+          g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
     end else
       g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
   end
@@ -6062,7 +6115,7 @@ begin
         if P[4] = '' then
           g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
         else
-          g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
+          g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
     end else
       g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
   end
@@ -6096,9 +6149,9 @@ begin
               g_Game_ChangeMap(s);
           end else
           begin
-            g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
             // Òàêîé êàðòû íåò, èùåì WAD ôàéë
             P[1] := addWadExtension(P[1]);
+            g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
             if FileExists(MapsDir + P[1]) then
             begin
               // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -6185,9 +6238,9 @@ begin
               nm := True;
             end else
             begin
-              g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
               // Òàêîé êàðòû íåò, èùåì WAD ôàéë
               P[1] := addWadExtension(P[1]);
+              g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
               if FileExists(MapsDir + P[1]) then
               begin
                 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -7138,6 +7191,11 @@ begin
     if (s <> '') then
       gMapOnce := True;
 
+  // Override map to test:
+    s := LowerCase(Find_Param_Value(pars, '-testmap'));
+    if s <> '' then
+      gTestMap := MapsDir + s;
+
   // Delete test map after play:
     s := Find_Param_Value(pars, '--testdelete');
     if (s <> '') then
@@ -7149,9 +7207,9 @@ begin
 
   // Delete temporary WAD after play:
     s := Find_Param_Value(pars, '--tempdelete');
-    if (s <> '') then
+    if (s <> '') and (gTestMap <> '') then
     begin
-      gMapToDelete := MapsDir + map;
+      gMapToDelete := gTestMap;
       gTempDelete := True;
     end;