Bazaar developer reference

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

Defined in
CvDealAI.cpp, line 3072
Class
CvDealAI
Hook name
CivHooks::CvDealAI_DoRemoveGPTFromThem

Hooks

static bool BeforeCvDealAI_DoRemoveGPTFromThem(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iDealDuration, bool bUseEvenValue);static void AfterCvDealAI_DoRemoveGPTFromThem(CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iDealDuration, bool bUseEvenValue);static void ReplaceCvDealAI_DoRemoveGPTFromThem(void (*original)(CvDealAI*, CvDeal*, PlayerTypes, int&, int&, int&, int, bool), CvDealAI* self, CvDeal* pDeal, PlayerTypes eThem, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iDealDuration, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_DoRemoveGPTFromThem>(host, &BeforeCvDealAI_DoRemoveGPTFromThem);CivRegisterAfter<CivHooks::CvDealAI_DoRemoveGPTFromThem>(host, &AfterCvDealAI_DoRemoveGPTFromThem);CivRegisterReplace<CivHooks::CvDealAI_DoRemoveGPTFromThem>(host, &ReplaceCvDealAI_DoRemoveGPTFromThem);

Code

3071/// See if removing Gold Per Turn from their side of the deal helps even out pDeal3072void CvDealAI::DoRemoveGPTFromThem(CvDeal* pDeal, PlayerTypes eThem, int& iTotalValue, int& iValueImOffering, int& iValueTheyreOffering, int iDealDuration, bool bUseEvenValue)3073{3074	CvAssert(eThem >= 0);3075	CvAssert(eThem < MAX_MAJOR_CIVS);3076	CvAssertMsg(eThem != GetPlayer()->GetID(), "DEAL_AI: Trying to remove GPT from Them, but them is us.  Please show Jon");30773078//	if (!bDontChangeTheirExistingItems)3079	{3080		if(iTotalValue > 0)3081		{3082			// Try to remove a bit more than the actual value discrepancy, as this should get us closer to even in the long-run3083			int iValueToRemove = iTotalValue * 150;3084			iValueToRemove /= 100;30853086			int iNumGoldPerTurnToRemove = GetGPTforForValueExchange(iValueToRemove, /*bNumGPTFromValue*/ true, iDealDuration, /*bFromMe*/ false, eThem, bUseEvenValue, /*bRoundUp*/ true);30873088			int iNumGoldPerTurnInThisDeal = pDeal->GetGoldPerTurnTrade(eThem);3089			if(iNumGoldPerTurnInThisDeal > 0)3090			{3091				// Found some GoldPerTurn to remove3092				iNumGoldPerTurnToRemove = min(iNumGoldPerTurnToRemove, iNumGoldPerTurnInThisDeal);3093				iNumGoldPerTurnInThisDeal -= iNumGoldPerTurnToRemove;30943095				// Removing ALL GoldPerTurn, so just erase the item from the deal3096				if(iNumGoldPerTurnInThisDeal == 0)3097				{3098					pDeal->RemoveByType(TRADE_ITEM_GOLD_PER_TURN);3099					iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);3100				}3101				// Remove some of the GoldPerTurn from the deal3102				else3103				{3104					if(!pDeal->ChangeGoldPerTurnTrade(eThem, iNumGoldPerTurnInThisDeal, iDealDuration))3105					{3106						CvAssertMsg(false, "DEAL_AI: DealAI is trying to remove GoldPerTurn from a deal but couldn't find the item for some reason.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");3107					}31083109					iTotalValue = GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, bUseEvenValue);3110				}3111			}3112		}3113	}3114}

Calls

Called by