1 /* Patrick 5/6/97 -------------------------------------------------------------
2   AvP Project sound source
3   ----------------------------------------------------------------------------*/
4 #include "3dc.h"
5 #include "module.h"
6 #include "inline.h"
7 #include "stratdef.h"
8 #include "gamedef.h"
9 #include "gameplat.h"
10 #include "bh_types.h"
11 #include "inventry.h"
12 #include "weapons.h"
13 #include "psnd.h"
14 #include "psndplat.h"
15 #include "avp_menus.h"
16 #include "scream.h"
17 
18 #define UseLocalAssert Yes
19 #include "ourasert.h"
20 #include "ffstdio.h"
21 #include "db.h"
22 #include "dxlog.h"
23 
24 #define PRED_PISTOL_PITCH_CHANGE 300
25 
26 #define CDDA_TEST 			No
27 #define CD_VOLUME_TEST 	No
28 #define SOUND_TEST_3D 	No
29 
30 #define LOAD_SOUND_FROM_FAST_FILE 	   Yes
31 #if 1
32 //allow loading from outside of fastfiles to help with custom levels
33 #define LOAD_SOUND_FROM_FAST_FILE_ONLY No
34 #else
35 #define LOAD_SOUND_FROM_FAST_FILE_ONLY (LOAD_USING_FASTFILES)
36 #endif
37 
38 #define USE_REBSND_LOADERS  (LOAD_USING_FASTFILES||PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO||DEATHMATCH_DEMO)
39 #define USE_COMMON_FLL_FILE  (LOAD_USING_FASTFILES||PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO||DEATHMATCH_DEMO)
40 
41 
42 /* Andy 9/6/97 ----------------------------------------------------------------
43   Internal globals
44 -----------------------------------------------------------------------------*/
45 int weaponHandle = SOUND_NOACTIVEINDEX;
46 
47 #if 0
48 static int weaponReloading = 0;
49 static int backgroundHandle = SOUND_NOACTIVEINDEX;
50 #endif
51 static int sadarReloadTimer = 0;
52 static int weaponPitchTimer = 0;
53 static int playOneShotWS = 1;
54 static int oldRandomValue = -1;
55 
56 #if SOUND_TEST_3D
57 static int testLoop = SOUND_NOACTIVEINDEX;
58 #endif
59 
60 #if CDDA_TEST
61 static int doneCDDA = 0;
62 #endif
63 
64 /* Has the player made a noise? */
65 int playerNoise;
66 
67 /* Patrick 5/6/97 -------------------------------------------------------------
68   External refernces
69   ----------------------------------------------------------------------------*/
70 extern int NormalFrameTime;
71 extern ACTIVESOUNDSAMPLE ActiveSounds[];
72 
73 /* Patrick 5/6/97 -------------------------------------------------------------
74   Function definitions
75   ----------------------------------------------------------------------------*/
76 
77 /* Patrick 16/6/97 ----------------------------------------------------------------
78   A.N.Other background sound management function
79 ------------------------------------------------------------------------------*/
80 
81 #if 0
82 static void DoPredatorBackgroundLoop(void)
83 {
84 	if (backgroundHandle == SOUND_NOACTIVEINDEX)
85   {
86     Sound_Play(SID_VISION_LOOP,"evl",&backgroundHandle,75);
87   }
88 }
89 #endif
90 
91 
DoPlayerSounds(void)92 void DoPlayerSounds(void)
93 {
94 	PLAYER_STATUS *playerStatusPtr;
95 	PLAYER_WEAPON_DATA *weaponPtr;
96 
97 	#if CDDA_TEST
98 	if (doneCDDA == 0)
99 	{
100 		CDDA_SwitchOn();
101 
102 		doneCDDA = 1;
103 
104 		if (AvP.PlayerType == I_Marine) 				CDDA_Play(CDTrack1);
105 		else if (AvP.PlayerType == I_Predator)	CDDA_Play(CDTrack3);
106 		else if (AvP.PlayerType == I_Alien) 		CDDA_Play(CDTrack2);
107 
108 	}
109 	#endif
110 
111  	#if CD_VOLUME_TEST
112 	{
113 		extern unsigned char KeyboardInput[];
114 		static int CDVolume = CDDA_VOLUME_DEFAULT;
115 
116 		if(!CDDA_IsPlaying()) CDDA_Play(CDTrack1);
117 		if(KeyboardInput[KEY_L])
118 		{
119 			CDVolume++;
120 			CDDA_ChangeVolume(CDVolume);
121 		}
122 		else if(KeyboardInput[KEY_K])
123 		{
124 			CDVolume--;
125 			CDDA_ChangeVolume(CDVolume);
126 		}
127 
128 		{
129 			int currentSetting = CDDA_GetCurrentVolumeSetting();
130 			textprint("CD VOL: %d \n",currentSetting);
131 		}
132 	}
133 	#endif
134 
135 	#if SOUND_TEST_3D
136 	if(testLoop == SOUND_NOACTIVEINDEX)
137 	{
138 		VECTORCH zeroLoc = {0,0,0};
139 		Sound_Play(SID_VISION_LOOP,"del",&zeroLoc,&testLoop);
140 	}
141 	#endif
142 
143 	#if 0
144 	/* sort out background sounds */
145 	if(AvP.PlayerType == I_Predator) DoPredatorBackgroundLoop();
146 	else DoBackgroundSound();
147 	#endif
148 
149 	/* do weapon sound */
150 
151  	/* access the extra data hanging off the strategy block */
152 	playerStatusPtr= (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr);
153  	GLOBALASSERT(playerStatusPtr);
154 
155  	/* init a pointer to the weapon's data */
156  	weaponPtr = &(playerStatusPtr->WeaponSlot[playerStatusPtr->SelectedWeaponSlot]);
157 
158  	if (sadarReloadTimer)
159  	{
160  		sadarReloadTimer -= NormalFrameTime;
161  		if (sadarReloadTimer <= 0)
162 		{
163 			sadarReloadTimer = 0;
164 			playerNoise=1;
165 		}
166  	}
167 
168  	/* Handle weapon reloading */
169  	#if 0
170  	if (weaponPtr->CurrentState == WEAPONSTATE_RELOAD_PRIMARY)
171  	{
172  		if (weaponReloading == 0)
173  		{
174    		weaponReloading = 1;
175 
176    		switch (weaponPtr->WeaponIDNumber)
177    		{
178    			case WEAPON_SADAR:
179    				sadarReloadTimer = ONE_FIXED;
180    				break;
181 				case WEAPON_GRENADELAUNCHER:
182    				Sound_Play(SID_NADELOAD,"h");
183 				playerNoise=1;
184    				break;
185    			case WEAPON_FLAMETHROWER:
186    				/* Flame thrower reload? */
187    				break;
188    			case WEAPON_SMARTGUN:
189    				Sound_Play(SID_LONGLOAD,"h");
190 				playerNoise=1;
191    				break;
192    			case WEAPON_FRISBEE_LAUNCHER:
193    				sadarReloadTimer = ONE_FIXED;
194    				break;
195 				case WEAPON_GRENADELAUNCHER:
196    				Sound_Play(SID_NADELOAD,"h");
197 				playerNoise=1;
198    				break;
199    			default:
200    				Sound_Play(SID_SHRTLOAD,"h");
201 				playerNoise=1;
202    				break;
203 		 	}
204  		}
205 	}
206 	else
207 	{
208   	weaponReloading = 0;
209 	}
210 	#endif
211 
212 	switch(weaponPtr->WeaponIDNumber)
213 	{
214 		case(WEAPON_PRED_PISTOL):
215 		{
216 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
217 			{
218 		 		if(weaponHandle == SOUND_NOACTIVEINDEX)
219 				{
220 		 		  //Sound_Play(SID_PULSE_START,"hp",-PRED_PISTOL_PITCH_CHANGE);
221 				  //Sound_Play(SID_PULSE_LOOP,"elhp",&weaponHandle,-PRED_PISTOL_PITCH_CHANGE);
222 			   	  //weaponPitchTimer=ONE_FIXED>>3;
223 				  Sound_Play(SID_PRED_PISTOL,"h");
224 					playerNoise=1;
225 			  	}
226 				else
227 				{
228 					//weaponPitchTimer-=NormalFrameTime;
229 					//if (weaponPitchTimer<=0)
230 					//{
231 					//	weaponPitchTimer=ONE_FIXED>>3;
232 					//	Sound_ChangePitch(weaponHandle,(FastRandom()&63)-(32+PRED_PISTOL_PITCH_CHANGE));
233 					//}
234 				}
235 			}
236 	   		else
237 			{
238 				//if(weaponHandle != SOUND_NOACTIVEINDEX)
239 				//{
240 		          //if (ActiveSounds[weaponHandle].soundIndex == SID_PULSE_LOOP)
241 		          //{
242 			      //    Sound_Play(SID_PULSE_END,"hp",-PRED_PISTOL_PITCH_CHANGE);
243 				  //	  Sound_Stop(weaponHandle);
244 			 	  //}
245 			 	//}
246 			}
247   		break;
248    	}
249 
250 		case(WEAPON_PULSERIFLE):
251 		{
252 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
253 			{
254 		 		if(weaponHandle == SOUND_NOACTIVEINDEX)
255 				{
256 		 		  Sound_Play(SID_PULSE_START,"h");
257 			   	Sound_Play(SID_PULSE_LOOP,"elh",&weaponHandle);
258 					playerNoise=1;
259 			   	weaponPitchTimer=ONE_FIXED>>3;
260 			  }
261 				else
262 				{
263 					weaponPitchTimer-=NormalFrameTime;
264 					if (weaponPitchTimer<=0)
265 					{
266 						weaponPitchTimer=ONE_FIXED>>3;
267 						Sound_ChangePitch(weaponHandle,(FastRandom()&63)-32);
268 						playerNoise=1;
269 					}
270 				}
271 			}
272    		else if (weaponPtr->CurrentState == WEAPONSTATE_FIRING_SECONDARY)
273    		{
274    			if (weaponHandle == SOUND_NOACTIVEINDEX)
275    			{
276      			Sound_Play(SID_NADEFIRE,"h");
277 				playerNoise=1;
278    			}
279 	 		}
280    		else
281 			{
282 				if(weaponHandle != SOUND_NOACTIVEINDEX)
283 				{
284          	Sound_Play(SID_PULSE_END,"h");
285 				  Sound_Stop(weaponHandle);
286 			 	}
287 			}
288    		break;
289    	}
290 
291    	case(WEAPON_FLAMETHROWER):
292 		{
293 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
294 			{
295 	 			if(weaponHandle == SOUND_NOACTIVEINDEX)
296 				{
297 	    		Sound_Play(SID_INCIN_START,"h");
298 	  			Sound_Play(SID_INCIN_LOOP,"elh",&weaponHandle);
299 				playerNoise=1;
300 			}
301 	  	}
302 			else
303 			{
304 				if(weaponHandle != SOUND_NOACTIVEINDEX)
305 				{
306 					Sound_Play(SID_INCIN_END,"h");
307 					Sound_Stop(weaponHandle);
308 		 		}
309 			}
310      	break;
311 		}
312 
313    	case (WEAPON_MINIGUN):
314    	{
315 		#if 0
316      	if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
317      	{
318      		if(weaponHandle == SOUND_NOACTIVEINDEX) {
319      			Sound_Play(SID_MINIGUN_LOOP,"elh",&weaponHandle);
320 				playerNoise=1;
321 			}
322 	   	}
323      	else
324      	{
325      		if(weaponHandle != SOUND_NOACTIVEINDEX)
326      		{
327        		Sound_Play(SID_MINIGUN_END,"h");
328        		Sound_Stop(weaponHandle);
329      		}
330      	}
331 		#else
332         if (PlayerStatusPtr->IsAlive==0) {
333      		if(weaponHandle != SOUND_NOACTIVEINDEX)
334      		{
335        		Sound_Play(SID_MINIGUN_END,"h");
336        		Sound_Stop(weaponHandle);
337      		}
338 		}
339 		#endif
340      	break;
341    	}
342 
343    	case (WEAPON_AUTOSHOTGUN):
344    	{
345      	if (weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
346      	{
347 	   		Sound_Play(SID_SHOTGUN,"h");
348 			playerNoise=1;
349 	 	}
350      	break;
351    	}
352 
353    	case (WEAPON_MARINE_PISTOL):
354    	case (WEAPON_TWO_PISTOLS):
355    	{
356      	if ((weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
357 			||(weaponPtr->CurrentState == WEAPONSTATE_FIRING_SECONDARY))
358      	{
359 	   		Sound_Play(SID_SHOTGUN,"h");
360 			playerNoise=1;
361 	 	}
362 
363      	break;
364    	}
365 
366  	case (WEAPON_SADAR):
367    	{
368      	if (weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
369      	{
370   	 		Sound_Play(SID_SADAR_FIRE,"h");
371 			playerNoise=1;
372 	 	}
373      	break;
374    	}
375 
376  	case (WEAPON_FRISBEE_LAUNCHER):
377    	{
378      	if (weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
379      	{
380 			if (weaponPtr->StateTimeOutCounter == WEAPONSTATE_INITIALTIMEOUTCOUNT) {
381 				playerNoise=1;
382 	 			if (weaponHandle == SOUND_NOACTIVEINDEX) {
383 		  	 		Sound_Play(SID_ED_SKEETERCHARGE,"eh",&weaponHandle);
384 				}
385 			} else {
386 	 			if (weaponHandle == SOUND_NOACTIVEINDEX) {
387 					playerNoise=0;
388 				}
389 			}
390 	 	} else {
391  			if (weaponHandle != SOUND_NOACTIVEINDEX) {
392 				Sound_Stop(weaponHandle);
393 			}
394 		}
395      	break;
396    	}
397 
398 
399    	case(WEAPON_SMARTGUN):
400 		{
401 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
402 			{
403 				if(weaponHandle == SOUND_NOACTIVEINDEX)
404 				{
405 				 	unsigned int rand=FastRandom() % 3;
406          	if (rand == oldRandomValue) rand=(rand + 1) % 3;
407          	oldRandomValue = rand;
408 			playerNoise=1;
409          	switch (rand)
410          	{
411          		case 0:
412          		{
413           		Sound_Play(SID_SMART1,"ehp",&weaponHandle,(FastRandom()&255)-128);
414           		break;
415          		}
416         		case 1:
417          		{
418           		Sound_Play(SID_SMART2,"ehp",&weaponHandle,(FastRandom()&255)-128);
419           		break;
420          		}
421         		case 2:
422          		{
423           		Sound_Play(SID_SMART3,"ehp",&weaponHandle,(FastRandom()&255)-128);
424           		break;
425          		}
426 			 		default:
427 				 		{
428 				 			break;
429 				 		}
430 				 	}
431 			 	}
432      	}
433 			break;
434 		}
435 
436 		case(WEAPON_GRENADELAUNCHER):
437 		{
438 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
439 			{
440 				if(playOneShotWS)
441 				{
442 					Sound_Play(SID_ROCKFIRE,"h");
443 					playerNoise=1;
444 					playOneShotWS = 0;
445 				}
446 			}
447 			else playOneShotWS = 1;
448 			break;
449 		}
450 
451 		case(WEAPON_PRED_WRISTBLADE):
452 		{
453 			#if 0
454 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
455 			{
456 				if(playOneShotWS)
457 				{
458 		        	unsigned int rand=FastRandom() % 6;
459 		        	if (rand == oldRandomValue) rand = (rand + 1) % 6;
460 	     			oldRandomValue = rand;
461 				  	switch (rand)
462 		        	{
463 		         		case 0:
464 		        		{
465 			          		Sound_Play(SID_SWIPE,"ehp",&weaponHandle,(FastRandom()&255)-128);
466 			          		break;
467 			          	}
468 			          	case 1:
469 			          	{
470 			          		Sound_Play(SID_SWIPE2,"ehp",&weaponHandle,(FastRandom()&255)-128);
471 			          		break;
472 			          	}
473 			          	case 2:
474 			          	{
475 			  	       		Sound_Play(SID_SWIPE3,"ehp",&weaponHandle,(FastRandom()&255)-128);
476 				         		break;
477 			           	}
478 						case 3:
479 			          	{
480 			          		Sound_Play(SID_SWIPE4,"ehp",&weaponHandle,(FastRandom()&255)-128);
481 			         		break;
482 			         	}
483 						case 4:
484 			         	{
485 			         		Sound_Play(SID_PRED_SLASH,"ehp",&weaponHandle,(FastRandom()&255)-128);
486 			        		break;
487 			         	}
488 						case 5:
489 			         	{
490 			        		Sound_Play(SID_RIP,"ehp",&weaponHandle,(FastRandom()&255)-128);
491 				       		break;
492 			         	}
493 					 	default:
494 					 	{
495 					 		break;
496 					 	}
497 				 	}
498 					playOneShotWS = 0;
499 				}
500 			}
501 			else playOneShotWS = 1;
502 			#endif
503 			break;
504 		}
505 
506 		case(WEAPON_ALIEN_CLAW):
507 		{
508 			#if 0
509 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
510 			{
511 				if(playOneShotWS)
512 				{
513 	       			unsigned int rand=FastRandom() & 3;
514         			if (rand == oldRandomValue) rand=(rand + 1) & 3;
515 
516 				   	oldRandomValue = rand;
517         			switch (rand)
518         			{
519          				case 0:
520          				{
521           					Sound_Play(SID_SWIPE,"ehp",&weaponHandle,(FastRandom()&255)-128);
522           					break;
523           				}
524           				case 1:
525           				{
526           					Sound_Play(SID_SWIPE2,"ehp",&weaponHandle,(FastRandom()&255)-128);
527           					break;
528           				}
529           				case 2:
530           				{
531           					Sound_Play(SID_SWIPE3,"ehp",&weaponHandle,(FastRandom()&255)-128);
532           					break;
533            				}
534 						case 3:
535           				{
536           					Sound_Play(SID_SWIPE4,"ehp",&weaponHandle,(FastRandom()&255)-128);
537           					break;
538            				}
539 						default:
540 						{
541 							break;
542 						}
543 					}
544 			 		playOneShotWS = 0;
545 				}
546 			} else {
547 				playOneShotWS = 1;
548 			}
549 			#endif
550 			break;
551 		}
552 
553 		case(WEAPON_ALIEN_GRAB):
554 		{
555 			#if 0
556 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
557 			{
558 				if(playOneShotWS)
559 				{
560 			  	unsigned int rand=FastRandom() & 1;
561        		if (rand == oldRandomValue) rand=(rand + 1) & 1;
562 					oldRandomValue = rand;
563 			   	switch (rand)
564         	{
565          		case 0:
566          		{
567           		Sound_Play(SID_SWISH,"ehp",&weaponHandle,(FastRandom()&255)-128);
568           		break;
569           	}
570           	case 1:
571           	{
572           		Sound_Play(SID_TAIL,"ehp",&weaponHandle,(FastRandom()&255)-128);
573           		break;
574           	}
575 
576 					 	default:
577 					 	{
578 					 		break;
579 					 	}
580 				 	}
581 			 		playOneShotWS = 0;
582 				}
583 			}
584 			else playOneShotWS = 1;
585 			#endif
586 			break;
587 		}
588 
589 		case(WEAPON_PRED_RIFLE):
590 		{
591 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
592 			{
593 				if(playOneShotWS)
594 				{
595 					Sound_Play(SID_PRED_LASER,"hp",(FastRandom()&255)-128);
596 					playerNoise=1;
597 					playOneShotWS = 0;
598 				}
599 			}
600 			else playOneShotWS = 1;
601 			break;
602 		}
603 
604 		case(WEAPON_PRED_SHOULDERCANNON):
605 		{
606 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
607 			{
608 				if(playOneShotWS)
609 				{
610 					//Sound_Play(SID_PRED_LAUNCHER,"hp",(FastRandom()&255)-128);
611 					playOneShotWS = 0;
612 				}
613 			}
614 			else playOneShotWS = 1;
615 			break;
616 		}
617 
618 		case(WEAPON_PRED_DISC):
619 		{
620 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
621 			{
622 				if(playOneShotWS)
623 				{
624 					Sound_Play(SID_PRED_FRISBEE,"hp",(FastRandom()&255)-128);
625 					playerNoise=1;
626 					playOneShotWS = 0;
627 				}
628 			}
629 			else playOneShotWS = 1;
630 			break;
631 		}
632 
633 		case(WEAPON_ALIEN_SPIT):
634 		{
635 			if(weaponPtr->CurrentState == WEAPONSTATE_FIRING_PRIMARY)
636 			{
637 				if(playOneShotWS)
638 				{
639 				 	Sound_Play(SID_ACID_SPRAY,"hp",(FastRandom()&255)-128);
640 					playerNoise=1;
641 			 		playOneShotWS = 0;
642 				}
643 			}
644 			else playOneShotWS = 1;
645 			break;
646 		}
647 		default:
648 		{
649 			break;
650 		}
651 	}
652 }
653 
654 static int SpotEffectWeaponHandle = SOUND_NOACTIVEINDEX;
PlayWeaponClickingNoise(enum WEAPON_ID weaponIDNumber)655 void PlayWeaponClickingNoise(enum WEAPON_ID weaponIDNumber)
656 {
657  	if(SpotEffectWeaponHandle != SOUND_NOACTIVEINDEX)
658 		return;
659 
660 	switch(weaponIDNumber)
661 	{
662 		// Marine weapons
663 		case WEAPON_PULSERIFLE:
664 		{
665  			Sound_Play(SID_PULSE_RIFLE_FIRING_EMPTY,"eh",&SpotEffectWeaponHandle);
666 			break;
667 		}
668 		case WEAPON_SMARTGUN:
669 		{
670  			Sound_Play(SID_NOAMMO,"eh",&SpotEffectWeaponHandle);
671 			break;
672 		}
673 		case WEAPON_MINIGUN:
674 		{
675 			#if 0
676 			Sound_Play(SID_MINIGUN_EMPTY,"eh",&SpotEffectWeaponHandle);
677 			#endif
678 			break;
679 		}
680 		// Predator weapons
681 		case WEAPON_PRED_RIFLE:
682 		{
683 			Sound_Play(SID_PREDATOR_SPEARGUN_EMPTY,"eh",&SpotEffectWeaponHandle);
684 			break;
685 		}
686 
687 		default:
688 			break;
689 	}
690 }
691 
692 
MakeRicochetSound(VECTORCH * position)693 void MakeRicochetSound(VECTORCH *position)
694 {
695 	switch(NormalFrameTime&0x3)
696 	{
697 		case(0):
698 			Sound_Play(SID_RICOCH1,"pd",((FastRandom()&255)-128),position);
699 			break;
700 		case(1):
701 			Sound_Play(SID_RICOCH2,"pd",((FastRandom()&255)-128),position);
702 			break;
703 		case(2):
704 			Sound_Play(SID_RICOCH3,"pd",((FastRandom()&255)-128),position);
705 			break;
706 		case(3):
707 			Sound_Play(SID_RICOCH4,"pd",((FastRandom()&255)-128),position);
708 			break;
709 		default:
710 			break;
711 	}
712 }
713 
714 
715 
PlayAlienSwipeSound(void)716 void PlayAlienSwipeSound(void) {
717 
718 	#if 0
719 	 unsigned int rand=FastRandom() & 3;
720      if (rand == oldRandomValue) rand=(rand + 1) & 3;
721 
722 	 oldRandomValue = rand;
723      switch (rand)
724      {
725      	case 0:
726      	{
727      		Sound_Play(SID_SWIPE,"ehp",&weaponHandle,(FastRandom()&255)-128);
728      		break;
729      	}
730      	case 1:
731      	{
732      		Sound_Play(SID_SWIPE2,"ehp",&weaponHandle,(FastRandom()&255)-128);
733      		break;
734      	}
735      	case 2:
736      	{
737      		Sound_Play(SID_SWIPE3,"ehp",&weaponHandle,(FastRandom()&255)-128);
738      		break;
739      	}
740 	 	case 3:
741      	{
742      		Sound_Play(SID_SWIPE4,"ehp",&weaponHandle,(FastRandom()&255)-128);
743      		break;
744      	}
745 	 	default:
746 	 	{
747 	 		break;
748 	 	}
749 	 }
750 	#else
751 	PlayAlienSound(0,ASC_Swipe,((FastRandom()&255)-128),
752 		&weaponHandle,NULL);
753 	#endif
754 }
755 
PlayAlienTailSound(void)756 void PlayAlienTailSound(void) {
757 
758 	PlayAlienSound(0,ASC_TailSound,((FastRandom()&255)-128),
759 		&weaponHandle,NULL);
760 
761 }
762 
PlayPredSlashSound(void)763 void PlayPredSlashSound(void) {
764 
765 	#if 0
766 	unsigned int rand=FastRandom() % 6;
767 	if (rand == oldRandomValue) rand = (rand + 1) % 6;
768 	oldRandomValue = rand;
769 	switch (rand)
770 	{
771 		case 0:
772 		{
773 	  		Sound_Play(SID_SWIPE,"ehp",&weaponHandle,(FastRandom()&255)-128);
774 	  		break;
775 	  	}
776 	  	case 1:
777 	  	{
778 	  		Sound_Play(SID_SWIPE2,"ehp",&weaponHandle,(FastRandom()&255)-128);
779 	  		break;
780 	  	}
781 	  	case 2:
782 	  	{
783 	   		Sound_Play(SID_SWIPE3,"ehp",&weaponHandle,(FastRandom()&255)-128);
784 	     		break;
785 	   	}
786 		case 3:
787 	  	{
788 	  		Sound_Play(SID_SWIPE4,"ehp",&weaponHandle,(FastRandom()&255)-128);
789 	 		break;
790 	 	}
791 		case 4:
792 	 	{
793 	   		Sound_Play(SID_SWIPE3,"ehp",&weaponHandle,(FastRandom()&255)-128);
794 			break;
795 	 	}
796 		case 5:
797 	 	{
798 	  		Sound_Play(SID_SWIPE2,"ehp",&weaponHandle,(FastRandom()&255)-128);
799 	   		break;
800 	 	}
801 	 	default:
802 	 	{
803 	 		break;
804 	 	}
805 	}
806 	#else
807 	PlayPredatorSound(0,PSC_Swipe,((FastRandom()&255)-128),
808 		&weaponHandle,NULL);
809 	#endif
810 }
811 
PlayCudgelSound(void)812 void PlayCudgelSound(void) {
813 
814 	unsigned int rand=FastRandom() % 4;
815 	if (rand == oldRandomValue) rand = (rand + 1) % 4;
816 	oldRandomValue = rand;
817 	switch (rand)
818 	{
819 		case 0:
820 		{
821 	  		Sound_Play(SID_PULSE_SWIPE01,"ehp",&weaponHandle,(FastRandom()&255)-128);
822 	  		break;
823 	  	}
824 	  	case 1:
825 	  	{
826 	  		Sound_Play(SID_PULSE_SWIPE02,"ehp",&weaponHandle,(FastRandom()&255)-128);
827 	  		break;
828 	  	}
829 	  	case 2:
830 	  	{
831 	   		Sound_Play(SID_PULSE_SWIPE03,"ehp",&weaponHandle,(FastRandom()&255)-128);
832 	     		break;
833 	   	}
834 		case 3:
835 	  	{
836 	  		Sound_Play(SID_PULSE_SWIPE04,"ehp",&weaponHandle,(FastRandom()&255)-128);
837 	 		break;
838 	 	}
839 	 	default:
840 	 	{
841 	 		break;
842 	 	}
843 	}
844 
845 }
846 
847 
848 char * SecondSoundDir = 0;
849 static const char * FirstSoundDir = "SOUND\\";
850 
FindAndLoadWavFile(int soundNum,char * wavFileName)851 int FindAndLoadWavFile(int soundNum,char* wavFileName)
852 {
853 	static char sound_name[200];
854 	sprintf (sound_name, "%s%s", FirstSoundDir,wavFileName);
855 
856 #if LOAD_SOUND_FROM_FAST_FILE
857 	//first look in fast file
858 	{
859 		size_t nLen;
860 		if(ffreadbuf(sound_name,&nLen))
861 		{
862 			return LoadWavFromFastFile(soundNum,sound_name);
863 		}
864 	}
865 #endif
866 
867 #if !LOAD_SOUND_FROM_FAST_FILE_ONLY
868 	//look for sound locally
869 	{
870 
871 		{
872 			//check to see if file exists locally first
873 			FILE* wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
874 			if(!wavFile && SecondSoundDir)
875 			{
876 				//look for sound over network
877 				sprintf (sound_name, "%s%s", SecondSoundDir,wavFileName);
878 
879 				wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
880 				if(!wavFile) {
881 					LOGDXFMT(("Failed to find %s\n",wavFileName));
882 					return 0;
883 				}
884 
885 			}
886 			fclose(wavFile);
887 		}
888 
889 		return LoadWavFile(soundNum,sound_name) ;
890 	}
891 #else
892 	LOGDXFMT(("Failed to find %s\n",wavFileName));
893 	return 0;
894 #endif
895 }
896 
897 
898 
899 /* Patrick 5/6/97 -------------------------------------------------------------
900   Sound data loaders
901   ----------------------------------------------------------------------------*/
902 
903 extern unsigned char *ExtractWavFile(int soundIndex, unsigned char *bufferPtr);
LoadRebSndFile(char * filename)904 void *LoadRebSndFile(char *filename)
905 {
906 	void *bufferPtr;
907 	long int save_pos, size_of_file;
908 	FILE *fp;
909 	fp = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
910 
911 	if (!fp) goto error;
912 
913 	save_pos=ftell(fp);
914 	fseek(fp,0L,SEEK_END);
915 	size_of_file=ftell(fp);
916 	fseek(fp,save_pos,SEEK_SET);
917 
918 	bufferPtr = AllocateMem(size_of_file);
919 	LOCALASSERT(bufferPtr);
920 
921 
922 	if (!fread(bufferPtr, size_of_file,1,fp))
923 	{
924 		fclose(fp);
925 		DeallocateMem(bufferPtr);
926 		goto error;
927 	}
928 
929 	fclose(fp);
930 	return bufferPtr;
931 
932 error:
933 	{
934 		return 0;
935 	}
936 }
937 
ReleaseRebSndFile(void * bufferPtr)938 void ReleaseRebSndFile(void *bufferPtr)
939 {
940 	LOCALASSERT(bufferPtr);
941 	DeallocateMem(bufferPtr);
942 }
943 
LoadSounds(char * soundDirectory)944 void LoadSounds(char *soundDirectory)
945 {
946 	void *rebSndBuffer;
947 	unsigned char *bufferPtr;
948 	int soundIndex;
949 	int pitch;
950 
951 	LOCALASSERT(soundDirectory);
952 
953 	/* first check that sound has initialised and is turned on */
954 	if(!SoundSys_IsOn()) return;
955 
956 	/* load RebSnd file into a (big) buffer	*/
957 	{
958 		char filename[64];
959 #if ALIEN_DEMO
960 		strcpy(filename, "./alienfastfile");
961 #else
962 		strcpy(filename, "./fastfile");
963 #endif
964 		strcat(filename, "/common.ffl");
965 
966 		rebSndBuffer = LoadRebSndFile(filename);
967 
968 		if (!rebSndBuffer)
969 		{
970 			LOCALASSERT(0);
971 			return;
972 		}
973 	}
974 
975 	/* Process the file */
976 	bufferPtr = (unsigned char*) rebSndBuffer;
977 	soundIndex = (int)(*bufferPtr++);
978 	pitch = (int)((signed char)(*bufferPtr++));
979 	while((soundIndex!=0xff)||(pitch!=-1))
980 	{
981 		if((soundIndex<0)||(soundIndex>=SID_MAXIMUM))
982 		{
983 			/* invalid sound number */
984 			LOCALASSERT("Invalid Sound Index"==0);
985 		}
986 		if(GameSounds[soundIndex].loaded)
987 		{
988 			/* Duplicate game sound loaded */
989 			LOCALASSERT("Duplicate game sound loaded"==0);
990 		}
991 
992 	  	bufferPtr = ExtractWavFile(soundIndex, bufferPtr);
993 
994 	  	GameSounds[soundIndex].loaded = 1;
995 		GameSounds[soundIndex].activeInstances = 0;
996 		GameSounds[soundIndex].volume = VOLUME_DEFAULT;
997 
998 		/* pitch offset is in semitones: need to convert to 1/128ths */
999 		GameSounds[soundIndex].pitch = pitch;
1000 
1001 		InitialiseBaseFrequency(soundIndex);
1002 		soundIndex = (int)(*bufferPtr++);
1003 		pitch = (int)((signed char)(*bufferPtr++));
1004 	}
1005 
1006 	ReleaseRebSndFile(rebSndBuffer);
1007 }
1008