Bazaar developer reference

CvCityBuildings::SetNumRealBuildingTimed(BuildingTypes, int, bool, PlayerTypes, int)

Defined in
CvBuildingClasses.cpp, line 2678
Class
CvCityBuildings
Hook name
CivHooks::CvCityBuildings_SetNumRealBuildingTimed

Hand-placed hooks inside

A replacement for this function that does not call original stops these hooks from running.

Hooks

static bool BeforeCvCityBuildings_SetNumRealBuildingTimed(CvCityBuildings* self, BuildingTypes eIndex, int iNewValue, bool bFirst, PlayerTypes eOriginalOwner, int iOriginalTime);static void AfterCvCityBuildings_SetNumRealBuildingTimed(CvCityBuildings* self, BuildingTypes eIndex, int iNewValue, bool bFirst, PlayerTypes eOriginalOwner, int iOriginalTime);static void ReplaceCvCityBuildings_SetNumRealBuildingTimed(void (*original)(CvCityBuildings*, BuildingTypes, int, bool, PlayerTypes, int), CvCityBuildings* self, BuildingTypes eIndex, int iNewValue, bool bFirst, PlayerTypes eOriginalOwner, int iOriginalTime);CivRegisterBefore<CivHooks::CvCityBuildings_SetNumRealBuildingTimed>(host, &BeforeCvCityBuildings_SetNumRealBuildingTimed);CivRegisterAfter<CivHooks::CvCityBuildings_SetNumRealBuildingTimed>(host, &AfterCvCityBuildings_SetNumRealBuildingTimed);CivRegisterReplace<CivHooks::CvCityBuildings_SetNumRealBuildingTimed>(host, &ReplaceCvCityBuildings_SetNumRealBuildingTimed);

Code

