Advertisement
Guest User

Untitled

a guest
Aug 13th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.26 KB | None | 0 0
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "Utils All.h"
  3. #else
  4. #include "types.h"
  5. #include "Music Control.h"
  6. #include "soundman.h"
  7. #include "Random.h"
  8. #include "jascreens.h"
  9. #include "overhead.h"
  10. #include "timer control.h"
  11. #include "strategicmap.h"
  12. #endif
  13.  
  14. //extern int iScreenMode;
  15.  
  16. static UINT32 uiMusicHandle = NO_SAMPLE;
  17. static BOOLEAN fMusicPlaying = FALSE;
  18.  
  19. static BOOLEAN fMusicFadingOut = FALSE;
  20. static BOOLEAN fMusicFadingIn = FALSE;
  21. static UINT32 uiMusicVolume = 50;
  22.  
  23. static BOOLEAN gfMusicEnded = FALSE;
  24.  
  25. static UINT8 gubMusicMode = 0;
  26.  
  27. static UINT8 gubOldMusicMode = 0;
  28.  
  29. static INT8 gbVictorySongCount = 0;
  30. static INT8 gbDeathSongCount = 0;
  31.  
  32. static INT8 bNothingModeSong;
  33. static INT8 bEnemyModeSong;
  34. static INT8 bBattleModeSong;
  35.  
  36. static BOOLEAN gfUseCreatureMusic = FALSE;
  37.  
  38. static INT8 gbFadeSpeed = 1;
  39.  
  40. static BOOLEAN gfDontRestartSong = FALSE;
  41. // unused
  42. //BOOLEAN gfForceMusicToTense = FALSE;
  43.  
  44.  
  45. CHAR8 *szMusicList[NUM_MUSIC]=
  46. {
  47. "MUSIC\\marimbad 2",
  48. "MUSIC\\menumix1",
  49. "MUSIC\\nothing A",
  50. "MUSIC\\nothing B",
  51. "MUSIC\\nothing C",
  52. "MUSIC\\nothing D",
  53. "MUSIC\\tensor A",
  54. "MUSIC\\tensor B",
  55. "MUSIC\\tensor C",
  56. "MUSIC\\triumph",
  57. "MUSIC\\death",
  58. "MUSIC\\battle A",
  59. "MUSIC\\battle B",
  60. "MUSIC\\battle c",
  61. "MUSIC\\battle D",
  62. "MUSIC\\battle E",
  63. "MUSIC\\battle F",
  64. "MUSIC\\battle G",
  65. "MUSIC\\battle H",
  66. "MUSIC\\battle I",
  67. "MUSIC\\creepy",
  68. "MUSIC\\creature battle",
  69. };
  70.  
  71. BOOLEAN StartMusicBasedOnMode(void);
  72. void DoneFadeOutDueToEndMusic(void);
  73. void MusicStopCallback(void *pData);
  74. BOOLEAN MusicStop(void);
  75. BOOLEAN MusicFadeOut(void);
  76. BOOLEAN MusicFadeIn(void);
  77.  
  78. //extern void HandleEndDemoInCreatureLevel( );
  79.  
  80. //BOOLEAN NoEnemiesInSight( )
  81. //{
  82. // SOLDIERTYPE *pSoldier;
  83. // INT32 cnt;
  84. //
  85. // // Loop through our guys
  86. // // End the turn of player charactors
  87. // cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID;
  88. //
  89. // // look for all mercs on the same team,
  90. // for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++, pSoldier++ )
  91. // {
  92. // if ( pSoldier->bActive && pSoldier->stats.bLife >= OKLIFE )
  93. // {
  94. // if ( pSoldier->aiData.bOppCnt != 0 )
  95. // {
  96. // return( FALSE );
  97. // }
  98. // }
  99. // }
  100. //
  101. // return( TRUE );
  102. //}
  103.  
  104.  
  105.  
  106. //********************************************************************************
  107. // MusicPlay
  108. //
  109. // Starts up one of the tunes in the music list.
  110. //
  111. // Returns: TRUE if the music was started, FALSE if an error occurred
  112. //
  113. //********************************************************************************
  114. BOOLEAN MusicPlay(UINT32 uiNum)
  115. {
  116. // WANNE: We want music in windowed mode
  117. //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/
  118. //return FALSE;
  119.  
  120. static CHAR8 zFileName[164];
  121. SOUNDPARMS spParms;
  122.  
  123. if(fMusicPlaying)
  124. MusicStop();
  125.  
  126. memset(&spParms, 0xff, sizeof(SOUNDPARMS));
  127. spParms.uiPriority = PRIORITY_MAX;
  128. spParms.uiVolume = 0;
  129. spParms.uiLoop = 1; // Lesh: only 1 line added
  130.  
  131. spParms.EOSCallback = MusicStopCallback;
  132.  
  133. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "About to call SoundPlayStreamedFile" );
  134.  
  135. // Lesh: patch to allow playback ogg files
  136. sprintf( zFileName, "%s.ogg", szMusicList[uiNum] );
  137. if ( !FileExists( zFileName ) )
  138. sprintf( zFileName, "%s.wav", szMusicList[uiNum] );
  139.  
  140. uiMusicHandle = SoundPlayStreamedFile(zFileName, &spParms);
  141.  
  142. if(uiMusicHandle != SOUND_ERROR)
  143. {
  144. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music PLay %d %d", uiMusicHandle, gubMusicMode ) );
  145.  
  146. gfMusicEnded = FALSE;
  147. fMusicPlaying = TRUE;
  148. MusicFadeIn();
  149. return TRUE;
  150. }
  151.  
  152. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music PLay %d %d", uiMusicHandle, gubMusicMode ) );
  153. return FALSE;
  154. }
  155.  
  156. //********************************************************************************
  157. // MusicSetVolume
  158. //
  159. // Sets the volume on the currently playing music.
  160. //
  161. // Returns: TRUE if the volume was set, FALSE if an error occurred
  162. //
  163. //********************************************************************************
  164. BOOLEAN MusicSetVolume(UINT32 uiVolume)
  165. {
  166. INT32 uiOldMusicVolume = uiMusicVolume;
  167.  
  168. // WANNE: We want music in windowed mode
  169. //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/
  170. //return FALSE;
  171.  
  172. uiMusicVolume = __min(uiVolume, 127);
  173.  
  174. if(uiMusicHandle != NO_SAMPLE)
  175. {
  176. // get volume and if 0 stop music!
  177. if (uiMusicVolume == 0)
  178. {
  179. gfDontRestartSong = TRUE;
  180. MusicStop();
  181. return TRUE;
  182. }
  183.  
  184. SoundSetVolume(uiMusicHandle, uiMusicVolume);
  185.  
  186. return TRUE;
  187. }
  188.  
  189. // If here, check if we need to re-start music
  190. // Have we re-started?
  191. if (uiMusicVolume > 0 && uiOldMusicVolume == 0)
  192. {
  193. StartMusicBasedOnMode();
  194. }
  195.  
  196. return FALSE;
  197. }
  198.  
  199. //********************************************************************************
  200. // MusicGetVolume
  201. //
  202. // Gets the volume on the currently playing music.
  203. //
  204. // Returns: TRUE if the volume was set, FALSE if an error occurred
  205. //
  206. //********************************************************************************
  207. UINT32 MusicGetVolume(void)
  208. {
  209. return uiMusicVolume;
  210. }
  211.  
  212. //********************************************************************************
  213. // MusicStop
  214. //
  215. // Stops the currently playing music.
  216. //
  217. // Returns: TRUE if the music was stopped, FALSE if an error occurred
  218. //
  219. //********************************************************************************
  220. static BOOLEAN MusicStop(void)
  221. {
  222. // WANNE: We want music in windowed mode
  223. //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/
  224. // return(FALSE);
  225.  
  226. if(uiMusicHandle != NO_SAMPLE)
  227. {
  228. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music Stop %d %d", uiMusicHandle, gubMusicMode ) );
  229.  
  230. SoundStop(uiMusicHandle);
  231. fMusicPlaying = FALSE;
  232. uiMusicHandle = NO_SAMPLE;
  233. return TRUE;
  234. }
  235.  
  236. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music Stop %d %d", uiMusicHandle, gubMusicMode ) );
  237. return FALSE;
  238. }
  239.  
  240. //********************************************************************************
  241. // MusicFadeOut
  242. //
  243. // Fades out the current song.
  244. //
  245. // Returns: TRUE if the music has begun fading, FALSE if an error occurred
  246. //
  247. //********************************************************************************
  248. static BOOLEAN MusicFadeOut(void)
  249. {
  250. if(uiMusicHandle != NO_SAMPLE)
  251. {
  252. fMusicFadingOut = TRUE;
  253. return TRUE;
  254. }
  255. return FALSE;
  256. }
  257.  
  258. //********************************************************************************
  259. // MusicFadeIn
  260. //
  261. // Fades in the current song.
  262. //
  263. // Returns: TRUE if the music has begun fading in, FALSE if an error occurred
  264. //
  265. //********************************************************************************
  266. static BOOLEAN MusicFadeIn(void)
  267. {
  268. if(uiMusicHandle != NO_SAMPLE)
  269. {
  270. fMusicFadingIn = TRUE;
  271. return TRUE;
  272. }
  273. return FALSE;
  274. }
  275.  
  276. //********************************************************************************
  277. // MusicPoll
  278. //
  279. // Handles any maintenance the music system needs done. Should be polled from
  280. // the main loop, or somewhere with a high frequency of calls.
  281. //
  282. // Returns: TRUE always
  283. //
  284. //********************************************************************************
  285. BOOLEAN MusicPoll(BOOLEAN /*fForce*/)
  286. {
  287. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll");
  288.  
  289. // WANNE: We want music in windowed mode
  290. //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/
  291. // return(TRUE);
  292.  
  293. INT32 iVol;
  294.  
  295. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: SoundServiceStreams ");
  296. SoundServiceStreams();
  297. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: SoundServiceRandom ");
  298. SoundServiceRandom();
  299.  
  300. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: Handle Sound every sound overhead time");
  301. // Handle Sound every sound overhead time....
  302. if (COUNTERDONE(MUSICOVERHEAD))
  303. {
  304. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: Reset counter");
  305. // Reset counter
  306. RESETCOUNTER(MUSICOVERHEAD);
  307.  
  308. if (fMusicFadingIn)
  309. {
  310. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: music fading in");
  311. if(uiMusicHandle != NO_SAMPLE)
  312. {
  313. iVol = SoundGetVolume(uiMusicHandle);
  314. iVol = __min( (INT32)uiMusicVolume, iVol+gbFadeSpeed );
  315. SoundSetVolume(uiMusicHandle, iVol);
  316. if(iVol == (INT32)uiMusicVolume)
  317. {
  318. fMusicFadingIn = FALSE;
  319. gbFadeSpeed = 1;
  320. }
  321. }
  322. }
  323. else if (fMusicFadingOut)
  324. {
  325. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: music fading out");
  326. if(uiMusicHandle != NO_SAMPLE)
  327. {
  328. iVol = SoundGetVolume(uiMusicHandle);
  329. iVol = (iVol >=1)? iVol-gbFadeSpeed : 0;
  330.  
  331. iVol = __max( (INT32)iVol, 0 );
  332.  
  333. SoundSetVolume(uiMusicHandle, iVol);
  334. if(iVol == 0)
  335. {
  336. MusicStop();
  337. fMusicFadingOut = FALSE;
  338. gbFadeSpeed = 1;
  339. }
  340. }
  341. }
  342.  
  343. if (gfMusicEnded)
  344. {
  345. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: music ended");
  346. // OK, based on our music mode, play another!
  347. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music End Loop %d %d", uiMusicHandle, gubMusicMode ) );
  348.  
  349. // If we were in victory mode, change!
  350. if (gbVictorySongCount == 1 || gbDeathSongCount == 1)
  351. {
  352. if (gbDeathSongCount == 1 && guiCurrentScreen == GAME_SCREEN)
  353. {
  354. CheckAndHandleUnloadingOfCurrentWorld();
  355. }
  356.  
  357. if (gbVictorySongCount == 1)
  358. {
  359. SetMusicMode(MUSIC_TACTICAL_NOTHING);
  360. }
  361. }
  362. else
  363. {
  364. if (!gfDontRestartSong)
  365. {
  366. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: don't restart song, StartMusicBasedOnMode");
  367. StartMusicBasedOnMode();
  368. }
  369. }
  370.  
  371. gfMusicEnded = FALSE;
  372. gfDontRestartSong = FALSE;
  373. }
  374. }
  375.  
  376. //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll done");
  377. return TRUE;
  378. }
  379.  
  380.  
  381. static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce)
  382. {
  383. static INT8 bPreviousMode = 0;
  384.  
  385. // OK, check if we want to restore
  386. if (ubMusicMode == MUSIC_RESTORE)
  387. {
  388. if (bPreviousMode == MUSIC_TACTICAL_VICTORY || bPreviousMode == MUSIC_TACTICAL_DEATH)
  389. {
  390. bPreviousMode = MUSIC_TACTICAL_NOTHING;
  391. }
  392.  
  393. ubMusicMode = bPreviousMode;
  394. }
  395. else
  396. {
  397. // Save previous mode...
  398. bPreviousMode = gubOldMusicMode;
  399. }
  400.  
  401. // if different, start a new music song
  402. if (fForce || gubOldMusicMode != ubMusicMode)
  403. {
  404. // Set mode....
  405. gubMusicMode = ubMusicMode;
  406.  
  407. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music New Mode %d %d", uiMusicHandle, gubMusicMode ) );
  408.  
  409. gbVictorySongCount = 0;
  410. gbDeathSongCount = 0;
  411.  
  412. if(uiMusicHandle != NO_SAMPLE)
  413. {
  414. // Fade out old music
  415. MusicFadeOut();
  416. }
  417. else
  418. {
  419. // Change music!
  420. StartMusicBasedOnMode();
  421. }
  422. }
  423.  
  424. gubOldMusicMode = gubMusicMode;
  425.  
  426. return TRUE;
  427. }
  428.  
  429.  
  430. static BOOLEAN StartMusicBasedOnMode(void)
  431. {
  432. static BOOLEAN fFirstTime = TRUE;
  433.  
  434. if (fFirstTime)
  435. {
  436. fFirstTime = FALSE;
  437.  
  438. bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4));
  439. bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3));
  440. bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(9));
  441. }
  442.  
  443.  
  444. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "StartMusicBasedOnMode() %d %d", uiMusicHandle, gubMusicMode ) );
  445.  
  446. // Setup a song based on mode we're in!
  447. switch(gubMusicMode)
  448. {
  449. case MUSIC_MAIN_MENU:
  450. // ATE: Don't fade in
  451. gbFadeSpeed = (INT8)uiMusicVolume;
  452. MusicPlay(MENUMIX_MUSIC);
  453. break;
  454.  
  455. case MUSIC_LAPTOP:
  456. gbFadeSpeed = (INT8)uiMusicVolume;
  457. MusicPlay(MARIMBAD2_MUSIC);
  458. break;
  459.  
  460. case MUSIC_TACTICAL_NOTHING:
  461. // ATE: Don't fade in
  462. gbFadeSpeed = (INT8)uiMusicVolume;
  463. if(gfUseCreatureMusic)
  464. {
  465. MusicPlay(CREEPY_MUSIC);
  466. }
  467. else
  468. {
  469. MusicPlay(bNothingModeSong);
  470. bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4));
  471. }
  472. break;
  473.  
  474. case MUSIC_TACTICAL_ENEMYPRESENT:
  475. // ATE: Don't fade in EnemyPresent...
  476. gbFadeSpeed = (INT8)uiMusicVolume;
  477. if(gfUseCreatureMusic)
  478. {
  479. MusicPlay(CREEPY_MUSIC);
  480. }
  481. else
  482. {
  483. MusicPlay(bEnemyModeSong);
  484. bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3));
  485. }
  486. break;
  487.  
  488. case MUSIC_TACTICAL_BATTLE:
  489. // ATE: Don't fade in
  490. gbFadeSpeed = (INT8)uiMusicVolume;
  491. if(gfUseCreatureMusic)
  492. {
  493. MusicPlay(CREATURE_BATTLE_MUSIC);
  494. }
  495. else
  496. {
  497. MusicPlay(bBattleModeSong);
  498. }
  499. bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(9));
  500. break;
  501.  
  502. case MUSIC_TACTICAL_VICTORY:
  503.  
  504. // ATE: Don't fade in EnemyPresent...
  505. gbFadeSpeed = (INT8)uiMusicVolume;
  506. MusicPlay(TRIUMPH_MUSIC);
  507. gbVictorySongCount++;
  508.  
  509. if(gfUseCreatureMusic && !gbWorldSectorZ)
  510. {
  511. //We just killed all the creatures that just attacked the town.
  512. gfUseCreatureMusic = FALSE;
  513. }
  514. break;
  515.  
  516. case MUSIC_TACTICAL_DEATH:
  517.  
  518. // ATE: Don't fade in EnemyPresent...
  519. gbFadeSpeed = (INT8)uiMusicVolume;
  520. MusicPlay(DEATH_MUSIC);
  521. gbDeathSongCount++;
  522. break;
  523.  
  524. default:
  525. MusicFadeOut();
  526. break;
  527. }
  528.  
  529. return TRUE;
  530. }
  531.  
  532. BOOLEAN SetMusicMode(UINT8 ubMusicMode)
  533. {
  534. return SetMusicMode(ubMusicMode, FALSE);
  535. }
  536.  
  537. static void MusicStopCallback(void *pData)
  538. {
  539. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music EndCallback %d %d", uiMusicHandle, gubMusicMode ) );
  540.  
  541. gfMusicEnded = TRUE;
  542. uiMusicHandle = NO_SAMPLE;
  543.  
  544. //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Music EndCallback completed" );
  545. }
  546.  
  547.  
  548. void SetMusicFadeSpeed(INT8 bFadeSpeed)
  549. {
  550. gbFadeSpeed = bFadeSpeed;
  551. }
  552.  
  553. UINT8 GetMusicMode(void)
  554. {
  555. return gubMusicMode;
  556. }
  557.  
  558. BOOLEAN UsingCreatureMusic(void)
  559. {
  560. return gfUseCreatureMusic;
  561. }
  562.  
  563. void UseCreatureMusic(BOOLEAN fUseCreatureMusic)
  564. {
  565. if (gfUseCreatureMusic != fUseCreatureMusic)
  566. {
  567. // this means a change
  568. gfUseCreatureMusic = fUseCreatureMusic;
  569. SetMusicMode(gubMusicMode, TRUE); // same as before
  570. }
  571. }
  572.  
  573. BOOLEAN IsMusicPlaying(void)
  574. {
  575. return fMusicPlaying;
  576. }
  577.  
  578. UINT32 GetMusicHandle(void)
  579. {
  580. return uiMusicHandle;
  581. }
  582.  
  583. // unused
  584. //void FadeMusicForXSeconds( UINT32 uiDelay )
  585. //{
  586. // INT16 sNumTimeSteps, sNumVolumeSteps;
  587. //
  588. // // get # time steps in delay....
  589. // sNumTimeSteps = (INT16)( uiDelay / 10 );
  590. //
  591. // // Devide this by music volume...
  592. // sNumVolumeSteps = (INT16)( uiMusicVolume / sNumTimeSteps );
  593. //
  594. // // Set fade delay...
  595. // SetMusicFadeSpeed( (INT8)sNumVolumeSteps );
  596. //}
  597.  
  598. // unused
  599. //void DoneFadeOutDueToEndMusic( void )
  600. //{
  601. // // Quit game....
  602. // InternalLeaveTacticalScreen( MAINMENU_SCREEN );
  603. // //SetPendingNewScreen( MAINMENU_SCREEN );
  604. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement