DEADSOFTWARE

added common file with compiler flags; cosmetic fix in g_monsters.pas
[d2df-sdl.git] / src / game / g_sound.pas
index 55098850892c9b9e40c9079296181f58d87fea12..a3ef547a60254c6e46fba00506768e11e5e0f4cd 100644 (file)
@@ -1,3 +1,19 @@
+(* 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/>.
+ *)
+{$INCLUDE g_amodes.inc}
 unit g_sound;
 
 interface
@@ -68,7 +84,7 @@ procedure g_Sound_SetupAllVolumes(SoundVol, MusicVol: Byte);
 implementation
 
 uses
-  e_log, SysUtils, g_console, g_options, WADEDITOR,
+  e_log, SysUtils, g_console, g_options, wadreader,
   g_game, g_basic, g_items, g_map, Math,
   g_language;
 
@@ -279,10 +295,8 @@ end;
 
 function g_Sound_CreateWAD(var ID: DWORD; Resource: string; isMusic: Boolean = False): Boolean;
 var
-  WAD: TWADEditor_1;
-  FileName,
-  SectionName,
-  ResourceName: string;
+  WAD: TWADFile;
+  FileName: string;
   SoundData: Pointer;
   ResLength: Integer;
   ok: Boolean;
@@ -291,12 +305,12 @@ begin
   ok := False;
 
   // e_WriteLog('Loading sound: ' + Resource, MSG_NOTIFY);
-  g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+  FileName := g_ExtractWadName(Resource);
 
-  WAD := TWADEditor_1.Create();
+  WAD := TWADFile.Create();
   WAD.ReadFile(FileName);
 
-  if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then
+  if WAD.GetResource(g_ExtractFilePathName(Resource), SoundData, ResLength) then
     begin
       if e_LoadSoundMem(SoundData, ResLength, ID, isMusic) then
         ok := True
@@ -304,26 +318,28 @@ begin
         FreeMem(SoundData);
     end
   else
-    e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+  begin
+    //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+  end;
 
   WAD.Free();
-
-  if not ok then
+  if (not ok) then
   begin
+{$IFNDEF HEADLESS}
     if isMusic then
       e_WriteLog(Format('Error loading music %s', [Resource]), MSG_WARNING)
     else
       e_WriteLog(Format('Error loading sound %s', [Resource]), MSG_WARNING);
     Exit;
+{$ENDIF}
   end;
-
   Result := True;
 end;
 
 function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False): Boolean;
 var
-  WAD: TWADEditor_1;
-  FileName, SectionName, ResourceName: string;
+  WAD: TWADFile;
+  FileName: string;
   SoundData: Pointer;
   ResLength: Integer;
   find_id: DWORD;
@@ -333,14 +349,14 @@ begin
   ok := False;
 
   // e_WriteLog('Loading sound: ' + Resource, MSG_NOTIFY);
-  g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+  FileName := g_ExtractWadName(Resource);
 
   find_id := FindSound();
 
-  WAD := TWADEditor_1.Create();
+  WAD := TWADFile.Create();
   WAD.ReadFile(FileName);
 
-  if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then
+  if WAD.GetResource(g_ExtractFilePathName(Resource), SoundData, ResLength) then
     begin
       if e_LoadSoundMem(SoundData, ResLength, SoundArray[find_id].ID, isMusic) then
         begin
@@ -352,19 +368,21 @@ begin
         FreeMem(SoundData);
     end
   else
-    e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+  begin
+    //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+  end;
 
   WAD.Free();
-
-  if not ok then
+  if (not ok) then
   begin
+{$IFNDEF HEADLESS}
     if isMusic then
       e_WriteLog(Format('Error loading music %s', [Resource]), MSG_WARNING)
     else
       e_WriteLog(Format('Error loading sound %s', [Resource]), MSG_WARNING);
     Exit;
+{$ENDIF}
   end;
-
   Result := True;
 end;