Skip to content

Commit 1969d0a

Browse files
authored
feat(audio): Implement 'MoneyTransactionVolume' option to modify the volume of money deposit and withdraw audio events (#1353)
In Options.ini add MoneyTransactionVolume=0 to turn off and MoneyTransactionVolume=100 to turn on
1 parent 0dd58aa commit 1969d0a

File tree

10 files changed

+109
-20
lines changed

10 files changed

+109
-20
lines changed

Core/GameEngine/Include/Common/AudioSettings.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,19 @@
3535

3636
enum { MAX_HW_PROVIDERS = 4 };
3737

38+
// TheSuperHackers @tweak xezon 23/07/2025 Adds setting to modify the volume of money deposit and withdraw sounds
39+
3840
struct AudioSettings
3941
{
42+
AudioSettings()
43+
#if RTS_GENERALS
44+
: m_defaultMoneyTransactionVolume(1.0f)
45+
#elif RTS_ZEROHOUR
46+
: m_defaultMoneyTransactionVolume(0.0f) // Uses zero volume by default because originally the money sounds did not work in Zero Hour
47+
#endif
48+
{
49+
}
50+
4051
AsciiString m_audioRoot;
4152
AsciiString m_soundsFolder;
4253
AsciiString m_musicFolder;
@@ -66,6 +77,7 @@ struct AudioSettings
6677
Real m_default3DSoundVolume;
6778
Real m_defaultSpeechVolume;
6879
Real m_defaultMusicVolume;
80+
Real m_defaultMoneyTransactionVolume;
6981
UnsignedInt m_defaultSpeakerType2D;
7082
UnsignedInt m_defaultSpeakerType3D;
7183

@@ -74,6 +86,7 @@ struct AudioSettings
7486
Real m_preferred3DSoundVolume;
7587
Real m_preferredSpeechVolume;
7688
Real m_preferredMusicVolume;
89+
Real m_preferredMoneyTransactionVolume;
7790

7891
//The desired altitude of the microphone to improve panning relative to terrain.
7992
Real m_microphoneDesiredHeightAboveTerrain;

Core/GameEngine/Source/Common/Audio/GameAudio.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static const FieldParse audioSettingsFieldParseTable[] =
126126
{ "Default3DSoundVolume", INI::parsePercentToReal, NULL, offsetof( AudioSettings, m_default3DSoundVolume) },
127127
{ "DefaultSpeechVolume", INI::parsePercentToReal, NULL, offsetof( AudioSettings, m_defaultSpeechVolume) },
128128
{ "DefaultMusicVolume", INI::parsePercentToReal, NULL, offsetof( AudioSettings, m_defaultMusicVolume) },
129+
{ "DefaultMoneyTransactionVolume", INI::parsePercentToReal, NULL, offsetof( AudioSettings, m_defaultMoneyTransactionVolume) },
129130
{ "MicrophoneDesiredHeightAboveTerrain", INI::parseReal, NULL, offsetof( AudioSettings, m_microphoneDesiredHeightAboveTerrain ) },
130131
{ "MicrophoneMaxPercentageBetweenGroundAndCamera", INI::parsePercentToReal, NULL, offsetof( AudioSettings, m_microphoneMaxPercentageBetweenGroundAndCamera ) },
131132
{ "ZoomMinDistance", INI::parseReal, NULL, offsetof( AudioSettings, m_zoomMinDistance ) },
@@ -1150,6 +1151,7 @@ void INI::parseAudioSettingsDefinition( INI *ini )
11501151
TheAudio->friend_getAudioSettings()->m_preferred3DSoundVolume = prefs.get3DSoundVolume() / 100.0f;
11511152
TheAudio->friend_getAudioSettings()->m_preferredSpeechVolume = prefs.getSpeechVolume() / 100.0f;
11521153
TheAudio->friend_getAudioSettings()->m_preferredMusicVolume = prefs.getMusicVolume() / 100.0f;
1154+
TheAudio->friend_getAudioSettings()->m_preferredMoneyTransactionVolume = prefs.getMoneyTransactionVolume() / 100.0f;
11531155
}
11541156

11551157
//-------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Include/Common/Money.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include "Common/Debug.h"
5252
#include "Common/Snapshot.h"
5353

54+
class AudioEventRTS;
55+
5456
// ----------------------------------------------------------------------------------------------
5557
/**
5658
How much "money" (Tiberium, Gems, Magic Resource Boxes, whatever) the Player has.
@@ -91,6 +93,9 @@ class Money : public Snapshot
9193
}
9294

9395
protected:
96+
97+
void triggerAudioEvent(const AudioEventRTS& audioEvent);
98+
9499
// snapshot methods
95100
virtual void crc( Xfer *xfer );
96101
virtual void xfer( Xfer *xfer );

Generals/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class OptionPreferences : public UserPreferences
102102
Real get3DSoundVolume(void); // convenience function
103103
Real getSpeechVolume(void); // convenience function
104104
Real getMusicVolume(void); // convenience function
105+
Real getMoneyTransactionVolume(void) const;
105106
Bool saveCameraInReplays(void);
106107
Bool useCameraInReplays(void);
107108
Int getStaticGameDetail(void); // detail level selected by the user.

Generals/Code/GameEngine/Source/Common/RTS/Money.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
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,18 +83,28 @@ 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;
9992
}
10093

94+
void Money::triggerAudioEvent(const AudioEventRTS& audioEvent)
95+
{
96+
Real volume = TheAudio->getAudioSettings()->m_preferredMoneyTransactionVolume;
97+
volume *= audioEvent.getVolume();
98+
if (volume <= 0.0f)
99+
return;
100+
101+
//@todo: Do we do this frequently enough that it is a performance hit?
102+
AudioEventRTS event = audioEvent;
103+
event.setPlayerIndex(m_playerIndex);
104+
event.setVolume(volume);
105+
TheAudio->addAudioEvent(&event);
106+
}
107+
101108
// ------------------------------------------------------------------------------------------------
102109
/** CRC */
103110
// ------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ Real OptionPreferences::getMusicVolume(void)
725725
return volume;
726726
}
727727

