bugfix(energy): Don't increase power production for disabled power plants on save game load#2508
bugfix(energy): Don't increase power production for disabled power plants on save game load#2508Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
…ants on save game load Moved code.
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp | Moves setOrRestoreTeam call from before to after m_disabledMask and m_disabledTillFrame are xfer'd, ensuring isDisabled() returns the correct value when power production is evaluated on save load. |
Sequence Diagram
sequenceDiagram
participant X as Object::xfer (XFER_LOAD)
participant S as Object::setOrRestoreTeam
participant P as Player::becomingTeamMember
participant A as Object::friend_adjustPowerForPlayer
Note over X: xfer status bits (m_status, m_scriptStatus, m_privateStatus)
Note over X: xfer geometry / vision / shroud data
Note over X: ✅ xfer m_disabledMask (NEW ORDER)
Note over X: ✅ xfer m_disabledTillFrame (NEW ORDER)
X->>S: setOrRestoreTeam(team, restoring=true)
S->>P: becomingTeamMember(this, yes=true)
P->>A: friend_adjustPowerForPlayer(incoming=true)
Note over A: isDisabled() now correctly reads<br/>the already-loaded m_disabledMask
alt isDisabled() == true && energyProduction > 0
A-->>P: return early (no power added ✅)
else not disabled
A-->>P: objectEnteringInfluence(this)
end
Reviews (1): Last reviewed commit: "Updated comment." | Re-trigger Greptile
| // disabled till frame | ||
| xfer->xferUser( m_disabledTillFrame, sizeof( UnsignedInt ) * DISABLED_COUNT ); | ||
|
|
||
| // OK, now that we have xferred our status bits and disabled data, it's safe to set the team... |
There was a problem hiding this comment.
Can it perhaps be moved into Object::loadPostProcess or would that be too late then?
There was a problem hiding this comment.
Not sure. The most immediate issue I see is that the teamID would need to be accessible in Object::loadPostProcess.
There was a problem hiding this comment.
Team id can be grapped with TeamID teamID = m_team ? m_team->getID() : TEAM_ID_INVALID;
There was a problem hiding this comment.
That wouldn't work because m_team wouldn't be set yet.
There was a problem hiding this comment.
Maybe do a simple assignment in xfer:
if( xfer->getXferMode() == XFER_LOAD )
{
m_team = TheTeamFactory->findTeamByID( teamID );
if ( m_team == nullptr )
{
DEBUG_CRASH(( "Object::xfer - Unable to load team" ));
throw SC_INVALID_DATA;
}
}And then the full assignment in loadPostProcess
Team *team = m_team;
m_team = nullptr;
const Bool restoring = true;
setOrRestoreTeam( team, restoring );Not sure if worth it, but that is what what loadPostProcess is for - to do logic that goes beyond loading and writing.
Setting m_team to null looks also a bit shady. This code sucks.
There was a problem hiding this comment.
Probably cleaner to just store the teamID in the class and use that in loadPostProcess.
There was a problem hiding this comment.
Yes but then we have + 4 bytes in each object. Probably better to leave as is for now.
There was a problem hiding this comment.
Perhaps I can add a comment above it?
// OK, now that we have xferred our status bits and disabled data, it's safe to set the team...
// TheSuperHackers @todo Refactor so that this code can move to loadPostProcess.
When loading a save game with disabled power plants, players still get the power production from those plants. That's because the power production is increased before the
Objectdisabled flags are xfer'd. The following code is supposed to prevent the increase in power production, but the disabled flag would have to be xfer'd before this is called. This PR fixes that.GeneralsGameCode/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Lines 3829 to 3835 in 920c4e6
Callstack:
TODO: