Can unitPresence count total number of units that belong to any of a few types?
-
I am trying to sometimes allow ships to pass through each others' sea zones, so that one Japanese destroyer can't block the entire US Pacific Fleet.
However, I'm running into a problem with unitPresence -- it looks like if I use a list of more than one type of unit and have a count greater than 1, then the option will check to see if any one of those unit types has at least that many units in the same sea zone. For example, with
<attachment foreach="$Players$^$SeaZones$" name="conditionAttachment_@Players@_No_Double_Naval_Obstacle_In_@SeaZones@" attachTo="@Players@" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player"> <option name="enemyExclusionTerritories" value="@SeaZones@" count="1"/> <option name="unitPresence" value="carrier:battleship:cruiser:destroyer" count="2"/> </attachment>
the engine will check and see if there are at least 2 destroyers in the sea zone, and/or at least 2 cruisers in the sea zone, and/or at least 2 battleships in the sea zone, but what I'm really looking for is to see if there are at least 2 surface warships in the sea zone. So, if there is 1 destroyer and 1 cruiser in the sea zone, then this condition should be violated...but the engine is still marking the condition as true.
Any way to get the result I'm looking for?
-
pack_of_steel_2.xml: "unitPresence can be put in multiple times. ...
"For an "AND" relationship between the required units, put them in separately. For an "OR" relationship, put them in on one line with a colon separating them."So, 'value="carrier:battleship:cruiser:destroyer" count="2"', means any combination of 2 units, not any 2 of the same units, where as value="carrier" count="2"... value="battleship" count="2"... means 2 of each. From what I understand this not what you want. You'll need to create a separate condition for each unit, and then or the conditions together.
Hope this helps.
Cheers...
-
@wc_sumpton Yes, I agree with all of that, but for some reason my code does not seem to be behaving the way you describe.
Here is a chart showing my desired behavior:
No enemy warships in sea zone --> PASSABLE
1 enemy warship in sea zone, and also 3+ friendly warships in sea zone --> PASSABLE
1 enemy warship in sea zone, with 0-2 friendly warships in sea zone --> BLOCKED
2 enemy warships in sea zone --> BLOCKEDNote that should does not matter at all what type or type(s) of warships are used. For example, my desired behavior is...
1 enemy destroyer + 1 enemy cruiser in sea zone --> BLOCKED
2 enemy destroyers in sea zone --> BLOCKEDUnfortunately, the code below instead gives me the behavior...
1 enemy destroyer + 1 enemy cruiser in sea zone --> PASSABLE
2 enemy destroyers in sea zone --> BLOCKEDI do not know what the problem is here. Presumably I have made an error, but I can't find it.
<attachment foreach="$Players$^$SeaZones$" name="conditionAttachment_@Players@_Naval_Obstacle_In_@SeaZones@" attachTo="@Players@" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player"> <option name="enemyPresenceTerritories" value="@SeaZones@" count="1"/> <option name="unitPresence" value="carrier:battleship:cruiser:destroyer" count="1"/> </attachment> <attachment foreach="$Players$^$SeaZones$" name="conditionAttachment_@Players@_No_Double_Naval_Obstacle_In_@SeaZones@" attachTo="@Players@" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player"> <option name="enemyExclusionTerritories" value="@SeaZones@" count="1"/> <option name="unitPresence" value="carrier:battleship:cruiser:destroyer" count="2"/> </attachment> <attachment foreach="$Players$^$SeaZones$" name="conditionAttachment_@Players@_Naval_Screen_In_@SeaZones@" attachTo="@Players@" javaClass="games.strategy.triplea.attachments.RulesAttachment" type="player"> <option name="alliedPresenceTerritories" value="@SeaZones@" count="1"/> <option name="unitPresence" value="carrier:battleship:cruiser:destroyer" count="3"/> </attachment> <attachment foreach="$SeaZones$^$Players$:$LCPlayers$" name="triggerAttachment_Naval_Penetration_In_@SeaZones@" attachTo="@Players@" javaClass="games.strategy.triplea.attachments.TriggerAttachment" type="player"> <option name="conditions" value="conditionAttachment_@Players@_Naval_Obstacle_In_@SeaZones@:conditionAttachment_@Players@_Naval_Screen_In_@SeaZones@:conditionAttachment_@Players@_No_Double_Naval_Obstacle_In_@SeaZones@"/> <option name="when" value="after:@LCPlayers@CombatMove"/> <option name='unitAttachmentName' value='UnitAttachment' count='unitAttachment'/> <option name="unitType" value="carrier:battleship:cruiser:destroyer"/> <option name="unitProperty" value="canBeMovedThroughByEnemies" count="true"/> </attachment>
-
count="X" is not an exact count. To be true count can be equal to or greater than "X", so think of count as '>=' and not just '='.
So, to check for just a single unit two conditions are needed, count="1" and an invert of count="2". To check for 2 units, count="2" and an invert of count="3".
Cheers...
P.S. Sorry I got caught up in the coding and not the problem. If 'canBeMovedThroughByEnemies' is set on 'carrier:battleship:cruiser:destroyer' every one of those units, enemy, allied, British, Japanese, etc... will be set. Not just in sea zones with just 1 enemy unit, but also in sea zones with 100 units. This type of rule would be better done with a 'supportAttachment' where units stacked together will nullify the ability.
Try asking for a Feature Request to support the idea.
Again Cheers...
-
@wc_sumpton Well, yes, I agree that the way I'm creating the feature is far from ideal. I've got a cleanup trigger that resets the canBeMovedThroughByEnemies back to false at the end of each combat move.
I would indeed prefer to have a supportAttachment, but my understanding is that those wouldn't work right now with the existing code, and I think tripleA is short enough on developers right now that it's not practical to request special features just for my map.
I tried switching from directExclusion to (directPresence + invert), and that did the trick. Thanks again for the help!