Bazaar developer reference

CvPlayerCulture::DoTurn()

Defined in
CvCultureClasses.cpp, line 2349
Class
CvPlayerCulture
Hook name
CivHooks::CvPlayerCulture_DoTurn

Hooks

static bool BeforeCvPlayerCulture_DoTurn(CvPlayerCulture* self);static void AfterCvPlayerCulture_DoTurn(CvPlayerCulture* self);static void ReplaceCvPlayerCulture_DoTurn(void (*original)(CvPlayerCulture*), CvPlayerCulture* self);CivRegisterBefore<CivHooks::CvPlayerCulture_DoTurn>(host, &BeforeCvPlayerCulture_DoTurn);CivRegisterAfter<CivHooks::CvPlayerCulture_DoTurn>(host, &AfterCvPlayerCulture_DoTurn);CivRegisterReplace<CivHooks::CvPlayerCulture_DoTurn>(host, &ReplaceCvPlayerCulture_DoTurn);

Code

2348/// Update cultural influence numbers for this turn2349void CvPlayerCulture::DoTurn()2350{2351	int iInfluentialCivsForWin = GC.getGame().GetGameCulture()->GetNumCivsInfluentialForWin();2352	int iLastTurnInfluentialCivs = GetNumCivsInfluentialOn();23532354	for (int iLoopPlayer = 0; iLoopPlayer < MAX_MAJOR_CIVS; iLoopPlayer++)2355	{2356		// Move over last turn's numbers2357		m_aiLastTurnCulturalInfluence[iLoopPlayer] = m_aiCulturalInfluence[iLoopPlayer];23582359		CvPlayer &kOtherPlayer = GET_PLAYER((PlayerTypes)iLoopPlayer);2360		CvTeam &kOtherTeam = GET_TEAM(kOtherPlayer.getTeam());2361		if (iLoopPlayer != m_pPlayer->GetID() && kOtherPlayer.isAlive() && !kOtherPlayer.isMinorCiv() && kOtherTeam.isHasMet(m_pPlayer->getTeam()))2362		{2363			m_aiCulturalInfluence[iLoopPlayer] += GetInfluencePerTurn((PlayerTypes)iLoopPlayer);2364		}2365	}2366	2367	DoPublicOpinion();23682369	CvString strSummary;2370	CvString strInfo;2371	CvNotifications* pTargetNotifications = m_pPlayer->GetNotifications();2372	int iThisTurnInfluentialCivs = GetNumCivsInfluentialOn();23732374	VictoryTypes eVictory = (VictoryTypes) GC.getInfoTypeForString("VICTORY_CULTURAL", true);2375	const bool bCultureVictoryValid = (eVictory == NO_VICTORY || GC.getGame().isVictoryValid(eVictory));23762377	if (iThisTurnInfluentialCivs > 0 && !GC.getGame().GetGameCulture()->GetReportedSomeoneInfluential())2378	{2379		if(bCultureVictoryValid)2380		{//This civilization is the first civ to be influential over another civs.  Notify the masses!2381			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_SOMEONE_INFLUENTIAL");2382			CvString							targFirstInfluentialInfo = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_SOMEONE_INFLUENTIAL_ACTIVE_PLAYER_TT");2383			Localization::String	someoneFirstInfluentialInfo = Localization::Lookup("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_SOMEONE_INFLUENTIAL_TT");2384			CvString							unmetFirstInfluentialInfo = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_UNMET_INFLUENTIAL_TT");23852386			for(int iNotifyPlayerID = 0; iNotifyPlayerID < MAX_MAJOR_CIVS; ++iNotifyPlayerID){2387				PlayerTypes eNotifyPlayer = (PlayerTypes) iNotifyPlayerID;2388				CvPlayerAI& kNotifyPlayer = GET_PLAYER(eNotifyPlayer);23892390				if (m_pPlayer->GetID() == eNotifyPlayer){	2391					strInfo = targFirstInfluentialInfo;2392				}2393				else2394				{2395					CvTeam& kCurTeam = GET_TEAM(kNotifyPlayer.getTeam());2396					if(kCurTeam.isHasMet(m_pPlayer->getTeam())){2397						Localization::String strTemp = someoneFirstInfluentialInfo;2398						strTemp << m_pPlayer->getCivilizationShortDescriptionKey();2399						strInfo = strTemp.toUTF8();2400					}2401					else2402					{2403						strInfo = unmetFirstInfluentialInfo;2404					}					2405				}2406				kNotifyPlayer.GetNotifications()->Add(NOTIFICATION_CULTURE_VICTORY_SOMEONE_INFLUENTIAL, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2407			}2408		}24092410		GC.getGame().GetGameCulture()->SetReportedSomeoneInfluential(true);2411	}24122413	if (iThisTurnInfluentialCivs < iLastTurnInfluentialCivs && bCultureVictoryValid)2414	{2415		Localization::String strTemp;2416		strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_NO_LONGER_INFLUENTIAL");2417		strInfo = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_NO_LONGER_INFLUENTIAL_TT");2418		pTargetNotifications->Add(NOTIFICATION_CULTURE_VICTORY_NO_LONGER_INFLUENTIAL, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2419	}24202421	if (!m_bReportedTwoCivsAway && iThisTurnInfluentialCivs > 0 && iThisTurnInfluentialCivs == iInfluentialCivsForWin - 2 && GC.getGame().countMajorCivsEverAlive() >= 4)2422	{2423		if(bCultureVictoryValid)2424		{//This civilization is the first civ to be two civilizations away from getting a cultural victory.  Notify the masses!2425			CvString							targCloseTwoSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO_ACTIVE_PLAYER");2426			Localization::String	targCloseTwoInfo = Localization::Lookup("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO_ACTIVE_PLAYER_TT");2427			CvString							someoneCloseTwoSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO");2428			Localization::String	someoneCloseTwoInfo = Localization::Lookup("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO_TT");2429			CvString							unmetCloseTwoInfo = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO_UNMET_TT");2430			for(int iNotifyLoop = 0; iNotifyLoop < MAX_MAJOR_CIVS; ++iNotifyLoop){2431				PlayerTypes eCurPlayer = (PlayerTypes) iNotifyLoop;2432				CvPlayerAI& kCurPlayer = GET_PLAYER(eCurPlayer);24332434				if (eCurPlayer == m_pPlayer->GetID()){	2435					strSummary = targCloseTwoSummary;2436					Localization::String strTemp = targCloseTwoInfo;2437					strTemp << m_pPlayer->getCivilizationShortDescriptionKey();2438					strInfo = strTemp.toUTF8();2439					kCurPlayer.GetNotifications()->Add(NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO_ACTIVE_PLAYER, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2440				}2441				else{2442					strSummary = someoneCloseTwoSummary;2443					CvTeam& kCurTeam = GET_TEAM(kCurPlayer.getTeam());2444					if(kCurTeam.isHasMet(m_pPlayer->getTeam())){2445						Localization::String strTemp = someoneCloseTwoInfo;2446						strTemp << m_pPlayer->getCivilizationShortDescriptionKey();2447						strInfo = strTemp.toUTF8();2448					}2449					else{2450						strInfo = unmetCloseTwoInfo;2451					}24522453					kCurPlayer.GetNotifications()->Add(NOTIFICATION_CULTURE_VICTORY_WITHIN_TWO, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2454				}2455			}2456		}24572458		m_bReportedTwoCivsAway = true;2459	}24602461	if (!m_bReportedOneCivAway && iThisTurnInfluentialCivs == iInfluentialCivsForWin - 1 && GC.getGame().countMajorCivsEverAlive() >= 3)2462	{2463		if(bCultureVictoryValid)2464		{//This civilization is the first civ to be one civilizations away from getting a cultural victory.  Notify the masses!2465#if defined(MOD_BUGFIX_MINOR)2466		  // but don't notify if there are only two players left in the game!2467		  if (GC.getGame().countMajorCivsAlive() > 2) {2468#endif2469			CvString							targCloseOneSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE_ACTIVE_PLAYER");2470			Localization::String	targCloseOneInfo = Localization::Lookup("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE_ACTIVE_PLAYER_TT");2471			CvString							someoneCloseOneSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE");2472			Localization::String	someoneCloseOneInfo = Localization::Lookup("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE_TT");2473			CvString							unmetCloseOneInfo = GetLocalizedText("TXT_KEY_NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE_UNMET_TT");2474			for(int iNotifyLoop = 0; iNotifyLoop < MAX_MAJOR_CIVS; ++iNotifyLoop){2475				PlayerTypes eCurPlayer = (PlayerTypes) iNotifyLoop;2476				CvPlayerAI& kCurPlayer = GET_PLAYER(eCurPlayer);24772478				if (eCurPlayer == m_pPlayer->GetID()){	2479					strSummary = targCloseOneSummary;2480					Localization::String strTemp = targCloseOneInfo;2481					strTemp << m_pPlayer->getCivilizationShortDescriptionKey();2482					strInfo = strTemp.toUTF8();2483					kCurPlayer.GetNotifications()->Add(NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE_ACTIVE_PLAYER, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2484				}2485				else2486				{2487					strSummary = someoneCloseOneSummary;2488					CvTeam& kCurTeam = GET_TEAM(kCurPlayer.getTeam());2489					if(kCurTeam.isHasMet(m_pPlayer->getTeam())){2490						Localization::String strTemp = someoneCloseOneInfo;2491						strTemp << m_pPlayer->getCivilizationShortDescriptionKey();2492						strInfo = strTemp.toUTF8();2493					}2494					else{2495						strInfo = unmetCloseOneInfo;2496					}2497					kCurPlayer.GetNotifications()->Add(NOTIFICATION_CULTURE_VICTORY_WITHIN_ONE, strInfo, strSummary, -1, -1, m_pPlayer->GetID());2498				}2499			}2500#if defined(MOD_BUGFIX_MINOR)2501		  }2502#endif2503		}25042505		m_bReportedOneCivAway = true;2506	}25072508	if (m_pPlayer->isHuman() && !GC.getGame().isGameMultiPlayer())2509	{2510		// check for having city-state artifacts2511		std::vector<int> aiCityStateArtifact;2512		int iLoop;2513		CvCity* pLoopCity = NULL;2514		for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))2515		{2516			for(int iBuildingClassLoop = 0; iBuildingClassLoop < GC.getNumBuildingClassInfos(); iBuildingClassLoop++)2517			{2518				CvCivilizationInfo& playerCivilizationInfo = m_pPlayer->getCivilizationInfo();2519				BuildingTypes eBuilding = (BuildingTypes)playerCivilizationInfo.getCivilizationBuildings((BuildingClassTypes)iBuildingClassLoop);2520				if (eBuilding != NO_BUILDING)2521				{2522					CvBuildingEntry *pkBuilding = GC.getBuildingInfo(eBuilding);2523					if (pkBuilding)2524					{2525						if (pLoopCity->GetCityBuildings()->GetNumBuilding(eBuilding) > 0)2526						{2527							int iNumSlots = pkBuilding->GetGreatWorkCount();2528							for (int iI = 0; iI < iNumSlots; iI++)2529							{2530								int iGreatWorkIndex = pLoopCity->GetCityBuildings()->GetBuildingGreatWork((BuildingClassTypes)iBuildingClassLoop, iI);2531								if (iGreatWorkIndex != NO_GREAT_WORK)2532								{2533									bool bDupe = false;2534									PlayerTypes eCreatingPlayer = GC.getGame().GetGameCulture()->GetGreatWorkCreator(iGreatWorkIndex);2535									if (GET_PLAYER(eCreatingPlayer).isMinorCiv())2536									{2537										for (uint ui = 0; ui < aiCityStateArtifact.size(); ui++)2538										{2539											if (aiCityStateArtifact[ui] == eCreatingPlayer)2540											{2541												bDupe = true;2542												break;2543											}2544										}25452546										if (!bDupe)2547										{2548											aiCityStateArtifact.push_back(eCreatingPlayer);2549#if !defined(NO_ACHIEVEMENTS)2550											if (aiCityStateArtifact.size() >= 10)2551											{2552												gDLL->UnlockAchievement(ACHIEVEMENT_XP2_35);2553												break;2554											}2555#endif2556										}2557									}2558								}2559							}2560						}2561					}2562				}2563			}2564		}25652566		// check for having broadcast towers filled2567		PolicyBranchTypes eCurrentBranchType = m_pPlayer->GetPlayerPolicies()->GetLateGamePolicyTree();25682569		if (eCurrentBranchType == (PolicyBranchTypes)GC.getPOLICY_BRANCH_FREEDOM())2570		{2571			int iNumWorksInBroadcastTowers = 0;2572			for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))2573			{2574				for(int iBuildingClassLoop = 0; iBuildingClassLoop < GC.getNumBuildingClassInfos(); iBuildingClassLoop++)2575				{2576					CvCivilizationInfo& playerCivilizationInfo = m_pPlayer->getCivilizationInfo();2577					BuildingTypes eBuilding = (BuildingTypes)playerCivilizationInfo.getCivilizationBuildings((BuildingClassTypes)iBuildingClassLoop);2578					if (eBuilding != NO_BUILDING)2579					{2580						CvBuildingEntry *pkBuilding = GC.getBuildingInfo(eBuilding);2581#if defined(MOD_BUGFIX_BUILDINGCLASS_NOT_BUILDING)2582						if (pkBuilding && iBuildingClassLoop == GC.getInfoTypeForString("BUILDINGCLASS_BROADCAST_TOWER"))2583#else2584						if (pkBuilding && strcmp(pkBuilding->GetType(), "BUILDING_BROADCAST_TOWER") == 0)2585#endif2586						{2587							if (pLoopCity->GetCityBuildings()->GetNumBuilding(eBuilding) > 0)2588							{2589								int iNumSlots = pkBuilding->GetGreatWorkCount();2590								bool bAnySlotEmpty = false;2591								for (int iI = 0; iI < iNumSlots; iI++)2592								{2593									int iGreatWorkIndex = pLoopCity->GetCityBuildings()->GetBuildingGreatWork((BuildingClassTypes)iBuildingClassLoop, iI);2594									if (iGreatWorkIndex == NO_GREAT_WORK)2595									{2596										bAnySlotEmpty = true;2597									}2598								}25992600								if (!bAnySlotEmpty)2601								{2602									iNumWorksInBroadcastTowers++;2603								}2604							}2605						}2606					}2607				}2608			}26092610#if !defined(NO_ACHIEVEMENTS)2611			if (iNumWorksInBroadcastTowers >= 10)2612			{2613				gDLL->UnlockAchievement(ACHIEVEMENT_XP2_38);2614			}2615#endif2616		}2617	}	26182619	LogCultureData();2620}

Calls

Called by