Bazaar developer reference

CvDealAI::DoAddCitiesToUs(CvDeal *, PlayerTypes, bool, int &, int &, int &, int, bool)

Defined in
CvDealAI.cpp, line 2824
Class
CvDealAI
Hook name
CivHooks::CvDealAI_DoAddCitiesToUs

Hooks

static bool BeforeCvDealAI_DoAddCitiesToUs(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, bool bUseEvenValue);static void AfterCvDealAI_DoAddCitiesToUs(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, bool bUseEvenValue);static void ReplaceCvDealAI_DoAddCitiesToUs(void (*original)(CvDealAI*, CvDeal*, PlayerTypes, bool, int&, int&, int&, int, bool), CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_DoAddCitiesToUs>(host, &BeforeCvDealAI_DoAddCitiesToUs);CivRegisterAfter<CivHooks::CvDealAI_DoAddCitiesToUs>(host, &AfterCvDealAI_DoAddCitiesToUs);CivRegisterReplace<CivHooks::CvDealAI_DoAddCitiesToUs>(host, &ReplaceCvDealAI_DoAddCitiesToUs);

Code

2823/// See if adding Cities to our side of the deal helps even out pDeal2824void CvDealAI::DoAddCitiesToUs(CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, bool bUseEvenValue)2825{2826	CvAssert(eThem >= 0);2827	CvAssert(eThem < MAX_MAJOR_CIVS);2828	CvAssertMsg(eThem != GetPlayer()->GetID(), "DEAL_AI: Trying to add Open Borders to Us, but them is us.  Please show Jon");28292830	PlayerTypes eMyPlayer = GetPlayer()->GetID();28312832	// If we're not the one surrendering here, don't bother2833	if(pDeal->GetSurrenderingPlayer() != eMyPlayer)2834		return;28352836	// Don't change things2837	if(bDontChangeMyExistingItems)2838		return;28392840	// We don't owe them anything2841	if(iTotalValue <= 0)2842		return;28432844	CvPlayer* pLosingPlayer = GetPlayer();2845	CvPlayer* pWinningPlayer = &GET_PLAYER(eThem);28462847	// If the player only has 1 City then we can't get any more from him2848	if(pLosingPlayer->getNumCities() == 1)2849		return;28502851	//int iCityValue = 0;28522853	int iCityDistanceFromWinnersCapital = 0;2854	int iWinnerCapitalX = -1, iWinnerCapitalY = -1;28552856	// If winner has no capital then we can't use proximity - it will stay at 02857	CvCity* pWinnerCapital = pWinningPlayer->getCapitalCity();2858	if(pWinnerCapital != NULL)2859	{2860		iWinnerCapitalX = pWinningPlayer->getCapitalCity()->getX();2861		iWinnerCapitalY = pWinningPlayer->getCapitalCity()->getY();2862	}28632864	// Create vector of the losing players' Cities so we can see which are the closest to the winner2865	CvWeightedVector<int> viCityProximities;28662867	// Loop through all of the loser's Cities2868	CvCity* pLoopCity;2869	int iCityLoop;2870	for(pLoopCity = pLosingPlayer->firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = pLosingPlayer->nextCity(&iCityLoop))2871	{2872		// Get total city value of the loser2873		//iCityValue += GetCityValue(pLoopCity->getX(), pLoopCity->getY(), /*bFromMe*/ true, eThem, bUseEvenValue);2874		//iCityValue += GetCityValue(pLoopCity->getX(), pLoopCity->getY(), /*bFromMe*/ true, eThem, /*bUseEvenValue*/ true);28752876		// If winner has no capital, Distance defaults to 02877		if(pWinnerCapital != NULL)2878		{2879			iCityDistanceFromWinnersCapital = plotDistance(iWinnerCapitalX, iWinnerCapitalY, pLoopCity->getX(), pLoopCity->getY());2880		}28812882		// Don't include the capital in the list of Cities the winner can receive2883		if(!pLoopCity->isCapital())2884		{2885			viCityProximities.push_back(pLoopCity->GetID(), iCityDistanceFromWinnersCapital);2886		}2887	}28882889	// Sort the vector based on distance from winner's capital2890	viCityProximities.SortItems();28912892	// Loop through sorted Cities and add them to the deal if they're under the amount to give up - start from the back of the list, because that's where the CLOSEST cities are2893	int iSortedCityID;2894	//			for (int iSortedCityIndex = 0; iSortedCityIndex < viCityProximities.size(); iSortedCityIndex++)2895	for(int iSortedCityIndex = viCityProximities.size() - 1; iSortedCityIndex > -1 ; iSortedCityIndex--)2896	{2897		iSortedCityID = viCityProximities.GetElement(iSortedCityIndex);2898		pLoopCity = pLosingPlayer->getCity(iSortedCityID);28992900		//iCityValue = GetCityValue(pLoopCity->getX(), pLoopCity->getY(), bMeSurrendering, eOtherPlayer, /*bUseEvenValue*/ true);29012902		// See if we can actually trade it to them2903		if(pDeal->IsPossibleToTradeItem(eMyPlayer, eThem, TRADE_ITEM_CITIES, pLoopCity->getX(), pLoopCity->getY()))2904			//if (pDeal->IsPossibleToTradeItem(eMyPlayer, eThem, TRADE_ITEM_OPEN_BORDERS))2905		{2906			int iItemValue = GetCityValue(pLoopCity->getX(), pLoopCity->getY(), /*bFromMe*/ true, eThem, bUseEvenValue);2907			//int iItemValue = GetTradeItemValue(TRADE_ITEM_CITIES, /*bFromMe*/ true, eThem, pLoopCity->getX(), pLoopCity->getY(), iDealDuration, bUseEvenValue);2908			//int iItemValue = GetTradeItemValue(TRADE_ITEM_OPEN_BORDERS, /*bFromMe*/ true, eThem, -1, -1, iDealDuration, bUseEvenValue);29092910			// If adding this to the deal doesn't take it under the min limit, do it2911			if(-iItemValue + iTotalValue >= iAmountUnderWeWillOffer)2912			{2913				//pDeal->AddOpenBorders(eMyPlayer, iDealDuration);2914				pDeal->AddCityTrade(eMyPlayer, iSortedCityID);2915				iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);2916			}2917		}29182919		// City is worth less than what is left to be added to the deal, so add it2920		//if (iCityValue < iCityValueToSurrender)2921		//{2922		//	if (pDeal->IsPossibleToTradeItem(eLosingPlayer, eWinningPlayer, TRADE_ITEM_CITIES, pLoopCity->getX(), pLoopCity->getY()))2923		//	{2924		//		pDeal->AddCityTrade(eLosingPlayer, iSortedCityID);29252926		//		// Remove GPT from this City so we don't give more than we can support2927		//		iGPTToGive -= pLoopCity->getYieldRate(YIELD_GOLD);29282929		//		iCityValueToSurrender -= iCityValue;2930		//	}2931		//}2932	}2933}

Calls

Called by