Bazaar developer reference

CvDealAI::IsMakeOfferForLuxuryResource(PlayerTypes, CvDeal *)

Defined in
CvDealAI.cpp, line 3748
Class
CvDealAI
Hook name
CivHooks::CvDealAI_IsMakeOfferForLuxuryResource

Hooks

static bool BeforeCvDealAI_IsMakeOfferForLuxuryResource(CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal, bool& result);static void AfterCvDealAI_IsMakeOfferForLuxuryResource(CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal, bool& result);static bool ReplaceCvDealAI_IsMakeOfferForLuxuryResource(bool (*original)(CvDealAI*, PlayerTypes, CvDeal*), CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal);CivRegisterBefore<CivHooks::CvDealAI_IsMakeOfferForLuxuryResource>(host, &BeforeCvDealAI_IsMakeOfferForLuxuryResource);CivRegisterAfter<CivHooks::CvDealAI_IsMakeOfferForLuxuryResource>(host, &AfterCvDealAI_IsMakeOfferForLuxuryResource);CivRegisterReplace<CivHooks::CvDealAI_IsMakeOfferForLuxuryResource>(host, &ReplaceCvDealAI_IsMakeOfferForLuxuryResource);

Code

3747/// A good time to make an offer for someone's extra Luxury?3748bool CvDealAI::IsMakeOfferForLuxuryResource(PlayerTypes eOtherPlayer, CvDeal* pDeal)3749{3750	CvAssert(eOtherPlayer >= 0);3751	CvAssert(eOtherPlayer < MAX_MAJOR_CIVS);37523753	ResourceTypes eLuxuryFromThem = NO_RESOURCE;37543755	// Don't ask for a Luxury if we're hostile or planning a war3756	MajorCivApproachTypes eApproach = GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ false);3757	if(eApproach == MAJOR_CIV_APPROACH_HOSTILE ||3758	        eApproach == MAJOR_CIV_APPROACH_WAR)3759	{3760		return false;3761	}37623763	int iResourceLoop;3764	ResourceTypes eResource;37653766	// See if the other player has a Resource to trade3767	for(iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++)3768	{3769		eResource = (ResourceTypes) iResourceLoop;37703771		// Only look at Luxuries3772		const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);3773		if(pkResourceInfo == NULL || pkResourceInfo->getResourceUsage() != RESOURCEUSAGE_LUXURY)3774		{3775			continue;3776		}37773778		// Must not be banned by World Congress3779		if (GC.getGame().GetGameLeagues()->IsLuxuryHappinessBanned(GetPlayer()->GetID(), eResource))3780		{3781			continue;3782		}37833784		// Any extras?3785		if(GET_PLAYER(eOtherPlayer).getNumResourceAvailable(eResource, false) > 1)3786		{3787			eLuxuryFromThem = eResource;3788			break;3789		}3790	}37913792	// Extra Luxury found!3793	if(eLuxuryFromThem != NO_RESOURCE)3794	{3795		// Can we actually complete this deal?3796		if(!pDeal->IsPossibleToTradeItem(eOtherPlayer, GetPlayer()->GetID(), TRADE_ITEM_RESOURCES, eLuxuryFromThem, 1))3797		{3798			return false;3799		}38003801		// Seed the deal with the item we want3802		pDeal->AddResourceTrade(eOtherPlayer, eLuxuryFromThem, 1, GC.getGame().GetDealDuration());38033804		bool bDealAcceptable = false;38053806		// AI evaluation3807		if(!GET_PLAYER(eOtherPlayer).isHuman())3808		{3809			bDealAcceptable = DoEqualizeDealWithAI(pDeal, eOtherPlayer);	// Change the deal as necessary to make it work3810		}3811		else3812		{3813			bool bUselessReferenceVariable;3814			bool bCantMatchOffer;3815			bDealAcceptable = DoEqualizeDealWithHuman(pDeal, eOtherPlayer, /*bDontChangeMyExistingItems*/ false, /*bDontChangeTheirExistingItems*/ true, bUselessReferenceVariable, bCantMatchOffer);	// Change the deal as necessary to make it work3816		}38173818		return bDealAcceptable;3819	}38203821	return false;3822}

Calls

Called by