728+
Real OptionPreferences::getMoneyTransactionVolume(void) const
729+
{
730+
OptionPreferences::const_iterator it = find("MoneyTransactionVolume");
731+
if (it == end())
732+
return TheAudio->getAudioSettings()->m_defaultMoneyTransactionVolume * 100.0f;
733+
734+
Real volume = (Real) atof(it->second.str());
735+
if (volume < 0.0f)
736+
volume = 0.0f;
737+
738+
return volume;
739+
}
740+
728741
Int OptionPreferences::getSystemTimeFontSize(void)
729742
{
730743
OptionPreferences::const_iterator it = find("SystemTimeFontSize");
@@ -1195,6 +1208,17 @@ static void saveOptions( void )
11951208
TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Speech | AudioAffect_SystemSetting));
11961209
}
11971210

1211+
//-------------------------------------------------------------------------------------------------
1212+
// Money tick volume
1213+
// TheSuperHackers @todo Add options slider ?
1214+
{
1215+
val = pref->getMoneyTransactionVolume();
1216+
AsciiString prefString;
1217+
prefString.format("%d", val);
1218+
(*pref)["MoneyTransactionVolume"] = prefString;
1219+
TheAudio->friend_getAudioSettings()->m_preferredMoneyTransactionVolume = val / 100.0f;
1220+
}
1221+
11981222
//-------------------------------------------------------------------------------------------------
11991223
// slider Gamma
12001224
val = GadgetSliderGetPosition(sliderGamma);

GeneralsMD/Code/GameEngine/Include/Common/Money.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include "Common/Debug.h"
5252
#include "Common/Snapshot.h"
5353

54+
class AudioEventRTS;
55+
5456
// ----------------------------------------------------------------------------------------------
5557
/**
5658
How much "money" (Tiberium, Gems, Magic Resource Boxes, whatever) the Player has.
@@ -91,6 +93,9 @@ class Money : public Snapshot
9193
}
9294

9395
protected:
96+
97+
void triggerAudioEvent(const AudioEventRTS& audioEvent);
98+
9499
// snapshot methods
95100
virtual void crc( Xfer *xfer );
96101
virtual void xfer( Xfer *xfer );

GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class OptionPreferences : public UserPreferences
106106
Real get3DSoundVolume(void); // convenience function
107107
Real getSpeechVolume(void); // convenience function
108108
Real getMusicVolume(void); // convenience function
109+
Real getMoneyTransactionVolume(void) const;
109110
Bool saveCameraInReplays(void);
110111
Bool useCameraInReplays(void);
111112
Int getStaticGameDetail(void); // detail level selected by the user.

GeneralsMD/Code/GameEngine/Source/Common/RTS/Money.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
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
// ------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,19 @@ Real OptionPreferences::getMusicVolume(void)
769769
return volume;
770770
}
771771

772+
Real OptionPreferences::getMoneyTransactionVolume(void) const
773+
{
774+
OptionPreferences::const_iterator it = find("MoneyTransactionVolume");
775+
if (it == end())
776+
return TheAudio->getAudioSettings()->m_defaultMoneyTransactionVolume * 100.0f;
777+
778+
Real volume = (Real) atof(it->second.str());
779+
if (volume < 0.0f)
780+
volume = 0.0f;
781+
782+
return volume;
783+
}
784+
772785
Int OptionPreferences::getSystemTimeFontSize(void)
773786
{
774787
OptionPreferences::const_iterator it = find("SystemTimeFontSize");
@@ -1255,6 +1268,17 @@ static void saveOptions( void )
12551268
TheAudio->setVolume(val / 100.0f, (AudioAffect) (AudioAffect_Speech | AudioAffect_SystemSetting));
12561269
}
12571270

1271+
//-------------------------------------------------------------------------------------------------
1272+
// Money tick volume
1273+
// TheSuperHackers @todo Add options slider ?
1274+
{
1275+
val = pref->getMoneyTransactionVolume();
1276+
AsciiString prefString;
1277+
prefString.format("%d", val);
1278+
(*pref)["MoneyTransactionVolume"] = prefString;
1279+
TheAudio->friend_getAudioSettings()->m_preferredMoneyTransactionVolume = val / 100.0f;
1280+
}
1281+
12581282
//-------------------------------------------------------------------------------------------------
12591283
// slider Gamma
12601284
val = GadgetSliderGetPosition(sliderGamma);

0 commit comments

Comments
 (0)