Triggering a UA when a deal is refused

S3rgeus

Emperor
Joined
Apr 10, 2011
Messages
1,270
Location
London, United Kingdom
I'm attempting to make the following part of a UA:

This civilization declares war on any civilization that refuses a trade proposal from it.

There's gonna be a DLL as a part of my mod, so I've been trying to work it out in there. But I cannot, to save my life, find where deals are 'refused'. My initial thoughts had me put my code just after "end hack" comment in the CvDealClasses.cpp file (line 2043):

Code:
		// If the deal was refused, and the player being refused's trait causes war then, we've gotta start a war!
		if (bValid && !bAccepted)
		{
			CvPlayer& kPlayer = GET_PLAYER(kDeal.GetFromPlayer());
			CvTeam& kTeam = GET_TEAM(kPlayer.getTeam());

			TeamTypes eOtherTeam = GET_PLAYER(kDeal.GetToPlayer()).getTeam();

			if (kPlayer.GetPlayerTraits()->IsRefusingTradeCausesWar() && kTeam.canDeclareWar(eOtherTeam))
			{
				kTeam.declareWar(eOtherTeam);
			}
		}

I've added IsRefusingTradeCausesWar and it functions correctly. Some debugging has shown me that this section of the code (the stuff within "if (bFoundIt) {" from line 2004 in CvDealClasses.cpp) only executes when AIs are negotiating with each other, not the player. Even then, I'm unsure if it runs when an AI refuses a trade.

I've looked into CvDiplomacyRequests, CvDealAI, and CvDiplomacyAI, as well as tried to follow the 'refuse' button down from lua into the DLL, but no luck. The button seems to just close the screen. And I'm beginning to get the creeping sensation that unless you're in a networked multiplayer game "refusals" aren't ever transmitted, the proposed deal is just deleted.
 
A better idea would be to send an event via the lua system whenever a deal is finished (successfully or not) with the info on it's success, and then make the UA in lua trigger off your event.
 
You probably have to break this UA into two parts, and understand a basic principle:

AI players won't send a deal out unless it's already acceptable between both parties.

Thus, this UA will only fire for human players, and that function is handled under CvDealAI::DoHumanOfferDealToThisAI(CvDeal* pDeal) not even what you want.

Doing this between Human to AI players is simple if you add a bunch of checks to DoFromUIDiploEvent().

Doing this between AI to AI players is impossible without heavy edits to CvDiplomacyAI, because the AI only sends statements out to AI players that agree (with a few exceptions - like coop war stuff). Understand that this is handled through several functions, like DoLuxuryTrade(), which then calls into DealAI which then checks if deal is acceptable based on whether it can successfully equalize the deal or not.

Good luck.
 
A better idea would be to send an event via the lua system whenever a deal is finished (successfully or not) with the info on it's success, and then make the UA in lua trigger off your event.

That only catches deals with the human player though.

You probably have to break this UA into two parts, and understand a basic principle:

AI players won't send a deal out unless it's already acceptable between both parties.

Thus, this UA will only fire for human players, and that function is handled under CvDealAI::DoHumanOfferDealToThisAI(CvDeal* pDeal) not even what you want.

Doing this between Human to AI players is simple if you add a bunch of checks to DoFromUIDiploEvent().

Doing this between AI to AI players is impossible without heavy edits to CvDiplomacyAI, because the AI only sends statements out to AI players that agree (with a few exceptions - like coop war stuff). Understand that this is handled through several functions, like DoLuxuryTrade(), which then calls into DealAI which then checks if deal is acceptable based on whether it can successfully equalize the deal or not.

Good luck.

Now that you point this out, I see what you mean. Firaxis never send deals between AIs that they won't accept. :( I may rethink this UA then. It was already, I thought, the weakest in the group I'm working on, so no sense in putting so much more work into it than the others. It's flavorful, but not overly useful, so we'll see what other UAs I can come up with.

Thanks all!
 
Back
Top Bottom