| 1 |
/* |
| 2 |
* Descent 3 |
| 3 |
* Copyright (C) 2024 Parallax Software |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
/* |
| 21 |
* $Logfile: /DescentIII/Main/sndlib/soundload.cpp $ |
| 22 |
* $Revision: 59 $ |
| 23 |
* $Date: 10/21/99 3:23p $ |
| 24 |
* $Author: Kevin $ |
| 25 |
* |
| 26 |
* Code to load sounds |
| 27 |
* |
| 28 |
* $Log: /DescentIII/Main/sndlib/soundload.cpp $ |
| 29 |
* |
| 30 |
* 59 10/21/99 3:23p Kevin |
| 31 |
* Mac merge w/memory savings |
| 32 |
* |
| 33 |
* 58 5/11/99 12:10a Ardussi |
| 34 |
* changes to compile on Mac |
| 35 |
* |
| 36 |
* 57 5/08/99 3:30p Matt |
| 37 |
* Added weapon-hit-water sound. |
| 38 |
* |
| 39 |
* 56 4/30/99 3:28p Matt |
| 40 |
* Weapons now make a special sound when colliding with lava & volatile |
| 41 |
* surfaces, instead of the standard hit-wall sound. |
| 42 |
* |
| 43 |
* 55 4/29/99 3:50p Matt |
| 44 |
* Added hiss sound for volatile surface damage |
| 45 |
* |
| 46 |
* 54 4/29/99 1:10p Jeff |
| 47 |
* added sounds for inventory and countermeasure switch |
| 48 |
* |
| 49 |
* 53 4/14/99 1:46a Jeff |
| 50 |
* fixed case mismatched #includes |
| 51 |
* |
| 52 |
* 52 4/12/99 4:18p Jason |
| 53 |
* remap textures during sound remapping |
| 54 |
* |
| 55 |
* 51 4/11/99 5:03p Matt |
| 56 |
* Changed static sound remapping code to use simpler & more |
| 57 |
* space-efficient scheme. Also deleted an unused entry in the static |
| 58 |
* sound list. |
| 59 |
* |
| 60 |
* 50 3/04/99 10:57a Matt |
| 61 |
* Added goal message notification sound |
| 62 |
* |
| 63 |
* 49 2/22/99 10:24p Matt |
| 64 |
* Added a static sound for debris explosion |
| 65 |
* |
| 66 |
* 48 2/18/99 4:48p Matt |
| 67 |
* Changed the default import volume for new sounds to 100% |
| 68 |
* |
| 69 |
* 47 2/18/99 2:49p Matt |
| 70 |
* Added goal complete sound |
| 71 |
* |
| 72 |
* 46 2/10/99 4:38p Matt |
| 73 |
* Misc. changes for table file parsing |
| 74 |
* |
| 75 |
* 45 1/29/99 12:48p Matt |
| 76 |
* Rewrote the doorway system |
| 77 |
* |
| 78 |
* 44 1/13/99 6:55a Jeff |
| 79 |
* fixed #includes to work for linux |
| 80 |
* |
| 81 |
* 43 11/23/98 1:50p Jason |
| 82 |
* added thruster sounds |
| 83 |
* |
| 84 |
* 42 10/22/98 8:31p Chris |
| 85 |
* Sounds use GlobalAlloc and GlobalFree |
| 86 |
* |
| 87 |
* 41 10/21/98 4:53p Jeff |
| 88 |
* added some sounds to sounds array |
| 89 |
* |
| 90 |
* 40 10/20/98 2:09p Jeff |
| 91 |
* added 2 more sounds to static sounds |
| 92 |
* |
| 93 |
* 39 10/20/98 12:49p Matt |
| 94 |
* Removed obsolete sounds from static sound list. |
| 95 |
* |
| 96 |
* 38 10/19/98 7:19p Matt |
| 97 |
* Added system to support different types of damage to the player and |
| 98 |
* have these different types make different sounds. |
| 99 |
* |
| 100 |
* 37 10/19/98 11:57a Chris |
| 101 |
* Update the sound system to use the import volume |
| 102 |
* |
| 103 |
* 36 10/14/98 1:02p Jason |
| 104 |
* fixed FindSoundName issues |
| 105 |
* |
| 106 |
* 35 10/12/98 1:27p Jeff |
| 107 |
* all mem_free's do set the value to NULL after they are complete |
| 108 |
* |
| 109 |
* 34 9/21/98 8:19p Chris |
| 110 |
* Improved volatile and forcefield hits |
| 111 |
* |
| 112 |
* 33 9/18/98 1:27p Matt |
| 113 |
* Added afterburner release sound |
| 114 |
* |
| 115 |
* 32 9/08/98 12:05p Jason |
| 116 |
* moved doorway.h out of room.h |
| 117 |
* |
| 118 |
* 31 7/24/98 5:22p Samir |
| 119 |
* took out WAV file stuff because low level sound libray needs this code. |
| 120 |
* |
| 121 |
* 30 6/19/98 3:03p Chris |
| 122 |
* Made CheckAndForceSoundDataAlloc a SoundSystem function - useful for |
| 123 |
* multiple mixers. Added IsSoundPlaying to the high level sound lib. |
| 124 |
* |
| 125 |
* 29 6/17/98 4:39p Chris |
| 126 |
* Added the playing of 8bit samples with the 16 bit sound mixer |
| 127 |
* |
| 128 |
* 28 5/26/98 10:54p Chris |
| 129 |
* Ooops again |
| 130 |
* |
| 131 |
* 27 5/26/98 10:42p Chris |
| 132 |
* Fixed door sound paging |
| 133 |
* |
| 134 |
* 26 5/26/98 10:21p Chris |
| 135 |
* Added door sound paging |
| 136 |
* |
| 137 |
* 25 5/22/98 11:59a Chris |
| 138 |
* Fixed improper uses of FindSoundName and made the proper static sounds |
| 139 |
* |
| 140 |
* 24 5/17/98 4:08p Chris |
| 141 |
* Fixed bugs with initial sound loading. :) |
| 142 |
* |
| 143 |
* 23 5/14/98 1:28p Chris |
| 144 |
* Improved sound loading stuff |
| 145 |
* |
| 146 |
* 22 5/14/98 11:49a Chris |
| 147 |
* Bettered the sound paging system |
| 148 |
* |
| 149 |
* 21 5/03/98 10:22p Matt |
| 150 |
* Added breaking glass sound |
| 151 |
* |
| 152 |
* 20 5/03/98 5:38p Chris |
| 153 |
* Added sounds to anim page |
| 154 |
* |
| 155 |
* 19 4/24/98 3:02p Chris |
| 156 |
* Removed GlobalAlloc and GlobalFree |
| 157 |
* |
| 158 |
* 18 4/22/98 5:38p Chris |
| 159 |
* Fixed problems with adding new sounds |
| 160 |
* |
| 161 |
* 17 4/22/98 11:55a Jeff |
| 162 |
* fixed stack overrun in ChangeSoundFileName |
| 163 |
* |
| 164 |
* 16 4/21/98 2:35p Chris |
| 165 |
* Made soundload use the standard mem_malloc stuff |
| 166 |
* |
| 167 |
* 15 4/06/98 5:13p Chris |
| 168 |
* Sounds page in at the beginning of a level |
| 169 |
* |
| 170 |
* 14 3/31/98 3:49p Jason |
| 171 |
* added memory lib |
| 172 |
* |
| 173 |
* 13 3/02/98 4:16p Chris |
| 174 |
* Added 14 new fields to the AI Settings Dialog/page. |
| 175 |
* |
| 176 |
* 12 2/23/98 5:03p Chris |
| 177 |
* Added the global alloc calls (deifned them to malloc and free when not |
| 178 |
* Win32) |
| 179 |
* |
| 180 |
* 11 2/16/98 4:55p Chris |
| 181 |
* Added default sounds for explosions |
| 182 |
* |
| 183 |
* 10 2/12/98 4:23p Chris |
| 184 |
* Fixed problem with sound dialog and allowing users to enter invalid |
| 185 |
* values |
| 186 |
* |
| 187 |
* 9 1/02/98 5:32p Chris |
| 188 |
* More radical changes to the sound system |
| 189 |
* |
| 190 |
* 8 12/31/97 2:58a Chris |
| 191 |
* Another major revision to the SoundLib. This cleaned up the code after |
| 192 |
* removing the direct sound secondary buffers. |
| 193 |
* |
| 194 |
* 7 12/30/97 2:15p Chris |
| 195 |
* Adding further support for software 3d stuff |
| 196 |
* |
| 197 |
* 6 12/22/97 6:19p Chris |
| 198 |
* Moved weapon battery firing sound off the projectile (weapon) and into |
| 199 |
* the weapon battery. |
| 200 |
* |
| 201 |
* 5 12/19/97 4:09p Chris |
| 202 |
* New dynamically loading sounds |
| 203 |
* |
| 204 |
* 4 12/10/97 4:47p Chris |
| 205 |
* Revision 1.0 of new sound library (no hardware -- uses primary buffer |
| 206 |
* streaming) |
| 207 |
* |
| 208 |
* 3 7/15/97 7:29p Chris |
| 209 |
* Added a sound for helicopter blades. |
| 210 |
* |
| 211 |
* 13 5/29/97 3:26p Chris |
| 212 |
* |
| 213 |
* 12 5/29/97 3:11p Chris |
| 214 |
* Fixed loadsound |
| 215 |
* |
| 216 |
* 11 5/22/97 3:29p Jason |
| 217 |
* made sounds loading faster |
| 218 |
* |
| 219 |
* 10 5/14/97 11:31p Jason |
| 220 |
* fixed annoying printf |
| 221 |
* |
| 222 |
* 9 5/14/97 12:31p Chris |
| 223 |
* |
| 224 |
* 8 5/13/97 10:31p Matt |
| 225 |
* Added hook for refueling sound |
| 226 |
* |
| 227 |
* $NoKeywords: $ |
| 228 |
*/ |
| 229 |
|
| 230 |
#include <cstring> |
| 231 |
|
| 232 |
#include "pserror.h" |
| 233 |
#include "ssl_lib.h" |
| 234 |
#include "object.h" |
| 235 |
#include "ddio.h" |
| 236 |
#include "mem.h" |
| 237 |
#include "soundload.h" |
| 238 |
#include "weapon.h" |
| 239 |
#include "ship.h" |
| 240 |
#include "door.h" |
| 241 |
#include "room.h" |
| 242 |
#include "doorway.h" |
| 243 |
|
| 244 |
#if defined(WIN32) || defined(POSIX) |
| 245 |
#include "../manage/soundpage.h" |
| 246 |
#include "../Descent3/sounds.h" |
| 247 |
#endif |
| 248 |
|
| 249 |
int Num_sounds = 0; |
| 250 |
int Num_sound_files = 0; |
| 251 |
|
| 252 |
const char *Static_sound_names[NUM_STATIC_SOUNDS] = { |
| 253 |
TBL_SOUND("Default"), // 0 SOUND_NONE_INDEX |
| 254 |
TBL_SOUND("Refuel"), // 1 SOUND_REFUELING |
| 255 |
TBL_SOUND("DefaultRobotExplode1"), // 2 SOUND_ROBOT_EXPLODE_1 |
| 256 |
TBL_SOUND("DefaultRobotExplode2"), // 3 SOUND_ROBOT_EXPLODE_2 |
| 257 |
TBL_SOUND("DefaultBuildingExplode"), // 4 SOUND_BUILDING_EXPLODE |
| 258 |
TBL_SOUND("BreakingGlass"), // 5 SOUND_BREAKING_GLASS |
| 259 |
TBL_SOUND("Tear01"), // 6 SOUND_MELEE_HIT_0 |
| 260 |
TBL_SOUND("Tear02"), // 7 SOUND_MELEE_HIT_1 |
| 261 |
TBL_SOUND("Afterburner"), // 8 SOUND_AFTERBURNER |
| 262 |
TBL_SOUND("Drop unknown "), // 9 SOUND_ENERGY_DRAIN |
| 263 |
TBL_SOUND("Missle lock"), // 10 SOUND_MISSLE_LOCK |
| 264 |
TBL_SOUND("Powerup pickup"), // 11 SOUND_POWERUP_PICKUP |
| 265 |
TBL_SOUND("You don't have it BEEP"), // 12 SOUND_DO_NOT_HAVE_IT |
| 266 |
TBL_SOUND("Change primary weapon"), // 13 SOUND_CHANGE_PRIMARY |
| 267 |
TBL_SOUND("Change secondary weapon"), // 14 SOUND_CHANGE_SECONDARY |
| 268 |
TBL_SOUND("HitWall"), // 15 SOUND_PLAYER_HIT_WALL |
| 269 |
TBL_SOUND("AftrBrnrTail"), // 16 SOUND_AFTERBURNER_TAIL |
| 270 |
TBL_SOUND("Forcefield bounce"), // 17 SOUND_FORCEFIELD_BOUNCE |
| 271 |
TBL_SOUND("Headlight1"), // 18 SOUND_HEADLIGHT |
| 272 |
TBL_SOUND("Cheater!"), // 19 SOUND_CHEATER |
| 273 |
TBL_SOUND("Energy Converter"), // 20 SOUND_ENERGY_CONVERTER |
| 274 |
TBL_SOUND("CockpitSequenceTest1"), // 21 SOUND_COCKPIT |
| 275 |
TBL_SOUND("Metallic Door Hit"), // 22 SOUND_METALLIC_DOOR_HIT |
| 276 |
TBL_SOUND("Wall Fade ???"), // 23 SOUND_WALL_FADE |
| 277 |
TBL_SOUND("Raindrop"), // 24 SOUND_RAINDROP |
| 278 |
TBL_SOUND("Lightning"), // 25 SOUND_LIGHTNING |
| 279 |
TBL_SOUND("HitEnergy"), // 26 SOUND_HIT_BY_ENERGY_WEAPON |
| 280 |
TBL_SOUND("HitMatter"), // 27 SOUND_HIT_BY_MATTER_WEAPON |
| 281 |
TBL_SOUND("HitConcussion"), // 28 SOUND_HIT_BY_CONCUSSIVE_FORCE |
| 282 |
TBL_SOUND("HitFire"), // 29 SOUND_PLAYER_BURNING |
| 283 |
TBL_SOUND("Menu Slider Click"), // 30 SOUND_MENU_SOUND_CLICK |
| 284 |
TBL_SOUND("Hostage pickup"), // 31 SOUND_HOSTAGE_PICKUP |
| 285 |
TBL_SOUND("Briefstartup1"), // 32 SOUND_BRIEF_STARTUP |
| 286 |
TBL_SOUND("BriefStatic"), // 33 SOUND_BRIEF_STATIC |
| 287 |
TBL_SOUND("Briefmonitoroff1"), // 34 SOUND_BRIEF_MONITOROFF |
| 288 |
TBL_SOUND("Briefingrunning"), // 35 SOUND_BRIEF_RUNNING |
| 289 |
TBL_SOUND("Briefbulb1"), // 36 SOUND_BRIEF_BULLB |
| 290 |
TBL_SOUND("Briefingtype"), // 37 SOUND_BRIEF_TYPE |
| 291 |
TBL_SOUND("ShpIdle"), // 38 SHIP_IDLE |
| 292 |
TBL_SOUND("ShpForwardThrust"), // 39 SHIP_FORWARD_THRUST |
| 293 |
TBL_SOUND("ShpForwardThrRelease"), // 40 SHIP_FORWARD_THRUST_RELEASE |
| 294 |
TBL_SOUND("GoalComplete"), // 41 SOUND_GOAL_COMPLETE |
| 295 |
TBL_SOUND("DebrisExplosion"), // 42 SOUND_DEBRIS_EXPLODE |
| 296 |
TBL_SOUND("GameMessageNotify"), // 43 SOUND_GAME_MESSAGE |
| 297 |
TBL_SOUND("Change countermeasure weapon"), // 44 SOUND_CHANGE_COUNTERMEASURE |
| 298 |
TBL_SOUND("Change inventory item"), // 45 SOUND_CHANGE_INVENTORY |
| 299 |
TBL_SOUND("VolatileHiss"), // 46 SOUND_VOLATILE_HISS |
| 300 |
TBL_SOUND("WeaponHitLava"), // 47 SOUND_WEAPON_HIT_LAVA |
| 301 |
TBL_SOUND("WeaponHitWater"), // 48 SOUND_WEAPON_HIT_WATER |
| 302 |
}; |
| 303 |
|
| 304 |
// Allocs a sound file for use, returns -1 if error, else index on success |
| 305 |
int AllocSoundFile() { |
| 306 |
for (int i = 0; i < MAX_SOUND_FILES; i++) { |
| 307 |
if (SoundFiles[i].used == 0) { |
| 308 |
memset(&SoundFiles[i], 0, sizeof(sound_file_info)); |
| 309 |
SoundFiles[i].used = 1; |
| 310 |
|
| 311 |
Num_sound_files++; |
| 312 |
return i; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
Int3(); // No sound files free! |
| 317 |
return -1; |
| 318 |
} |
| 319 |
|
| 320 |
// Frees sound index n |
| 321 |
void FreeSoundFile(int n) { |
| 322 |
ASSERT(SoundFiles[n].used > 0); |
| 323 |
|
| 324 |
SoundFiles[n].used = 0; |
| 325 |
SoundFiles[n].name[0] = 0; |
| 326 |
if (SoundFiles[n].sample_8bit) { |
| 327 |
mem_free(SoundFiles[n].sample_8bit); |
| 328 |
SoundFiles[n].sample_8bit = NULL; |
| 329 |
} |
| 330 |
if (SoundFiles[n].sample_16bit) { |
| 331 |
mem_free(SoundFiles[n].sample_16bit); |
| 332 |
SoundFiles[n].sample_16bit = NULL; |
| 333 |
} |
| 334 |
Num_sound_files--; |
| 335 |
} |
| 336 |
|
| 337 |
// Gets next sound file from n that has actually been alloced |
| 338 |
int GetNextSoundFile(int n) { |
| 339 |
int i; |
| 340 |
|
| 341 |
ASSERT(n >= 0 && n < MAX_SOUND_FILES); |
| 342 |
|
| 343 |
if (Num_sound_files == 0) |
| 344 |
return -1; |
| 345 |
|
| 346 |
for (i = n + 1; i < MAX_SOUND_FILES; i++) |
| 347 |
if (SoundFiles[i].used) |
| 348 |
return i; |
| 349 |
for (i = 0; i < n; i++) |
| 350 |
if (SoundFiles[i].used) |
| 351 |
return i; |
| 352 |
|
| 353 |
// this is the only one |
| 354 |
|
| 355 |
return n; |
| 356 |
} |
| 357 |
|
| 358 |
// Gets previous sound file from n that has actually been alloced |
| 359 |
int GetPrevSoundFile(int n) { |
| 360 |
int i; |
| 361 |
|
| 362 |
ASSERT(n >= 0 && n < MAX_SOUND_FILES); |
| 363 |
|
| 364 |
if (Num_sound_files == 0) |
| 365 |
return -1; |
| 366 |
|
| 367 |
for (i = n - 1; i >= 0; i--) { |
| 368 |
if (SoundFiles[i].used) |
| 369 |
return i; |
| 370 |
} |
| 371 |
for (i = MAX_SOUND_FILES - 1; i > n; i--) { |
| 372 |
if (SoundFiles[i].used) |
| 373 |
return i; |
| 374 |
} |
| 375 |
|
| 376 |
// this is the only one |
| 377 |
return n; |
| 378 |
} |
| 379 |
// Searches thru all sounds for a specific name, returns -1 if not found |
| 380 |
// or index of sound with name |
| 381 |
int FindSoundFileName(char *name) { |
| 382 |
int i; |
| 383 |
|
| 384 |
ASSERT(name != NULL); |
| 385 |
|
| 386 |
for (i = 0; i < MAX_SOUND_FILES; i++) |
| 387 |
if (SoundFiles[i].used && !stricmp(name, SoundFiles[i].name)) |
| 388 |
return i; |
| 389 |
|
| 390 |
return -1; |
| 391 |
} |
| 392 |
|
| 393 |
// gets the filename from a path, plus appends our .wav extension |
| 394 |
void ChangeSoundFileName(const char *src, char *dest) { |
| 395 |
int limit; |
| 396 |
char path[256], ext[256], filename[256]; |
| 397 |
|
| 398 |
limit = PAGENAME_LEN - 5; |
| 399 |
|
| 400 |
ddio_SplitPath(src, path, filename, ext); |
| 401 |
|
| 402 |
// Make sure we don't go over our name length limit |
| 403 |
strncpy(dest, filename, limit); |
| 404 |
|
| 405 |
strcat(dest, ".wav"); |
| 406 |
} |
| 407 |
|
| 408 |
// Given a filename, loads the sound file. |
| 409 |
int LoadSoundFile(const char *filename, float import_volume, bool f_get_data) { |
| 410 |
int sound_file_index; |
| 411 |
char extension[10]; |
| 412 |
char name[90]; |
| 413 |
int len; |
| 414 |
|
| 415 |
ChangeSoundFileName(filename, name); |
| 416 |
|
| 417 |
// See if the file was already loaded |
| 418 |
sound_file_index = FindSoundFileName(name); |
| 419 |
if (sound_file_index != -1) |
| 420 |
return sound_file_index; |
| 421 |
|
| 422 |
// Make room for the new sound |
| 423 |
sound_file_index = AllocSoundFile(); |
| 424 |
if (sound_file_index == -1) { |
| 425 |
mprintf(0, "SOUND LOADER: No free sound file slots are available.\n", filename); |
| 426 |
Int3(); |
| 427 |
return -1; |
| 428 |
} |
| 429 |
|
| 430 |
// Validate the extension length |
| 431 |
|
| 432 |
len = strlen(filename); |
| 433 |
if (len < 4) { |
| 434 |
mprintf(0, "SOUND LOADER: %s does not have a 3 charactor extension.\n", filename); |
| 435 |
Int3(); // Get chris |
| 436 |
goto error_state; |
| 437 |
} |
| 438 |
|
| 439 |
strcpy(SoundFiles[sound_file_index].name, name); |
| 440 |
|
| 441 |
// Load the file by its type (as defined by the extension) |
| 442 |
strncpy(extension, &filename[len - 3], 5); |
| 443 |
if (strnicmp("wav", extension, 3) == 0) { |
| 444 |
if (!SoundLoadWaveFile(filename, import_volume, sound_file_index, false, f_get_data)) { |
| 445 |
mprintf(0, "SOUND LOADER: Error loading %s.\n", filename); |
| 446 |
goto error_state; |
| 447 |
} |
| 448 |
} else { |
| 449 |
mprintf(0, "SOUND LOADER: %s in not a supported file type.\n", extension); |
| 450 |
goto error_state; |
| 451 |
} |
| 452 |
|
| 453 |
return sound_file_index; |
| 454 |
|
| 455 |
error_state: |
| 456 |
if (SoundFiles[sound_file_index].used) |
| 457 |
FreeSoundFile(sound_file_index); |
| 458 |
return -1; |
| 459 |
} |
| 460 |
|
| 461 |
// Sets all sounds to unused |
| 462 |
void InitSounds() { |
| 463 |
int i; |
| 464 |
|
| 465 |
for (i = 0; i < MAX_SOUNDS; i++) { |
| 466 |
Sounds[i].used = 0; |
| 467 |
Sounds[i].name[0] = 0; |
| 468 |
Sounds[i].flags = 0; |
| 469 |
} |
| 470 |
Num_sounds = 0; |
| 471 |
|
| 472 |
for (i = 0; i < MAX_SOUND_FILES; i++) { |
| 473 |
SoundFiles[i].name[0] = 0; |
| 474 |
SoundFiles[i].used = 0; |
| 475 |
} |
| 476 |
Num_sound_files = 0; |
| 477 |
} |
| 478 |
|
| 479 |
// Allocs a sound for use, returns -1 if error, else index on success |
| 480 |
int AllocSound() { |
| 481 |
// Don't alloc sound 0, because 0 means something special (default/none) |
| 482 |
for (int i = 1; i < MAX_SOUNDS; i++) { |
| 483 |
if (Sounds[i].used == 0) { |
| 484 |
memset(&Sounds[i], 0, sizeof(sound_info)); |
| 485 |
|
| 486 |
Sounds[i].min_distance = 10.0; |
| 487 |
Sounds[i].max_distance = 256.0; |
| 488 |
Sounds[i].outer_cone_volume = 1.0; |
| 489 |
Sounds[i].inner_cone_angle = 360; |
| 490 |
Sounds[i].outer_cone_angle = 360; |
| 491 |
Sounds[i].import_volume = 1.0; |
| 492 |
|
| 493 |
Sounds[i].flags = SPF_LISTENER_UPDATE; |
| 494 |
|
| 495 |
Sounds[i].used = 1; |
| 496 |
Num_sounds++; |
| 497 |
return i; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
Int3(); // No sounds free! |
| 502 |
return -1; |
| 503 |
} |
| 504 |
|
| 505 |
// Frees sound index n |
| 506 |
void FreeSound(int n) { |
| 507 |
ASSERT(Sounds[n].used > 0); |
| 508 |
|
| 509 |
Sounds[n].used = 0; |
| 510 |
Sounds[n].name[0] = 0; |
| 511 |
Sounds[n].flags = 0; |
| 512 |
Num_sounds--; |
| 513 |
} |
| 514 |
|
| 515 |
// Gets next sound from n that has actually been alloced |
| 516 |
int GetNextSound(int n) { |
| 517 |
int i; |
| 518 |
|
| 519 |
ASSERT(n >= 0 && n < MAX_SOUNDS); |
| 520 |
|
| 521 |
if (Num_sounds == 0) |
| 522 |
return -1; |
| 523 |
|
| 524 |
for (i = n + 1; i < MAX_SOUNDS; i++) |
| 525 |
if (Sounds[i].used) |
| 526 |
return i; |
| 527 |
for (i = 0; i < n; i++) |
| 528 |
if (Sounds[i].used) |
| 529 |
return i; |
| 530 |
|
| 531 |
// this is the only one |
| 532 |
|
| 533 |
return n; |
| 534 |
} |
| 535 |
|
| 536 |
// Gets previous sound from n that has actually been alloced |
| 537 |
int GetPrevSound(int n) { |
| 538 |
int i; |
| 539 |
|
| 540 |
ASSERT(n >= 0 && n < MAX_SOUNDS); |
| 541 |
|
| 542 |
if (Num_sounds == 0) |
| 543 |
return -1; |
| 544 |
|
| 545 |
for (i = n - 1; i >= 0; i--) { |
| 546 |
if (Sounds[i].used) |
| 547 |
return i; |
| 548 |
} |
| 549 |
for (i = MAX_SOUNDS - 1; i > n; i--) { |
| 550 |
if (Sounds[i].used) |
| 551 |
return i; |
| 552 |
} |
| 553 |
|
| 554 |
// this is the only one |
| 555 |
return n; |
| 556 |
} |
| 557 |
// Searches thru all sounds for a specific name, returns -1 if not found |
| 558 |
// or index of sound with name |
| 559 |
int FindSoundName(const char *name) { |
| 560 |
int i; |
| 561 |
|
| 562 |
ASSERT(name != NULL); |
| 563 |
|
| 564 |
for (i = 0; i < MAX_SOUNDS; i++) |
| 565 |
if (Sounds[i].used && !stricmp(name, Sounds[i].name)) |
| 566 |
return i; |
| 567 |
|
| 568 |
return -1; |
| 569 |
} |
| 570 |
|
| 571 |
// Given a filename, loads the sound. |
| 572 |
int LoadSound(char *filename) { |
| 573 |
int sound_handle; |
| 574 |
|
| 575 |
sound_handle = mng_GetGuaranteedSoundPage(filename); |
| 576 |
|
| 577 |
return sound_handle; |
| 578 |
} |
| 579 |
|
| 580 |
void RemapSounds() { |
| 581 |
// Loop through the static sounds and move them to the correct slots |
| 582 |
for (int i = 0; i < NUM_STATIC_SOUNDS; i++) { |
| 583 |
|
| 584 |
int cur_index = FindSoundName(Static_sound_names[i]); |
| 585 |
|
| 586 |
if (cur_index == -1) { |
| 587 |
Int3(); // couldn't find statically-mapped sound |
| 588 |
continue; |
| 589 |
} |
| 590 |
|
| 591 |
if (cur_index != i) { // not in right slot |
| 592 |
|
| 593 |
if (Sounds[i].used) { // someone else in this slot, so swap |
| 594 |
sound_info tsound = Sounds[i]; |
| 595 |
Sounds[i] = Sounds[cur_index]; |
| 596 |
Sounds[cur_index] = tsound; |
| 597 |
RemapAllSoundObjects(i, MAX_SOUNDS); |
| 598 |
RemapAllSoundObjects(cur_index, i); |
| 599 |
RemapAllSoundObjects(MAX_SOUNDS, cur_index); |
| 600 |
} else { // slot is unused, so just take it |
| 601 |
Sounds[i] = Sounds[cur_index]; |
| 602 |
Sounds[cur_index].used = 0; |
| 603 |
RemapAllSoundObjects(cur_index, i); |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
// goes thru every entity that could possible have a sound index (ie objects, robots, etc) |
| 610 |
// and changes the old index to the new index |
| 611 |
void RemapAllSoundObjects(int old_index, int new_index) { |
| 612 |
int i, j, k; |
| 613 |
|
| 614 |
// Remaps weapon sounds |
| 615 |
for (i = 0; i < MAX_WEAPONS; i++) { |
| 616 |
|
| 617 |
if (Weapons[i].used) { |
| 618 |
for (j = 0; j < MAX_WEAPON_SOUNDS; j++) { |
| 619 |
if (Weapons[i].sounds[j] == old_index) { |
| 620 |
Weapons[i].sounds[j] = new_index; |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
// Remaps all non-wb object sounds |
| 627 |
for (i = 0; i < MAX_OBJECT_IDS; i++) { |
| 628 |
for (j = 0; j < MAX_OBJ_SOUNDS; j++) { |
| 629 |
if (Object_info[i].sounds[j] == old_index) { |
| 630 |
Object_info[i].sounds[j] = new_index; |
| 631 |
} |
| 632 |
} |
| 633 |
if (Object_info[i].ai_info) { |
| 634 |
for (j = 0; j < MAX_AI_SOUNDS; j++) { |
| 635 |
if (Object_info[i].ai_info->sound[j] == old_index) { |
| 636 |
Object_info[i].ai_info->sound[j] = new_index; |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
// Remaps weapon battery sounds contained by generic objects |
| 643 |
for (i = 0; i < MAX_OBJECT_IDS; i++) { |
| 644 |
if (Object_info[i].static_wb) { |
| 645 |
for (j = 0; j < MAX_WBS_PER_OBJ; j++) { |
| 646 |
for (k = 0; k < MAX_WB_FIRING_MASKS; k++) { |
| 647 |
if (Object_info[i].static_wb[j].fm_fire_sound_index[k] == old_index) { |
| 648 |
Object_info[i].static_wb[j].fm_fire_sound_index[k] = new_index; |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
// Remaps anim sounds contained by generic objects |
| 656 |
for (i = 0; i < MAX_OBJECT_IDS; i++) { |
| 657 |
if (Object_info[i].anim) { |
| 658 |
for (j = 0; j < NUM_MOVEMENT_CLASSES; j++) { |
| 659 |
for (k = 0; k < NUM_ANIMS_PER_CLASS; k++) { |
| 660 |
if (Object_info[i].anim[j].elem[k].anim_sound_index == old_index) { |
| 661 |
Object_info[i].anim[j].elem[k].anim_sound_index = new_index; |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
// Remaps weapons contained by Ships |
| 669 |
for (i = 0; i < MAX_SHIPS; i++) { |
| 670 |
for (j = 0; j < MAX_WBS_PER_OBJ; j++) { |
| 671 |
|
| 672 |
if (Ships[i].firing_sound[j] == old_index) { |
| 673 |
Ships[i].firing_sound[j] = new_index; |
| 674 |
} |
| 675 |
|
| 676 |
if (Ships[i].firing_release_sound[j] == old_index) { |
| 677 |
Ships[i].firing_release_sound[j] = new_index; |
| 678 |
} |
| 679 |
|
| 680 |
for (k = 0; k < MAX_WB_FIRING_MASKS; k++) { |
| 681 |
if (Ships[i].static_wb[j].fm_fire_sound_index[k] == old_index) { |
| 682 |
Ships[i].static_wb[j].fm_fire_sound_index[k] = new_index; |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
for (i = 0; i <= Highest_room_index; i++) { |
| 689 |
if (Rooms[i].used) { |
| 690 |
if (Rooms[i].flags & RF_DOOR) { |
| 691 |
door *door = &Doors[Rooms[i].doorway_data->doornum]; |
| 692 |
|
| 693 |
if (door->open_sound == old_index) |
| 694 |
door->open_sound = new_index; |
| 695 |
if (door->close_sound == old_index) |
| 696 |
door->close_sound = new_index; |
| 697 |
} |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
// Remaps textures |
| 702 |
for (i = 0; i < MAX_TEXTURES; i++) { |
| 703 |
if (GameTextures[i].used) { |
| 704 |
if (GameTextures[i].sound == old_index) { |
| 705 |
GameTextures[i].sound = new_index; |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
} |