Skip to content

Commit 217b582

Browse files
authored
feat(gui): Implement money per minute display for local player (#1481)
Is disabled by default and can be enabled by setting ShowMoneyPerMinute=yes in Options.ini
1 parent 24f8da9 commit 217b582

File tree

38 files changed

+355
-55
lines changed

38 files changed

+355
-55
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ class GlobalData : public SubsystemInterface
408408
Int m_systemTimeFontSize;
409409
Int m_gameTimeFontSize;
410410

411+
// TheSuperHackers @feature L3-M 21/08/2025 toggle the money per minute display, false shows only the original current money
412+
Bool m_showMoneyPerMinute;
413+
411414
Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
412415
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
413416
Real m_shakeStrongIntensity; ///< Intensity for shaking a camera with SHAKE_STRONG

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ class Money : public Snapshot
6161

6262
public:
6363

64-
inline Money() : m_money(0), m_playerIndex(0)
64+
inline Money() : m_playerIndex(0)
6565
{
66+
init();
6667
}
6768

6869
void init()
6970
{
70-
m_money = 0;
71+
setStartingCash(0);
7172
}
7273

7374
inline UnsignedInt countMoney() const
@@ -77,7 +78,11 @@ class Money : public Snapshot
7778

7879
/// returns the actual amount withdrawn, which may be less than you want. (sorry, can't go into debt...)
7980
UnsignedInt withdraw(UnsignedInt amountToWithdraw, Bool playSound = TRUE);
80-
void deposit(UnsignedInt amountToDeposit, Bool playSound = TRUE);
81+
void deposit(UnsignedInt amountToDeposit, Bool playSound = TRUE, Bool trackIncome = TRUE);
82+
83+
void setStartingCash(UnsignedInt amount);
84+
void updateIncomeBucket();
85+
UnsignedInt getCashPerMinute() const;
8186

8287
void setPlayerIndex(Int ndx) { m_playerIndex = ndx; }
8388

@@ -102,4 +107,7 @@ class Money : public Snapshot
102107

103108
UnsignedInt m_money; ///< amount of money
104109
Int m_playerIndex; ///< what is my player index?
110+
UnsignedInt m_incomeBuckets[60]; ///< circular buffer of 60 seconds for income tracking
111+
UnsignedInt m_currentBucket;
112+
UnsignedInt m_cashPerMinute;
105113
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum DrawableID CPP_11(: Int);
7070
#include <Utility/hash_map_adapter.h>
7171
#include <list>
7272
#include <map>
73+
#include <numeric>
7374
#include <queue>
7475
#include <set>
7576
#include <stack>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class OptionPreferences : public UserPreferences
145145
Int getGameTimeFontSize(void);
146146

147147
Real getResolutionFontAdjustment(void);
148+
149+
Bool getShowMoneyPerMinute(void) const;
148150
};
149151

150152
//-----------------------------------------------------------------------------

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ GlobalData::GlobalData()
939939
m_systemTimeFontSize = 8;
940940
m_gameTimeFontSize = 8;
941941

942+
m_showMoneyPerMinute = FALSE;
943+
942944
m_debugShowGraphicalFramerate = FALSE;
943945

944946
// By default, show all asserts.
@@ -1192,6 +1194,7 @@ void GlobalData::parseGameDataDefinition( INI* ini )
11921194
TheWritableGlobalData->m_renderFpsFontSize = optionPref.getRenderFpsFontSize();
11931195
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
11941196
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
1197+
TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute();
11951198

11961199
Int val=optionPref.getGammaValue();
11971200
//generate a value between 0.6 and 2.0.

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "Common/Player.h"
5252
#include "Common/PlayerList.h"
5353
#include "Common/Xfer.h"
54+
#include "GameLogic/GameLogic.h"
5455

5556
// ------------------------------------------------------------------------------------------------
5657
UnsignedInt Money::withdraw(UnsignedInt amountToWithdraw, Bool playSound)
@@ -78,7 +79,7 @@ UnsignedInt Money::withdraw(UnsignedInt amountToWithdraw, Bool playSound)
7879
}
7980

8081
// ------------------------------------------------------------------------------------------------
81-
void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
82+
void Money::deposit(UnsignedInt amountToDeposit, Bool playSound, Bool trackIncome)
8283
{
8384
if (amountToDeposit == 0)
8485
return;
@@ -88,9 +89,43 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
8889
triggerAudioEvent(TheAudio->getMiscAudio()->m_moneyDepositSound);
8990
}
9091

92+
if (trackIncome)
93+
{
94+
m_incomeBuckets[m_currentBucket] += amountToDeposit;
95+
m_cashPerMinute += amountToDeposit;
96+
}
97+
9198
m_money += amountToDeposit;
9299
}
93100

