4545#include " PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
4646#include " Common/Money.h"
4747
48+ #include " Common/AudioSettings.h"
4849#include " Common/GameAudio.h"
4950#include " Common/MiscAudio.h"
5051#include " Common/Player.h"
@@ -66,13 +67,9 @@ UnsignedInt Money::withdraw(UnsignedInt amountToWithdraw, Bool playSound)
6667 if (amountToWithdraw == 0 )
6768 return amountToWithdraw;
6869
69- // Play a sound
7070 if (playSound)
7171 {
72- // @todo: Do we do this frequently enough that it is a performance hit?
73- AudioEventRTS event = TheAudio->getMiscAudio ()->m_moneyWithdrawSound ;
74- event.setPlayerIndex (m_playerIndex);
75- TheAudio->addAudioEvent (&event);
72+ triggerAudioEvent (TheAudio->getMiscAudio ()->m_moneyWithdrawSound );
7673 }
7774
7875 m_money -= amountToWithdraw;
@@ -86,13 +83,9 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
8683 if (amountToDeposit == 0 )
8784 return ;
8885
89- // Play a sound
9086 if (playSound)
9187 {
92- // @todo: Do we do this frequently enough that it is a performance hit?
93- AudioEventRTS event = TheAudio->getMiscAudio ()->m_moneyDepositSound ;
94- event.setPlayerIndex (m_playerIndex);
95- TheAudio->addAudioEvent (&event);
88+ triggerAudioEvent (TheAudio->getMiscAudio ()->m_moneyDepositSound );
9689 }
9790
9891 m_money += amountToDeposit;
@@ -107,6 +100,20 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
107100 }
108101}
109102
103+ void Money::triggerAudioEvent (const AudioEventRTS& audioEvent)
104+ {
105+ Real volume = TheAudio->getAudioSettings ()->m_preferredMoneyTransactionVolume ;
106+ volume *= audioEvent.getVolume ();
107+ if (volume <= 0 .0f )
108+ return ;
109+
110+ // @todo: Do we do this frequently enough that it is a performance hit?
111+ AudioEventRTS event = audioEvent;
112+ event.setPlayerIndex (m_playerIndex);
113+ event.setVolume (volume);
114+ TheAudio->addAudioEvent (&event);
115+ }
116+
110117// ------------------------------------------------------------------------------------------------
111118/* * CRC */
112119// ------------------------------------------------------------------------------------------------
0 commit comments