Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): show seconds remaining instead of percent while constructing

Olcay Seygand393aca9f887
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
index fd15a52f3..ccd34d6b7 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
@@ -397,8 +397,9 @@ public:
ObjectID calculateCountermeasureToDivertTo( const Object& victim );
void calcNaturalRallyPoint(Coord2D *pt); ///< calc the "natural" starting rally point
- void setConstructionPercent( Real percent ) { m_constructionPercent = percent; }
+ void setConstructionPercent( Real percent );
Real getConstructionPercent() const { return m_constructionPercent; }
+ Int getConstructionSecondsRemaining() const; ///< estimate from the rate the builders actually achieve (nominal single-builder rate until measured)
void setLayer( PathfindLayerEnum layer );
PathfindLayerEnum getLayer() const { return m_layer; }
@@ -756,6 +757,9 @@ private:
UnsignedInt m_containedByFrame; ///< frame we were contained by m_containedBy
Real m_constructionPercent; ///< for objects being built ... this is the amount completed (0.0 to 100.0)
+ Real m_constructionRate; ///< percent gained per logic frame, all builders summed (0 = not measured yet)
+ Real m_constructionRateAccum; ///< percent gained so far in frame m_constructionRateFrame
+ UnsignedInt m_constructionRateFrame;
UpgradeMaskType m_objectUpgradesCompleted; ///< Bit field of upgrades locally completed.
Team* m_team; ///< team that is current owner of this guy
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 41c4b5098..2f808b6e6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -3718,17 +3718,16 @@ void Drawable::drawConstructPercent( const IRegion2D *healthBarRegion )
if( m_constructDisplayString == NULL )
m_constructDisplayString = TheDisplayStringManager->newDisplayString();
- // set the string if the value has changed
- if( m_lastConstructDisplayed != obj->getConstructionPercent() )
+ // set the string if the value has changed (seconds left, not percent)
+ Int secondsLeft = obj->getConstructionSecondsRemaining();
+ if( m_lastConstructDisplayed != INT_TO_REAL( secondsLeft ) )
{
UnicodeString buffer;
-
-
- buffer.format( TheGameText->fetch("CONTROLBAR:UnderConstructionDesc"), obj->getConstructionPercent());
+ buffer.format( L"%ds", secondsLeft );
m_constructDisplayString->setText( buffer );
- // record this percent as our last displayed so we don't un-necessarily rebuild the string
- m_lastConstructDisplayed = obj->getConstructionPercent();
+ // record this value as our last displayed so we don't un-necessarily rebuild the string
+ m_lastConstructDisplayed = INT_TO_REAL( secondsLeft );
} // end if
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarUnderConstruction.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarUnderConstruction.cpp
index fab6b00b4..7c647ae45 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarUnderConstruction.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarUnderConstruction.cpp
@@ -54,13 +54,12 @@ void ControlBar::updateConstructionTextDisplay( Object *obj )
// santiy
DEBUG_ASSERTCRASH( descWindow, ("Under construction window not found\n") );
- // format the message
- text.format( TheGameText->fetch( "CONTROLBAR:UnderConstructionDesc" ),
- obj->getConstructionPercent() );
+ // format the message: seconds left rather than percent
+ text.format( L"%ds", obj->getConstructionSecondsRemaining() );
GadgetStaticTextSetText( descWindow, text );
- // record this as the last percentage displayed
- m_displayedConstructPercent = obj->getConstructionPercent();
+ // record this as the last value displayed
+ m_displayedConstructPercent = INT_TO_REAL( obj->getConstructionSecondsRemaining() );
} // end updateConstructionTextDisplay
@@ -117,7 +116,7 @@ void ControlBar::updateContextUnderConstruction( void )
} // end if
// if the construction percent has changed since what was last shown to the user update the text
- if( m_displayedConstructPercent != obj->getConstructionPercent() )
+ if( m_displayedConstructPercent != INT_TO_REAL( obj->getConstructionSecondsRemaining() ) )
updateConstructionTextDisplay( obj );
} // end updatecontextUnderConstruction
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 389e64abc..f0a8f93bc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -290,6 +290,9 @@ Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatu
m_group = NULL;
m_constructionPercent = CONSTRUCTION_COMPLETE; // complete by default
+ m_constructionRate = 0.0f;
+ m_constructionRateAccum = 0.0f;
+ m_constructionRateFrame = 0;
m_visionRange = tt->friend_calcVisionRange();
m_shroudClearingRange = tt->friend_calcShroudClearingRange();
@@ -3044,6 +3047,37 @@ Bool Object::isSelectable() const
return FALSE;
}
+//-------------------------------------------------------------------------------------------------
+void Object::setConstructionPercent( Real percent )
+{
+ // every builder adds its share once per logic frame; sum a frame's gains to get the real rate
+ UnsignedInt now = TheGameLogic->getFrame();
+ if( now != m_constructionRateFrame )
+ {
+ if( m_constructionRateAccum > 0.0f )
+ m_constructionRate = m_constructionRateAccum;
+ m_constructionRateAccum = 0.0f;
+ m_constructionRateFrame = now;
+ }
+ Real delta = percent - m_constructionPercent;
+ if( delta > 0.0f )
+ m_constructionRateAccum += delta;
+ m_constructionPercent = percent;
+}
+
+//-------------------------------------------------------------------------------------------------
+Int Object::getConstructionSecondsRemaining() const
+{
+ Real rate = m_constructionRate;
+ if( rate <= 0.0f )
+ {
+ Int framesToBuild = getTemplate()->calcTimeToBuild( getControllingPlayer() );
+ rate = 100.0f / INT_TO_REAL( max( 1, framesToBuild ) );
+ }
+ Real left = max( 0.0f, 100.0f - m_constructionPercent );
+ return REAL_TO_INT_CEIL( left / rate / LOGICFRAMES_PER_SECOND );
+}
+
//-------------------------------------------------------------------------------------------------
Bool Object::isMassSelectable() const
{