Bazaar developer reference

CvGameDeals::DoEndTradedItem(CvTradedItem *, PlayerTypes, bool)

Defined in
CvDealClasses.cpp, line 3238
Class
CvGameDeals
Hook name
CivHooks::CvGameDeals_DoEndTradedItem

Hooks

static bool BeforeCvGameDeals_DoEndTradedItem(CvGameDeals* self, CvTradedItem* pItem, PlayerTypes eToPlayer, bool bCancelled);static void AfterCvGameDeals_DoEndTradedItem(CvGameDeals* self, CvTradedItem* pItem, PlayerTypes eToPlayer, bool bCancelled);static void ReplaceCvGameDeals_DoEndTradedItem(void (*original)(CvGameDeals*, CvTradedItem*, PlayerTypes, bool), CvGameDeals* self, CvTradedItem* pItem, PlayerTypes eToPlayer, bool bCancelled);CivRegisterBefore<CivHooks::CvGameDeals_DoEndTradedItem>(host, &BeforeCvGameDeals_DoEndTradedItem);CivRegisterAfter<CivHooks::CvGameDeals_DoEndTradedItem>(host, &AfterCvGameDeals_DoEndTradedItem);CivRegisterReplace<CivHooks::CvGameDeals_DoEndTradedItem>(host, &ReplaceCvGameDeals_DoEndTradedItem);

Code

