Bazaar developer reference

CvGame::doTurn()

Defined in
CvGame.cpp, line 7601
Class
CvGame
Hook name
CivHooks::CvGame_doTurn
Changed in
0.5.0

Hooks

static bool BeforeCvGame_doTurn(CvGame* self);static void AfterCvGame_doTurn(CvGame* self);static void ReplaceCvGame_doTurn(void (*original)(CvGame*), CvGame* self);CivRegisterBefore<CivHooks::CvGame_doTurn>(host, &BeforeCvGame_doTurn);CivRegisterAfter<CivHooks::CvGame_doTurn>(host, &AfterCvGame_doTurn);CivRegisterReplace<CivHooks::CvGame_doTurn>(host, &ReplaceCvGame_doTurn);

Code

7601void CvGame::doTurn()7602{7603#ifndef FINAL_RELEASE7604	char temp[256];7605	sprintf_s(temp, "Turn %i\n", getGameTurn());7606	OutputDebugString(temp);7607#endif76087609	int aiShuffle[MAX_PLAYERS];7610	int iLoopPlayer;7611	int iI;76127613	if(getAIAutoPlay())7614	{7615#if defined(CIV_HOST_API)7616		if (CivHostSavingAllowed())7617#endif7618		gDLL->AutoSave(false);7619	}76207621	// END OF TURN76227623	//We reset the turn timer now so that we know that the turn timer has been reset at least once for7624	//this turn.  CvGameController::Update() will continue to reset the timer if there is prolonged ai processing.7625	resetTurnTimer(true);76267627	// If player unit cycling has been canceled for this turn, set it back to normal for the next7628	GC.GetEngineUserInterface()->setNoSelectionListCycle(false);76297630	gDLL->DoTurn();76317632	CvBarbarians::BeginTurn();76337634	doUpdateCacheOnTurn();76357636	DoUpdateCachedWorldReligionTechProgress();76377638	updateScore();76397640	m_kGameDeals.DoTurn();76417642	for(iI = 0; iI < MAX_TEAMS; iI++)7643	{7644		if(GET_TEAM((TeamTypes)iI).isAlive())7645		{7646			GET_TEAM((TeamTypes)iI).doTurn();7647		}7648	}76497650	GC.getMap().doTurn();76517652	GC.GetEngineUserInterface()->doTurn();76537654	CvBarbarians::DoCamps();76557656	CvBarbarians::DoUnits();76577658	GetGameReligions()->DoTurn();7659	GetGameTrade()->DoTurn();7660	GetGameLeagues()->DoTurn();7661	GetGameCulture()->DoTurn();76627663	GC.GetEngineUserInterface()->setCanEndTurn(false);7664	GC.GetEngineUserInterface()->setHasMovedUnit(false);76657666	if(getAIAutoPlay() > 0)7667	{7668		changeAIAutoPlay(-1);76697670		if(getAIAutoPlay() == 0)7671		{7672			ReviveActivePlayer();7673		}7674	}76757676	incrementGameTurn();7677	incrementElapsedGameTurns();76787679	if(isOption(GAMEOPTION_DYNAMIC_TURNS))7680	{// update turn mode for dynamic turn mode.7681		for(int teamIdx = 0; teamIdx < MAX_TEAMS; ++teamIdx)7682		{7683			CvTeam& curTeam = GET_TEAM((TeamTypes)teamIdx);7684			curTeam.setDynamicTurnsSimultMode(!curTeam.isHuman() || !curTeam.isAtWarWithHumans());7685		}7686	}76877688	// Configure turn active status for the beginning of the new turn.7689	if(isOption(GAMEOPTION_DYNAMIC_TURNS) || isOption(GAMEOPTION_SIMULTANEOUS_TURNS))7690	{// In multi-player with simultaneous turns, we activate all of the AI players7691	 // at the same time.  The human players who are playing simultaneous turns will be activated in updateMoves after all7692	 // the AI players are processed.7693		shuffleArray(aiShuffle, MAX_PLAYERS, getJonRand());76947695		for(iI = 0; iI < MAX_PLAYERS; iI++)7696		{7697			iLoopPlayer = aiShuffle[iI];7698			CvPlayer& player = GET_PLAYER((PlayerTypes)iLoopPlayer);7699			// activate AI here, when they are done, activate human players in7700			// updateMoves7701			if(player.isAlive() && !player.isHuman())7702			{7703				player.setTurnActive(true);7704			}7705		}7706	}77077708	if(isSimultaneousTeamTurns())7709	{//We're doing simultaneous team turns, activate the first team in sequence.7710		for(iI = 0; iI < MAX_TEAMS; iI++)7711		{7712			CvTeam& kTeam = GET_TEAM((TeamTypes)iI);7713			if(kTeam.isAlive() && !kTeam.isSimultaneousTurns()) 7714			{7715				kTeam.setTurnActive(true);7716				break;7717			}7718		}7719	}7720	else if(!isOption(GAMEOPTION_SIMULTANEOUS_TURNS))7721	{// player sequential turns.7722		// Sequential turns.  Activate the first player we find from the start, human or AI, who wants a sequential turn.7723		for(iI = 0; iI < MAX_PLAYERS; iI++)7724		{7725			if(GET_PLAYER((PlayerTypes)iI).isAlive() 7726				&& !GET_PLAYER((PlayerTypes)iI).isSimultaneousTurns()) //we don't want to be a person who's doing a simultaneous turn for dynamic turn mode.7727			{7728				if(isPbem() && GET_PLAYER((PlayerTypes)iI).isHuman())7729				{7730					if(iI == getActivePlayer())7731					{7732						// Nobody else left alive7733						CvPreGame::setGameType(GAME_HOTSEAT_MULTIPLAYER);7734						GET_PLAYER((PlayerTypes)iI).setTurnActive(true);7735					}7736					else if(!getPbemTurnSent())7737					{7738						gDLL->sendPbemTurn((PlayerTypes)iI);7739					}7740				}7741				else7742				{7743					GET_PLAYER((PlayerTypes)iI).setTurnActive(true);7744					CvAssert(getNumGameTurnActive() == 1);7745				}77467747				break;7748			}7749		}7750	}77517752#if defined(MOD_AI_MP_DIPLOMACY)7753	if (MOD_AI_MP_DIPLOMACY) {7754		CvDiplomacyRequests::DoAIDiplomacyWithHumans();7755	}7756#endif77577758	// Victory stuff7759	testVictory();77607761	// Who's Winning7762	if(GET_PLAYER(getActivePlayer()).isAlive() && !IsStaticTutorialActive())7763	{7764		// Don't show this stuff in MP7765#if defined(MOD_API_EXTENSIONS)7766		if(!isReallyNetworkMultiPlayer() && !isPbem() && !isHotSeat())7767#else7768		if(!isGameMultiPlayer())7769#endif7770		{7771			int iTurnFrequency = /*25*/ GC.getPROGRESS_POPUP_TURN_FREQUENCY();77727773			// This isn't exactly appropriate, but it'll do7774			iTurnFrequency *= getGameSpeedInfo().getTrainPercent();7775			iTurnFrequency /= 100;77767777			if(getElapsedGameTurns() % iTurnFrequency == 0)7778			{7779				// This popup his the sync rand, so beware7780				CvPopupInfo kPopupInfo(BUTTONPOPUP_WHOS_WINNING);7781				GC.GetEngineUserInterface()->AddPopup(kPopupInfo);7782			}7783		}7784	}77857786	LogGameState();77877788	if(isNetworkMultiPlayer())7789	{//autosave after doing a turn7790#if defined(CIV_HOST_API)7791		if (CivHostSavingAllowed())7792#endif7793		gDLL->AutoSave(false);7794	}77957796	gDLL->PublishNewGameTurn(getGameTurn());7797}

Calls

Called by