Skip to content
This repository was archived by the owner on Jul 23, 2020. It is now read-only.

Commit 0818cc7

Browse files
committed
Adds missing StageClass function, renames Delay to the more proper name, Rate.
1 parent a9cba59 commit 0818cc7

File tree

9 files changed

+52
-42
lines changed

9 files changed

+52
-42
lines changed

src/game/engine/anim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ AnimClass::AnimClass(AnimType type, coord_t coord, unsigned char loop_delay, uns
5656
m_Class->Set_End(m_Class->Get_End());
5757
}
5858
if (m_Class->Is_Normalized()) {
59-
m_LoopStage.Set_Delay(g_Options.Normalize_Delay(m_Class->Get_Rate()));
59+
m_LoopStage.Set_Rate(g_Options.Normalize_Delay(m_Class->Get_Rate()));
6060
} else {
61-
m_LoopStage.Set_Delay(m_Class->Get_Rate());
61+
m_LoopStage.Set_Rate(m_Class->Get_Rate());
6262
}
6363
m_LoopStage.Set_Stage(0);
6464
if (m_Class->Is_Surface()) {

src/game/engine/door.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
void DoorClass::AI()
2222
{
23-
if (m_DoorTimer.Stage_Changed()) {
23+
if (m_DoorTimer.Stage_AI()) {
2424
if (m_DoorTimer.Get_Stage() >= m_Stage) {
25-
m_DoorTimer.Set_Delay(0);
25+
m_DoorTimer.Set_Rate(0);
2626

2727
switch (m_State) {
2828
case DOOR_OPENING:
@@ -41,9 +41,9 @@ void DoorClass::AI()
4141
}
4242

4343
/**
44-
* @brief Sets the door opening process to take the given stages with the given frame delay between each stage.
44+
* @brief Sets the door opening process to take the given stages with the given rate between each stage.
4545
*/
46-
BOOL DoorClass::Open_Door(int delay, int stages)
46+
BOOL DoorClass::Open_Door(int rate, int stages)
4747
{
4848
if (m_State != DOOR_CLOSED && m_State != DOOR_CLOSING) {
4949
return false;
@@ -52,15 +52,15 @@ BOOL DoorClass::Open_Door(int delay, int stages)
5252
m_State = DOOR_OPENING;
5353
m_Stage = stages - 1;
5454
m_DoorTimer.Set_Stage(0);
55-
m_DoorTimer.Set_Delay(delay);
55+
m_DoorTimer.Set_Rate(rate);
5656

5757
return true;
5858
}
5959

6060
/**
61-
* @brief Sets the door closing process to take the given stages with the given frame delay between each stage.
61+
* @brief Sets the door closing process to take the given stages with the given rate between each stage.
6262
*/
63-
BOOL DoorClass::Close_Door(int delay, int stages)
63+
BOOL DoorClass::Close_Door(int rate, int stages)
6464
{
6565
if (m_State != DOOR_OPEN && m_State != DOOR_OPENING) {
6666
return false;
@@ -69,7 +69,7 @@ BOOL DoorClass::Close_Door(int delay, int stages)
6969
m_State = DOOR_CLOSING;
7070
m_Stage = stages - 1;
7171
m_DoorTimer.Set_Stage(0);
72-
m_DoorTimer.Set_Delay(delay);
72+
m_DoorTimer.Set_Rate(rate);
7373

7474
return true;
7575
}

src/game/engine/door.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class DoorClass
3737
DoorClass(const NoInitClass &noinit) : m_DoorTimer(noinit) {}
3838

3939
void AI();
40-
BOOL Open_Door(int delay, int stages);
41-
BOOL Close_Door(int delay, int stages);
40+
BOOL Open_Door(int rate, int stages);
41+
BOOL Close_Door(int rate, int stages);
4242
int Door_Stage() const;
4343
void Mark_To_Redraw() const { m_ToRedraw = true; }
4444
BOOL To_Redraw() const { return m_ToRedraw; }

src/game/engine/factory.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void FactoryClass::AI()
7979
{
8080
if (!m_IsSuspended && (m_Object != nullptr || m_SpecialItem != -1)) {
8181
if (!Has_Completed()) {
82-
if (m_ProductionTime.Stage_Changed()) {
82+
if (m_ProductionTime.Stage_AI()) {
8383
m_IsDifferent = true;
8484
unsigned int tick_cost = std::min(Cost_Per_Tick(), m_Balance);
8585
if (m_Owner->Available_Money() >= tick_cost) {
@@ -95,7 +95,7 @@ void FactoryClass::AI()
9595
#endif
9696
if (m_ProductionTime.Get_Stage() == MAX_CLOCK_STAGES) {
9797
m_IsSuspended = true;
98-
m_ProductionTime.Set_Delay(0);
98+
m_ProductionTime.Set_Rate(0);
9999
m_Owner->Spend_Money(m_Balance);
100100
m_Balance = 0;
101101
}
@@ -123,7 +123,7 @@ BOOL FactoryClass::Set(TechnoTypeClass &objecttype, HouseClass &house)
123123
m_IsSuspended = true;
124124

125125
m_ProductionTime.Set_Stage(0);
126-
m_ProductionTime.Set_Delay(0);
126+
m_ProductionTime.Set_Rate(0);
127127

128128
m_Balance = 0;
129129

@@ -161,7 +161,7 @@ BOOL FactoryClass::Set(int &special, HouseClass &house)
161161
m_Balance = 0;
162162

163163
m_ProductionTime.Set_Stage(0);
164-
m_ProductionTime.Set_Delay(0);
164+
m_ProductionTime.Set_Rate(0);
165165

166166
return m_SpecialItem != -1;
167167
}
@@ -178,14 +178,14 @@ void FactoryClass::Set(TechnoClass &object)
178178
m_Balance = 0;
179179

180180
m_ProductionTime.Set_Stage(0);
181-
m_ProductionTime.Set_Delay(0);
181+
m_ProductionTime.Set_Rate(0);
182182
}
183183

184184
BOOL FactoryClass::Suspend()
185185
{
186186
if (!m_IsSuspended) {
187187
m_IsSuspended = true;
188-
m_ProductionTime.Set_Delay(0);
188+
m_ProductionTime.Set_Rate(0);
189189
return true;
190190
}
191191
return false;
@@ -216,7 +216,7 @@ BOOL FactoryClass::Abandon()
216216
m_IsDifferent = true;
217217

218218
m_ProductionTime.Set_Stage(0);
219-
m_ProductionTime.Set_Delay(0);
219+
m_ProductionTime.Set_Rate(0);
220220

221221
++g_ScenarioInit;
222222

@@ -264,15 +264,15 @@ BOOL FactoryClass::Completed()
264264
m_IsSuspended = true;
265265
m_IsDifferent = true;
266266
m_ProductionTime.Set_Stage(0);
267-
m_ProductionTime.Set_Delay(0);
267+
m_ProductionTime.Set_Rate(0);
268268
return true;
269269
}
270270
if (m_SpecialItem != -1 && m_ProductionTime.Get_Stage() == MAX_CLOCK_STAGES) {
271271
m_SpecialItem = -1;
272272
m_IsSuspended = true;
273273
m_IsDifferent = true;
274274
m_ProductionTime.Set_Stage(0);
275-
m_ProductionTime.Set_Delay(0);
275+
m_ProductionTime.Set_Rate(0);
276276
return true;
277277
}
278278
return false;

src/game/engine/factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class FactoryClass
6161
BOOL Abandon();
6262
int Completion() const { return m_ProductionTime.Get_Stage(); }
6363
BOOL Has_Completed() const;
64-
BOOL Is_Building() const { return m_ProductionTime.Get_Delay() != 0; }
64+
BOOL Is_Building() const { return m_ProductionTime.Get_Rate() != 0; }
6565
TechnoClass *const Get_Object() const { return m_Object; }
6666
int Get_Special_Item() const { return m_SpecialItem; }
6767
unsigned int Cost_Per_Tick() const;

src/game/engine/stage.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,50 @@
2424
class StageClass
2525
{
2626
public:
27-
StageClass() : m_Stage(0), m_Timer(0), m_Delay(0) {}
27+
StageClass() : m_Stage(0), m_Timer(0), m_Rate(0) {}
2828
StageClass(const NoInitClass &noinit) : m_Timer(noinit) {}
2929
StageClass &operator=(StageClass &that);
3030

3131
int Get_Stage() const { return m_Stage; }
3232
void Set_Stage(int stage) { m_Stage = stage; }
33-
int Get_Delay() const { return m_Delay; }
34-
void Set_Delay(int delay);
35-
BOOL Stage_Changed();
33+
int Get_Rate() const { return m_Rate; }
34+
void Set_Rate(int rate);
35+
BOOL To_Change();
36+
BOOL Stage_AI();
3637
void Reset();
3738

3839
private:
3940
int m_Stage; // Current stage we are at.
4041
TCountDownTimerClass<FrameTimerClass> m_Timer; // Countdown timer, 0 indicates time to go to next stage.
41-
int m_Delay; // Delay in frames to the next stage transition.
42+
int m_Rate; // Rate at which the stage transition occurs.
4243
};
4344

4445
/**
4546
* @brief Sets the delay between stage transitions in game frames.
4647
*/
47-
inline void StageClass::Set_Delay(int delay)
48+
inline void StageClass::Set_Rate(int rate)
4849
{
49-
m_Timer = delay;
50-
m_Delay = delay;
50+
m_Timer = rate;
51+
m_Rate = rate;
5152
}
5253

5354
/**
54-
* @brief Checks if a stage change has occured.
55+
* @brief Is a stage change going to occur.
5556
*/
56-
inline BOOL StageClass::Stage_Changed()
57+
inline BOOL StageClass::To_Change()
5758
{
58-
if (m_Timer.Time() <= 0 && m_Delay > 0) {
59+
return m_Timer.Expired() && m_Rate > 0;
60+
}
61+
62+
/**
63+
* @brief Handles a stage change should it be needed.
64+
* Returns if a stage change has occured.
65+
*/
66+
inline BOOL StageClass::Stage_AI()
67+
{
68+
if (To_Change()) {
5969
++m_Stage;
60-
m_Timer = m_Delay;
70+
m_Timer = m_Rate;
6171

6272
return true;
6373
}
@@ -72,15 +82,15 @@ inline void StageClass::Reset()
7282
{
7383
m_Stage = 0;
7484
m_Timer = 0;
75-
m_Delay = 0;
85+
m_Rate = 0;
7686
}
7787

7888
inline StageClass &StageClass::operator=(StageClass &that)
7989
{
8090
if (this != &that) {
8191
m_Stage = that.m_Stage;
8292
m_Timer = that.m_Timer;
83-
m_Delay = that.m_Delay;
93+
m_Rate = that.m_Rate;
8494
}
8595

8696
return *this;

src/game/engine/techno.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ void TechnoClass::Do_Uncloak()
11571157

11581158
m_CloakState = CLOAK_UNCLOAKING;
11591159
m_CloakingStage.Set_Stage(0);
1160-
m_CloakingStage.Set_Delay(1);
1160+
m_CloakingStage.Set_Rate(1);
11611161

11621162
// BUGFIX: The following stops the uncloaking sound from playing upon game start.
11631163
if (g_GameFrame > 25) {
@@ -1183,7 +1183,7 @@ void TechnoClass::Do_Cloak()
11831183

11841184
m_CloakState = CLOAK_CLOAKING;
11851185
m_CloakingStage.Set_Stage(0);
1186-
m_CloakingStage.Set_Delay(1);
1186+
m_CloakingStage.Set_Rate(1);
11871187

11881188
// BUGFIX: The following stops the cloaking sound from playing upon game start.
11891189
if (g_GameFrame > 25) {

src/game/engine/terrain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TerrainClass::TerrainClass(TerrainType type, cell_t cellnum) :
4444
delete this;
4545
}
4646
}
47-
m_AnimStage.Set_Delay(0);
47+
m_AnimStage.Set_Rate(0);
4848
}
4949

5050
/**
@@ -144,7 +144,7 @@ void TerrainClass::AI()
144144
if (What_Type() == TERRAIN_MINE && !(g_GameFrame % (900 * g_Rule.Ore_Growth_Rate()))) {
145145
g_Map[As_Cell(As_Target())].Spread_Ore(true);
146146
}
147-
if (m_AnimStage.Stage_Changed()) {
147+
if (m_AnimStage.Stage_AI()) {
148148
Mark(MARK_REMOVE);
149149
if (m_Crumbling) {
150150
if (m_AnimStage.Get_Stage() == Get_Build_Frame_Count(Get_Image_Data()) - 1) {
@@ -331,7 +331,7 @@ void TerrainClass::Start_To_Crumble()
331331
if (!m_Crumbling) {
332332
m_Crumbling = true;
333333
m_AnimStage.Set_Stage(0);
334-
m_AnimStage.Set_Delay(2);
334+
m_AnimStage.Set_Rate(2);
335335
}
336336
}
337337

src/game/engine/unit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ UnitClass::UnitClass(UnitType type, HousesType house) :
5050
m_Cloakable = Class_Of().Is_Cloakable();
5151

5252
if (Class_Of().Is_Viceroid()) {
53-
m_AnimStage.Set_Delay(g_Options.Normalize_Delay(3));
53+
m_AnimStage.Set_Rate(g_Options.Normalize_Delay(3));
5454
}
5555

5656
m_Bit2_16 = !Class_Of().Is_Two_Shooter();

0 commit comments

Comments
 (0)