Bazaar developer reference

CvPlayer::getProductionNeeded(BuildingTypes) const

Defined in
CvPlayer.cpp, line 8648
Class
CvPlayer
Hook name
CivHooks::CvPlayer_getProductionNeeded_with_BuildingTypes_const

Hooks

static bool BeforeCvPlayer_getProductionNeeded_with_BuildingTypes_const(const CvPlayer* self, BuildingTypes eBuilding, int& result);static void AfterCvPlayer_getProductionNeeded_with_BuildingTypes_const(const CvPlayer* self, BuildingTypes eBuilding, int& result);static int ReplaceCvPlayer_getProductionNeeded_with_BuildingTypes_const(int (*original)(const CvPlayer*, BuildingTypes), const CvPlayer* self, BuildingTypes eBuilding);CivRegisterBefore<CivHooks::CvPlayer_getProductionNeeded_with_BuildingTypes_const>(host, &BeforeCvPlayer_getProductionNeeded_with_BuildingTypes_const);CivRegisterAfter<CivHooks::CvPlayer_getProductionNeeded_with_BuildingTypes_const>(host, &AfterCvPlayer_getProductionNeeded_with_BuildingTypes_const);CivRegisterReplace<CivHooks::CvPlayer_getProductionNeeded_with_BuildingTypes_const>(host, &ReplaceCvPlayer_getProductionNeeded_with_BuildingTypes_const);

Code

8648int CvPlayer::getProductionNeeded(BuildingTypes eBuilding) const8649{8650	int iProductionNeeded;86518652	CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);8653	if(pkBuildingInfo == NULL)8654	{8655		//This should never happen.8656		return 1;8657	}86588659	iProductionNeeded = pkBuildingInfo->GetProductionCost();86608661	if(pkBuildingInfo->GetNumCityCostMod() > 0 && getNumCities() > 0)8662	{8663		iProductionNeeded += (pkBuildingInfo->GetNumCityCostMod() * getNumCities());8664	}86658666	if(isMinorCiv())8667	{8668		iProductionNeeded *= GC.getMINOR_CIV_PRODUCTION_PERCENT();8669		iProductionNeeded /= 100;8670	}86718672	iProductionNeeded *= GC.getBUILDING_PRODUCTION_PERCENT();8673	iProductionNeeded /= 100;86748675	iProductionNeeded *= GC.getGame().getGameSpeedInfo().getConstructPercent();8676	iProductionNeeded /= 100;86778678	iProductionNeeded *= GC.getGame().getStartEraInfo().getConstructPercent();8679	iProductionNeeded /= 100;86808681	if(pkBuildingInfo->GetPrereqAndTech() != NO_TECH)8682	{8683		CvTechEntry* pkTechInfo = GC.getTechInfo((TechTypes)pkBuildingInfo->GetPrereqAndTech());8684		if(pkTechInfo)8685		{8686			// Loop through all eras and apply Building production mod based on how much time has passed8687			int iTotalEraMod = 100;8688			EraTypes eBuildingUnlockedEra = (EraTypes) pkTechInfo->GetEra();86898690			if(eBuildingUnlockedEra < GetCurrentEra())8691			{8692				for(int iLoop = eBuildingUnlockedEra; iLoop < GetCurrentEra(); iLoop++)8693				{8694					CvAssertMsg(iLoop >= 0, "Loop should be within era bounds");8695					CvAssertMsg(iLoop <GC.getNumEraInfos(), "Loop should be within era bounds");86968697					if(iLoop >= 0 && iLoop < GC.getNumEraInfos())8698					{8699						CvEraInfo* pkEraInfo = GC.getEraInfo((EraTypes)iLoop);8700						if(pkEraInfo)8701						{8702							iTotalEraMod += pkEraInfo->getLaterEraBuildingConstructMod();8703						}8704					}8705				}87068707				// Don't make a change if there's no change to make8708				if(iTotalEraMod != 100)8709				{8710					iProductionNeeded *= iTotalEraMod;8711					iProductionNeeded /= 100;8712				}8713			}8714		}8715	}87168717	if(!isHuman() && !IsAITeammateOfHuman() && !isBarbarian())8718	{8719		if(isWorldWonderClass(pkBuildingInfo->GetBuildingClassInfo()))8720		{8721			iProductionNeeded *= GC.getGame().getHandicapInfo().getAIWorldConstructPercent();8722			iProductionNeeded /= 100;8723		}8724		else8725		{8726			iProductionNeeded *= GC.getGame().getHandicapInfo().getAIConstructPercent();8727			iProductionNeeded /= 100;8728		}87298730		iProductionNeeded *= std::max(0, ((GC.getGame().getHandicapInfo().getAIPerEraModifier() * GetCurrentEra()) + 100));8731		iProductionNeeded /= 100;8732	}87338734	return std::max(1, iProductionNeeded);8735}

Calls

Called by