Skip to content

Commit 8a09853

Browse files
committed
Implement suggestions 2
1 parent 4c9114b commit 8a09853

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,14 @@ class Money : public Snapshot
6464

6565
public:
6666

67-
inline Money() : m_money(0), m_playerIndex(0), m_startingCash(0), m_currentBucket(0), m_lastBucketFrame(0)
67+
inline Money() : m_playerIndex(0)
6868
{
69-
for (UnsignedInt i = 0; i < 60; ++i)
70-
{
71-
m_incomeBuckets[i] = 0;
72-
}
69+
init();
7370
}
7471

7572
void init()
7673
{
77-
m_money = 0;
78-
m_startingCash = 0;
79-
m_currentBucket = 0;
80-
m_lastBucketFrame = 0;
81-
for (UnsignedInt i = 0; i < 60; ++i)
82-
{
83-
m_incomeBuckets[i] = 0;
84-
}
74+
setStartingCash(0);
8575
}
8676

8777
inline UnsignedInt countMoney() const
@@ -120,7 +110,6 @@ class Money : public Snapshot
120110

121111
UnsignedInt m_money; ///< amount of money
122112
Int m_playerIndex; ///< what is my player index?
123-
UnsignedInt m_startingCash;
124113
UnsignedInt m_incomeBuckets[60];
125114
UnsignedInt m_currentBucket;
126115
UnsignedInt m_lastBucketFrame;

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

Lines changed: 13 additions & 8 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
#include <numeric>
48+
#include <algorithm>
4849

4950
#include "Common/AudioSettings.h"
5051
#include "Common/GameAudio.h"
@@ -88,10 +89,10 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
8889
if (playSound)
8990
{
9091
triggerAudioEvent(TheAudio->getMiscAudio()->m_moneyDepositSound);
92+
m_incomeBuckets[m_currentBucket] += amountToDeposit;
9193
}
9294

9395
m_money += amountToDeposit;
94-
m_incomeBuckets[m_currentBucket] += amountToDeposit;
9596

9697
if( amountToDeposit > 0 )
9798
{
@@ -106,12 +107,10 @@ void Money::deposit(UnsignedInt amountToDeposit, Bool playSound)
106107
// ------------------------------------------------------------------------------------------------
107108
void Money::setStartingCash(UnsignedInt amount)
108109
{
109-
m_startingCash = amount;
110110
m_money = amount;
111111
m_currentBucket = 0;
112112
m_lastBucketFrame = 0;
113-
for (UnsignedInt i = 0; i < ARRAY_SIZE(m_incomeBuckets); ++i)
114-
m_incomeBuckets[i] = 0;
113+
std::fill(m_incomeBuckets, m_incomeBuckets + ARRAY_SIZE(m_incomeBuckets), 0u);
115114
}
116115

117116
// ------------------------------------------------------------------------------------------------
@@ -123,11 +122,17 @@ void Money::updateIncomeBucket()
123122
UnsignedInt diff = (curSec > lastSec) ? curSec - lastSec : 0;
124123
if (diff > 0)
125124
{
126-
if (diff > 60)
127-
diff = 60;
125+
if (diff > ARRAY_SIZE(m_incomeBuckets))
126+
diff = ARRAY_SIZE(m_incomeBuckets);
127+
128+
UnsignedInt next = (m_currentBucket + 1) % ARRAY_SIZE(m_incomeBuckets);
129+
UnsignedInt first = std::min(diff, ARRAY_SIZE(m_incomeBuckets) - next);
130+
std::fill(m_incomeBuckets + next, m_incomeBuckets + next + first, 0u);
131+
132+
if (diff > first)
133+
std::fill(m_incomeBuckets, m_incomeBuckets + (diff - first), 0u);
134+
128135
m_currentBucket = (m_currentBucket + diff) % ARRAY_SIZE(m_incomeBuckets);
129-
for (UnsignedInt i = 0; i < diff; ++i)
130-
m_incomeBuckets[m_currentBucket] = 0;
131136
}
132137
m_lastBucketFrame = frame;
133138
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ void Player::init(const PlayerTemplate* pt)
462462
{
463463
m_money.deposit( TheGlobalData->m_defaultStartingCash.countMoney(), FALSE );
464464
}
465-
m_money.setStartingCash(m_money.countMoney());
466465
}
467466

468467
m_playerDisplayName.clear();

GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,40 @@
9696
static const Real placementOpacity = 0.45f;
9797
static const RGBColor illegalBuildColor = { 1.0, 0.0, 0.0 };
9898

99+
// ------------------------------------------------------------------------------------------------
100+
static UnicodeString formatMoneyValue(UnsignedInt amount)
101+
{
102+
UnicodeString result;
103+
if (amount >= 100000)
104+
{
105+
result.format(L"%dk", amount / 1000);
106+
}
107+
else
108+
{
109+
result.format(L"%d", amount);
110+
}
111+
return result;
112+
}
113+
114+
static UnicodeString formatIncomeValue(UnsignedInt cashPerMin)
115+
{
116+
UnicodeString result;
117+
if (cashPerMin >= 10000)
118+
{
119+
result.format(L"%dk", cashPerMin / 1000);
120+
}
121+
else if (cashPerMin >= 1000)
122+
{
123+
UnsignedInt k = cashPerMin / 100;
124+
result.format(L"%d.%dk", k / 10, k % 10);
125+
}
126+
else
127+
{
128+
result.format(L"%d", cashPerMin);
129+
}
130+
return result;
131+
}
132+
99133
//-------------------------------------------------------------------------------------------------
100134
/// The InGameUI singleton instance.
101135
InGameUI *TheInGameUI = NULL;
@@ -1877,31 +1911,9 @@ void InGameUI::update( void )
18771911
if (lastMoney != (Int)currentMoney || lastIncome != (Int)cashPerMin)
18781912
{
18791913
UnicodeString buffer;
1880-
UnicodeString moneyStr;
1881-
UnicodeString incomeStr;
1882-
1883-
if (currentMoney >= 100000)
1884-
{
1885-
moneyStr.format(L"%dk", currentMoney / 1000);
1886-
}
1887-
else
1888-
{
1889-
moneyStr.format(L"%d", currentMoney);
1890-
}
1914+
UnicodeString moneyStr = formatMoneyValue(currentMoney);
1915+
UnicodeString incomeStr = formatIncomeValue(cashPerMin);
18911916

1892-
if (cashPerMin >= 10000)
1893-
{
1894-
incomeStr.format(L"%dk", cashPerMin / 1000);
1895-
}
1896-
else if (cashPerMin >= 1000)
1897-
{
1898-
UnsignedInt k = cashPerMin / 100;
1899-
incomeStr.format(L"%d.%dk", k / 10, k % 10);
1900-
}
1901-
else
1902-
{
1903-
incomeStr.format(L"%d", cashPerMin);
1904-
}
19051917
buffer.format(TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:ControlBarMoneyDisplayIncome", L"%ls (%ls)", moneyStr.str(), incomeStr.str()));
19061918
GadgetStaticTextSetText(moneyWin, buffer);
19071919
lastMoney = currentMoney;

0 commit comments

Comments
 (0)