| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: AudioEventRTS.cpp
- /*---------------------------------------------------------------------------*/
- /* EA Pacific */
- /* Confidential Information */
- /* Copyright (C) 2001 - All Rights Reserved */
- /* DO NOT DISTRIBUTE */
- /*---------------------------------------------------------------------------*/
- /* Project: RTS3 */
- /* File name: AudioEventRTS.cpp */
- /* Created: John K. McDonald, Jr., 3/21/2002 */
- /* Desc: AudioEventRTS constructors and assignment operator, etc. */
- /* Revision History: */
- /* 3/21/2002 : Initial creation */
- /*---------------------------------------------------------------------------*/
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/AudioEventRTS.h"
- #include "Common/AudioEventInfo.h"
- #include "Common/AudioRandomValue.h"
- #include "Common/AudioSettings.h"
- #include "Common/File.h"
- #include "Common/FileSystem.h"
- #include "Common/GameSounds.h"
- #include "Common/GlobalData.h"
- #include "Common/Player.h"
- #include "Common/Registry.h"
- #include "GameLogic/GameLogic.h" // For getObjectByID
- #include "GameLogic/LogicRandomValue.h"
- #include "GameLogic/Object.h"
- #include "GameClient/Drawable.h" // For getPosition
- #include "GameClient/GameClient.h" // For getDrawableByID
- #ifdef _INTERNAL
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS()
- : m_eventName(AsciiString::TheEmptyString),
- m_priority(AP_NORMAL),
- m_volume(-1.0),
- m_timeOfDay(TIME_OF_DAY_AFTERNOON),
- m_ownerType(OT_INVALID),
- m_shouldFade(false),
- m_isLogicalAudio(false),
- m_filenameToLoad(AsciiString::TheEmptyString),
- m_eventInfo(NULL),
- m_playingHandle(0),
- m_killThisHandle(0),
- m_pitchShift(1.0),
- m_volumeShift(0.0),
- m_loopCount(1),
- m_playingAudioIndex(-1),
- m_allCount(0),
- m_playerIndex(-1),
- m_delay(0.0f),
- m_uninterruptable(FALSE)
- {
- m_attackName.clear();
- m_decayName.clear();
- m_positionOfAudio.zero();
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS( const AsciiString& eventName )
- : m_eventName(eventName),
- m_priority(AP_NORMAL),
- m_volume(-1.0),
- m_timeOfDay(TIME_OF_DAY_AFTERNOON),
- m_ownerType(OT_INVALID),
- m_shouldFade(false),
- m_isLogicalAudio(false),
- m_filenameToLoad(AsciiString::TheEmptyString),
- m_eventInfo(NULL),
- m_playingHandle(0),
- m_killThisHandle(0),
- m_pitchShift(1.0),
- m_volumeShift(0.0),
- m_loopCount(1),
- m_playingAudioIndex(-1),
- m_allCount(0),
- m_playerIndex(-1),
- m_delay(0.0f),
- m_uninterruptable(FALSE)
- {
- m_attackName.clear();
- m_decayName.clear();
- m_positionOfAudio.zero();
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS( const AsciiString& eventName, ObjectID ownerID )
- : m_eventName(eventName),
- m_priority(AP_NORMAL),
- m_volume(-1.0),
- m_timeOfDay(TIME_OF_DAY_AFTERNOON),
- m_objectID(ownerID),
- m_ownerType(OT_INVALID),
- m_shouldFade(false),
- m_isLogicalAudio(false),
- m_filenameToLoad(AsciiString::TheEmptyString),
- m_eventInfo(NULL),
- m_playingHandle(0),
- m_killThisHandle(0),
- m_pitchShift(1.0),
- m_volumeShift(0.0),
- m_loopCount(1),
- m_playingAudioIndex(-1),
- m_allCount(0),
- m_playerIndex(-1),
- m_delay(0.0f),
- m_uninterruptable(FALSE)
- {
- m_attackName.clear();
- m_decayName.clear();
- if( m_objectID )
- {
- m_ownerType = OT_Object;
- }
- else
- {
- m_objectID = INVALID_ID;
- }
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS( const AsciiString& eventName, DrawableID drawableID )
- : m_eventName(eventName),
- m_priority(AP_NORMAL),
- m_volume(-1.0),
- m_timeOfDay(TIME_OF_DAY_AFTERNOON),
- m_drawableID(drawableID),
- m_ownerType(OT_INVALID),
- m_shouldFade(false),
- m_isLogicalAudio(false),
- m_filenameToLoad(AsciiString::TheEmptyString),
- m_eventInfo(NULL),
- m_playingHandle(0),
- m_killThisHandle(0),
- m_pitchShift(1.0),
- m_volumeShift(0.0),
- m_loopCount(1),
- m_playingAudioIndex(-1),
- m_allCount(0),
- m_playerIndex(-1),
- m_delay(0.0f),
- m_uninterruptable(FALSE)
- {
- m_attackName.clear();
- m_decayName.clear();
- if( m_drawableID )
- {
- m_ownerType = OT_Drawable;
- }
- else
- {
- m_drawableID = INVALID_DRAWABLE_ID;
- }
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio )
- : m_eventName(eventName),
- m_priority(AP_NORMAL),
- m_volume(-1.0),
- m_timeOfDay(TIME_OF_DAY_AFTERNOON),
- m_ownerType(OT_Positional),
- m_shouldFade(false),
- m_isLogicalAudio(false),
- m_filenameToLoad(AsciiString::TheEmptyString),
- m_eventInfo(NULL),
- m_playingHandle(0),
- m_killThisHandle(0),
- m_pitchShift(1.0),
- m_volumeShift(0.0),
- m_loopCount(1),
- m_playingAudioIndex(-1),
- m_allCount(0),
- m_playerIndex(-1),
- m_delay(0.0f),
- m_uninterruptable(FALSE)
- {
- m_positionOfAudio.set( positionOfAudio );
- m_attackName.clear();
- m_decayName.clear();
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::AudioEventRTS( const AudioEventRTS& right )
- {
- m_filenameToLoad = right.m_filenameToLoad;
- m_eventInfo = right.m_eventInfo;
- m_playingHandle = right.m_playingHandle;
- m_killThisHandle = right.m_killThisHandle;
- m_eventName = right.m_eventName;
- m_priority = right.m_priority;
- m_volume = right.m_volume;
- m_timeOfDay = right.m_timeOfDay;
- m_ownerType = right.m_ownerType;
- m_shouldFade = right.m_shouldFade;
- m_isLogicalAudio = right.m_isLogicalAudio;
- m_pitchShift = right.m_pitchShift;
- m_volumeShift = right.m_volumeShift;
- m_loopCount = right.m_loopCount;
- m_playingAudioIndex = right.m_playingAudioIndex;
- m_allCount = right.m_allCount;
- m_playerIndex = right.m_playerIndex;
- m_delay = right.m_delay;
- m_attackName = right.m_attackName;
- m_decayName = right.m_decayName;
- m_portionToPlayNext = right.m_portionToPlayNext;
- m_uninterruptable = right.m_uninterruptable;
- if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
- {
- m_positionOfAudio.set( &right.m_positionOfAudio );
- }
- else if( m_ownerType == OT_Drawable )
- {
- m_drawableID = right.m_drawableID;
- }
- else if( m_ownerType == OT_Object )
- {
- m_objectID = right.m_objectID;
- }
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS& AudioEventRTS::operator=( const AudioEventRTS& right )
- {
- m_filenameToLoad = right.m_filenameToLoad;
- m_eventInfo = right.m_eventInfo;
- m_playingHandle = right.m_playingHandle;
- m_killThisHandle = right.m_killThisHandle;
- m_eventName = right.m_eventName;
- m_priority = right.m_priority;
- m_volume = right.m_volume;
- m_timeOfDay = right.m_timeOfDay;
- m_ownerType = right.m_ownerType;
- m_shouldFade = right.m_shouldFade;
- m_isLogicalAudio = right.m_isLogicalAudio;
- m_pitchShift = right.m_pitchShift;
- m_volumeShift = right.m_volumeShift;
- m_loopCount = right.m_loopCount;
- m_playingAudioIndex = right.m_playingAudioIndex;
- m_allCount = right.m_allCount;
- m_playerIndex = right.m_playerIndex;
- m_delay = right.m_delay;
- m_attackName = right.m_attackName;
- m_decayName = right.m_decayName;
- m_portionToPlayNext = right.m_portionToPlayNext;
- m_uninterruptable = right.m_uninterruptable;
- if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
- {
- m_positionOfAudio.set( &right.m_positionOfAudio );
- }
- else if( m_ownerType == OT_Drawable )
- {
- m_drawableID = right.m_drawableID;
- }
- else if( m_ownerType == OT_Object )
- {
- m_objectID = right.m_objectID;
- }
- return *this;
- }
- //-------------------------------------------------------------------------------------------------
- AudioEventRTS::~AudioEventRTS()
- {
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setEventName( AsciiString name )
- {
- if ((name != m_eventName) && m_eventInfo != NULL) {
- // Clear out the audio event info, cause its not valid for the new event.
- m_eventInfo = NULL;
- }
- m_eventName = name;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::generateFilename( void )
- {
- // A Logic Random Value is used because we may ask "How long will it take to play this sound?"
- // In that case, we need the same answer across all pcs.
- if (!m_eventInfo) {
- return;
- }
-
- m_filenameToLoad = generateFilenamePrefix(m_eventInfo->m_soundType, false);
-
- Int which = 0;
- if (m_eventInfo->m_soundType == AT_Music || m_eventInfo->m_soundType == AT_Streaming) {
- m_filenameToLoad.concat(m_eventInfo->m_filename);
- adjustForLocalization(m_filenameToLoad);
- return;
- } else {
- if (m_eventInfo->m_sounds.size() == 0) {
- m_filenameToLoad = AsciiString::TheEmptyString;
- return;
- }
-
- if (BitTest(m_eventInfo->m_control, AC_RANDOM))
- {
- if (m_isLogicalAudio)
- {
- which = GameLogicRandomValue(0, m_eventInfo->m_sounds.size() - 1);
- }
- else
- {
- which = GameAudioRandomValue(0, m_eventInfo->m_sounds.size() - 1);
- }
- if (which == m_playingAudioIndex && m_eventInfo->m_sounds.size() > 2)
- which = ( which + 1 ) % m_eventInfo->m_sounds.size();
- m_playingAudioIndex = which;//caching random choice to compare next call
- }
- else
- which = (++m_playingAudioIndex) % m_eventInfo->m_sounds.size();
-
- }
-
- m_filenameToLoad.concat(m_eventInfo->m_sounds[which]);
- m_filenameToLoad.concat(generateFilenameExtension(m_eventInfo->m_soundType));
- adjustForLocalization(m_filenameToLoad);
- // Note: Also generate Delay when generating a filename, cause
- // we want delay to apply between every loop of a sound.
- m_delay = GameAudioRandomValueReal(m_eventInfo->m_delayMin, m_eventInfo->m_delayMax);
- }
- //-------------------------------------------------------------------------------------------------
- AsciiString AudioEventRTS::getFilename( void )
- {
- return m_filenameToLoad;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::generatePlayInfo( void )
- {
- m_pitchShift = GameAudioRandomValueReal(m_eventInfo->m_pitchShiftMin, m_eventInfo->m_pitchShiftMax);
- m_volumeShift = GameAudioRandomValueReal(1.0f + m_eventInfo->m_volumeShift, 1.0f); // volume shifts are between 0 and 1
- m_loopCount = m_eventInfo->m_loopCount;
-
- m_portionToPlayNext = PP_Attack;
- Int attackSize = m_eventInfo->m_attackSounds.size();
- if (attackSize > 0) {
- m_attackName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
- // needs to be logic because it needs to be the same on all systems.
- Int attackToPlay;
- if (m_isLogicalAudio) {
- attackToPlay = GameLogicRandomValue(0, attackSize - 1);
- } else {
- attackToPlay = GameAudioRandomValue(0, attackSize - 1);
- }
-
- m_attackName.concat(m_eventInfo->m_attackSounds[attackToPlay]);
- m_attackName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
- adjustForLocalization(m_attackName);
- } else {
- m_portionToPlayNext = PP_Sound;
- }
- Int decaySize = m_eventInfo->m_decaySounds.size();
- if (decaySize > 0) {
- m_decayName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
- // needs to be logic because it needs to be the same on all systems.
- Int decayToPlay;
- if (m_isLogicalAudio) {
- decayToPlay = GameLogicRandomValue(0, decaySize - 1);
- } else {
- decayToPlay = GameAudioRandomValue(0, decaySize - 1);
- }
-
- m_decayName.concat(m_eventInfo->m_decaySounds[decayToPlay]);
- m_decayName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
- adjustForLocalization(m_decayName);
- }
- m_isLogicalAudio = FALSE;
- }
- //-------------------------------------------------------------------------------------------------
- Real AudioEventRTS::getPitchShift( void ) const
- {
- return m_pitchShift;
- }
- //-------------------------------------------------------------------------------------------------
- Real AudioEventRTS::getVolumeShift( void ) const
- {
- return m_volumeShift;
- }
- //-------------------------------------------------------------------------------------------------
- AsciiString AudioEventRTS::getAttackFilename( void ) const
- {
- return m_attackName;
- }
- //-------------------------------------------------------------------------------------------------
- AsciiString AudioEventRTS::getDecayFilename( void ) const
- {
- return m_decayName;
- }
- //-------------------------------------------------------------------------------------------------
- Real AudioEventRTS::getDelay( void ) const
- {
- return m_delay;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::decrementDelay( Real timeToDecrement )
- {
- m_delay -= timeToDecrement;
- }
- //-------------------------------------------------------------------------------------------------
- PortionToPlay AudioEventRTS::getNextPlayPortion( void ) const
- {
- return m_portionToPlayNext;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::advanceNextPlayPortion( void )
- {
- switch (m_portionToPlayNext)
- {
- case PP_Attack:
- m_portionToPlayNext = PP_Sound;
- break;
- case PP_Sound:
- if (m_eventInfo && BitTest(m_eventInfo->m_control, AC_ALL))
- {
- if (m_allCount == m_eventInfo->m_sounds.size()) {
- m_portionToPlayNext = PP_Decay;
- }
- // Advance the all count so that we move to the next sound.
- ++m_allCount;
- }
- if (!m_decayName.isEmpty()) {
- m_portionToPlayNext = PP_Decay;
- } else {
- m_portionToPlayNext = PP_Done;
- }
- break;
- case PP_Decay:
- m_portionToPlayNext = PP_Done;
- break;
- }
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setNextPlayPortion( PortionToPlay ptp )
- {
- m_portionToPlayNext = ptp;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::decreaseLoopCount( void )
- {
- if (m_loopCount == 1) {
- m_loopCount = -1;
- } else if (m_loopCount > 1) {
- --m_loopCount;
- }
- }
- //-------------------------------------------------------------------------------------------------
- Bool AudioEventRTS::hasMoreLoops( void ) const
- {
- return (m_loopCount >= 0);
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setAudioEventInfo( const AudioEventInfo *eventInfo ) const
- {
- m_eventInfo = eventInfo;
- }
- //-------------------------------------------------------------------------------------------------
- const AudioEventInfo *AudioEventRTS::getAudioEventInfo( void ) const
- {
- if (m_eventInfo) {
- if (m_eventInfo->m_audioName == m_eventName) {
- return m_eventInfo;
- } else {
- m_eventInfo = NULL;
- }
- }
- return m_eventInfo;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setPlayingHandle( AudioHandle handle )
- {
- m_playingHandle = handle;
- }
- //-------------------------------------------------------------------------------------------------
- AudioHandle AudioEventRTS::getPlayingHandle( void )
- {
- return m_playingHandle;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setPosition( const Coord3D *pos )
- {
- if (!pos) {
- return;
- }
- if (!(m_ownerType == OT_Positional || m_ownerType == OT_INVALID)) {
- return;
- }
- m_positionOfAudio = *pos;
- m_ownerType = OT_Positional;
- }
- //-------------------------------------------------------------------------------------------------
- const Coord3D* AudioEventRTS::getPosition( void )
- {
- if( m_ownerType != OT_INVALID )
- {
- return &m_positionOfAudio;
- }
- return NULL;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setObjectID( ObjectID objID )
- {
- if (!(m_ownerType == OT_Object || m_ownerType == OT_INVALID)) {
- return;
- }
- m_objectID = objID;
- m_ownerType = OT_Object;
- }
- //-------------------------------------------------------------------------------------------------
- ObjectID AudioEventRTS::getObjectID( void )
- {
- if (m_ownerType == OT_Object) {
- return m_objectID;
- }
- return INVALID_ID;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setDrawableID( DrawableID drawID )
- {
- if (!(m_ownerType == OT_Drawable || m_ownerType == OT_INVALID)) {
- return;
- }
- m_drawableID = drawID;
- m_ownerType = OT_Drawable;
- }
- //-------------------------------------------------------------------------------------------------
- DrawableID AudioEventRTS::getDrawableID( void )
- {
- if (m_ownerType == OT_Drawable) {
- return m_drawableID;
- }
- return INVALID_DRAWABLE_ID;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setTimeOfDay( TimeOfDay tod )
- {
- m_timeOfDay = tod;
- }
- //-------------------------------------------------------------------------------------------------
- TimeOfDay AudioEventRTS::getTimeOfDay( void ) const
- {
- return m_timeOfDay;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setHandleToKill( AudioHandle handleToKill )
- {
- m_killThisHandle = handleToKill;
- }
- //-------------------------------------------------------------------------------------------------
- AudioHandle AudioEventRTS::getHandleToKill( void ) const
- {
- return m_killThisHandle;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setShouldFade( Bool shouldFade )
- {
- m_shouldFade = shouldFade;
- }
- //-------------------------------------------------------------------------------------------------
- Bool AudioEventRTS::getShouldFade( void ) const
- {
- return m_shouldFade;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setIsLogicalAudio( Bool isLogicalAudio )
- {
- m_isLogicalAudio = isLogicalAudio;
- }
- //-------------------------------------------------------------------------------------------------
- Bool AudioEventRTS::getIsLogicalAudio( void ) const
- {
- return m_isLogicalAudio;
- }
- //-------------------------------------------------------------------------------------------------
- Bool AudioEventRTS::isPositionalAudio( void ) const
- {
- if( m_eventInfo )
- {
- if( !BitTest( m_eventInfo->m_type, ST_WORLD ) )
- {
- return FALSE;
- }
- }
- if( m_ownerType != OT_INVALID )
- {
- if( m_drawableID != INVALID_DRAWABLE_ID || m_objectID != INVALID_ID || m_ownerType == OT_Positional )
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- //-------------------------------------------------------------------------------------------------
- Bool AudioEventRTS::isCurrentlyPlaying( void ) const
- {
- return TheAudio->isCurrentlyPlaying(m_playingHandle);
- }
- //-------------------------------------------------------------------------------------------------
- AudioPriority AudioEventRTS::getAudioPriority( void ) const
- {
- return m_priority;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setAudioPriority( AudioPriority newPriority )
- {
- m_priority = newPriority;
- }
- //-------------------------------------------------------------------------------------------------
- Real AudioEventRTS::getVolume( void ) const
- {
- if (m_volume == -1.0f) {
- if (m_eventInfo) {
- return m_eventInfo->m_volume;
- }
- return 0.5;
- }
-
- return m_volume;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setVolume( Real vol )
- {
- m_volume = vol;
- }
- //-------------------------------------------------------------------------------------------------
- const Coord3D *AudioEventRTS::getCurrentPosition( void )
- {
- if (m_ownerType == OT_Positional)
- {
- return &m_positionOfAudio;
- }
- else if (m_ownerType == OT_Object)
- {
- Object *obj = TheGameLogic->findObjectByID(m_objectID);
- if (obj)
- {
- m_positionOfAudio.set( obj->getPosition() );
- }
- else
- {
- m_ownerType = OT_Dead;
- }
- return &m_positionOfAudio;
- }
- else if (m_ownerType == OT_Drawable)
- {
- Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
- if( draw )
- {
- m_positionOfAudio.set( draw->getPosition() );
- }
- else
- {
- m_ownerType = OT_Dead;
- }
- return &m_positionOfAudio;
- }
- else if( m_ownerType == OT_Dead )
- {
- return &m_positionOfAudio;
- }
- return NULL;
- }
- //-------------------------------------------------------------------------------------------------
- AsciiString AudioEventRTS::generateFilenamePrefix( AudioType audioTypeToPlay, Bool localized )
- {
- AsciiString retStr;
- retStr = TheAudio->getAudioSettings()->m_audioRoot;
- retStr.concat("\\");
- if (audioTypeToPlay == AT_Music) {
- retStr.concat(TheAudio->getAudioSettings()->m_musicFolder);
- } else if (audioTypeToPlay == AT_Streaming) {
- retStr.concat(TheAudio->getAudioSettings()->m_streamingFolder);
- } else {
- retStr.concat(TheAudio->getAudioSettings()->m_soundsFolder);
- }
- retStr.concat("\\");
- if (localized) {
- retStr.concat(GetRegistryLanguage());
- retStr.concat("\\");
- }
- return retStr;
- }
- //-------------------------------------------------------------------------------------------------
- AsciiString AudioEventRTS::generateFilenameExtension( AudioType audioTypeToPlay )
- {
- AsciiString retStr = AsciiString::TheEmptyString;
- if (audioTypeToPlay != AT_Music) {
- retStr = ".";
- retStr.concat(TheAudio->getAudioSettings()->m_soundsExtension);
- }
- return retStr;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::adjustForLocalization(AsciiString &strToAdjust)
- {
- const char *str = strToAdjust.reverseFind('\\');
- if (!str) {
- return;
- }
- // try the localized version first so that we're guarenteed to get it
- // even if the generic data directory holds a version of the file
- AsciiString localizedFilePath = generateFilenamePrefix(m_eventInfo->m_soundType, TRUE);
- AsciiString filename = str;
- localizedFilePath.concat(filename);
- if (TheFileSystem->doesFileExist(localizedFilePath.str())) {
- strToAdjust = localizedFilePath;
- }
- // else there was no localized version, so leave the path we received unchanged
- return;
- }
- //-------------------------------------------------------------------------------------------------
- Int AudioEventRTS::getPlayerIndex( void ) const
- {
- if (m_ownerType == OT_Object) {
- Object *obj = TheGameLogic->findObjectByID(m_objectID);
- if (obj) {
- return obj->getControllingPlayer()->getPlayerIndex();
- }
- } else if (m_ownerType == OT_Drawable) {
- Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
- if (draw) {
- Object *obj = draw->getObject();
- if (obj) {
- return obj->getControllingPlayer()->getPlayerIndex();
- }
- }
- }
- return m_playerIndex;
- }
- //-------------------------------------------------------------------------------------------------
- void AudioEventRTS::setPlayerIndex( Int playerNdx )
- {
- m_playerIndex = playerNdx;
- }
|