We have a 20 question-per-post limit here at CFC, but I'll let ya slide this time.
There is nothing like getAttitude I can find; how can I tell if player1 is friendly to player2?
You'll love this one: it's called AI_getAttitude(), and it is on CyPlayer and takes a player ID.
Code:
# From BUG's AttitudeUtils module
def getAttitudeCategory (nPlayer, nTarget):
"""Returns the attitude level nPlayer has toward nTarget [0,4]."""
if hasAttitude(nPlayer, nTarget):
return [B]gc.getPlayer(nPlayer).AI_getAttitude(nTarget)[/B]
return None
I have coded my function using deal.kill and it is working. But, it only shows up as a transient message. If an AI player actually cancels a deal with a human player, doesn't the LH window pop up with some text? Is there any way to get that effect?
You are correct about a window popping up when an AI cancels a deal. I'm not sure if you can make this happen. I know you can check if an AI will accept a deal from Python, but I haven't experimented with this. I would take a look at CyDiplomacy and CvDiplomacy. Maybe you can initiate the diplomacy window.
I am not positive that this popup will be desirable; if the player has OB with a number of AI's and they all show up to cancel, that is a bunch of popups.
In this case I as a player would prefer a simple popup telling me that everyone is closing their borders and why rather than each AI do it separately.
However, I was going to suggest that instead of every AI closing at the same time, have a percentage chance (based on difficulty maybe?) that any given AI will close its borders once you get over the threshold, or make it depend on the percentage of your religion's spread. It could depend on other factors like attitude, aggressiveness, total value of all trade routes they have with you, etc. Maybe you check each time you spread your religion into a city of theirs rather than every turn.
My point is that I prefer a more fluid rule with some randomness built in rather than a hard 60% and everyone closes their borders all on the same turn.
It seems that the player who didn't cancel, should be mad at the player who did cancel.
Actually, I think you only get the diplomatic penalty if you agree to another AI's trade embargo. I just tested in my current game, and canceling every deal against an AI causes no penalty. I am positive that joining a trade embargo earns you the penalty.
Now, this game mechanic sounds very much like a trade embargo of a different sort -- a religion embargo.
So maybe you want a diplomatic penalty. I suppose you could create one of your own, though I suspect that humans will be pursuing this victory more often than AIs.
The code written by Dresden is correct, *as long as* there is never a deal where OB is traded for something else. Otherwise we would have to check both FirstTrades and SecondTrades to see if an item is OB.
I'm writing code right now for BUG that intercepts the diplomacy window actions, including trades, gifts, and demands, and I've found that both sides trade OB to each other in a single deal. Therefore, Dresden's code of searching only one side of the deal should work.
You are correct, though, that you'll be canceling other trades in these cases. Tough petunias. This is precisely why I always trade OB in a separate trade, especially since all AIs value it the same (yours vs. theirs), unlike maps and bonuses.
That means I need to know on what turn a deal was created. There is no information in the trade data objects about that.
CyDeal.getInitialGameTurn() doesn't work for this? If not, I'll have my DiplomacyEvents code done soon and you're free to use it. You'll get a new event for each trade.