Bazaar developer reference

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

Defined in
CvDealAI.cpp, line 2608
Class
CvDealAI
Hook name
CivHooks::CvDealAI_DoAddResourceToUs

Hooks

static bool BeforeCvDealAI_DoAddResourceToUs(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, int iDealDuration, bool bUseEvenValue);static void AfterCvDealAI_DoAddResourceToUs(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, int iDealDuration, bool bUseEvenValue);static void ReplaceCvDealAI_DoAddResourceToUs(void (*original)(CvDealAI*, CvDeal*, PlayerTypes, bool, int&, int&, int&, int, int, bool), CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, int iDealDuration, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_DoAddResourceToUs>(host, &BeforeCvDealAI_DoAddResourceToUs);CivRegisterAfter<CivHooks::CvDealAI_DoAddResourceToUs>(host, &AfterCvDealAI_DoAddResourceToUs);CivRegisterReplace<CivHooks::CvDealAI_DoAddResourceToUs>(host, &ReplaceCvDealAI_DoAddResourceToUs);

Code

2607/// See if adding a Resource to our side of the deal helps even out pDeal2608void CvDealAI::DoAddResourceToUs(CvDeal* pDeal, PlayerTypes eThem, bool bDontChangeMyExistingItems, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iAmountUnderWeWillOffer, int iDealDuration, bool bUseEvenValue)2609{2610	CvAssert(eThem >= 0);2611	CvAssert(eThem < MAX_MAJOR_CIVS);2612	CvAssertMsg(eThem != GetPlayer()->GetID(), "DEAL_AI: Trying to add Resource to Us, but them is us.  Please show Jon");26132614	if(!bDontChangeMyExistingItems)2615	{2616		if(iTotalValue > 0)2617		{2618			PlayerTypes eMyPlayer = GetPlayer()->GetID();26192620			int iItemValue;26212622			ResourceTypes eResource;2623			int iResourceQuantity;2624			for(int iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++)2625			{2626				eResource = (ResourceTypes) iResourceLoop;2627				iResourceQuantity = GET_PLAYER(eMyPlayer).getNumResourceAvailable(eResource, false);26282629				// Don't bother looking at this Resource if we don't even have any of it2630				if(iResourceQuantity == 0)2631				{2632					continue;2633				}26342635				const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);2636				if (pkResourceInfo == NULL)2637					continue;26382639				// Quantity is always 1 if it's a Luxury, 5 if Strategic2640				if(pkResourceInfo->getResourceUsage() == RESOURCEUSAGE_LUXURY)2641				{2642					iResourceQuantity = 1;26432644					// Don't bother if they wouldn't get Happiness from it due to World Congress2645					if(GC.getGame().GetGameLeagues()->IsLuxuryHappinessBanned(eThem, eResource))2646						continue;2647				}2648				else2649				{2650					iResourceQuantity = min(5, iResourceQuantity);	// 5 or what we have, whichever is less2651				}26522653				// See if we can actually trade it to them2654				if(pDeal->IsPossibleToTradeItem(eMyPlayer, eThem, TRADE_ITEM_RESOURCES, eResource, iResourceQuantity))2655				{2656					iItemValue = GetTradeItemValue(TRADE_ITEM_RESOURCES, /*bFromMe*/ true, eThem, eResource, iResourceQuantity, -1, /*bFlag1*/false, iDealDuration, bUseEvenValue);26572658					// If adding this to the deal doesn't take it under the min limit, do it2659#if defined(MOD_AI_NO_ZERO_VALUE_TRADE_ITEMS)2660					if((iItemValue > 0) && (-iItemValue + iTotalValue >= iAmountUnderWeWillOffer))2661#else2662					if(-iItemValue + iTotalValue >= iAmountUnderWeWillOffer)2663#endif2664					{2665						// Try to change the current item if it already exists, otherwise add it2666						if(!pDeal->ChangeResourceTrade(eMyPlayer, eResource, iResourceQuantity, iDealDuration))2667						{2668							pDeal->AddResourceTrade(eMyPlayer, eResource, iResourceQuantity, iDealDuration);2669							iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);2670						}2671					}2672				}2673			}2674		}2675	}2676}

Calls

Called by