Attached is a foreign advisor (based on rev 1122) which refuses to display the favorite civic if random personalities is on.
Committed.
Detecting the modifier isn't too hard if we can make the assumption that everything between the quotes of the defined string will be listed in the diplo summary.
This would make an excellent addition to AttitudeUtils.py:
Code:
def hasModifier(attitudeText, xmlKey) -> boolean
if AttitudeUtils.hasModifier(szDiplo, "TXT_KEY_MISC_ATTITUDE_FAVORITE_CIVIC"):
...
And I bet we could find good uses for one that splits the text apart into all of the modifiers:
Code:
def getModifiers(attitudeText) -> dict { string xmlKey: int modifier }
If that modifier appears after a civics change we then have to see which civics match (you are right that both must run it) and assume that the favorite is one of those.
Assuming the attitude modifier doesn't appear immediately, you could track all civics switches over time . . . hmm, actually you couldn't really. Say you switch from A to B, 10 turns later from X to Y (different categories), and 10 turns later you get a modifier. Is B or Y their favorite civic?
In any case, you're right that we can narrow it down to a list of possibles. I believe the modifier disappears immediately upon a switch away, so that would help too. Also, will the AI ever ask you to switch to a non-favorite civic, or can we assume that a request to switch civics will always be to a favorite?
So how do you store and retrieve data to keep track of this stuff?
SdToolkit, already included in BUG for UnitNaming and Reminders. You can register a "mod" key (e.g. "FavoriteCivics") with SdToolkit and then attach any structured data you want (from a simple int to a complex class with lists and dictionaries and other data types).
We'd need to track the set of possible favorite civics for each AI as well as the history of civics changes for the player and any AIs for whom we are unsure of their favorite.
You can start by skipping the saving of data and just code up the checks. Go ahead and check each turn as well for the modifier change as I think it's not immediate. I do know that it grows over time, but if it turns out to show up immediately, this gets a whole lot easier.
On a slightly related note, I had originally added a feature to the EFA for my personal copy of Ruff's mod (may the hard drive that held it rest in peace): each civic that you shared in common with an AI was highlighted (just need to call setSelected() (IIRC) on the GFC checkbox. I also added the player as the first row on that INFO page.
Also, I put a * next to an AI's religion if you shared it and a * next to their favorite civic if you shared that.
Finally, for trade I hid the 0 if you could not possibly trade with them (not connected or at war). Now that we have a war icon, we could even add the reason instead of simply hiding the 0 value.
Wanna take a stab at any of these?