Bazaar developer reference

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

Defined in
CvDealAI.cpp, line 2502
Class
CvDealAI
Hook name
CivHooks::CvDealAI_DoAddResourceToThem

Hooks

static bool BeforeCvDealAI_DoAddResourceToThem(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeTheirExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountOverWeWillRequest, int iDealDuration, bool bUseEvenValue);static void AfterCvDealAI_DoAddResourceToThem(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeTheirExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountOverWeWillRequest, int iDealDuration, bool bUseEvenValue);static void ReplaceCvDealAI_DoAddResourceToThem(void (*original)(CvDealAI*, CvDeal*, PlayerTypes, bool, int&, int&, int&, int, int, bool), CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeTheirExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountOverWeWillRequest, int iDealDuration, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_DoAddResourceToThem>(host, &BeforeCvDealAI_DoAddResourceToThem);CivRegisterAfter<CivHooks::CvDealAI_DoAddResourceToThem>(host, &AfterCvDealAI_DoAddResourceToThem);CivRegisterReplace<CivHooks::CvDealAI_DoAddResourceToThem>(host, &ReplaceCvDealAI_DoAddResourceToThem);

Code

2501/// See if adding a Resource to their side of the deal helps even out pDeal2502void CvDealAI::DoAddResourceToThem(CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeTheirExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountOverWeWillRequest, int iDealDuration, bool bUseEvenValue)2503{2504	CvAssert(eThem >= 0);2505	CvAssert(eThem < MAX_MAJOR_CIVS);2506	CvAssertMsg(eThem != GetPlayer()->GetID(), "DEAL_AI: Trying to add Resource to Them, but them is us.  Please show Jon");25072508	if(!bDontChangeTheirExistingItems)2509	{2510		if(iTotalValue < 0)2511		{2512			PlayerTypes eMyPlayer = GetPlayer()->GetID();25132514			int iItemValue;25152516			int iResourceLoop;2517			ResourceTypes eResource;2518			int iResourceQuantity;25192520			// Look to trade Luxuries first2521			for(iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++)2522			{2523				eResource = (ResourceTypes) iResourceLoop;25242525				const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);2526				if(pkResourceInfo == NULL || pkResourceInfo->getResourceUsage() != RESOURCEUSAGE_LUXURY)2527					continue;25282529				iResourceQuantity = GET_PLAYER(eThem).getNumResourceAvailable(eResource, false);25302531				// Don't bother looking at this Resource if the other player doesn't even have any of it2532				if(iResourceQuantity <= 0)2533					continue;25342535				// Don't bother if we wouldn't get Happiness from it due to World Congress2536				if(GC.getGame().GetGameLeagues()->IsLuxuryHappinessBanned(eMyPlayer, eResource))2537					continue;25382539				// Quantity is always 1 if it's a Luxury, 5 if Strategic2540				iResourceQuantity = 1;25412542				// See if they can actually trade it to us2543				if(pDeal->IsPossibleToTradeItem(eThem, eMyPlayer, TRADE_ITEM_RESOURCES, eResource, iResourceQuantity))2544				{2545					iItemValue = GetTradeItemValue(TRADE_ITEM_RESOURCES, /*bFromMe*/ false, eThem, eResource, iResourceQuantity, -1, /*bFlag1*/false, iDealDuration, bUseEvenValue);25462547					// If adding this to the deal doesn't take it over the limit, do it2548#if defined(MOD_AI_NO_ZERO_VALUE_TRADE_ITEMS)2549					if((iItemValue > 0) && (iItemValue + iTotalValue <= iAmountOverWeWillRequest))2550#else2551					if(iItemValue + iTotalValue <= iAmountOverWeWillRequest)2552#endif2553					{2554						// Try to change the current item if it already exists, otherwise add it2555						if(!pDeal->ChangeResourceTrade(eThem, eResource, iResourceQuantity, iDealDuration))2556						{2557							pDeal->AddResourceTrade(eThem, eResource, iResourceQuantity, iDealDuration);2558							iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);2559						}2560					}2561				}2562			}25632564			// Now look at Strategic Resources2565			for(iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++)2566			{2567				eResource = (ResourceTypes) iResourceLoop;25682569				const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);2570				if(pkResourceInfo == NULL || pkResourceInfo->getResourceUsage() == RESOURCEUSAGE_LUXURY)2571					continue;25722573				iResourceQuantity = GET_PLAYER(eThem).getNumResourceAvailable(eResource, false);25742575				// Don't bother looking at this Resource if the other player doesn't even have any of it2576				if(iResourceQuantity <= 0)2577					continue;25782579				// Quantity is always 1 if it's a Luxury, 5 if Strategic2580				iResourceQuantity = min(5, iResourceQuantity);	// 5 or what they have, whichever is less25812582				// See if they can actually trade it to us2583				if(pDeal->IsPossibleToTradeItem(eThem, eMyPlayer, TRADE_ITEM_RESOURCES, eResource, iResourceQuantity))2584				{2585					iItemValue = GetTradeItemValue(TRADE_ITEM_RESOURCES, /*bFromMe*/ false, eThem, eResource, iResourceQuantity, -1, /*bFlag1*/false, iDealDuration, bUseEvenValue);25862587					// If adding this to the deal doesn't take it over the limit, do it2588#if defined(MOD_AI_NO_ZERO_VALUE_TRADE_ITEMS)2589					if((iItemValue > 0) && (iItemValue + iTotalValue <= iAmountOverWeWillRequest))2590#else2591					if(iItemValue + iTotalValue <= iAmountOverWeWillRequest)2592#endif2593					{2594						// Try to change the current item if it already exists, otherwise add it2595						if(!pDeal->ChangeResourceTrade(eThem, eResource, iResourceQuantity, iDealDuration))2596						{2597							pDeal->AddResourceTrade(eThem, eResource, iResourceQuantity, iDealDuration);2598							iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);2599						}2600					}2601				}2602			}2603		}2604	}2605}

Calls

Called by