Skip to content

Commit ec23198

Browse files
committed
feat(display): Implement player money per minute
1 parent 487e5ce commit ec23198

File tree

20 files changed

+180
-29
lines changed

20 files changed

+180
-29
lines changed

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

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

417+
// TheSuperHackers @feature L3-M 21/08/2025 toggle the money per minute display, false shows only the original current money
418+
Bool m_showMoneyPerMinute;
419+
417420
Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
418421
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
419422
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
@@ -64,13 +64,14 @@ class Money : public Snapshot
6464

6565
public:
6666

67-
inline Money() : m_money(0), m_playerIndex(0)
67+
inline Money() : m_playerIndex(0)
6868
{
69+
init();
6970
}
7071

7172
void init()
7273
{
73-
m_money = 0;
74+
setStartingCash(0);
7475
}
7576

7677
inline UnsignedInt countMoney() const
@@ -80,7 +81,11 @@ class Money : public Snapshot
8081

8182
/// returns the actual amount withdrawn, which may be less than you want. (sorry, can't go into debt...)
8283
UnsignedInt withdraw(UnsignedInt amountToWithdraw, Bool playSound = TRUE);
83-
void deposit(UnsignedInt amountToDeposit, Bool playSound = TRUE);
84+
void deposit(UnsignedInt amountToDeposit, Bool playSound = TRUE, Bool trackIncome = TRUE);
85+
86+
void setStartingCash(UnsignedInt amount);
87+
void updateIncomeBucket();
88+
UnsignedInt getCashPerMinute() const;
8489

8590
void setPlayerIndex(Int ndx) { m_playerIndex = ndx; }
8691

@@ -105,6 +110,9 @@ class Money : public Snapshot
105110

106111
UnsignedInt m_money; ///< amount of money
107112
Int m_playerIndex; ///< what is my player index?
113+
UnsignedInt m_incomeBuckets[60]; ///< circular buffer of 60 seconds for income tracking
114+
UnsignedInt m_currentBucket;
115+
UnsignedInt m_cashPerMinute;
108116
};
109117

110118
#endif // _MONEY_H_

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enum DrawableID CPP_11(: Int);
7474
#include <Utility/hash_map_adapter.h>
7575
#include <list>
7676
#include <map>
77+
#include <numeric>
7778
#include <queue>
7879
#include <set>
7980
#include <stack>

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

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

151151
Real getResolutionFontAdjustment(void);
152+
153+
Bool getShowMoneyPerMinute(void) const;
152154
};
153155

154156
//-----------------------------------------------------------------------------

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

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

950+
m_showMoneyPerMinute = FALSE;
951+
950952
m_debugShowGraphicalFramerate = FALSE;
951953

952954
// By default, show all asserts.
@@ -1218,6 +1220,7 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12181220
TheWritableGlobalData->m_renderFpsFontSize = optionPref.getRenderFpsFontSize();
12191221
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
12201222
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
1223+
TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute();
12211224

12221225
Int val=optionPref.getGammaValue();
12231226
//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

@@ -2148,7 +2148,7 @@ void Player::transferAssetsFromThat(Player *that)
21482148
// transfer all his money
21492149
UnsignedInt allMoney = that->getMoney()->countMoney();
21502150
that->getMoney()->withdraw(allMoney);
2151-
getMoney()->deposit(allMoney);
2151+
getMoney()->deposit(allMoney, TRUE, FALSE);
21522152
}
21532153

21542154
//=============================================================================

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)