3237/// End a TradedItem (if it's an ongoing item)3238void CvGameDeals::DoEndTradedItem(CvTradedItem* pItem, PlayerTypes eToPlayer, bool bCancelled)3239{3240	CvString strBuffer;3241	CvString strSummary;32423243	PlayerTypes eFromPlayer = pItem->m_eFromPlayer;32443245	CvPlayerAI& fromPlayer = GET_PLAYER(eFromPlayer);3246	CvPlayerAI& toPlayer = GET_PLAYER(eToPlayer);32473248	TeamTypes eFromTeam = fromPlayer.getTeam();3249	TeamTypes eToTeam = toPlayer.getTeam();32503251	CvNotifications* pNotifications = NULL;32523253	pItem->m_bToRenewed = false; // if this item is properly ended, then don't have it marked with "to renew"32543255	if(pItem->m_bFromRenewed)3256	{3257		return;3258	}32593260	// Gold Per Turn3261	if(pItem->m_eItemType == TRADE_ITEM_GOLD_PER_TURN)3262	{3263		int iGoldPerTurn = pItem->m_iData1;3264		fromPlayer.GetTreasury()->ChangeGoldPerTurnFromDiplomacy(iGoldPerTurn);3265		toPlayer.GetTreasury()->ChangeGoldPerTurnFromDiplomacy(-iGoldPerTurn);32663267		pNotifications = GET_PLAYER(eFromPlayer).GetNotifications();3268		if(pNotifications)3269		{3270			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_GPT_FROM_US", toPlayer.getNameKey());3271			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_GPT_FROM_US", toPlayer.getNameKey());3272			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_GPT, strBuffer, strSummary, -1, -1, -1);3273		}32743275		pNotifications = toPlayer.GetNotifications();3276		if(pNotifications)3277		{3278			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_GPT_TO_US", fromPlayer.getNameKey());3279			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_GPT_TO_US", fromPlayer.getNameKey());3280			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_GPT, strBuffer, strSummary, -1, -1, -1);3281		}3282	}3283	// Resource3284	else if(pItem->m_eItemType == TRADE_ITEM_RESOURCES)3285	{3286		ResourceTypes eResource = (ResourceTypes) pItem->m_iData1;3287		int iResourceQuantity = pItem->m_iData2;32883289		fromPlayer.changeResourceExport(eResource, -iResourceQuantity);3290		toPlayer.changeResourceImport(eResource, -iResourceQuantity);32913292		CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);3293		const char* szResourceDescription = (pkResourceInfo)? pkResourceInfo->GetDescriptionKey() : "";32943295		pNotifications = fromPlayer.GetNotifications();3296		if(pNotifications)3297		{32983299			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_RESOURCE_FROM_US", toPlayer.getNameKey(), szResourceDescription);3300			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_RESOURCE_FROM_US", toPlayer.getNameKey(), szResourceDescription);3301			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_RESOURCE, strBuffer, strSummary, -1, -1, -1);3302		}33033304		pNotifications = toPlayer.GetNotifications();3305		if(pNotifications)3306		{3307			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_RESOURCE_TO_US", fromPlayer.getNameKey(), szResourceDescription);3308			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_RESOURCE_TO_US", fromPlayer.getNameKey(), szResourceDescription);3309			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_RESOURCE, strBuffer, strSummary, -1, -1, -1);3310		}3311	}3312	// Open Borders3313	else if(pItem->m_eItemType == TRADE_ITEM_OPEN_BORDERS)3314	{3315		GET_TEAM(eFromTeam).SetAllowsOpenBordersToTeam(eToTeam, false);33163317		pNotifications = fromPlayer.GetNotifications();3318		if(pNotifications)3319		{3320			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_OPEN_BORDERS_FROM_US", toPlayer.getNameKey());3321			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_OPEN_BORDERS_FROM_US", toPlayer.getNameKey());3322			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_OPEN_BORDERS, strBuffer, strSummary, -1, -1, -1);3323		}33243325		pNotifications = toPlayer.GetNotifications();3326		if(pNotifications)3327		{3328			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_OPEN_BORDERS_TO_US", fromPlayer.getNameKey());3329			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_OPEN_BORDERS_TO_US", fromPlayer.getNameKey());3330			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_OPEN_BORDERS, strBuffer, strSummary, -1, -1, -1);3331		}3332	}3333	// Defensive Pact3334	else if(pItem->m_eItemType == TRADE_ITEM_DEFENSIVE_PACT)3335	{3336		GET_TEAM(eFromTeam).SetHasDefensivePact(eToTeam, false);33373338		pNotifications = fromPlayer.GetNotifications();3339		if(pNotifications)3340		{3341			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_DEFENSIVE_PACT_FROM_US", toPlayer.getNameKey());3342			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_DEFENSIVE_PACT_FROM_US", toPlayer.getNameKey());3343			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_DEFENSIVE_PACT, strBuffer, strSummary, -1, -1, -1);3344		}33453346		pNotifications = toPlayer.GetNotifications();3347		if(pNotifications)3348		{3349			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_DEFENSIVE_PACT_TO_US", fromPlayer.getNameKey());3350			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_DEFENSIVE_PACT_TO_US", fromPlayer.getNameKey());3351			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_DEFENSIVE_PACT, strBuffer, strSummary, -1, -1, -1);3352		}3353	}3354	// Research Agreement3355	else if(pItem->m_eItemType == TRADE_ITEM_RESEARCH_AGREEMENT)3356	{3357		GET_TEAM(eFromTeam).SetHasResearchAgreement(eToTeam, false);33583359		if(!GET_TEAM(eFromTeam).isAtWar(eToTeam) && !bCancelled)3360		{3361			// Beaker boost = ((sum of both players' beakers over term of RA) / 2) / 3) * (median tech percentage rate)3362			CvTeam& kTeam = GET_TEAM(toPlayer.getTeam());3363			int iToPlayerBeakers = toPlayer.GetResearchAgreementCounter(eFromPlayer);3364			int iFromPlayerBeakers = fromPlayer.GetResearchAgreementCounter(eToPlayer);3365			int iBeakersBonus = min(iToPlayerBeakers, iFromPlayerBeakers) / GC.getRESEARCH_AGREEMENT_BOOST_DIVISOR(); //one (third) of minimum contribution3366			iBeakersBonus = (iBeakersBonus * toPlayer.GetMedianTechPercentage()) / 100;33673368			TechTypes eCurrentTech = toPlayer.GetPlayerTechs()->GetCurrentResearch();3369			if(eCurrentTech == NO_TECH)3370			{3371				toPlayer.changeOverflowResearch(iBeakersBonus);3372			}3373			else3374			{3375				kTeam.GetTeamTechs()->ChangeResearchProgress(eCurrentTech, iBeakersBonus, eToPlayer);3376			}33773378			pNotifications = toPlayer.GetNotifications();3379			if(pNotifications)3380			{3381				strBuffer = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH", fromPlayer.getNameKey());3382				strSummary = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH_S", fromPlayer.getNameKey());3383				pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_RESEARCH_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3384			}3385		}3386		else3387		{3388			pNotifications = toPlayer.GetNotifications();3389			if(pNotifications)3390			{3391				if(GET_TEAM(eFromTeam).isAtWar(eToTeam))3392				{3393					strBuffer = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH_WAR_CANCEL", fromPlayer.getNameKey());3394					strSummary = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH_WAR_CANCEL_S");3395				}3396				else3397				{3398					strBuffer = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH_CANCEL", fromPlayer.getNameKey());3399					strSummary = GetLocalizedText("TXT_KEY_NTFN_RA_FREE_TECH_CANCEL_S");3400				}34013402				pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_RESEARCH_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3403			}3404		}3405	}3406	// Trade Agreement3407	else if(pItem->m_eItemType == TRADE_ITEM_TRADE_AGREEMENT)3408	{3409		GET_TEAM(eFromTeam).SetHasTradeAgreement(eToTeam, false);34103411		pNotifications = fromPlayer.GetNotifications();3412		if(pNotifications)3413		{3414			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT_FROM_US", toPlayer.getNameKey());3415			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_TRADE_AGREEMENT_FROM_US", toPlayer.getNameKey());3416			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3417		}34183419		pNotifications = toPlayer.GetNotifications();3420		if(pNotifications)3421		{3422			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT_TO_US", fromPlayer.getNameKey());3423			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_TRADE_AGREEMENT_TO_US", fromPlayer.getNameKey());3424			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3425		}3426	}3427	// Peace Treaty3428	else if(pItem->m_eItemType == TRADE_ITEM_PEACE_TREATY)3429	{3430		GET_TEAM(eFromTeam).setForcePeace(eToTeam, false);34313432		pNotifications = toPlayer.GetNotifications();3433		if(pNotifications)3434		{3435			strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_PEACE", fromPlayer.getNameKey());3436			strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_PEACE");3437			pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3438		}3439	}3440	// Third Party Peace Treaty3441	else if(pItem->m_eItemType == TRADE_ITEM_THIRD_PARTY_PEACE)3442	{3443		TeamTypes eTargetTeam = (TeamTypes) pItem->m_iData1;3444		GET_TEAM(eFromTeam).setForcePeace(eTargetTeam, false);3445		GET_TEAM(eTargetTeam).setForcePeace(eFromTeam, false);34463447		CvPlayer* targetPlayer = &GET_PLAYER(GET_TEAM(eTargetTeam).getLeaderID());34483449		if (targetPlayer->isAlive())3450		{3451			// Notification for FROM player3452			pNotifications = fromPlayer.GetNotifications();3453			if(pNotifications)3454			{3455				strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_PEACE", targetPlayer->getNameKey());3456				strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_PEACE");3457				pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3458			}34593460			// Notification for TARGET player3461			pNotifications = targetPlayer->GetNotifications();3462			if(pNotifications)3463			{3464				strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_DEAL_EXPIRED_PEACE", fromPlayer.getNameKey());3465				strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_DEAL_EXPIRED_PEACE");3466				pNotifications->Add(NOTIFICATION_DEAL_EXPIRED_TRADE_AGREEMENT, strBuffer, strSummary, -1, -1, -1);3467			}3468		}3469	}3470	// Vote Commitment3471	else if(pItem->m_eItemType == TRADE_ITEM_VOTE_COMMITMENT)3472	{3473		fromPlayer.GetLeagueAI()->CancelVoteCommitmentsToPlayer(eToPlayer);3474		toPlayer.GetLeagueAI()->CancelVoteCommitmentsToPlayer(eFromPlayer);3475	}3476}

Calls

Called by