Bazaar developer reference

CvGame::hasTurnTimerExpired(PlayerTypes)

Defined in
CvGame.cpp, line 1891
Class
CvGame
Hook name
CivHooks::CvGame_hasTurnTimerExpired

Hooks

static bool BeforeCvGame_hasTurnTimerExpired(CvGame* self, PlayerTypes playerID, bool& result);static void AfterCvGame_hasTurnTimerExpired(CvGame* self, PlayerTypes playerID, bool& result);static bool ReplaceCvGame_hasTurnTimerExpired(bool (*original)(CvGame*, PlayerTypes), CvGame* self, PlayerTypes playerID);CivRegisterBefore<CivHooks::CvGame_hasTurnTimerExpired>(host, &BeforeCvGame_hasTurnTimerExpired);CivRegisterAfter<CivHooks::CvGame_hasTurnTimerExpired>(host, &AfterCvGame_hasTurnTimerExpired);CivRegisterReplace<CivHooks::CvGame_hasTurnTimerExpired>(host, &ReplaceCvGame_hasTurnTimerExpired);

Code

1891bool CvGame::hasTurnTimerExpired(PlayerTypes playerID)1892{//gameLoopUpdate - Indicates that we're updating the turn timer for the game loop update.  1893 //					This forces the active player's turn to finish if her turn time has elapsed.1894 //					We also reset the turn timer when ai processing is occurring.1895 //					If false, we're simply querying the game for a player's turn timer status.1896	bool gameTurnTimerExpired = false;1897	bool isLocalPlayer = getActivePlayer() == playerID;1898	if(isOption(GAMEOPTION_END_TURN_TIMER_ENABLED) && !isPaused() && GC.getGame().getGameState() == GAMESTATE_ON)1899	{1900		ICvUserInterface2* iface = GC.GetEngineUserInterface();1901		if(getElapsedGameTurns() > 0)1902		{1903			if(isLocalPlayer && (!gDLL->allAICivsProcessedThisTurn() || !allUnitAIProcessed()))1904			{//the turn timer doesn't doesn't start until all ai processing has been completed for this game turn.1905				resetTurnTimer(true);19061907				//hold the turn timer at 0 seconds with 0% completion1908				CvPreGame::setEndTurnTimerLength(0.0f);1909				iface->updateEndTurnTimer(0.0f);1910			}1911			else1912			{//turn timer is actively ticking.1913				if(playerID == NO_PLAYER)1914				{//can't do a turn timer check for an invalid player.1915					return false;1916				}1917				CvPlayer& curPlayer = GET_PLAYER(playerID);19181919				// Has the turn expired?1920				float gameTurnEnd = static_cast<float>(getMaxTurnLen());19211922				//NOTE:  These times exclude the time used for AI processing.1923				//Time since the current player's turn started.  Used for measuring time for players in sequential turn mode.1924				float timeSinceCurrentTurnStart = m_curTurnTimer.Peek() + m_fCurrentTurnTimerPauseDelta; 1925				//Time since the game (year) turn started.  Used for measuring time for players in simultaneous turn mode.1926				float timeSinceGameTurnStart = m_timeSinceGameTurnStart.Peek() + m_fCurrentTurnTimerPauseDelta; 1927				1928				float timeElapsed = (curPlayer.isSimultaneousTurns() ? timeSinceGameTurnStart : timeSinceCurrentTurnStart);1929				if(curPlayer.isTurnActive())1930				{//The timer is ticking for our turn1931					if(timeElapsed > gameTurnEnd)1932					{1933						if(s_unitMoveTurnSlice == 0)1934						{1935							gameTurnTimerExpired = true;1936						}1937						else if(s_unitMoveTurnSlice + 10 < getTurnSlice())1938						{1939							gameTurnTimerExpired = true;1940						}1941					}1942				}19431944				if((!curPlayer.isTurnActive() || gDLL->HasReceivedTurnComplete(playerID)) //Active player has finished their turn.1945					&& getNumSequentialHumans() > 1)	//or sequential turn mode1946				{//It's not our turn and there are sequential turn human players in the game.19471948					//In this case, the turn timer shows progress in terms of the max possible time until our next turn.1949					//As such, timeElapsed has to be adjusted to be a value in terms of the max possible time.19501951					//determine number of players in the sequential turn sequence, not counting the active player.1952					int playersInSeq = getNumSequentialHumans(playerID);19531954					//The max turn length is multiplied by the number of other human players in the sequential turn sequence.1955					gameTurnEnd *= playersInSeq;19561957					float timePerPlayer = gameTurnEnd / playersInSeq; //time limit per human1958					//count how many human players are left until us in the sequence.1959					int humanTurnsUntilMe = countSeqHumanTurnsUntilPlayerTurn(playerID);1960					int humanTurnsCompleted = playersInSeq - humanTurnsUntilMe;19611962					if(humanTurnsUntilMe)1963					{//We're waiting on other sequential players1964						timeElapsed =  timeSinceCurrentTurnStart + humanTurnsCompleted*timePerPlayer;1965					}1966					else1967					{//All the other sequential players have finished.1968					 //Either we're waiting on turn processing or on players who are playing simultaneous turns.19691970						//scale time to be that of the remaining possible time for the simultaneous players.1971						//From the player's perspective, the timer will simply creep down for the remaining simultaneous turn time1972						//rather than skipping straight to zero like it would by just tracking the sequential players' turn time.1973						timeElapsed = timeSinceGameTurnStart + (humanTurnsCompleted-1)*timePerPlayer;1974					}1975				}19761977				if(isLocalPlayer)1978				{//update the local end turn timer.1979					CvPreGame::setEndTurnTimerLength(gameTurnEnd);1980					iface->updateEndTurnTimer(timeElapsed / gameTurnEnd);1981				}1982			}1983		}1984		else if(isLocalPlayer){1985			//hold the turn timer at 0 seconds with 0% completion1986			CvPreGame::setEndTurnTimerLength(0.0f);1987			iface->updateEndTurnTimer(0.0f);1988		}1989	}19901991	return gameTurnTimerExpired;1992}

Calls

Called by