diff --git a/src/game/engine/anim.cpp b/src/game/engine/anim.cpp index 67366f27..0d45b825 100644 --- a/src/game/engine/anim.cpp +++ b/src/game/engine/anim.cpp @@ -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()) { diff --git a/src/game/engine/door.cpp b/src/game/engine/door.cpp index 0c0b9c24..29eaab97 100644 --- a/src/game/engine/door.cpp +++ b/src/game/engine/door.cpp @@ -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: @@ -41,9 +41,9 @@ void DoorClass::AI() } /** - * @brief Sets the door opening process to take the given stages with the given frame delay between each stage. + * @brief Sets the door opening process to take the given stages with the given rate between each stage. */ -BOOL DoorClass::Open_Door(int delay, int stages) +BOOL DoorClass::Open_Door(int rate, int stages) { if (m_State != DOOR_CLOSED && m_State != DOOR_CLOSING) { return false; @@ -52,15 +52,15 @@ 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(rate); return true; } /** - * @brief Sets the door closing process to take the given stages with the given frame delay between each stage. + * @brief Sets the door closing process to take the given stages with the given rate between each stage. */ -BOOL DoorClass::Close_Door(int delay, int stages) +BOOL DoorClass::Close_Door(int rate, int stages) { if (m_State != DOOR_OPEN && m_State != DOOR_OPENING) { return false; @@ -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(rate); return true; } diff --git a/src/game/engine/door.h b/src/game/engine/door.h index 98030473..6cc3c9d2 100644 --- a/src/game/engine/door.h +++ b/src/game/engine/door.h @@ -37,8 +37,8 @@ class DoorClass DoorClass(const NoInitClass &noinit) : m_DoorTimer(noinit) {} void AI(); - BOOL Open_Door(int delay, int stages); - BOOL Close_Door(int delay, int stages); + BOOL Open_Door(int rate, int stages); + BOOL Close_Door(int rate, int stages); int Door_Stage() const; void Mark_To_Redraw() const { m_ToRedraw = true; } BOOL To_Redraw() const { return m_ToRedraw; } diff --git a/src/game/engine/factory.cpp b/src/game/engine/factory.cpp index 4ff30aa1..898805f4 100644 --- a/src/game/engine/factory.cpp +++ b/src/game/engine/factory.cpp @@ -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) { @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; @@ -264,7 +264,7 @@ 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) { @@ -272,7 +272,7 @@ 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; } return false; diff --git a/src/game/engine/factory.h b/src/game/engine/factory.h index 7c557576..2dcd9615 100644 --- a/src/game/engine/factory.h +++ b/src/game/engine/factory.h @@ -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; diff --git a/src/game/engine/stage.h b/src/game/engine/stage.h index 038ae170..50e27c13 100644 --- a/src/game/engine/stage.h +++ b/src/game/engine/stage.h @@ -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 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; } @@ -72,7 +82,7 @@ inline void StageClass::Reset() { m_Stage = 0; m_Timer = 0; - m_Delay = 0; + m_Rate = 0; } inline StageClass &StageClass::operator=(StageClass &that) @@ -80,7 +90,7 @@ 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; diff --git a/src/game/engine/techno.cpp b/src/game/engine/techno.cpp index 2f097f8d..ad71cb13 100644 --- a/src/game/engine/techno.cpp +++ b/src/game/engine/techno.cpp @@ -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) { @@ -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) { diff --git a/src/game/engine/terrain.cpp b/src/game/engine/terrain.cpp index f35e6d0c..33bb795d 100644 --- a/src/game/engine/terrain.cpp +++ b/src/game/engine/terrain.cpp @@ -44,7 +44,7 @@ TerrainClass::TerrainClass(TerrainType type, cell_t cellnum) : delete this; } } - m_AnimStage.Set_Delay(0); + m_AnimStage.Set_Rate(0); } /** @@ -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) { @@ -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); } } diff --git a/src/game/engine/unit.cpp b/src/game/engine/unit.cpp index 51d83e5d..e215a51a 100644 --- a/src/game/engine/unit.cpp +++ b/src/game/engine/unit.cpp @@ -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();