Bazaar developer reference

CvDealAI::IsOfferPeace(PlayerTypes, CvDeal *, bool)

Defined in
CvDealAI.cpp, line 3244
Class
CvDealAI
Hook name
CivHooks::CvDealAI_IsOfferPeace

Hooks

static bool BeforeCvDealAI_IsOfferPeace(CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal, bool bEqualizingDeals, bool& result);static void AfterCvDealAI_IsOfferPeace(CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal, bool bEqualizingDeals, bool& result);static bool ReplaceCvDealAI_IsOfferPeace(bool (*original)(CvDealAI*, PlayerTypes, CvDeal*, bool), CvDealAI* self, PlayerTypes eOtherPlayer, CvDeal* pDeal, bool bEqualizingDeals);CivRegisterBefore<CivHooks::CvDealAI_IsOfferPeace>(host, &BeforeCvDealAI_IsOfferPeace);CivRegisterAfter<CivHooks::CvDealAI_IsOfferPeace>(host, &AfterCvDealAI_IsOfferPeace);CivRegisterReplace<CivHooks::CvDealAI_IsOfferPeace>(host, &ReplaceCvDealAI_IsOfferPeace);

Code

3243/// Offer peace3244bool CvDealAI::IsOfferPeace(PlayerTypes eOtherPlayer, CvDeal* pDeal, bool bEqualizingDeals)3245{3246	bool result = false;3247	CvAssert(eOtherPlayer >= 0);3248	CvAssert(eOtherPlayer < MAX_MAJOR_CIVS);32493250	// Can we actually complete this deal?32513252	if(!pDeal->IsPossibleToTradeItem(GetPlayer()->GetID(), eOtherPlayer, TRADE_ITEM_PEACE_TREATY))3253	{3254		return false;3255	}3256	if(!pDeal->IsPossibleToTradeItem(eOtherPlayer, GetPlayer()->GetID(), TRADE_ITEM_PEACE_TREATY))3257	{3258		return false;3259	}32603261	PlayerTypes eMyPlayer = GetPlayer()->GetID();32623263	PeaceTreatyTypes ePeaceTreatyImWillingToOffer = GetPlayer()->GetDiplomacyAI()->GetTreatyWillingToOffer(eOtherPlayer);3264	PeaceTreatyTypes ePeaceTreatyImWillingToAccept = GetPlayer()->GetDiplomacyAI()->GetTreatyWillingToAccept(eOtherPlayer);32653266	// Peace between AI players3267	if(!GET_PLAYER(eOtherPlayer).isHuman())3268	{3269		PeaceTreatyTypes ePeaceTreatyTheyreWillingToAccept = GET_PLAYER(eOtherPlayer).GetDiplomacyAI()->GetTreatyWillingToAccept(eMyPlayer);3270		PeaceTreatyTypes ePeaceTreatyTheyreWillingToOffer = GET_PLAYER(eOtherPlayer).GetDiplomacyAI()->GetTreatyWillingToOffer(eMyPlayer);32713272		// Is what we're willing to offer acceptable to eOtherPlayer?3273		if(ePeaceTreatyImWillingToOffer < ePeaceTreatyTheyreWillingToAccept)3274		{3275			return false;3276		}3277		// Is what eOtherPalyer is willing to offer acceptable to us?3278		if(ePeaceTreatyTheyreWillingToOffer < ePeaceTreatyImWillingToAccept)3279		{3280			return false;3281		}32823283		// If we're both willing to give something up (for whatever reason) reduce the surrender level of both parties until White Peace is on one side3284		if(ePeaceTreatyImWillingToOffer > PEACE_TREATY_WHITE_PEACE && ePeaceTreatyTheyreWillingToOffer > PEACE_TREATY_WHITE_PEACE)3285		{3286			int iAmountToReduce = min(ePeaceTreatyImWillingToOffer, ePeaceTreatyTheyreWillingToOffer);32873288			ePeaceTreatyImWillingToOffer = PeaceTreatyTypes(ePeaceTreatyImWillingToOffer - iAmountToReduce);3289			ePeaceTreatyTheyreWillingToOffer = PeaceTreatyTypes(ePeaceTreatyTheyreWillingToOffer - iAmountToReduce);3290		}32913292		// Get the Peace in between if there's a gap3293		if(ePeaceTreatyImWillingToOffer > ePeaceTreatyTheyreWillingToAccept)3294		{3295			ePeaceTreatyImWillingToOffer = PeaceTreatyTypes((ePeaceTreatyImWillingToOffer + ePeaceTreatyTheyreWillingToAccept) / 2);3296		}3297		if(ePeaceTreatyTheyreWillingToOffer > ePeaceTreatyImWillingToAccept)3298		{3299			ePeaceTreatyTheyreWillingToOffer = PeaceTreatyTypes((ePeaceTreatyTheyreWillingToOffer + ePeaceTreatyImWillingToAccept) / 2);3300		}33013302		CvAssertMsg(ePeaceTreatyImWillingToOffer >= PEACE_TREATY_WHITE_PEACE, "DEAL_AI: I'm offering a peace treaty with negative ID.  Please show Jon");3303		CvAssertMsg(ePeaceTreatyTheyreWillingToOffer >= PEACE_TREATY_WHITE_PEACE, "DEAL_AI: They're offering a peace treaty with negative ID.  Please show Jon");33043305		// I'm surrendering in this deal3306		if(ePeaceTreatyImWillingToOffer > ePeaceTreatyTheyreWillingToOffer)3307		{3308			pDeal->SetSurrenderingPlayer(eMyPlayer);3309			pDeal->SetPeaceTreatyType(ePeaceTreatyImWillingToOffer);33103311			DoAddItemsToDealForPeaceTreaty(eOtherPlayer, pDeal, ePeaceTreatyImWillingToOffer, /*bMeSurrendering*/ true);3312		}3313		// They're surrendering in this deal3314		else if(ePeaceTreatyImWillingToOffer < ePeaceTreatyTheyreWillingToOffer)3315		{3316			pDeal->SetSurrenderingPlayer(eOtherPlayer);3317			pDeal->SetPeaceTreatyType(ePeaceTreatyTheyreWillingToOffer);33183319			DoAddItemsToDealForPeaceTreaty(eOtherPlayer, pDeal, ePeaceTreatyTheyreWillingToOffer, /*bMeSurrendering*/ false);3320		}33213322		// Add the peace items to the deal so that we actually stop the war3323		int iPeaceTreatyLength = GC.getGame().getGameSpeedInfo().getPeaceDealDuration();3324		pDeal->AddPeaceTreaty(eMyPlayer, iPeaceTreatyLength);3325		pDeal->AddPeaceTreaty(eOtherPlayer, iPeaceTreatyLength);33263327		result = true;3328	}33293330	// Peace with a human3331	else3332	{3333		// AI is surrendering3334		if(ePeaceTreatyImWillingToOffer > PEACE_TREATY_WHITE_PEACE)3335		{3336			pDeal->SetSurrenderingPlayer(eMyPlayer);3337			pDeal->SetPeaceTreatyType(ePeaceTreatyImWillingToOffer);33383339			DoAddItemsToDealForPeaceTreaty(eOtherPlayer, pDeal, ePeaceTreatyImWillingToOffer, /*bMeSurrendering*/ true);33403341			// Store the value of the deal with the human so that we have a number to use for renegotiation (if necessary)3342			int iValueImOffering, iValueTheyreOffering;3343			GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, /*bUseEvenValue*/ false);3344			if (!bEqualizingDeals)3345			{3346				SetCachedValueOfPeaceWithHuman(-iValueImOffering);3347			}3348		}3349		// AI is asking human to surrender3350		else if(ePeaceTreatyImWillingToAccept > PEACE_TREATY_WHITE_PEACE)3351		{3352			pDeal->SetSurrenderingPlayer(eOtherPlayer);3353			pDeal->SetPeaceTreatyType(ePeaceTreatyImWillingToAccept);33543355			DoAddItemsToDealForPeaceTreaty(eOtherPlayer, pDeal, ePeaceTreatyImWillingToAccept, /*bMeSurrendering*/ false);33563357			// Store the value of the deal with the human so that we have a number to use for renegotiation (if necessary)3358			int iValueImOffering, iValueTheyreOffering;3359			GetDealValue(pDeal, iValueImOffering, iValueTheyreOffering, /*bUseEvenValue*/ false);3360			if (!bEqualizingDeals)3361			{3362				SetCachedValueOfPeaceWithHuman(iValueTheyreOffering);3363			}3364		}3365		else3366		{3367			// if the case is that we both want white peace, don't forget to add the city-states into the peace deal.3368			DoAddPlayersAlliesToTreaty(eOtherPlayer, pDeal);3369		}33703371		int iPeaceTreatyLength = GC.getGame().getGameSpeedInfo().getPeaceDealDuration();3372		pDeal->AddPeaceTreaty(eMyPlayer, iPeaceTreatyLength);3373		pDeal->AddPeaceTreaty(eOtherPlayer, iPeaceTreatyLength);33743375		result = true;3376	}33773378	return result;3379}

Calls

Called by