DEADSOFTWARE

Merge FGSFDS branch, fix build
[d2df-sdl.git] / src / game / g_game.pas
index 4a8afe82675df7280a114efedadab966da3a540a..938e07175a779844898f0196219a362ea03e5151 100644 (file)
@@ -1,10 +1,26 @@
+(* 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$MODE DELPHI}
 unit g_game;
 
 interface
 
 uses
   g_basic, g_player, e_graphics, Classes, g_res_downloader,
-  SysUtils, g_sound, g_gui, MAPSTRUCT, wadreader, md5;
+  SysUtils, g_sound, g_gui, g_scripts, MAPSTRUCT, wadreader, md5;
 
 type
   TGameSettings = record
@@ -482,7 +498,7 @@ begin
   w := TWADFile.Create();
   w.ReadFile(WAD);
 
-  if not w.GetResource('', 'INTERSCRIPT', p, len) then
+  if not w.GetResource('INTERSCRIPT', p, len) then
   begin
     w.Free();
     Exit;
@@ -541,7 +557,7 @@ begin
   w := TWADFile.Create();
   w.ReadFile(MapsDir + WAD);
 
-  if not w.GetResource('', 'INTERSCRIPT', p, len) then
+  if not w.GetResource('INTERSCRIPT', p, len) then
   begin
     w.Free();
     Exit;
@@ -578,14 +594,14 @@ begin
   MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
   if MegaWAD.endpic <> '' then
   begin
-    g_ProcessResourceStr(MegaWAD.endpic, @s, nil, nil);
+    s := g_ExtractWadName(MegaWAD.endpic);
     if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
     g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic);
   end;
   MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
   if MegaWAD.endmus <> '' then
   begin
-    g_ProcessResourceStr(MegaWAD.endmus, @s, nil, nil);
+    s := g_ExtractWadName(MegaWAD.endmus);
     if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
     g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True);
   end;
@@ -663,7 +679,7 @@ end;
 procedure EndGame();
 var
   a: Integer;
-  FileName, SectionName, ResName: string;
+  FileName: string;
 begin
   if g_Game_IsNet and g_Game_IsServer then
     MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
@@ -725,10 +741,10 @@ begin
     EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
       begin
       // Ñòàòèñòèêà Ñâîåé èãðû:
-        g_ProcessResourceStr(gMapInfo.Map, FileName, SectionName, ResName);
+        FileName := g_ExtractWadName(gMapInfo.Map);
 
         CustomStat.GameTime := gTime;
-        CustomStat.Map := ExtractFileName(FileName)+':'+ResName;
+        CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
         CustomStat.MapName := gMapInfo.Name;
         CustomStat.GameMode := gGameSettings.GameMode;
         if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
@@ -840,8 +856,8 @@ begin
   e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
   e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
 
-  g_ProcessResourceStr(gMapInfo.Map, @wad, nil, @map);
-  wad := ExtractFileName(wad);
+  wad := g_ExtractWadNameNoPath(gMapInfo.Map);
+  map := g_ExtractFileName(gMapInfo.Map);
   mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
 
   case gGameSettings.GameMode of
@@ -1082,6 +1098,9 @@ begin
 
     g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
     g_Menu_Init();
+    
+    g_Scripts_Init();
+    g_Scripts_Load('game.conprint("ass")');
 
     gMusic := TMusic.Create();
     gMusic.SetByName('MUSIC_MENU');
@@ -3661,7 +3680,7 @@ var
 begin
   if g_Game_IsClient then
     Exit;
-  g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
+  map := g_ExtractFileName(gMapInfo.Map);
 
   MessageTime := 0;
   gGameOn := False;
@@ -3692,7 +3711,8 @@ begin
 
   if Pos(':\', Map) > 0 then
   begin
-    g_ProcessResourceStr(Map, @NewWAD, nil, @ResName);
+    NewWAD := g_ExtractWadName(Map);
+    ResName := g_ExtractFileName(Map);
     if g_Game_IsServer then
     begin
       gWADHash := MD5File(MapsDir + NewWAD);
@@ -3870,7 +3890,7 @@ begin
     Exit;
   end;
   gExit := EXIT_ENDLEVELCUSTOM;
-  g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
+  Map := g_ExtractFileName(gMapInfo.Map);
   gNextMap := Map;
 end;
 
@@ -4018,7 +4038,7 @@ begin
   if MapList = nil then
     Exit;
 
-  g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
+  Map := g_ExtractFileName(gMapInfo.Map);
 
   SortSArray(MapList);
   MapIndex := -255;
@@ -4057,11 +4077,8 @@ begin
 end;
 
 function g_Game_IsTestMap(): Boolean;
-var
-  FName, Sect, Res: String;
 begin
-  g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res);
-  Result := UpperCase(Res) = TEST_MAP_NAME;
+  result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
 end;
 
 procedure g_Game_DeleteTestMap();
@@ -5853,7 +5870,10 @@ var
   a: Word;
   FileName: string;
   ssdir, t: string;
+  st: TStream;
+  ok: Boolean;
 begin
+  if e_NoGraphics then Exit;
   ssdir := GameDir+'/screenshots';
   if not findFileCI(ssdir, true) then
   begin
@@ -5867,14 +5887,21 @@ begin
   try
     for a := 1 to High(Word) do
     begin
-      FileName := Format(ssdir+'screenshot%.3d.bmp', [a]);
+      FileName := Format(ssdir+'screenshot%.3d.png', [a]);
       t := FileName;
       if findFileCI(t, true) then continue;
       if not findFileCI(FileName) then
       begin
-        e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
-        g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
-        Break;
+        ok := false;
+        st := createDiskFile(FileName);
+        try
+          e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
+          ok := true;
+        finally
+          st.Free();
+        end;
+        if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
+        break;
       end;
     end;
   except