Open a Dialog Box when event triggers?
-
I'd like to give players the choice of whether or not to return allied territories when they liberate a friendly capital. E.g., America re-takes first Algeria and Normandy from the Germans, and then later retakes Paris from the Germans, and then America chooses whether to return Paris, Normandy, Algeria, etc. to France or keep all three territories for America.
I'm pretty sure I've found the relevant variable to alter in the XML; it's givesBackOriginalTerritories. What I don't know how to do is to give the player the choice of whether to set this variable to true or false in the middle of a game. I assume a simple dialog box would make sense, and I probably know enough Java or VisualBasic to cobble one together, but I don't know how to get that dialog box to play nicely with TripleA once I've got it made.
Anyone have advice on this topic? I'm open to either suggestions on how to get the dialog box to work, or to creative workarounds. Maybe the easiest thing to do is have a territory worth 0 IPC on the map called "return French territories" and you can move an infantry into or out of it to indicate your preferences to the tripleA engine. Seems clunky, but I could imagine worse.
-
@Jason-Green-Lowe Nice I haven't seen this one before.
givesBackOriginalTerritories.
I still don't know how when your capital is captured and your allies take one of your territories and stays theirs until your capital is liberated works. I think it might be hardwired.
At any rate, yea, that'd be cool
-
@Jason-Green-Lowe you could maybe try user actions
-
I think userActions are probably the way to go, but they're somewhat thinly documented. I've put some sample code below -- can you help me troubleshoot it? Right now I'm not seeing any dialog box. The game runs fine, but the new code does not seem to have any effect.
Is there yet another property that I have to specifically set to 'true' in order for this to work? So far that's been the most common cause of my inadvertent null-ops.
<relationshipTypes> <relationshipType name="Allied"/> <relationshipType name="War"/> <relationshipType name="Neutrality"/> <relationshipType name="Stingy"/> </relationshipTypes> <attachment name="relationshipTypeAttachment" attachTo="Stingy" javaClass="games.strategy.triplea.attachments.RelationshipTypeAttachment" type="relationship"> <option name="archeType" value="allied"/> <option name="givesBackOriginalTerritories" value="false"/> </attachment> <!--Liberation Conditions and Triggers--> <attachment name="conditionAttachment_Germans_Liberate_Rome" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name="battle" value="Germans:any:any:currentRound:Rome"/> <option name="directOwnershipTerritories" value="Rome"/> </attachment> <attachment name="conditionAttachment_Germans_Keep_Italian_Territories" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name='switch' value='true'/> </attachment> <attachment name='triggerAttachment_Germans_Keep_Italian_Territories' attachTo='Germans' javaClass='TriggerAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='relationshipChange' value='Germans:Italians:any:Stingy'/> </attachment> <attachment name='userActionAttachment_Germans_Get_Choice_About_Rome' attachTo='Germans' javaClass='UserActionAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='activateTrigger' value='triggerAttachment_Germans_Keep_Italian_Territories:1:false:false:false:false'/> <option name='text' value='LIBERATE_ROME'/> <option name='actionAccept' value='Germans'/> </attachment>
-
@Jason-Green-Lowe just gonna throw some spaghetti as idk but ... Maybe an ownership change instead of relationship ? Or maybe even both ?
-
I appreciate the attempt, but an ownership change would be clunky because I'd have to find some way to specify a change in ownership of "all the territories that were originally owned by X but are currently owned by that player's teammates."
If I'm right, that's exactly what 'givesBackOriginalTerritories" does. Maybe there's some other similar variable that does that, or maybe I'm using it wrong, in which case I'd love a precise correction. If there's no variable that does that, I'm not going to bother to code it myself.
More importantly, no dialog box is popping up at all -- so it's not just that there is no effect when the user chooses option A, it's also that the user is not even being presented with a choice to make.
-
@Jason-Green-Lowe Do you have this?
<property name="Use Triggers" value="true" editable="false"> <boolean/> </property>
-
Yup! Made that mistake (and fixed it) two features ago. Thanks, though.
-
@Jason-Green-Lowe said in Open a Dialog Box when event triggers?:
More importantly, no dialog box is popping up at all -- so it's not just that there is no effect when the user chooses option A, it's also that the user is not even being presented with a choice to make.
Do you have the dialog in notifications.properties as well ?
-
Yes, I've got the dialog in notifications.properties.
-
Just guessing here but one of the problems might be in when the 'userActionAttachment' trigger are fires. The 'germanUserActions' delegate should be just before 'germanEndTurn' because the endTurn delegate might be clearing the 'battle' flag.
Also if German, Italian relationship changes is set to 'Allied' with 'givesBackOriginalTerritories' equals 'true' then German never control Rome because once the territory is liberated, Italy will assume control of the territory.
How to test what is happening. Run you map, and give Rome control to an enemy of Italy. On Germany's turn stage the battle so that German will win. If the color changes to Italy then condition 'German have 'directOwnershipTerritories' of Rome' will be false and the userAction will not fire.
Hope this explains what is happening, and give you some ideas on how you might fix them.
Cheers...
-
@wc_sumpton I think you've identified a key part of the problem; Italy returns to Italian control immediately before the userAction has a chance to trigger. My UserActions delegate is in a good place, but it's never true that Germans have direct ownership of Rome, so the condition is never passed.
I've re-written the condition to be based on the presence of units during the combatMove, but I'm getting an error message and I'm not sure why.
<attachment name="conditionAttachment_Rome_Occupied_By_Enemy" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name="alliedOwnershipTerritories" value="Rome" count="1"/> <option name="invert" value="true"/> </attachment> <attachment name="conditionAttachment_Germans_Liberate_Rome" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name="conditions" value="conditionAttachment_Rome_Occupied_By_Enemy"/> <option name="directPresenceTerritories" value="Rome"/> <option name="unitPresence" value="infantry:commando:artillery:tank:jeep:halftrack:flak"/> </attachment> <attachment name="conditionAttachment_Germans_Keep_Italian_Territories" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name='switch' value='true'/> </attachment> <attachment name='triggerAttachment_Germans_Keep_Italian_Territories' attachTo='Germans' javaClass='TriggerAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='relationshipChange' value='Germans:Italians:any:Stingy'/> <option name="when" value="after:germanBattle"/> </attachment> <attachment name='userActionAttachment_Germans_Get_Choice_About_Rome' attachTo='Germans' javaClass='UserActionAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='activateTrigger' value='triggerAttachment_Germans_Keep_Italian_Territories:1:false:false:false:false'/> <option name='text' value='LIBERATE_ROME'/> <option name='actionAccept' value='Germans'/> </attachment>
GameParseException: map name: 'file:/C:/Users/jason/triplea/downloadedMaps/argo/games/argo1939.xml', game name: 'argo1939', Unexpected Exception while setting values for attachment: RulesAttachment attached to: PlayerId named:Germans with name: conditionAttachment_Germans_Liberate_Rome
-
It hard to find the error with the information posted. I'm thinking that you don't have the console turn on. To show the console select 'Engine Preferences' from the main menu. Then the 'Game' tab.
As to you idea, once Rome is liberated, Italy will gain control of that territory. And since that is the Capital for the Italian player, all liberated territories will return to the Italian player.
The way I read this, the change of relationship happens after so 'givesBackOriginalTerritories' will have no effect until the next time Rome is captured. For this to work I think you are going to have to set the relationship to 'stingy' at the beginning of the game, then check if Germany wants to give back control of the liberated territories.
Hope this is helpful.
Cheers...
-
OK, I reworked the conditions as you suggested so that players on the same team start with the 'stingy' relationship and the trigger changes that to an 'allied' relationship, but I'm still not seeing any dialog box -- nothing seems to be triggering at all. I turned on the console as you suggested, and enabled verbose logging (debug mode), and got no messages at all.
I respectfully suggest that the problem here isn't the specific way I'm defining the liberation event -- I'm failing to invoke the idea of a dialog box at all. Can anyone help me with an example of code where they've successfully generated a dialog box in the middle of a game?
-
Here is the new code I was working with, and I'm also attaching the entire XML file in case anyone wants to review that.
<!--Liberation Conditions and Triggers--> <attachment name="conditionAttachment_Germans_Liberate_Rome" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name="directOwnershipTerritories" value="Rome"/> <option name="players" value="British:French:Russians:Chinese:Americans"/> <option name="battle" value="Germans:any:any:currentRound:Rome"/> </attachment> <attachment name="conditionAttachment_Germans_Keep_Italian_Territories" attachTo="Germans" javaClass='RulesAttachment' type='player'> <option name='switch' value='true'/> </attachment> <attachment name='triggerAttachment_Germans_Keep_Italian_Territories' attachTo='Germans' javaClass='TriggerAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='relationshipChange' value='Germans:Italians:any:Allied'/> <option name="when" value="after:germanBattle"/> </attachment> <attachment name='userActionAttachment_Germans_Get_Choice_About_Rome' attachTo='Germans' javaClass='UserActionAttachment' type='player'> <option name='conditions' value='conditionAttachment_Germans_Liberate_Rome'/> <option name='activateTrigger' value='triggerAttachment_Germans_Keep_Italian_Territories:1:false:false:false:false'/> <option name='text' value='LIBERATE_ROME'/> <option name='actionAccept' value='Germans'/> </attachment>
-
Sorry for the amount of time it has taken me to reply. Using conditions that test for 'battle', the presents of Italian troops and the presents of enemy troops. I have been able to trigger messages using both 'politics' and 'userActions'. But I have been unable to get Germany to retain control of Rome.
This maybe a bug. Sorry I was unable to help.
Cheers...
-
Thank you. I think it's not so much a bug as just a hardwired behavior that has unfortunate consequences for some games.
Like, the choice seems to be:
givesBackOriginalTerrritories = True: territories will always return to the original owner at the end of each politics step
givesBackOriginalTerritories = False: territories will only return to the original owner when the original owner's capital is liberatedWhat I want is an option that says "territories will never return to the original owner," but there doesn't seem to be a way to do that right now.
I'm not sure what my second-best option is. I could just make most of the territories non-original, but then it feels awkward if you liberate an ally's territory while they're still alive and kicking and you keep it. Right, like if on turn 1 Germany captures Normandy, and on turn 2 Britain liberates Normandy, and the French still own Paris, Marseilles, Algeria, etc., and the British wind up with control of Normandy that seems really weird; that's not what would happen.
So how do I make it so that you give back territories before a capital falls, but keep territories after a capital falls? I could maybe try to alter the status of the territories so they lose their 'original territory' status after the capital falls, but what do I alter the status to? Is there a clean way to set the originalTerritory value to "none"?
-
Actually, one option I might consider is allowing players to build a special 'flag' unit that permanently annexes the territory by setting the original owner to the player building the flag. Can I do that with triggers and territory attachments? Anything to watch out for?
-
'<originalOwner' can not be set to 'None' unless you create a player as 'None'. But it can set it to 'Natural'. So that is something to think about.
Cheers...
-
@Jason-Green-Lowe You can use a "changeOwnership" trigger with suitable conditions to change territories as you see fit.