Skip to content

Conversation

@Caball009
Copy link

This change fixes a bug where destroying disabled power plants would trigger a second reduction in energy production. This affects reactors from USA and China if they're upgraded / overcharged.

@Caball009 Caball009 added Bug Something is not working right, typically is user facing China Affects China faction Major Severity: Minor < Major < Critical < Blocker USA Affects USA faction Gen Relates to Generals ZH Relates to Zero Hour NoRetail This fix or change is not applicable with Retail game compatibility labels Nov 14, 2025
@Stubbjax
Copy link

I'm unsure about leaving the assertion only in the #else block. I think it is still correct to indicate erroneous logic / behaviour even if it has been rectified via a different path.

@Caball009
Copy link
Author

I'm unsure about leaving the assertion only in the #else block. I think it is still correct to indicate erroneous logic / behaviour even if it has been rectified via a different path.

I don't think I agree, but I also don't really care.

#if RETAIL_COMPATIBLE_CRC
addProduction( -obj->getTemplate()->getEnergyBonus() );
#else
if ( !obj->isDisabled() )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix is not robust. It will break again when external power conditions are changed.

Either unify the exclusion condition into a static function and call this everywhere applicable, or give the modules a state that tells whether they gave energy to the player.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or give the modules a state that tells whether they gave energy to the player.

I'm not sure what you mean by this.

Considering how closely related the two issues are, is your intention to also overhaul the solution used in the following PR? #1302

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refactors are better suited in a follow up change to not make this fix too complicated.

The reason these power bugs occur is that the conditions for adding and removing energy are scattered in code. Instead, there should be consistent conditions that the relevent energy consumptions go through. This way, when the conditions are changed, all code paths will recognize the new conditions.

or give the modules a state that tells whether they gave energy to the player.

This means make power modules stateful, whether they added energy to player. But perhaps that is too complicated because it would require Xfer.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the getObject()->isDisabled() conditions simply need moving into both addPowerBonus and removePowerBonus. But yes can be follow up then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that keeps this PR simple for me :)

@xezon xezon changed the title bugfix: Destroying disabled power plants lowers energy production twice bugfix: Destroying disabled Power Plant lowers energy production twice Nov 17, 2025
@xezon xezon changed the title bugfix: Destroying disabled Power Plant lowers energy production twice bugfix(energy): Destroying disabled Power Plant lowers energy production twice Nov 17, 2025
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 China Affects China faction Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker NoRetail This fix or change is not applicable with Retail game compatibility USA Affects USA faction ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destroying Disabled Power Plants Upgraded with PowerPlantUpgrade removes excess Energy

3 participants