-
Notifications
You must be signed in to change notification settings - Fork 203
bugfix(victory): Save victory status to prevent early exits from resulting in defeat in network matches #2292
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
Changes from 7 commits
bec5f12
87a75a4
6dead6c
aa5f363
5745099
f378df7
e297db3
cb93902
36f8103
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,10 +92,15 @@ class VictoryConditions : public VictoryConditionsInterface | |
| Bool amIObserver( void ) { return m_isObserver;} ///< Am I an observer?( need this for scripts ) | ||
| virtual UnsignedInt getEndFrame( void ) { return m_endFrame; } ///< on which frame was the game effectively over? | ||
| private: | ||
| Player* findFirstVictoriousPlayer(); ///< Find the first player that has achieved victory. | ||
| void markAllianceVictorious(Player* victoriousPlayer); ///< Mark the victorious player and his allies as victorious. | ||
| Bool multipleAlliancesExist(void); ///< Are there multiple alliances still alive? | ||
|
|
||
| Player* m_players[MAX_PLAYER_COUNT]; | ||
| Int m_localSlotNum; | ||
| UnsignedInt m_endFrame; | ||
| Bool m_isDefeated[MAX_PLAYER_COUNT]; | ||
| Bool m_isVictorious[MAX_PLAYER_COUNT]; | ||
| Bool m_localPlayerDefeated; ///< prevents condition from being signaled each frame | ||
| Bool m_singleAllianceRemaining; ///< prevents condition from being signaled each frame | ||
| Bool m_isObserver; | ||
|
|
@@ -127,6 +132,7 @@ void VictoryConditions::reset( void ) | |
| { | ||
| m_players[i] = nullptr; | ||
| m_isDefeated[i] = false; | ||
| m_isVictorious[i] = false; | ||
| } | ||
| m_localSlotNum = -1; | ||
|
|
||
|
|
@@ -139,42 +145,54 @@ void VictoryConditions::reset( void ) | |
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| void VictoryConditions::update( void ) | ||
| Bool VictoryConditions::multipleAlliancesExist() | ||
| { | ||
| if (!TheRecorder->isMultiplayer() || (m_localSlotNum < 0 && !m_isObserver)) | ||
| return; | ||
| Player* alive = nullptr; | ||
|
|
||
| // Check for a single winning alliance | ||
| if (!m_singleAllianceRemaining) | ||
| for (Int i = 0; i < MAX_PLAYER_COUNT; ++i) | ||
| { | ||
| Bool multipleAlliances = false; | ||
| Player *alive = nullptr; | ||
| Player *player; | ||
| for (Int i=0; i<MAX_PLAYER_COUNT; ++i) | ||
| Player* player = m_players[i]; | ||
|
|
||
| if (player && !hasSinglePlayerBeenDefeated(player)) | ||
| { | ||
| player = m_players[i]; | ||
| if (player && !hasSinglePlayerBeenDefeated(player)) | ||
| if (alive) | ||
| { | ||
| if (alive) | ||
| // check to verify they are on the same team | ||
| if (!areAllies(alive, player)) | ||
| { | ||
| // check to verify they are on the same team | ||
| if (!areAllies(alive, player)) | ||
| { | ||
| multipleAlliances = true; | ||
| break; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| alive = player; // save this pointer to check against | ||
| return true; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| alive = player; // save this pointer to check against | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!multipleAlliances) | ||
| return false; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| void VictoryConditions::update( void ) | ||
| { | ||
| if (!TheRecorder->isMultiplayer() || (m_localSlotNum < 0 && !m_isObserver)) | ||
| return; | ||
|
|
||
| // Check for a single winning alliance | ||
| if (!m_singleAllianceRemaining) | ||
| { | ||
| if (!multipleAlliancesExist()) | ||
| { | ||
| m_singleAllianceRemaining = true; // don't check again | ||
| m_endFrame = TheGameLogic->getFrame(); | ||
|
|
||
| // TheSuperHackers @bugfix Stubbjax 11/02/2026 Cache victory status so that premature exits don't void the victory. | ||
|
|
||
| Player* victoriousPlayer = findFirstVictoriousPlayer(); | ||
|
|
||
| if (victoriousPlayer) | ||
| markAllianceVictorious(victoriousPlayer); | ||
|
xezon marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -233,19 +251,51 @@ void VictoryConditions::update( void ) | |
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| Player* VictoryConditions::findFirstVictoriousPlayer() | ||
|
xezon marked this conversation as resolved.
Outdated
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conceptually, A better logic would be
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking for a single surviving alliance does not conceptually work either - we still want the condition to be satisfied if there are no alliances remaining. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. |
||
| { | ||
| for (Int i = 0; i < MAX_PLAYER_COUNT; ++i) | ||
| { | ||
| Player* player = m_players[i]; | ||
| if (player && !hasSinglePlayerBeenDefeated(player)) | ||
| return player; | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| void VictoryConditions::markAllianceVictorious(Player* victoriousPlayer) | ||
| { | ||
| // This marks the player and any allies as victorious, including defeated allies. | ||
| // This also ensures players retain their victorious status if their assets are destroyed after | ||
| // the victory conditions are met (e.g. when quitting the game prior to the victory screen). | ||
|
|
||
| for (Int i = 0; i < MAX_PLAYER_COUNT; ++i) | ||
| { | ||
| Player* player = m_players[i]; | ||
| if (player == victoriousPlayer || (player && areAllies(player, victoriousPlayer))) | ||
| m_isVictorious[i] = true; | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| Bool VictoryConditions::hasAchievedVictory(Player *player) | ||
| { | ||
| if (!player) | ||
| return false; | ||
|
|
||
| if (m_singleAllianceRemaining) | ||
| if (!m_singleAllianceRemaining) | ||
| return false; | ||
|
|
||
| for (Int i = 0; i < MAX_PLAYER_COUNT; ++i) | ||
| { | ||
| for (Int i=0; i<MAX_PLAYER_COUNT; ++i) | ||
| if (player == m_players[i]) | ||
| { | ||
| if ( m_players[i] && !hasSinglePlayerBeenDefeated(m_players[i]) && | ||
| (player == m_players[i] || areAllies(m_players[i], player)) ) | ||
| if (m_isVictorious[i]) | ||
| return true; | ||
|
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -258,8 +308,19 @@ Bool VictoryConditions::hasBeenDefeated(Player *player) | |
| if (!player) | ||
| return false; | ||
|
|
||
| if (m_singleAllianceRemaining && !hasAchievedVictory(player)) | ||
| return true; | ||
| if (!m_singleAllianceRemaining) | ||
| return false; | ||
|
|
||
| for (Int i = 0; i < MAX_PLAYER_COUNT; ++i) | ||
| { | ||
| if (player == m_players[i]) | ||
| { | ||
| if (m_isDefeated[i]) | ||
| return true; | ||
|
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.