DEADSOFTWARE

put "{$MODE ...}" directive in each source file; removed trailing spaces, and convert...
[d2df-sdl.git] / src / game / g_sound.pas
index 074d037c29da38b5f77c4652b71665fa08d382ed..0632efdfe9904859d6accc8222abd3e3e1e28363 100644 (file)
@@ -1,3 +1,4 @@
+{$MODE DELPHI}
 unit g_sound;
 
 interface
@@ -24,7 +25,7 @@ type
     function SetByName(SN: String): Boolean;
     function SetCoords(X, Y: Integer; Volume: Single): Boolean;
 
-    property Loop: Boolean read FLoop write FLoop;
+    property Loop: Boolean read FMusic write FMusic;
     property Name: String read FName;
   end;
 
@@ -68,8 +69,8 @@ procedure g_Sound_SetupAllVolumes(SoundVol, MusicVol: Byte);
 implementation
 
 uses
-  e_log, SysUtils, g_console, g_options, WADEDITOR,
-  g_game, g_basic, g_items, g_map, fmod, fmodtypes, Math,
+  e_log, SysUtils, g_console, g_options, wadreader,
+  g_game, g_basic, g_items, g_map, Math,
   g_language;
 
 type
@@ -119,7 +120,7 @@ begin
   for a := 0 to High(SoundArray) do
     if SoundArray[a].Name = SoundName then
     begin
-      Result := e_PlaySoundVolume(SoundArray[a].ID, gSoundLevel/255.0);
+      Result := (e_PlaySoundVolume(SoundArray[a].ID, gSoundLevel/255.0) >= 0);
       Exit;
     end;
 
@@ -137,7 +138,7 @@ begin
   for a := 0 to High(SoundArray) do
     if SoundArray[a].Name = SoundName then
     begin
-      Result := e_PlaySoundPanVolume(SoundArray[a].ID, Pan, Volume * (gSoundLevel/255.0));
+      Result := (e_PlaySoundPanVolume(SoundArray[a].ID, Pan, Volume * (gSoundLevel/255.0)) >= 0);
       Exit;
     end;
 
@@ -229,7 +230,7 @@ var
   Pan, Vol: Single;
 begin
   if PlaySoundAt(X, Y, Pan, Vol) then
-    Result := e_PlaySoundPanVolume(ID, Pan, Vol * (gSoundLevel/255.0))
+    Result := (e_PlaySoundPanVolume(ID, Pan, Vol * (gSoundLevel/255.0)) >= 0)
   else
     Result := False;
 end;
@@ -248,8 +249,7 @@ begin
     if SoundArray[a].Name = SoundName then
     begin
       if PlaySoundAt(X, Y, Pan, Vol) then
-        Result := e_PlaySoundPanVolume(SoundArray[a].ID,
-                    Pan, Vol * (gSoundLevel/255.0));
+        Result := (e_PlaySoundPanVolume(SoundArray[a].ID, Pan, Vol * (gSoundLevel/255.0)) >= 0);
       Exit;
     end;
 
@@ -280,7 +280,7 @@ end;
 
 function g_Sound_CreateWAD(var ID: DWORD; Resource: string; isMusic: Boolean = False): Boolean;
 var
-  WAD: TWADEditor_1;
+  WAD: TWADFile;
   FileName,
   SectionName,
   ResourceName: string;
@@ -294,7 +294,7 @@ begin
   // e_WriteLog('Loading sound: ' + Resource, MSG_NOTIFY);
   g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
 
-  WAD := TWADEditor_1.Create();
+  WAD := TWADFile.Create();
   WAD.ReadFile(FileName);
 
   if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then
@@ -305,25 +305,27 @@ 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;
+  WAD: TWADFile;
   FileName, SectionName, ResourceName: string;
   SoundData: Pointer;
   ResLength: Integer;
@@ -338,7 +340,7 @@ begin
 
   find_id := FindSound();
 
-  WAD := TWADEditor_1.Create();
+  WAD := TWADFile.Create();
   WAD.ReadFile(FileName);
 
   if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then
@@ -353,19 +355,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;