Hooks
static bool BeforeCvCityBuildings_SetNumFreeBuilding(CvCityBuildings* self, BuildingTypes eIndex, int iNewValue);static void AfterCvCityBuildings_SetNumFreeBuilding(CvCityBuildings* self, BuildingTypes eIndex, int iNewValue);static void ReplaceCvCityBuildings_SetNumFreeBuilding(void (*original)(CvCityBuildings*, BuildingTypes, int), CvCityBuildings* self, BuildingTypes eIndex, int iNewValue);CivRegisterBefore<CivHooks::CvCityBuildings_SetNumFreeBuilding>(host, &BeforeCvCityBuildings_SetNumFreeBuilding);CivRegisterAfter<CivHooks::CvCityBuildings_SetNumFreeBuilding>(host, &AfterCvCityBuildings_SetNumFreeBuilding);CivRegisterReplace<CivHooks::CvCityBuildings_SetNumFreeBuilding>(host, &ReplaceCvCityBuildings_SetNumFreeBuilding);
Code
2927/// Accessor: Set number of free buildings of this type in city2928void CvCityBuildings::SetNumFreeBuilding(BuildingTypes eIndex, int iNewValue)2929{2930 CvAssertMsg(eIndex >= 0, "eIndex expected to be >= 0");2931 CvAssertMsg(eIndex < m_pBuildings->GetNumBuildings(), "eIndex expected to be < m_pBuildings->GetNumBuildings()");29322933 if(GetNumFreeBuilding(eIndex) != iNewValue)2934 {2935#if defined(MOD_BUGFIX_MINOR)2936 // This condensed logic comes from SetNumRealBuilding()2937 int iChangeNumFreeBuilding = iNewValue - GetNumFreeBuilding(eIndex);2938 2939 m_paiNumFreeBuilding[eIndex] = iNewValue;29402941 // Process building effects2942 m_pCity->processBuilding(eIndex, iChangeNumFreeBuilding, true);2943#else2944 int iOldNumBuilding = GetNumBuilding(eIndex);29452946 if (iOldNumBuilding > 0 && iNewValue > 0)2947 {2948 DoSellBuilding(eIndex);2949 m_paiNumFreeBuilding[eIndex] = iNewValue;2950 m_pCity->processBuilding(eIndex, iNewValue, true); 2951 }2952 2953 else2954 {2955 m_paiNumFreeBuilding[eIndex] = iNewValue;29562957 if (iOldNumBuilding != GetNumBuilding(eIndex))2958 {2959 m_pCity->processBuilding(eIndex, iNewValue - iOldNumBuilding, true);2960 }2961 }2962#endif29632964#if defined(MOD_BUGFIX_MINOR)2965 CvBuildingEntry* buildingEntry = GC.getBuildingInfo(eIndex);2966 if(buildingEntry->IsCityWall())2967 {2968 auto_ptr<ICvPlot1> pDllPlot(new CvDllPlot(m_pCity->plot()));2969 gDLL->GameplayWallCreated(pDllPlot.get());2970 }29712972 m_pCity->updateStrengthValue();29732974 // Building might affect City Banner stats2975 auto_ptr<ICvCity1> pCity = GC.WrapCityPointer(m_pCity);2976 GC.GetEngineUserInterface()->SetSpecificCityInfoDirty(pCity.get(), CITY_UPDATE_TYPE_BANNER);2977#endif2978 }2979}