Allow Territory Effects for unitPlacementRestrictions and unitPlacementOnlyAllowedIn
-
Currently, you can only provide a list of territories for these unit options which ends up being a list of every territory that has a certain territory effect on certain maps. This ends up causing map makers to maintain long lists of territories and often leads to bugs.
Here is an example for TWW where AlpineInfantry can only be placed in Hill/Mountain terrain:
<attachment name="unitAttachment" attachTo="russianAlpineInfantry" javaClass="games.strategy.triplea.attachments.UnitAttachment" type="unitType"> <option name="movement" value="1"/> <option name="attack" value="2"/> <option name="defense" value="3"/> <option name="transportCost" value="2"/> <option name="isLandTransportable" value="true"/> <option name="requiresUnits" value="russianBarracks"/> <option name="canInvadeOnlyFrom" value="none"/> <option name="unitPlacementOnlyAllowedIn" value="Burma:Northern Finland:Manchuria:Quebec:Northern Mexico:Southwestern US:Southern Central US:Northwestern US:Western US:Eastern US:San Francisco:Los Angeles:British Columbia:Alaska:Eastern Mexico:Columbia:Venezuela:Rio de Janeiro:Chile:Western South Africa:Eastern South Africa:Tripolitania:Algeria:Madrid:Northern Spain:Vichy France:Scotland:Southern Germany:Austria:Northern Italy:Rome:Southern Italy:Sardinia:Sicily:Northern Yugoslavia:Southern Yugoslavia:Greece:Bulgaria:Romania:Norway:Central Norway:Western Turkey:Turkey:Southern Caucasus:Omsk:Novosibirsk:Soviet Far East:Hokkaido:Japan:Kyushu Shikoku:Hong Kong:Hupeh:Kweichow:Chungking:Kansu:Northern China:Tsinghai:Singkiang:Western Madras:Malay:Saigon:Sumatra:Java:Brunei:Phillippines:Luzon:New Zealand:Switzerland"/> </attachment>
Instead allow these 2 properties to also specify the territory effects instead of just territories so you can do this:
<attachment name="unitAttachment" attachTo="russianAlpineInfantry" javaClass="games.strategy.triplea.attachments.UnitAttachment" type="unitType"> <option name="movement" value="1"/> <option name="attack" value="2"/> <option name="defense" value="3"/> <option name="transportCost" value="2"/> <option name="isLandTransportable" value="true"/> <option name="requiresUnits" value="russianBarracks"/> <option name="canInvadeOnlyFrom" value="none"/> <option name="unitPlacementOnlyAllowedIn" value="Hills:Mountain"/> </attachment>
-
Here is the PR: https://github.com/triplea-game/triplea/pull/4805
One important note is that if you do use territory effects for these properties then the UnitAttachments must come after the TerritoryAttachments in your XML.
-
@redrum Minor correction, if I'm right, here we should say a list of zones, not a list of territories (it is not required that the zone has a territory attachment).
Personally, I don't like the concept of having the same option referring to different items indistinguishably, as this requires the reader to reference or know the called names, in order to know if we are talking of one thing (zones' names) or another (terrains' names). Moreover, I don't know what is going to happen if a territory and a terrain go by the same name (you might want to have a territory called Highlands and a terrain called the same, for example), but, if they are both affected, this should not be an actual issue, most likely (plus you can just assure at least different cases).
On top of the above, I definitely believe that the behaviour should rather be logically inverted, for territory effects, in that the terrains should disable, not enable, the ability of placing a unit, so that you are at least not obliged to have territory effects everywhere, to place the "regular" units you can place in "regular" territories, normally represented by the absence of territory effects.
So, either I suggest having a different option (like "unitPlacementNotAllowedInTerrains") for that, or put this element as on option of the terrains themselves (of course, in this case the values would be the units' names), and I tend to favour this last solution, considering that terrains already have an option for disabling units' entry (this would be logically the same thing, but for placement). In this last case, I would also add a count (so that you can set it to 0 to disable placement altogether, but you can also manage it).
I want to point out that I've not an idea on how to use it myself at the moment (but I believe it is a good addition); just arguing theorically.
-
Cernel said: "requires the reader to reference or know the called names, in order to know if we are talking of one thing (zones' names) or another (terrains' names)"
If the tooltips made it clear that it was a territory type and not a territory name that the unit could be placed in, then this should not be a problem? Like
"can only be placed in: Mountain territories, Hill territories"
or
"can only be placed in territory types: Mountains, Hills"@redrum would this also work with sea unit placement? Like if the sea territories had territory effects or the land territory with the factory had a territory effect that influenced the placements of sea units? How would it work?
-
@Cernel No, you need the territory attachments listed before the unit attachments as that is where you define which territories have territory effects.
It will always use the territory instead of the territory effect in the rare case you'd have a name conflict.
You can use restricted or allowed with territory effects just like territory names.
Long term, many places where you can specify territory names, I'd like to allow territory effects so I want to avoid duplicating lots of unit options.
@Frostion The tooltips will actually show a list of the territories as the engine maps the territory effect to all the territories that have it when the map is parsed. It should work for sea unit placement as well (you could have say a "coast" territory effect which is required for certain sea units). The territory effects only influence the territory that the unit is being placed in (land or sea) so having some territory effect where the land factory is has no influence on what sea units can be placed. But you could have land territory effects that limit what infrastructure can be placed so for example you could limit "naval base" unit can't be placed where there is a "mountain" territory effect.