Skip to content

bugfix(energy): Don't apply power production bonus for disabled power plants on save game load#2509

Open
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:bugfix_energy_loadPostProcess
Open

bugfix(energy): Don't apply power production bonus for disabled power plants on save game load#2509
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:bugfix_energy_loadPostProcess

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented Mar 30, 2026

When loading a save game with disabled power plants, players still get the power production bonus from those plants if they're either overcharged or upgraded. That's because the power production is increased without a check if the plant is disabled. This PR fixes that.

TODO:

  • Replicate in Generals.

@Caball009 Caball009 added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Saveload Is Saveload/Xfer related labels Mar 30, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR fixes a save-game load bug where disabled power plants (both overcharged and upgraded via PowerPlantUpgrade) incorrectly received their power production bonus because loadPostProcess re-fired the bonus unconditionally. The fix adds an !obj->isDisabled() guard in both loadPostProcess implementations and a DEBUG_ASSERTCRASH in Energy::addPowerBonus to enforce the invariant in debug builds. Changes are correctly mirrored across both Generals/ and GeneralsMD/.

Confidence Score: 5/5

Safe to merge — fix is correct, well-scoped, and consistently applied across both game directories.

All findings are P2 or lower. The core bug fix is sound: both loadPostProcess paths now guard against disabled buildings, and the DEBUG_ASSERTCRASH enforces the invariant in debug builds without affecting release behaviour. Other callers of addPowerBonus (onCapture, upgradeImplementation, enable) were already guarded or represent normal-gameplay paths where disabled state is controlled by the game UI/engine.

No files require special attention.

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Source/Common/RTS/Energy.cpp Adds a DEBUG_ASSERTCRASH to addPowerBonus to enforce the invariant that disabled objects must not receive a power bonus; no logic change in release builds.
Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/OverchargeBehavior.cpp loadPostProcess now checks obj->isDisabled() before adding the overcharge power bonus on save-game reload, fixing the reported bug.
Generals/Code/GameEngine/Source/GameLogic/Object/Upgrade/PowerPlantUpgrade.cpp loadPostProcess now checks obj->isDisabled() before adding the upgrade power bonus on save-game reload, fixing the reported bug.
GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp Mirror of Generals Energy.cpp change — identical DEBUG_ASSERTCRASH added to addPowerBonus for the Zero Hour build.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/OverchargeBehavior.cpp Mirror of Generals OverchargeBehavior.cpp change — isDisabled() check added in loadPostProcess for Zero Hour build.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Upgrade/PowerPlantUpgrade.cpp Mirror of Generals PowerPlantUpgrade.cpp change — isDisabled() check added in loadPostProcess for Zero Hour build.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Save Game Load] --> B[loadPostProcess called]
    B --> C{isAlreadyUpgraded / m_overchargeActive?}
    C -- No --> D[Skip — no bonus to restore]
    C -- Yes --> E{getControllingPlayer != null?}
    E -- No --> F[Skip — no player]
    E -- Yes --> G{obj->isDisabled?}
    G -- Yes --> H[Skip — BUG FIXED: disabled plant gets no bonus]
    G -- No --> I[player->addPowerBonus]
    I --> J[Energy::addPowerBonus]
    J --> K[DEBUG_ASSERTCRASH: !isDisabled]
    K --> L[addProduction + sanity check]
Loading

Reviews (2): Last reviewed commit: "Replicated in Generals." | Re-trigger Greptile

@Caball009
Copy link
Copy Markdown
Author

Replicated in Generals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Saveload Is Saveload/Xfer related ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants