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

Commit

Permalink
Adds missing StageClass function, renames Delay to the more proper na…
Browse files Browse the repository at this point in the history
…me, Rate.
  • Loading branch information
tomsons26 committed May 17, 2020
1 parent a9cba59 commit 430260e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/game/engine/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ AnimClass::AnimClass(AnimType type, coord_t coord, unsigned char loop_delay, uns
m_Class->Set_End(m_Class->Get_End());
}
if (m_Class->Is_Normalized()) {
m_LoopStage.Set_Delay(g_Options.Normalize_Delay(m_Class->Get_Rate()));
m_LoopStage.Set_Rate(g_Options.Normalize_Delay(m_Class->Get_Rate()));
} else {
m_LoopStage.Set_Delay(m_Class->Get_Rate());
m_LoopStage.Set_Rate(m_Class->Get_Rate());
}
m_LoopStage.Set_Stage(0);
if (m_Class->Is_Surface()) {
Expand Down
8 changes: 4 additions & 4 deletions src/game/engine/door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
*/
void DoorClass::AI()
{
if (m_DoorTimer.Stage_Changed()) {
if (m_DoorTimer.Stage_AI()) {
if (m_DoorTimer.Get_Stage() >= m_Stage) {
m_DoorTimer.Set_Delay(0);
m_DoorTimer.Set_Rate(0);

switch (m_State) {
case DOOR_OPENING:
Expand Down Expand Up @@ -52,7 +52,7 @@ BOOL DoorClass::Open_Door(int delay, int stages)
m_State = DOOR_OPENING;
m_Stage = stages - 1;
m_DoorTimer.Set_Stage(0);
m_DoorTimer.Set_Delay(delay);
m_DoorTimer.Set_Rate(delay);

return true;
}
Expand All @@ -69,7 +69,7 @@ BOOL DoorClass::Close_Door(int delay, int stages)
m_State = DOOR_CLOSING;
m_Stage = stages - 1;
m_DoorTimer.Set_Stage(0);
m_DoorTimer.Set_Delay(delay);
m_DoorTimer.Set_Rate(delay);

return true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/game/engine/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void FactoryClass::AI()
{
if (!m_IsSuspended && (m_Object != nullptr || m_SpecialItem != -1)) {
if (!Has_Completed()) {
if (m_ProductionTime.Stage_Changed()) {
if (m_ProductionTime.Stage_AI()) {
m_IsDifferent = true;
unsigned int tick_cost = std::min(Cost_Per_Tick(), m_Balance);
if (m_Owner->Available_Money() >= tick_cost) {
Expand All @@ -95,7 +95,7 @@ void FactoryClass::AI()
#endif
if (m_ProductionTime.Get_Stage() == MAX_CLOCK_STAGES) {
m_IsSuspended = true;
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);
m_Owner->Spend_Money(m_Balance);
m_Balance = 0;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ BOOL FactoryClass::Set(TechnoTypeClass &objecttype, HouseClass &house)
m_IsSuspended = true;

m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);

m_Balance = 0;

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

m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);

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

m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);
}

BOOL FactoryClass::Suspend()
{
if (!m_IsSuspended) {
m_IsSuspended = true;
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);
return true;
}
return false;
Expand Down Expand Up @@ -216,7 +216,7 @@ BOOL FactoryClass::Abandon()
m_IsDifferent = true;

m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);

++g_ScenarioInit;

Expand Down Expand Up @@ -264,15 +264,15 @@ BOOL FactoryClass::Completed()
m_IsSuspended = true;
m_IsDifferent = true;
m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);
return true;
}
if (m_SpecialItem != -1 && m_ProductionTime.Get_Stage() == MAX_CLOCK_STAGES) {
m_SpecialItem = -1;
m_IsSuspended = true;
m_IsDifferent = true;
m_ProductionTime.Set_Stage(0);
m_ProductionTime.Set_Delay(0);
m_ProductionTime.Set_Rate(0);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/game/engine/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FactoryClass
BOOL Abandon();
int Completion() const { return m_ProductionTime.Get_Stage(); }
BOOL Has_Completed() const;
BOOL Is_Building() const { return m_ProductionTime.Get_Delay() != 0; }
BOOL Is_Building() const { return m_ProductionTime.Get_Rate() != 0; }
TechnoClass *const Get_Object() const { return m_Object; }
int Get_Special_Item() const { return m_SpecialItem; }
unsigned int Cost_Per_Tick() const;
Expand Down
38 changes: 24 additions & 14 deletions src/game/engine/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,50 @@
class StageClass
{
public:
StageClass() : m_Stage(0), m_Timer(0), m_Delay(0) {}
StageClass() : m_Stage(0), m_Timer(0), m_Rate(0) {}
StageClass(const NoInitClass &noinit) : m_Timer(noinit) {}
StageClass &operator=(StageClass &that);

int Get_Stage() const { return m_Stage; }
void Set_Stage(int stage) { m_Stage = stage; }
int Get_Delay() const { return m_Delay; }
void Set_Delay(int delay);
BOOL Stage_Changed();
int Get_Rate() const { return m_Rate; }
void Set_Rate(int rate);
BOOL To_Change();
BOOL Stage_AI();
void Reset();

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

/**
* @brief Sets the delay between stage transitions in game frames.
*/
inline void StageClass::Set_Delay(int delay)
inline void StageClass::Set_Rate(int rate)
{
m_Timer = delay;
m_Delay = delay;
m_Timer = rate;
m_Rate = rate;
}

/**
* @brief Checks if a stage change has occured.
* @brief Is a stage change going to occur.
*/
inline BOOL StageClass::Stage_Changed()
inline BOOL StageClass::To_Change()
{
if (m_Timer.Time() <= 0 && m_Delay > 0) {
return m_Timer.Expired() && m_Rate > 0;
}

/**
* @brief Handles a stage change should it be needed.
* Returns if a stage change has occured.
*/
inline BOOL StageClass::Stage_AI()
{
if (To_Change()) {
++m_Stage;
m_Timer = m_Delay;
m_Timer = m_Rate;

return true;
}
Expand All @@ -72,15 +82,15 @@ inline void StageClass::Reset()
{
m_Stage = 0;
m_Timer = 0;
m_Delay = 0;
m_Rate = 0;
}

inline StageClass &StageClass::operator=(StageClass &that)
{
if (this != &that) {
m_Stage = that.m_Stage;
m_Timer = that.m_Timer;
m_Delay = that.m_Delay;
m_Rate = that.m_Rate;
}

return *this;
Expand Down
4 changes: 2 additions & 2 deletions src/game/engine/techno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ void TechnoClass::Do_Uncloak()

m_CloakState = CLOAK_UNCLOAKING;
m_CloakingStage.Set_Stage(0);
m_CloakingStage.Set_Delay(1);
m_CloakingStage.Set_Rate(1);

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

m_CloakState = CLOAK_CLOAKING;
m_CloakingStage.Set_Stage(0);
m_CloakingStage.Set_Delay(1);
m_CloakingStage.Set_Rate(1);

// BUGFIX: The following stops the cloaking sound from playing upon game start.
if (g_GameFrame > 25) {
Expand Down
6 changes: 3 additions & 3 deletions src/game/engine/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TerrainClass::TerrainClass(TerrainType type, cell_t cellnum) :
delete this;
}
}
m_AnimStage.Set_Delay(0);
m_AnimStage.Set_Rate(0);
}

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ void TerrainClass::AI()
if (What_Type() == TERRAIN_MINE && !(g_GameFrame % (900 * g_Rule.Ore_Growth_Rate()))) {
g_Map[As_Cell(As_Target())].Spread_Ore(true);
}
if (m_AnimStage.Stage_Changed()) {
if (m_AnimStage.Stage_AI()) {
Mark(MARK_REMOVE);
if (m_Crumbling) {
if (m_AnimStage.Get_Stage() == Get_Build_Frame_Count(Get_Image_Data()) - 1) {
Expand Down Expand Up @@ -331,7 +331,7 @@ void TerrainClass::Start_To_Crumble()
if (!m_Crumbling) {
m_Crumbling = true;
m_AnimStage.Set_Stage(0);
m_AnimStage.Set_Delay(2);
m_AnimStage.Set_Rate(2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/engine/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ UnitClass::UnitClass(UnitType type, HousesType house) :
m_Cloakable = Class_Of().Is_Cloakable();

if (Class_Of().Is_Viceroid()) {
m_AnimStage.Set_Delay(g_Options.Normalize_Delay(3));
m_AnimStage.Set_Rate(g_Options.Normalize_Delay(3));
}

m_Bit2_16 = !Class_Of().Is_Two_Shooter();
Expand Down

0 comments on commit 430260e

Please sign in to comment.