101+
// ------------------------------------------------------------------------------------------------
102+
void Money::setStartingCash(UnsignedInt amount)
103+
{
104+
m_money = amount;
105+
std::fill(m_incomeBuckets, m_incomeBuckets + ARRAY_SIZE(m_incomeBuckets), 0u);
106+
m_currentBucket = 0u;
107+
m_cashPerMinute = 0u;
108+
}
109+
110+
// ------------------------------------------------------------------------------------------------
111+
void Money::updateIncomeBucket()
112+
{
113+
UnsignedInt frame = TheGameLogic->getFrame();
114+
UnsignedInt nextBucket = (frame / LOGICFRAMES_PER_SECOND) % ARRAY_SIZE(m_incomeBuckets);
115+
if (nextBucket != m_currentBucket)
116+
{
117+
m_cashPerMinute -= m_incomeBuckets[nextBucket];
118+
m_currentBucket = nextBucket;
119+
m_incomeBuckets[m_currentBucket] = 0u;
120+
}
121+
}
122+
123+
// ------------------------------------------------------------------------------------------------
124+
UnsignedInt Money::getCashPerMinute() const
125+
{
126+
return m_cashPerMinute;
127+
}
128+
94129
void Money::triggerAudioEvent(const AudioEventRTS& audioEvent)
95130
{
96131
Real volume = TheAudio->getAudioSettings()->m_preferredMoneyTransactionVolume;
@@ -116,19 +151,35 @@ void Money::crc( Xfer *xfer )
116151
// ------------------------------------------------------------------------------------------------
117152
/** Xfer method
118153
* Version Info:
119-
* 1: Initial version */
154+
* 1: Initial version
155+
* 2: Add saveload support for the cash per minute income tracking */
120156
// ------------------------------------------------------------------------------------------------
121157
void Money::xfer( Xfer *xfer )
122158
{
123159

124160
// version
161+
#if RETAIL_COMPATIBLE_XFER_SAVE
125162
XferVersion currentVersion = 1;
163+
#else
164+
XferVersion currentVersion = 2;
165+
#endif
126166
XferVersion version = currentVersion;
127167
xfer->xferVersion( &version, currentVersion );
128168

129169
// money value
130170
xfer->xferUnsignedInt( &m_money );
131171

172+
if (version <= 1)
173+
{
174+
setStartingCash(m_money);
175+
}
176+
else
177+
{
178+
xfer->xferUser(m_incomeBuckets, sizeof(m_incomeBuckets));
179+
xfer->xferUnsignedInt(&m_currentBucket);
180+
181+
m_cashPerMinute = std::accumulate(m_incomeBuckets, m_incomeBuckets + ARRAY_SIZE(m_incomeBuckets), 0u);
182+
}
132183
}
133184

134185
// ------------------------------------------------------------------------------------------------
@@ -147,5 +198,7 @@ void Money::parseMoneyAmount( INI *ini, void *instance, void *store, const void*
147198
{
148199
// Someday, maybe, have mulitple fields like Gold:10000 Wood:1000 Tiberian:10
149200
Money * money = (Money *)store;
150-
INI::parseUnsignedInt( ini, instance, &money->m_money, userData );
201+
UnsignedInt moneyAmount;
202+
INI::parseUnsignedInt( ini, instance, &moneyAmount, userData );
203+
money->setStartingCash(moneyAmount);
151204
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ void Player::init(const PlayerTemplate* pt)
434434
// Note that copying the entire Money class instead would also copy the player index inside of it.
435435
if ( TheGameInfo )
436436
{
437-
m_money.deposit( TheGameInfo->getStartingCash().countMoney(), FALSE );
437+
m_money.deposit( TheGameInfo->getStartingCash().countMoney(), FALSE, FALSE );
438438
}
439439
else
440440
{
441-
m_money.deposit( TheGlobalData->m_defaultStartingCash.countMoney(), FALSE );
441+
m_money.deposit( TheGlobalData->m_defaultStartingCash.countMoney(), FALSE, FALSE );
442442
}
443443
}
444444

@@ -1771,7 +1771,7 @@ void Player::transferAssetsFromThat(Player *that)
17711771
// transfer all his money
17721772
UnsignedInt allMoney = that->getMoney()->countMoney();
17731773
that->getMoney()->withdraw(allMoney);
1774-
getMoney()->deposit(allMoney);
1774+
getMoney()->deposit(allMoney, TRUE, FALSE);
17751775
}
17761776

17771777
//=============================================================================

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ AsciiString PlayerTemplate::getStartingUnit( Int i ) const
171171
// assign the money into the 'Money' (m_money) pointed to at 'store'
172172
Money *theMoney = (Money *)store;
173173
theMoney->init();
174-
theMoney->deposit( money );
174+
theMoney->setStartingCash(money);
175175

176176
}
177177

Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void BuildAssistant::update( void )
250250
sellValue = REAL_TO_UNSIGNEDINT( obj->getTemplate()->calcCostToBuild( player ) *
251251
TheGlobalData->m_sellPercentage );
252252

253-
player->getMoney()->deposit( sellValue );
253+
player->getMoney()->deposit( sellValue, TRUE, FALSE );
254254
// this money shouldn't be scored since it wasn't really "earned."
255255
// player->getScoreKeeper()->addMoneyEarned( sellValue );
256256

Generals/Code/GameEngine/Source/Common/UserPreferences.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ Money CustomMatchPreferences::getStartingCash(void) const
700700
}
701701

702702
Money money;
703-
money.deposit( strtoul( it->second.str(), NULL, 10 ), FALSE );
703+
money.deposit( strtoul( it->second.str(), NULL, 10 ), FALSE, FALSE );
704704

705705
return money;
706706
}

0 commit comments

Comments
 (0)