AudioEventRTS.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: AudioEventRTS.cpp
  24. /*---------------------------------------------------------------------------*/
  25. /* EA Pacific */
  26. /* Confidential Information */
  27. /* Copyright (C) 2001 - All Rights Reserved */
  28. /* DO NOT DISTRIBUTE */
  29. /*---------------------------------------------------------------------------*/
  30. /* Project: RTS3 */
  31. /* File name: AudioEventRTS.cpp */
  32. /* Created: John K. McDonald, Jr., 3/21/2002 */
  33. /* Desc: AudioEventRTS constructors and assignment operator, etc. */
  34. /* Revision History: */
  35. /* 3/21/2002 : Initial creation */
  36. /*---------------------------------------------------------------------------*/
  37. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  38. #include "Common/AudioEventRTS.h"
  39. #include "Common/AudioEventInfo.h"
  40. #include "Common/AudioRandomValue.h"
  41. #include "Common/AudioSettings.h"
  42. #include "Common/File.h"
  43. #include "Common/FileSystem.h"
  44. #include "Common/GameSounds.h"
  45. #include "Common/GlobalData.h"
  46. #include "Common/Player.h"
  47. #include "Common/Registry.h"
  48. #include "GameLogic/GameLogic.h" // For getObjectByID
  49. #include "GameLogic/LogicRandomValue.h"
  50. #include "GameLogic/Object.h"
  51. #include "GameClient/Drawable.h" // For getPosition
  52. #include "GameClient/GameClient.h" // For getDrawableByID
  53. #ifdef _INTERNAL
  54. //#pragma optimize("", off)
  55. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  56. #endif
  57. //-------------------------------------------------------------------------------------------------
  58. AudioEventRTS::AudioEventRTS()
  59. : m_eventName(AsciiString::TheEmptyString),
  60. m_priority(AP_NORMAL),
  61. m_volume(-1.0),
  62. m_timeOfDay(TIME_OF_DAY_AFTERNOON),
  63. m_ownerType(OT_INVALID),
  64. m_shouldFade(false),
  65. m_isLogicalAudio(false),
  66. m_filenameToLoad(AsciiString::TheEmptyString),
  67. m_eventInfo(NULL),
  68. m_playingHandle(0),
  69. m_killThisHandle(0),
  70. m_pitchShift(1.0),
  71. m_volumeShift(0.0),
  72. m_loopCount(1),
  73. m_playingAudioIndex(-1),
  74. m_allCount(0),
  75. m_playerIndex(-1),
  76. m_delay(0.0f),
  77. m_uninterruptable(FALSE)
  78. {
  79. m_attackName.clear();
  80. m_decayName.clear();
  81. m_positionOfAudio.zero();
  82. }
  83. //-------------------------------------------------------------------------------------------------
  84. AudioEventRTS::AudioEventRTS( const AsciiString& eventName )
  85. : m_eventName(eventName),
  86. m_priority(AP_NORMAL),
  87. m_volume(-1.0),
  88. m_timeOfDay(TIME_OF_DAY_AFTERNOON),
  89. m_ownerType(OT_INVALID),
  90. m_shouldFade(false),
  91. m_isLogicalAudio(false),
  92. m_filenameToLoad(AsciiString::TheEmptyString),
  93. m_eventInfo(NULL),
  94. m_playingHandle(0),
  95. m_killThisHandle(0),
  96. m_pitchShift(1.0),
  97. m_volumeShift(0.0),
  98. m_loopCount(1),
  99. m_playingAudioIndex(-1),
  100. m_allCount(0),
  101. m_playerIndex(-1),
  102. m_delay(0.0f),
  103. m_uninterruptable(FALSE)
  104. {
  105. m_attackName.clear();
  106. m_decayName.clear();
  107. m_positionOfAudio.zero();
  108. }
  109. //-------------------------------------------------------------------------------------------------
  110. AudioEventRTS::AudioEventRTS( const AsciiString& eventName, ObjectID ownerID )
  111. : m_eventName(eventName),
  112. m_priority(AP_NORMAL),
  113. m_volume(-1.0),
  114. m_timeOfDay(TIME_OF_DAY_AFTERNOON),
  115. m_objectID(ownerID),
  116. m_ownerType(OT_INVALID),
  117. m_shouldFade(false),
  118. m_isLogicalAudio(false),
  119. m_filenameToLoad(AsciiString::TheEmptyString),
  120. m_eventInfo(NULL),
  121. m_playingHandle(0),
  122. m_killThisHandle(0),
  123. m_pitchShift(1.0),
  124. m_volumeShift(0.0),
  125. m_loopCount(1),
  126. m_playingAudioIndex(-1),
  127. m_allCount(0),
  128. m_playerIndex(-1),
  129. m_delay(0.0f),
  130. m_uninterruptable(FALSE)
  131. {
  132. m_attackName.clear();
  133. m_decayName.clear();
  134. if( m_objectID )
  135. {
  136. m_ownerType = OT_Object;
  137. }
  138. else
  139. {
  140. m_objectID = INVALID_ID;
  141. }
  142. }
  143. //-------------------------------------------------------------------------------------------------
  144. AudioEventRTS::AudioEventRTS( const AsciiString& eventName, DrawableID drawableID )
  145. : m_eventName(eventName),
  146. m_priority(AP_NORMAL),
  147. m_volume(-1.0),
  148. m_timeOfDay(TIME_OF_DAY_AFTERNOON),
  149. m_drawableID(drawableID),
  150. m_ownerType(OT_INVALID),
  151. m_shouldFade(false),
  152. m_isLogicalAudio(false),
  153. m_filenameToLoad(AsciiString::TheEmptyString),
  154. m_eventInfo(NULL),
  155. m_playingHandle(0),
  156. m_killThisHandle(0),
  157. m_pitchShift(1.0),
  158. m_volumeShift(0.0),
  159. m_loopCount(1),
  160. m_playingAudioIndex(-1),
  161. m_allCount(0),
  162. m_playerIndex(-1),
  163. m_delay(0.0f),
  164. m_uninterruptable(FALSE)
  165. {
  166. m_attackName.clear();
  167. m_decayName.clear();
  168. if( m_drawableID )
  169. {
  170. m_ownerType = OT_Drawable;
  171. }
  172. else
  173. {
  174. m_drawableID = INVALID_DRAWABLE_ID;
  175. }
  176. }
  177. //-------------------------------------------------------------------------------------------------
  178. AudioEventRTS::AudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio )
  179. : m_eventName(eventName),
  180. m_priority(AP_NORMAL),
  181. m_volume(-1.0),
  182. m_timeOfDay(TIME_OF_DAY_AFTERNOON),
  183. m_ownerType(OT_Positional),
  184. m_shouldFade(false),
  185. m_isLogicalAudio(false),
  186. m_filenameToLoad(AsciiString::TheEmptyString),
  187. m_eventInfo(NULL),
  188. m_playingHandle(0),
  189. m_killThisHandle(0),
  190. m_pitchShift(1.0),
  191. m_volumeShift(0.0),
  192. m_loopCount(1),
  193. m_playingAudioIndex(-1),
  194. m_allCount(0),
  195. m_playerIndex(-1),
  196. m_delay(0.0f),
  197. m_uninterruptable(FALSE)
  198. {
  199. m_positionOfAudio.set( positionOfAudio );
  200. m_attackName.clear();
  201. m_decayName.clear();
  202. }
  203. //-------------------------------------------------------------------------------------------------
  204. AudioEventRTS::AudioEventRTS( const AudioEventRTS& right )
  205. {
  206. m_filenameToLoad = right.m_filenameToLoad;
  207. m_eventInfo = right.m_eventInfo;
  208. m_playingHandle = right.m_playingHandle;
  209. m_killThisHandle = right.m_killThisHandle;
  210. m_eventName = right.m_eventName;
  211. m_priority = right.m_priority;
  212. m_volume = right.m_volume;
  213. m_timeOfDay = right.m_timeOfDay;
  214. m_ownerType = right.m_ownerType;
  215. m_shouldFade = right.m_shouldFade;
  216. m_isLogicalAudio = right.m_isLogicalAudio;
  217. m_pitchShift = right.m_pitchShift;
  218. m_volumeShift = right.m_volumeShift;
  219. m_loopCount = right.m_loopCount;
  220. m_playingAudioIndex = right.m_playingAudioIndex;
  221. m_allCount = right.m_allCount;
  222. m_playerIndex = right.m_playerIndex;
  223. m_delay = right.m_delay;
  224. m_attackName = right.m_attackName;
  225. m_decayName = right.m_decayName;
  226. m_portionToPlayNext = right.m_portionToPlayNext;
  227. m_uninterruptable = right.m_uninterruptable;
  228. if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
  229. {
  230. m_positionOfAudio.set( &right.m_positionOfAudio );
  231. }
  232. else if( m_ownerType == OT_Drawable )
  233. {
  234. m_drawableID = right.m_drawableID;
  235. }
  236. else if( m_ownerType == OT_Object )
  237. {
  238. m_objectID = right.m_objectID;
  239. }
  240. }
  241. //-------------------------------------------------------------------------------------------------
  242. AudioEventRTS& AudioEventRTS::operator=( const AudioEventRTS& right )
  243. {
  244. m_filenameToLoad = right.m_filenameToLoad;
  245. m_eventInfo = right.m_eventInfo;
  246. m_playingHandle = right.m_playingHandle;
  247. m_killThisHandle = right.m_killThisHandle;
  248. m_eventName = right.m_eventName;
  249. m_priority = right.m_priority;
  250. m_volume = right.m_volume;
  251. m_timeOfDay = right.m_timeOfDay;
  252. m_ownerType = right.m_ownerType;
  253. m_shouldFade = right.m_shouldFade;
  254. m_isLogicalAudio = right.m_isLogicalAudio;
  255. m_pitchShift = right.m_pitchShift;
  256. m_volumeShift = right.m_volumeShift;
  257. m_loopCount = right.m_loopCount;
  258. m_playingAudioIndex = right.m_playingAudioIndex;
  259. m_allCount = right.m_allCount;
  260. m_playerIndex = right.m_playerIndex;
  261. m_delay = right.m_delay;
  262. m_attackName = right.m_attackName;
  263. m_decayName = right.m_decayName;
  264. m_portionToPlayNext = right.m_portionToPlayNext;
  265. m_uninterruptable = right.m_uninterruptable;
  266. if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
  267. {
  268. m_positionOfAudio.set( &right.m_positionOfAudio );
  269. }
  270. else if( m_ownerType == OT_Drawable )
  271. {
  272. m_drawableID = right.m_drawableID;
  273. }
  274. else if( m_ownerType == OT_Object )
  275. {
  276. m_objectID = right.m_objectID;
  277. }
  278. return *this;
  279. }
  280. //-------------------------------------------------------------------------------------------------
  281. AudioEventRTS::~AudioEventRTS()
  282. {
  283. }
  284. //-------------------------------------------------------------------------------------------------
  285. void AudioEventRTS::setEventName( AsciiString name )
  286. {
  287. if ((name != m_eventName) && m_eventInfo != NULL) {
  288. // Clear out the audio event info, cause its not valid for the new event.
  289. m_eventInfo = NULL;
  290. }
  291. m_eventName = name;
  292. }
  293. //-------------------------------------------------------------------------------------------------
  294. void AudioEventRTS::generateFilename( void )
  295. {
  296. // A Logic Random Value is used because we may ask "How long will it take to play this sound?"
  297. // In that case, we need the same answer across all pcs.
  298. if (!m_eventInfo) {
  299. return;
  300. }
  301. m_filenameToLoad = generateFilenamePrefix(m_eventInfo->m_soundType, false);
  302. Int which = 0;
  303. if (m_eventInfo->m_soundType == AT_Music || m_eventInfo->m_soundType == AT_Streaming) {
  304. m_filenameToLoad.concat(m_eventInfo->m_filename);
  305. adjustForLocalization(m_filenameToLoad);
  306. return;
  307. } else {
  308. if (m_eventInfo->m_sounds.size() == 0) {
  309. m_filenameToLoad = AsciiString::TheEmptyString;
  310. return;
  311. }
  312. if (BitTest(m_eventInfo->m_control, AC_RANDOM))
  313. {
  314. if (m_isLogicalAudio)
  315. {
  316. which = GameLogicRandomValue(0, m_eventInfo->m_sounds.size() - 1);
  317. }
  318. else
  319. {
  320. which = GameAudioRandomValue(0, m_eventInfo->m_sounds.size() - 1);
  321. }
  322. if (which == m_playingAudioIndex && m_eventInfo->m_sounds.size() > 2)
  323. which = ( which + 1 ) % m_eventInfo->m_sounds.size();
  324. m_playingAudioIndex = which;//caching random choice to compare next call
  325. }
  326. else
  327. which = (++m_playingAudioIndex) % m_eventInfo->m_sounds.size();
  328. }
  329. m_filenameToLoad.concat(m_eventInfo->m_sounds[which]);
  330. m_filenameToLoad.concat(generateFilenameExtension(m_eventInfo->m_soundType));
  331. adjustForLocalization(m_filenameToLoad);
  332. // Note: Also generate Delay when generating a filename, cause
  333. // we want delay to apply between every loop of a sound.
  334. m_delay = GameAudioRandomValueReal(m_eventInfo->m_delayMin, m_eventInfo->m_delayMax);
  335. }
  336. //-------------------------------------------------------------------------------------------------
  337. AsciiString AudioEventRTS::getFilename( void )
  338. {
  339. return m_filenameToLoad;
  340. }
  341. //-------------------------------------------------------------------------------------------------
  342. void AudioEventRTS::generatePlayInfo( void )
  343. {
  344. m_pitchShift = GameAudioRandomValueReal(m_eventInfo->m_pitchShiftMin, m_eventInfo->m_pitchShiftMax);
  345. m_volumeShift = GameAudioRandomValueReal(1.0f + m_eventInfo->m_volumeShift, 1.0f); // volume shifts are between 0 and 1
  346. m_loopCount = m_eventInfo->m_loopCount;
  347. m_portionToPlayNext = PP_Attack;
  348. Int attackSize = m_eventInfo->m_attackSounds.size();
  349. if (attackSize > 0) {
  350. m_attackName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
  351. // needs to be logic because it needs to be the same on all systems.
  352. Int attackToPlay;
  353. if (m_isLogicalAudio) {
  354. attackToPlay = GameLogicRandomValue(0, attackSize - 1);
  355. } else {
  356. attackToPlay = GameAudioRandomValue(0, attackSize - 1);
  357. }
  358. m_attackName.concat(m_eventInfo->m_attackSounds[attackToPlay]);
  359. m_attackName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
  360. adjustForLocalization(m_attackName);
  361. } else {
  362. m_portionToPlayNext = PP_Sound;
  363. }
  364. Int decaySize = m_eventInfo->m_decaySounds.size();
  365. if (decaySize > 0) {
  366. m_decayName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
  367. // needs to be logic because it needs to be the same on all systems.
  368. Int decayToPlay;
  369. if (m_isLogicalAudio) {
  370. decayToPlay = GameLogicRandomValue(0, decaySize - 1);
  371. } else {
  372. decayToPlay = GameAudioRandomValue(0, decaySize - 1);
  373. }
  374. m_decayName.concat(m_eventInfo->m_decaySounds[decayToPlay]);
  375. m_decayName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
  376. adjustForLocalization(m_decayName);
  377. }
  378. m_isLogicalAudio = FALSE;
  379. }
  380. //-------------------------------------------------------------------------------------------------
  381. Real AudioEventRTS::getPitchShift( void ) const
  382. {
  383. return m_pitchShift;
  384. }
  385. //-------------------------------------------------------------------------------------------------
  386. Real AudioEventRTS::getVolumeShift( void ) const
  387. {
  388. return m_volumeShift;
  389. }
  390. //-------------------------------------------------------------------------------------------------
  391. AsciiString AudioEventRTS::getAttackFilename( void ) const
  392. {
  393. return m_attackName;
  394. }
  395. //-------------------------------------------------------------------------------------------------
  396. AsciiString AudioEventRTS::getDecayFilename( void ) const
  397. {
  398. return m_decayName;
  399. }
  400. //-------------------------------------------------------------------------------------------------
  401. Real AudioEventRTS::getDelay( void ) const
  402. {
  403. return m_delay;
  404. }
  405. //-------------------------------------------------------------------------------------------------
  406. void AudioEventRTS::decrementDelay( Real timeToDecrement )
  407. {
  408. m_delay -= timeToDecrement;
  409. }
  410. //-------------------------------------------------------------------------------------------------
  411. PortionToPlay AudioEventRTS::getNextPlayPortion( void ) const
  412. {
  413. return m_portionToPlayNext;
  414. }
  415. //-------------------------------------------------------------------------------------------------
  416. void AudioEventRTS::advanceNextPlayPortion( void )
  417. {
  418. switch (m_portionToPlayNext)
  419. {
  420. case PP_Attack:
  421. m_portionToPlayNext = PP_Sound;
  422. break;
  423. case PP_Sound:
  424. if (m_eventInfo && BitTest(m_eventInfo->m_control, AC_ALL))
  425. {
  426. if (m_allCount == m_eventInfo->m_sounds.size()) {
  427. m_portionToPlayNext = PP_Decay;
  428. }
  429. // Advance the all count so that we move to the next sound.
  430. ++m_allCount;
  431. }
  432. if (!m_decayName.isEmpty()) {
  433. m_portionToPlayNext = PP_Decay;
  434. } else {
  435. m_portionToPlayNext = PP_Done;
  436. }
  437. break;
  438. case PP_Decay:
  439. m_portionToPlayNext = PP_Done;
  440. break;
  441. }
  442. }
  443. //-------------------------------------------------------------------------------------------------
  444. void AudioEventRTS::setNextPlayPortion( PortionToPlay ptp )
  445. {
  446. m_portionToPlayNext = ptp;
  447. }
  448. //-------------------------------------------------------------------------------------------------
  449. void AudioEventRTS::decreaseLoopCount( void )
  450. {
  451. if (m_loopCount == 1) {
  452. m_loopCount = -1;
  453. } else if (m_loopCount > 1) {
  454. --m_loopCount;
  455. }
  456. }
  457. //-------------------------------------------------------------------------------------------------
  458. Bool AudioEventRTS::hasMoreLoops( void ) const
  459. {
  460. return (m_loopCount >= 0);
  461. }
  462. //-------------------------------------------------------------------------------------------------
  463. void AudioEventRTS::setAudioEventInfo( const AudioEventInfo *eventInfo ) const
  464. {
  465. m_eventInfo = eventInfo;
  466. }
  467. //-------------------------------------------------------------------------------------------------
  468. const AudioEventInfo *AudioEventRTS::getAudioEventInfo( void ) const
  469. {
  470. if (m_eventInfo) {
  471. if (m_eventInfo->m_audioName == m_eventName) {
  472. return m_eventInfo;
  473. } else {
  474. m_eventInfo = NULL;
  475. }
  476. }
  477. return m_eventInfo;
  478. }
  479. //-------------------------------------------------------------------------------------------------
  480. void AudioEventRTS::setPlayingHandle( AudioHandle handle )
  481. {
  482. m_playingHandle = handle;
  483. }
  484. //-------------------------------------------------------------------------------------------------
  485. AudioHandle AudioEventRTS::getPlayingHandle( void )
  486. {
  487. return m_playingHandle;
  488. }
  489. //-------------------------------------------------------------------------------------------------
  490. void AudioEventRTS::setPosition( const Coord3D *pos )
  491. {
  492. if (!pos) {
  493. return;
  494. }
  495. if (!(m_ownerType == OT_Positional || m_ownerType == OT_INVALID)) {
  496. return;
  497. }
  498. m_positionOfAudio = *pos;
  499. m_ownerType = OT_Positional;
  500. }
  501. //-------------------------------------------------------------------------------------------------
  502. const Coord3D* AudioEventRTS::getPosition( void )
  503. {
  504. if( m_ownerType != OT_INVALID )
  505. {
  506. return &m_positionOfAudio;
  507. }
  508. return NULL;
  509. }
  510. //-------------------------------------------------------------------------------------------------
  511. void AudioEventRTS::setObjectID( ObjectID objID )
  512. {
  513. if (!(m_ownerType == OT_Object || m_ownerType == OT_INVALID)) {
  514. return;
  515. }
  516. m_objectID = objID;
  517. m_ownerType = OT_Object;
  518. }
  519. //-------------------------------------------------------------------------------------------------
  520. ObjectID AudioEventRTS::getObjectID( void )
  521. {
  522. if (m_ownerType == OT_Object) {
  523. return m_objectID;
  524. }
  525. return INVALID_ID;
  526. }
  527. //-------------------------------------------------------------------------------------------------
  528. void AudioEventRTS::setDrawableID( DrawableID drawID )
  529. {
  530. if (!(m_ownerType == OT_Drawable || m_ownerType == OT_INVALID)) {
  531. return;
  532. }
  533. m_drawableID = drawID;
  534. m_ownerType = OT_Drawable;
  535. }
  536. //-------------------------------------------------------------------------------------------------
  537. DrawableID AudioEventRTS::getDrawableID( void )
  538. {
  539. if (m_ownerType == OT_Drawable) {
  540. return m_drawableID;
  541. }
  542. return INVALID_DRAWABLE_ID;
  543. }
  544. //-------------------------------------------------------------------------------------------------
  545. void AudioEventRTS::setTimeOfDay( TimeOfDay tod )
  546. {
  547. m_timeOfDay = tod;
  548. }
  549. //-------------------------------------------------------------------------------------------------
  550. TimeOfDay AudioEventRTS::getTimeOfDay( void ) const
  551. {
  552. return m_timeOfDay;
  553. }
  554. //-------------------------------------------------------------------------------------------------
  555. void AudioEventRTS::setHandleToKill( AudioHandle handleToKill )
  556. {
  557. m_killThisHandle = handleToKill;
  558. }
  559. //-------------------------------------------------------------------------------------------------
  560. AudioHandle AudioEventRTS::getHandleToKill( void ) const
  561. {
  562. return m_killThisHandle;
  563. }
  564. //-------------------------------------------------------------------------------------------------
  565. void AudioEventRTS::setShouldFade( Bool shouldFade )
  566. {
  567. m_shouldFade = shouldFade;
  568. }
  569. //-------------------------------------------------------------------------------------------------
  570. Bool AudioEventRTS::getShouldFade( void ) const
  571. {
  572. return m_shouldFade;
  573. }
  574. //-------------------------------------------------------------------------------------------------
  575. void AudioEventRTS::setIsLogicalAudio( Bool isLogicalAudio )
  576. {
  577. m_isLogicalAudio = isLogicalAudio;
  578. }
  579. //-------------------------------------------------------------------------------------------------
  580. Bool AudioEventRTS::getIsLogicalAudio( void ) const
  581. {
  582. return m_isLogicalAudio;
  583. }
  584. //-------------------------------------------------------------------------------------------------
  585. Bool AudioEventRTS::isPositionalAudio( void ) const
  586. {
  587. if( m_eventInfo )
  588. {
  589. if( !BitTest( m_eventInfo->m_type, ST_WORLD ) )
  590. {
  591. return FALSE;
  592. }
  593. }
  594. if( m_ownerType != OT_INVALID )
  595. {
  596. if( m_drawableID != INVALID_DRAWABLE_ID || m_objectID != INVALID_ID || m_ownerType == OT_Positional )
  597. {
  598. return TRUE;
  599. }
  600. }
  601. return FALSE;
  602. }
  603. //-------------------------------------------------------------------------------------------------
  604. Bool AudioEventRTS::isCurrentlyPlaying( void ) const
  605. {
  606. return TheAudio->isCurrentlyPlaying(m_playingHandle);
  607. }
  608. //-------------------------------------------------------------------------------------------------
  609. AudioPriority AudioEventRTS::getAudioPriority( void ) const
  610. {
  611. return m_priority;
  612. }
  613. //-------------------------------------------------------------------------------------------------
  614. void AudioEventRTS::setAudioPriority( AudioPriority newPriority )
  615. {
  616. m_priority = newPriority;
  617. }
  618. //-------------------------------------------------------------------------------------------------
  619. Real AudioEventRTS::getVolume( void ) const
  620. {
  621. if (m_volume == -1.0f) {
  622. if (m_eventInfo) {
  623. return m_eventInfo->m_volume;
  624. }
  625. return 0.5;
  626. }
  627. return m_volume;
  628. }
  629. //-------------------------------------------------------------------------------------------------
  630. void AudioEventRTS::setVolume( Real vol )
  631. {
  632. m_volume = vol;
  633. }
  634. //-------------------------------------------------------------------------------------------------
  635. const Coord3D *AudioEventRTS::getCurrentPosition( void )
  636. {
  637. if (m_ownerType == OT_Positional)
  638. {
  639. return &m_positionOfAudio;
  640. }
  641. else if (m_ownerType == OT_Object)
  642. {
  643. Object *obj = TheGameLogic->findObjectByID(m_objectID);
  644. if (obj)
  645. {
  646. m_positionOfAudio.set( obj->getPosition() );
  647. }
  648. else
  649. {
  650. m_ownerType = OT_Dead;
  651. }
  652. return &m_positionOfAudio;
  653. }
  654. else if (m_ownerType == OT_Drawable)
  655. {
  656. Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
  657. if( draw )
  658. {
  659. m_positionOfAudio.set( draw->getPosition() );
  660. }
  661. else
  662. {
  663. m_ownerType = OT_Dead;
  664. }
  665. return &m_positionOfAudio;
  666. }
  667. else if( m_ownerType == OT_Dead )
  668. {
  669. return &m_positionOfAudio;
  670. }
  671. return NULL;
  672. }
  673. //-------------------------------------------------------------------------------------------------
  674. AsciiString AudioEventRTS::generateFilenamePrefix( AudioType audioTypeToPlay, Bool localized )
  675. {
  676. AsciiString retStr;
  677. retStr = TheAudio->getAudioSettings()->m_audioRoot;
  678. retStr.concat("\\");
  679. if (audioTypeToPlay == AT_Music) {
  680. retStr.concat(TheAudio->getAudioSettings()->m_musicFolder);
  681. } else if (audioTypeToPlay == AT_Streaming) {
  682. retStr.concat(TheAudio->getAudioSettings()->m_streamingFolder);
  683. } else {
  684. retStr.concat(TheAudio->getAudioSettings()->m_soundsFolder);
  685. }
  686. retStr.concat("\\");
  687. if (localized) {
  688. retStr.concat(GetRegistryLanguage());
  689. retStr.concat("\\");
  690. }
  691. return retStr;
  692. }
  693. //-------------------------------------------------------------------------------------------------
  694. AsciiString AudioEventRTS::generateFilenameExtension( AudioType audioTypeToPlay )
  695. {
  696. AsciiString retStr = AsciiString::TheEmptyString;
  697. if (audioTypeToPlay != AT_Music) {
  698. retStr = ".";
  699. retStr.concat(TheAudio->getAudioSettings()->m_soundsExtension);
  700. }
  701. return retStr;
  702. }
  703. //-------------------------------------------------------------------------------------------------
  704. void AudioEventRTS::adjustForLocalization(AsciiString &strToAdjust)
  705. {
  706. if (TheFileSystem->doesFileExist(strToAdjust.str()))
  707. {
  708. return;
  709. }
  710. const char *str = strToAdjust.reverseFind('\\');
  711. if (!str) {
  712. return;
  713. }
  714. AsciiString filename = str;
  715. strToAdjust = generateFilenamePrefix(m_eventInfo->m_soundType, TRUE);
  716. strToAdjust.concat(filename);
  717. }
  718. //-------------------------------------------------------------------------------------------------
  719. Int AudioEventRTS::getPlayerIndex( void ) const
  720. {
  721. if (m_ownerType == OT_Object) {
  722. Object *obj = TheGameLogic->findObjectByID(m_objectID);
  723. if (obj) {
  724. return obj->getControllingPlayer()->getPlayerIndex();
  725. }
  726. } else if (m_ownerType == OT_Drawable) {
  727. Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
  728. if (draw) {
  729. Object *obj = draw->getObject();
  730. if (obj) {
  731. return obj->getControllingPlayer()->getPlayerIndex();
  732. }
  733. }
  734. }
  735. return m_playerIndex;
  736. }
  737. //-------------------------------------------------------------------------------------------------
  738. void AudioEventRTS::setPlayerIndex( Int playerNdx )
  739. {
  740. m_playerIndex = playerNdx;
  741. }