2677/// Accessor: Set number of these buildings that have been constructed in the city (with date)2678void CvCityBuildings::SetNumRealBuildingTimed(BuildingTypes eIndex, int iNewValue, bool bFirst, PlayerTypes eOriginalOwner, int iOriginalTime)2679{2680	CvPlayer* pPlayer = &GET_PLAYER(m_pCity->getOwner());26812682	CvAssertMsg(eIndex >= 0, "eIndex expected to be >= 0");2683	CvAssertMsg(eIndex < m_pBuildings->GetNumBuildings(), "eIndex expected to be < m_pBuildings->GetNumBuildings()");26842685	int iChangeNumRealBuilding = iNewValue - GetNumRealBuilding(eIndex);26862687	CvBuildingEntry* buildingEntry = GC.getBuildingInfo(eIndex);2688	const BuildingClassTypes buildingClassType = (BuildingClassTypes) buildingEntry->GetBuildingClassType();2689	const CvBuildingClassInfo& kBuildingClassInfo = buildingEntry->GetBuildingClassInfo();26902691	if(iChangeNumRealBuilding != 0)2692	{2693		int iOldNumBuilding = GetNumBuilding(eIndex);26942695		m_paiNumRealBuilding[eIndex] = iNewValue;26962697		if(GetNumRealBuilding(eIndex) > 0)2698		{2699			SetBuildingOriginalOwner(eIndex, eOriginalOwner);2700			SetBuildingOriginalTime(eIndex, iOriginalTime);2701		}2702		else2703		{2704			SetBuildingOriginalOwner(eIndex, NO_PLAYER);2705			SetBuildingOriginalTime(eIndex, MIN_INT);2706		}27072708		// Process building effects2709		if(iOldNumBuilding != GetNumBuilding(eIndex))2710		{2711			m_pCity->processBuilding(eIndex, iChangeNumRealBuilding, bFirst);2712		}27132714		// Maintenance cost2715		if(buildingEntry->GetGoldMaintenance() != 0)2716		{2717			pPlayer->GetTreasury()->ChangeBaseBuildingGoldMaintenance(buildingEntry->GetGoldMaintenance() * iChangeNumRealBuilding);2718		}27192720#if !defined(NO_ACHIEVEMENTS)2721		//Achievement for Temples2722		const char* szBuildingTypeC = buildingEntry->GetType();2723		CvString szBuildingType = szBuildingTypeC;2724		if(szBuildingType == "BUILDING_TEMPLE")2725		{2726			if(m_pCity->getOwner() == GC.getGame().getActivePlayer())2727			{2728				gDLL->IncrementSteamStatAndUnlock(ESTEAMSTAT_TEMPLES, 1000, ACHIEVEMENT_1000TEMPLES);2729			}2730		}2731#endif27322733		if(buildingEntry->GetPreferredDisplayPosition() > 0)2734		{2735			auto_ptr<ICvCity1> pDllCity(new CvDllCity(m_pCity));27362737			if(iNewValue > 0)2738			{2739				// if this is a WW that (likely has a half-built state)2740				if(isWorldWonderClass(kBuildingClassInfo))2741				{2742					if(GetBuildingProduction(eIndex))2743					{2744						GC.GetEngineUserInterface()->AddDeferredWonderCommand(WONDER_EDITED, pDllCity.get(), eIndex, 1);2745					}2746					else2747					{2748						GC.GetEngineUserInterface()->AddDeferredWonderCommand(WONDER_CREATED, pDllCity.get(), eIndex, 1);2749					}2750				}2751				else2752				{2753					GC.GetEngineUserInterface()->AddDeferredWonderCommand(WONDER_CREATED, pDllCity.get(), eIndex, 1);2754				}2755			}2756			else2757			{2758				GC.GetEngineUserInterface()->AddDeferredWonderCommand(WONDER_REMOVED, pDllCity.get(), eIndex, 0);2759			}2760		}27612762		if(!(kBuildingClassInfo.isNoLimit()))2763		{2764			if(isWorldWonderClass(kBuildingClassInfo))2765			{2766				m_pCity->changeNumWorldWonders(iChangeNumRealBuilding);2767				pPlayer->ChangeNumWonders(iChangeNumRealBuilding);2768			}2769			else if(isTeamWonderClass(kBuildingClassInfo))2770			{2771				m_pCity->changeNumTeamWonders(iChangeNumRealBuilding);2772			}2773			else if(isNationalWonderClass(kBuildingClassInfo))2774			{2775				m_pCity->changeNumNationalWonders(iChangeNumRealBuilding);2776				if(m_pCity->isHuman() && !GC.getGame().isGameMultiPlayer())2777				{2778					IncrementWonderStats(buildingClassType);2779				}2780			}2781			else2782			{2783				ChangeNumBuildings(iChangeNumRealBuilding);2784			}2785		}27862787		if(buildingEntry->IsCityWall())2788		{2789			auto_ptr<ICvPlot1> pDllPlot(new CvDllPlot(m_pCity->plot()));2790			gDLL->GameplayWallCreated(pDllPlot.get());2791		}27922793		// Update the amount of a Resource used up by this Building2794		int iNumResources = GC.getNumResourceInfos();2795		for(int iResourceLoop = 0; iResourceLoop < iNumResources; iResourceLoop++)2796		{2797			if(buildingEntry->GetResourceQuantityRequirement(iResourceLoop) > 0)2798			{2799				pPlayer->changeNumResourceUsed((ResourceTypes) iResourceLoop, iChangeNumRealBuilding * buildingEntry->GetResourceQuantityRequirement(iResourceLoop));2800			}2801		}28022803		if(iChangeNumRealBuilding > 0)2804		{2805			if(bFirst)2806			{2807				if(GC.getGame().isFinalInitialized()/* && !(gDLL->GetWorldBuilderMode() )*/)2808				{2809					// World Wonder Notification2810					if(isWorldWonderClass(kBuildingClassInfo))2811					{2812						Localization::String localizedText = Localization::Lookup("TXT_KEY_MISC_COMPLETES_WONDER");2813						localizedText << pPlayer->getNameKey() << buildingEntry->GetTextKey();2814						GC.getGame().addReplayMessage(REPLAY_MESSAGE_MAJOR_EVENT, m_pCity->getOwner(), localizedText.toUTF8(), m_pCity->getX(), m_pCity->getY());28152816						bool bDontShowRewardPopup = GC.GetEngineUserInterface()->IsOptionNoRewardPopups();28172818#if defined(CIV_HOST_API)2819						CivHandPopupRaised(m_pCity->getOwner(), BUTTONPOPUP_WONDER_COMPLETED_ACTIVE_PLAYER, eIndex, -1, -1, false, false, "");hand-placed hook: PopupRaised2820#endif2821						// Notification in MP games2822#if defined(MOD_API_EXTENSIONS)2823						if(bDontShowRewardPopup || GC.getGame().isReallyNetworkMultiPlayer())2824#else2825						if(bDontShowRewardPopup || GC.getGame().isNetworkMultiPlayer())	// KWG: Candidate for !GC.getGame().IsOption(GAMEOPTION_SIMULTANEOUS_TURNS)2826#endif2827						{2828							CvNotifications* pNotifications = GET_PLAYER(m_pCity->getOwner()).GetNotifications();2829							if(pNotifications)2830							{2831								localizedText = Localization::Lookup("TXT_KEY_MISC_WONDER_COMPLETED");2832								localizedText << pPlayer->getNameKey() << buildingEntry->GetTextKey();2833								pNotifications->Add(NOTIFICATION_WONDER_COMPLETED_ACTIVE_PLAYER, localizedText.toUTF8(), localizedText.toUTF8(), m_pCity->getX(), m_pCity->getY(), eIndex, pPlayer->GetID());2834							}2835						}2836						// Popup in SP games2837						else2838						{2839							if(m_pCity->getOwner() == GC.getGame().getActivePlayer())2840							{2841								CvPopupInfo kPopup(BUTTONPOPUP_WONDER_COMPLETED_ACTIVE_PLAYER, eIndex);2842								GC.GetEngineUserInterface()->AddPopup(kPopup);28432844#if !defined(NO_ACHIEVEMENTS)2845								if(GET_PLAYER(GC.getGame().getActivePlayer()).isHuman())2846								{2847									gDLL->UnlockAchievement(ACHIEVEMENT_BUILD_WONDER);28482849									//look to see if all wonders have been built to unlock the other one2850									IncrementWonderStats(buildingClassType);28512852								}2853#endif2854							}2855						}28562857						// Wonder notification for all other players2858						for(int iI = 0; iI < MAX_MAJOR_CIVS; iI++)2859						{2860							CvPlayerAI& thisPlayer = GET_PLAYER((PlayerTypes)iI);2861							if(thisPlayer.isAlive())2862							{2863								// Owner already got his messaging2864								if(iI != m_pCity->getOwner())2865								{2866									// If the builder is met, and the city is revealed2867									// Special case for DLC_06 Scenario: Always show the more informative notification2868									if((m_pCity->plot()->isRevealed(thisPlayer.getTeam()) && GET_TEAM(thisPlayer.getTeam()).isHasMet(m_pCity->getTeam())) || gDLL->IsModActivated(CIV5_DLC_06_SCENARIO_MODID))2869									{2870										CvNotifications* pNotifications = thisPlayer.GetNotifications();2871										if(pNotifications)2872										{2873											localizedText = Localization::Lookup("TXT_KEY_MISC_WONDER_COMPLETED");2874											localizedText << pPlayer->getNameKey() << buildingEntry->GetTextKey();2875											pNotifications->Add(NOTIFICATION_WONDER_COMPLETED, localizedText.toUTF8(), localizedText.toUTF8(), m_pCity->getX(), m_pCity->getY(), eIndex, pPlayer->GetID());2876										}2877									}2878									else2879									{2880										CvNotifications* pNotifications = thisPlayer.GetNotifications();2881										if(pNotifications)2882										{2883											localizedText = Localization::Lookup("TXT_KEY_MISC_WONDER_COMPLETED_UNKNOWN");2884											localizedText <<  buildingEntry->GetTextKey();2885											pNotifications->Add(NOTIFICATION_WONDER_COMPLETED, localizedText.toUTF8(), localizedText.toUTF8(), -1, -1, eIndex, -1);2886										}2887									}2888								}2889							}28902891#if !defined(NO_ACHIEVEMENTS)2892							//Achievements!2893							if(pPlayer->GetID() == GC.getGame().getActivePlayer() && strcmp(buildingEntry->GetType(), "BUILDING_GREAT_FIREWALL") == 0)2894							{2895								gDLL->UnlockAchievement(ACHIEVEMENT_XP1_16);2896							}2897#endif2898						}2899					}2900				}29012902				GC.getGame().incrementBuildingClassCreatedCount(buildingClassType);2903			}2904		}29052906		m_pCity->updateStrengthValue();29072908		// Building might affect City Banner stats2909		auto_ptr<ICvCity1> pCity = GC.WrapCityPointer(m_pCity);2910		GC.GetEngineUserInterface()->SetSpecificCityInfoDirty(pCity.get(), CITY_UPDATE_TYPE_BANNER);29112912#if !defined(NO_ACHIEVEMENTS)2913		//Test for any achievements being unlocked.2914		pPlayer->GetPlayerAchievements().FinishedBuilding(m_pCity, eIndex);2915#endif2916	}2917}

Calls

Called by