-
Notifications
You must be signed in to change notification settings - Fork 119
bugfix(energy): Destroying disabled Power Plant lowers energy production twice #1857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I'm unsure about leaving the assertion only in the |
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() ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
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.