Bazaar developer reference

CvEconomicAI::DoPlotPurchases()

Defined in
CvEconomicAI.cpp, line 1971
Class
CvEconomicAI
Hook name
CivHooks::CvEconomicAI_DoPlotPurchases

Hooks

static bool BeforeCvEconomicAI_DoPlotPurchases(CvEconomicAI* self);static void AfterCvEconomicAI_DoPlotPurchases(CvEconomicAI* self);static void ReplaceCvEconomicAI_DoPlotPurchases(void (*original)(CvEconomicAI*), CvEconomicAI* self);CivRegisterBefore<CivHooks::CvEconomicAI_DoPlotPurchases>(host, &BeforeCvEconomicAI_DoPlotPurchases);CivRegisterAfter<CivHooks::CvEconomicAI_DoPlotPurchases>(host, &AfterCvEconomicAI_DoPlotPurchases);CivRegisterReplace<CivHooks::CvEconomicAI_DoPlotPurchases>(host, &ReplaceCvEconomicAI_DoPlotPurchases);

Code

1970/// Spend money buying plots1971void CvEconomicAI::DoPlotPurchases()1972{1973	CvCity* pLoopCity = 0;1974	CvCity* pBestCity = NULL;1975	int iBestX = -1;1976	int iBestY = -1;1977	int iTempX = 0, iTempY = 0;19781979	int iScore = 0;1980	int iLoop = 0;19811982	// No plot buying for minors1983	if(m_pPlayer->isMinorCiv())1984	{1985		return;1986	}19871988	// No plot buying when at war1989	MilitaryAIStrategyTypes eStrategyAtWar = (MilitaryAIStrategyTypes) GC.getInfoTypeForString("MILITARYAISTRATEGY_AT_WAR");1990	if(eStrategyAtWar != NO_MILITARYAISTRATEGY)1991	{1992		if(m_pPlayer->GetMilitaryAI()->IsUsingStrategy(eStrategyAtWar))1993		{1994			return;1995		}1996	}19971998	// Set up the parameters1999	int iBestScore = /*150*/ GC.getAI_GOLD_PRIORITY_MINIMUM_PLOT_BUY_VALUE();2000	int iCurrentCost = m_pPlayer->GetBuyPlotCost();2001	int iGoldForHalfCost = /*1000*/ GC.getAI_GOLD_BALANCE_TO_HALVE_PLOT_BUY_MINIMUM();2002	int iBalance = m_pPlayer->GetTreasury()->GetGold();20032004	// Let's always invest any money we have in plot purchases2005	//  (LATER -- save up money to spend at newly settled cities)2006	if(iCurrentCost < iBalance && iGoldForHalfCost > iCurrentCost)2007	{2008		// Lower our requirements if we're building up a sizable treasury2009		int iDiscountPercent = 50 * (iBalance - iCurrentCost) / (iGoldForHalfCost - iCurrentCost);2010		iBestScore = iBestScore - (iBestScore * iDiscountPercent / 100);20112012		// Find the best city to buy a plot2013		for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))2014		{2015			if(pLoopCity->CanBuyAnyPlot())2016			{2017				iScore = pLoopCity->GetBuyPlotScore(iTempX, iTempY);20182019				if(iScore > iBestScore)2020				{2021					pBestCity = pLoopCity;2022					iBestScore = iScore;2023					iBestX = iTempX;2024					iBestY = iTempY;2025				}2026			}2027		}20282029		if(pBestCity != NULL)2030		{2031			if(iBestX != -1 && iBestY != -1)2032			{2033				int iCost = pBestCity->GetBuyPlotCost(iBestX, iBestY);20342035				if(CanWithdrawMoneyForPurchase(PURCHASE_TYPE_TILE, iCost, iBestScore))2036				{2037					if(GC.getLogging() && GC.getAILogging())2038					{2039						CvString strLogString;2040						strLogString.Format("Buying plot, X: %d, Y: %d, Cost: %d, Balance (before buy): %d, Priority: %d", iBestX, iBestY,2041						                    iCost, m_pPlayer->GetTreasury()->GetGold(), iBestScore);2042						m_pPlayer->GetHomelandAI()->LogHomelandMessage(strLogString);2043					}2044					pBestCity->BuyPlot(iBestX, iBestY);2045				}2046			}2047		}2048	}2049}

Calls

Called by