Bazaar developer reference

CvPlayer::setTurnActive(bool, bool)

Defined in
CvPlayer.cpp, line 17845
Class
CvPlayer
Hook name
CivHooks::CvPlayer_setTurnActive
Lua events
GameEvents.PlayerDoneTurn

Hooks

static bool BeforeCvPlayer_setTurnActive(CvPlayer* self, bool bNewValue, bool bDoTurn);static void AfterCvPlayer_setTurnActive(CvPlayer* self, bool bNewValue, bool bDoTurn);static void ReplaceCvPlayer_setTurnActive(void (*original)(CvPlayer*, bool, bool), CvPlayer* self, bool bNewValue, bool bDoTurn);CivRegisterBefore<CivHooks::CvPlayer_setTurnActive>(host, &BeforeCvPlayer_setTurnActive);CivRegisterAfter<CivHooks::CvPlayer_setTurnActive>(host, &AfterCvPlayer_setTurnActive);CivRegisterReplace<CivHooks::CvPlayer_setTurnActive>(host, &ReplaceCvPlayer_setTurnActive);

Code

17845void CvPlayer::setTurnActive(bool bNewValue, bool bDoTurn)17846{17847	if(isTurnActive() != bNewValue)17848	{17849		m_bTurnActive = bNewValue;17850		DLLUI->PublishEndTurnDirty();1785117852		CvGame& kGame = GC.getGame();1785317854		/////////////////////////////////////////////17855		// TURN IS BEGINNING17856		/////////////////////////////////////////////1785717858		if(isTurnActive())17859		{17860			CvAssertMsg(isAlive(), "isAlive is expected to be true");1786117862			setEndTurn(false);1786317864			DoUnitAttrition();1786517866			if(kGame.getActivePlayer() == m_eID)17867			{17868				CvMap& theMap = GC.getMap();17869				theMap.updateDeferredFog();17870			}1787117872			if((kGame.isHotSeat() || kGame.isPbem()) && isHuman() && bDoTurn)17873			{17874				DLLUI->clearEventMessages();1787517876				kGame.setActivePlayer(GetID());17877			}1787817879			if(CvPreGame::isPitBoss() && kGame.getActivePlayer() != m_eID && isHuman() && gDLL->IsHost() && !isConnected())17880			{//send turn reminder if the player isn't actively connected to the game.17881				sendTurnReminder();17882			}1788317884			std::ostringstream infoStream;17885			infoStream << "setTurnActive() for player ";17886			infoStream << (int)GetID();17887			infoStream << " ";17888			infoStream << getName();17889			kGame.changeNumGameTurnActive(1, infoStream.str());1789017891			DLLUI->PublishPlayerTurnStatus(DLLUIClass::TURN_START, GetID());1789217893			if(bDoTurn)17894			{17895				SetAllUnitsUnprocessed();1789617897				bool bCommonPathFinderMPCaching = GC.getPathFinder().SetMPCacheSafe(true);17898				bool bIgnoreUnitsPathFinderMPCaching = GC.getIgnoreUnitsPathFinder().SetMPCacheSafe(true);17899				bool bTacticalPathFinderMPCaching = GC.GetTacticalAnalysisMapFinder().SetMPCacheSafe(true);17900				bool bInfluencePathFinderMPCaching = GC.getInfluenceFinder().SetMPCacheSafe(true);17901				bool bRoutePathFinderMPCaching = GC.getRouteFinder().SetMPCacheSafe(true);17902				bool bWaterRoutePathFinderMPCaching = GC.GetWaterRouteFinder().SetMPCacheSafe(true);1790317904				{17905					AI_PERF_FORMAT("AI-perf.csv", ("Connections/Gold, Turn %03d, %s", kGame.getElapsedGameTurns(), getCivilizationShortDescription()) );1790617907					// This block all has things which might change based on city connections changing17908					m_pCityConnections->Update();17909					GetTreasury()->DoUpdateCityConnectionGold();17910					DoUpdateHappiness();17911				}1791217913				{17914					AI_PERF_FORMAT("AI-perf.csv", ("Builder Tasking, Turn %03d, %s", kGame.getElapsedGameTurns(), getCivilizationShortDescription()) );1791517916					m_pBuilderTaskingAI->Update();17917				}1791817919				if(kGame.isFinalInitialized())17920				{17921					if(isAlive())17922					{17923						if(GetDiplomacyRequests())17924						{17925							GetDiplomacyRequests()->BeginTurn();17926						}1792717928						doTurn();1792917930						doTurnUnits();17931					}17932				}1793317934				GC.getPathFinder().SetMPCacheSafe(bCommonPathFinderMPCaching);17935				GC.getIgnoreUnitsPathFinder().SetMPCacheSafe(bIgnoreUnitsPathFinderMPCaching);17936				GC.GetTacticalAnalysisMapFinder().SetMPCacheSafe(bTacticalPathFinderMPCaching);17937				GC.getInfluenceFinder().SetMPCacheSafe(bInfluencePathFinderMPCaching);17938				GC.getRouteFinder().SetMPCacheSafe(bRoutePathFinderMPCaching);17939				GC.GetWaterRouteFinder().SetMPCacheSafe(bWaterRoutePathFinderMPCaching);1794017941				if((GetID() == kGame.getActivePlayer()) && (kGame.getElapsedGameTurns() > 0))17942				{17943					if(kGame.isNetworkMultiPlayer())17944					{17945						DLLUI->AddMessage(0, GetID(), true, GC.getEVENT_MESSAGE_TIME(), GetLocalizedText("TXT_KEY_MISC_TURN_BEGINS").GetCString(), "AS2D_NEWTURN", MESSAGE_TYPE_DISPLAY_ONLY);17946					}17947				}1794817949				doWarnings();17950			}1795117952#if defined(MOD_AI_MP_DIPLOMACY)17953			if (MOD_AI_MP_DIPLOMACY && isHuman())17954			{17955				// We just activated a human, later the AI players need to try to contact the player17956				CvDiplomacyRequests::s_aDiploHumans.push_back(GetID());17957			}17958#endif1795917960			if(GetID() == kGame.getActivePlayer())17961			{17962				GetUnitCycler().Rebuild();1796317964				if(DLLUI->GetLengthSelectionList() == 0)17965				{17966					DLLUI->setCycleSelectionCounter(1);17967				}1796817969				DLLUI->setDirty(SelectionCamera_DIRTY_BIT, true);1797017971				// slewis - added this so the tutorial knows when a turn begins17972				DLLUI->PublishActivePlayerTurnStart();17973			}17974			else if(isHuman() && kGame.isGameMultiPlayer())17975			{17976				DLLUI->PublishRemotePlayerTurnStart();17977			}17978		}1797917980		/////////////////////////////////////////////17981		// TURN IS ENDING17982		/////////////////////////////////////////////1798317984		else17985		{17986#if defined(MOD_EVENTS_PLAYER_TURN)17987			if (MOD_EVENTS_PLAYER_TURN) {17988				GAMEEVENTINVOKE_HOOK(GAMEEVENT_PlayerDoneTurn, GetID());17989			}17990#endif1799117992			CvAssertFmt(GetEndTurnBlockingType() == NO_ENDTURN_BLOCKING_TYPE, "Expecting the end-turn blocking to be NO_ENDTURN_BLOCKING_TYPE, got %d", GetEndTurnBlockingType());17993			SetEndTurnBlocking(NO_ENDTURN_BLOCKING_TYPE, -1);	// Make sure this is clear so the UI doesn't block when it is not our turn.1799417995			DoUnitReset();1799617997			if(!isHuman())17998			{17999				RespositionInvalidUnits();18000			}1800118002			if(GetNotifications())18003			{18004				GetNotifications()->EndOfTurnCleanup();18005			}1800618007			if(GetDiplomacyRequests())18008			{18009				GetDiplomacyRequests()->EndTurn();18010			}1801118012			if(GetID() == kGame.getActivePlayer())18013			{18014				DLLUI->PublishActivePlayerTurnEnd();18015			}1801618017			if(!isHuman() || (isHuman() && !isAlive()) || (isHuman() && gDLL->HasReceivedTurnAllComplete(GetID())) || kGame.getAIAutoPlay())18018				kGame.changeNumGameTurnActive(-1, std::string("setTurnActive() for player ") + getName());1801918020			DLLUI->PublishPlayerTurnStatus(DLLUIClass::TURN_END, GetID());18021		}18022	}18023	else18024	{18025		CvString logOutput;18026		logOutput.Format("SetTurnActive() called without changing the end turn status. Player(%i) OldTurnActive(%i) NewTurnActive(%i)", GetID(), isTurnActive(), bNewValue);18027		gDLL->netMessageDebugLog(logOutput);18028	}18029}

Calls

Called by