Skip to content

Commit bfa3065

Browse files
committed
feat(display): Implement player money per minute
1 parent 24f8da9 commit bfa3065

File tree

20 files changed

+179
-29
lines changed

20 files changed

+179
-29
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ class GlobalData : public SubsystemInterface
415415
Int m_systemTimeFontSize;
416416
Int m_gameTimeFontSize;
417417

418+
// TheSuperHackers @feature L3-M 21/08/2025 toggle the money per minute display, false shows only the original current money
419+
Bool m_showMoneyPerMinute;
420+
418421
Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
419422
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
420423
Real m_shakeStrongIntensity; ///< Intensity for shaking a camera with SHAKE_STRONG

GeneralsMD/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
};

GeneralsMD/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>

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

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

150150
Real getResolutionFontAdjustment(void);
151+
152+
Bool getShowMoneyPerMinute(void) const;
151153
};
152154

153155
//-----------------------------------------------------------------------------

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ GlobalData::GlobalData()
948948
m_systemTimeFontSize = 8;
949949
m_gameTimeFontSize = 8;
950950

951+
m_showMoneyPerMinute = FALSE;
952+
951953
m_debugShowGraphicalFramerate = FALSE;
952954

953955
// By default, show all asserts.
@@ -1220,6 +1222,7 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12201222
TheWritableGlobalData->m_renderFpsFontSize = optionPref.getRenderFpsFontSize();
12211223
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
12221224
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
1225+
TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute();
12231226

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

GeneralsMD/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,6 +89,12 @@ 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
if( amountToDeposit > 0 )
@@ -100,6 +107,34 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
100107
}
101108
}
102109

110+
// ------------------------------------------------------------------------------------------------
111+
void Money::setStartingCash(UnsignedInt amount)
112+
{
113+
m_money = amount;
114+
std::fill(m_incomeBuckets, m_incomeBuckets + ARRAY_SIZE(m_incomeBuckets), 0u);
115+
m_currentBucket = 0u;
116+
m_cashPerMinute = 0u;
117+
}
118+
119+
// ------------------------------------------------------------------------------------------------
120+
void Money::updateIncomeBucket()
121+
{
122+
UnsignedInt frame = TheGameLogic->getFrame();
123+
UnsignedInt nextBucket = (frame / LOGICFRAMES_PER_SECOND) % ARRAY_SIZE(m_incomeBuckets);
124+
if (nextBucket != m_currentBucket)
125+
{
126+
m_cashPerMinute -= m_incomeBuckets[nextBucket];
127+
m_currentBucket = nextBucket;
128+
m_incomeBuckets[m_currentBucket] = 0u;
129+
}
130+
}
131+
132+
// ------------------------------------------------------------------------------------------------
133+
UnsignedInt Money::getCashPerMinute() const
134+
{
135+
return m_cashPerMinute;
136+
}
137+
103138
void Money::triggerAudioEvent(const AudioEventRTS& audioEvent)
104139
{
105140
Real volume = TheAudio->getAudioSettings()->m_preferredMoneyTransactionVolume;
@@ -125,19 +160,35 @@ void Money::crc( Xfer *xfer )
125160
// ------------------------------------------------------------------------------------------------
126161
/** Xfer method
127162
* Version Info:
128-
* 1: Initial version */
163+
* 1: Initial version
164+
* 2: Add saveload support for the cash per minute income tracking */
129165
// ------------------------------------------------------------------------------------------------
130166
void Money::xfer( Xfer *xfer )
131167
{
132168

133169
// version
170+
#if RETAIL_COMPATIBLE_XFER_SAVE
134171
XferVersion currentVersion = 1;
172+
#else
173+
XferVersion currentVersion = 2;
174+
#endif
135175
XferVersion version = currentVersion;
136176
xfer->xferVersion( &version, currentVersion );
137177

138178
// money value
139179
xfer->xferUnsignedInt( &m_money );
140180

181+
if (version <= 1)
182+
{
183+
setStartingCash(m_money);
184+
}
185+
else
186+
{
187+
xfer->xferUser(m_incomeBuckets, sizeof(m_incomeBuckets));
188+
xfer->xferUnsignedInt(&m_currentBucket);
189+
190+
m_cashPerMinute = std::accumulate(m_incomeBuckets, m_incomeBuckets + ARRAY_SIZE(m_incomeBuckets), 0u);
191+
}
141192
}
142193

143194
// ------------------------------------------------------------------------------------------------
@@ -156,5 +207,7 @@ void Money::parseMoneyAmount( INI *ini, void *instance, void *store, const void*
156207
{
157208
// Someday, maybe, have mulitple fields like Gold:10000 Wood:1000 Tiberian:10
158209
Money * money = (Money *)store;
159-
INI::parseUnsignedInt( ini, instance, &money->m_money, userData );
210+
UnsignedInt moneyAmount;
211+
INI::parseUnsignedInt( ini, instance, &moneyAmount, userData );
212+
money->setStartingCash(moneyAmount);
160213
}

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

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

@@ -2156,7 +2156,7 @@ void Player::transferAssetsFromThat(Player *that)
21562156
// transfer all his money
21572157
UnsignedInt allMoney = that->getMoney()->countMoney();
21582158
that->getMoney()->withdraw(allMoney);
2159-
getMoney()->deposit(allMoney);
2159+
getMoney()->deposit(allMoney, TRUE, FALSE);
21602160
}
21612161

21622162
//=============================================================================

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ AsciiString PlayerTemplate::getStartingUnit( Int i ) const
181181
// assign the money into the 'Money' (m_money) pointed to at 'store'
182182
Money *theMoney = (Money *)store;
183183
theMoney->init();
184-
theMoney->deposit( money );
184+
theMoney->setStartingCash(money);
185185

186186
}
187187

GeneralsMD/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

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

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

718718
Money money;
719-
money.deposit( strtoul( it->second.str(), NULL, 10 ), FALSE );
719+
money.deposit( strtoul( it->second.str(), NULL, 10 ), FALSE, FALSE );
720720

721721
return money;
722722
}

0 commit comments

Comments
 (0)