Skip to content

Commit

Permalink
Enforce active turn for first warring human
Browse files Browse the repository at this point in the history
Who knows if this will have bad side-effects, but it seems to
work in the lobby.

Test plan:

Load up my bad save game and check that India's turn is active
in the lobby. It does. Hopefully we can make it through India's
turn and then through every other warring players turns too.
Fingers crossed on that.

Also, I tried to reproduce the bad save game in a two player
game. Unfortunately (?), this game seems to load fine. I can
load this working save with the patch applied, and have verified
that it doesn't break anything.
  • Loading branch information
dmnd committed Jun 16, 2014
1 parent 6501d23 commit 1ba3dfb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CvGameCoreDLL_Expansion2/CvPlayer.cpp
Expand Up @@ -22194,6 +22194,50 @@ void CvPlayer::Read(FDataStream& kStream)
//m_pDiplomacyRequests->Read(kStream);
}

/**
* Warring sequential humans deadlock fix
*
* Upon loading an autosave, all human players at war were loaded into the
* game with inactive turns, making it impossible for them to end the turn.
*
* The following hack detects and fixes that problem by forcing the first
* human player in sequential turn mode to be active.
*
* Hopefully this has no side effects but it's impossible for me to know.
*/
if(GC.getGame().isOption(GAMEOPTION_DYNAMIC_TURNS) && isHuman()) {
NET_MESSAGE_DEBUG_OSTR_ALWAYS("read() for human player " << getName());
NET_MESSAGE_DEBUG_OSTR_ALWAYS("m_bTurnActive is " << m_bTurnActive);
NET_MESSAGE_DEBUG_OSTR_ALWAYS("m_bAutoMoves is " << m_bAutoMoves);
NET_MESSAGE_DEBUG_OSTR_ALWAYS("m_bProcessedAutoMoves is " << m_bProcessedAutoMoves);
NET_MESSAGE_DEBUG_OSTR_ALWAYS("m_bDynamicTurnsSimultMode is " << m_bDynamicTurnsSimultMode);

if (!m_bDynamicTurnsSimultMode) {
// this human is in sequential turns mode,
// so make sure there is an active human in the game
static bool s_bVerified1stSeqentialHumanIsActive = false;
if (!s_bVerified1stSeqentialHumanIsActive) {
s_bVerified1stSeqentialHumanIsActive = true;

if (m_bTurnActive) {
NET_MESSAGE_DEBUG_OSTR_ALWAYS(
"first sequential human was already active");
} else {
NET_MESSAGE_DEBUG_OSTR_ALWAYS(
"hacktivating unexpectedly inactive player :(");

// force the player to be active
m_bTurnActive = true;

// also turn off automoves - without this, the turn
// becomes inactive before the player can do anything
m_bAutoMoves = false;
m_bProcessedAutoMoves = false;
}
}
}
}

if(m_bTurnActive)
GC.getGame().changeNumGameTurnActive(1, std::string("setTurnActive() [loading save game] for player ") + getName());

Expand Down

1 comment on commit 1ba3dfb

@dmnd
Copy link
Owner Author

@dmnd dmnd commented on 1ba3dfb Jun 16, 2014

Choose a reason for hiding this comment

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

This patch fixes the issue described at: http://forums.civfanatics.com/showthread.php?t=528054

Please sign in to comment.