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.

fix(gameclient): draw a charge bar only while a power is really charging

Olcay Seygan4628afdf7bf8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be0654315..fade3fc98 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -120,7 +120,9 @@ Around it, the whole production loop got tightened:
including one whose builder died.
- **Workers go back to collecting supplies** after they finish, instead of standing there.
- **Timings everywhere**: seconds left on a building going up, the current unit and the whole queue
- behind it, a charge bar on superweapons, a progress clock on upgrades being researched.
+ behind it, a charge bar on superweapons, a progress clock on upgrades being researched. A bar only
+ appears while something is really happening: your command centre used to wear a yellow bar from
+ the first second of the match, charging a general's power nobody had bought yet.
- **Income per minute next to your money**, averaged over the last half-minute of what you actually
earned — so it does not swing wildly the moment you spend something.
- **Aircraft always show how many attack runs they have left**, selected or not. That is the number
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index d829d9aea..24ddb3c39 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -4018,8 +4018,15 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
//
// A superweapon charging, or a building on a timed payout (the supply drop zone), gets the
// same yellow bar the production queue uses. Only powers that carry a public timer count -
- // that is the flag the superweapon list in the corner goes by - so the command centre's
- // general's powers do not put a permanent bar on the main base.
+ // that is the flag the superweapon list in the corner goes by.
+ //
+ // A power only counts while it is really counting down towards something the player can
+ // fire. Every command centre carries one public-timer power from the first frame of the
+ // game (crate drop, napalm strike, black market nuke), all of them locked behind a general's
+ // promotion nobody has bought yet and all of them charging away regardless - so the main
+ // base wore a permanent bar that stood for nothing. A power whose science the player does
+ // not own is skipped, and so is one that has finished charging: a full bar that never
+ // empties is the same clutter in a different colour.
//
if( obj->isLocallyControlled() &&
!obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) &&
@@ -4028,22 +4035,29 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
const UnsignedInt now = TheGameLogic->getFrame();
Real chargePct = -1.0f;
+ const Player *owner = obj->getControllingPlayer();
+
for( BehaviorModule** m = obj->getBehaviorModules(); *m; ++m )
{
SpecialPowerModuleInterface* sp = (*m)->getSpecialPower();
- if( sp == NULL )
+ if( sp == NULL || sp->isReady() )
continue;
const SpecialPowerTemplate *tmpl = sp->getSpecialPowerTemplate();
if( tmpl == NULL || !tmpl->hasPublicTimer() )
continue;
+ ScienceType needed = sp->getRequiredScience();
+ if( needed != SCIENCE_INVALID && (owner == NULL || !owner->hasScience( needed )) )
+ continue;
+
Real full = INT_TO_REAL( tmpl->getReloadTime() );
if( full <= 0.0f )
continue;
UnsignedInt ready = sp->getReadyFrame();
- Real left = (ready > now) ? INT_TO_REAL( ready - now ) : 0.0f;
- Real pct = 100.0f * (1.0f - left / full);
+ if( ready <= now )
+ continue;
+ Real pct = 100.0f * (1.0f - INT_TO_REAL( ready - now ) / full);
if( pct < 0.0f ) pct = 0.0f;
if( pct > 100.0f ) pct = 100.0f;
if( chargePct < 0.0f || pct < chargePct )