<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is it possible to run a trigger for each unit found via unitPresence?]]></title><description><![CDATA[<p dir="auto">Another problem I've ran into, is for my map, I need a trigger to replace all units of a given type with a purchase of another type.</p>
<p dir="auto">The set up for doing it for one unit is simple. The question is there a good way to do it for an arbitrary number of units, ensuring to get the same number of purchases of the other unit?</p>
<p dir="auto">The "hack" I have right now supports 20 units using a variable list of numbers from 1 to 20:</p>
<pre><code class="language-xml">		&lt;attachment name="cond_build_fleet_@players@_@nums_1_to_20@" attachTo="@players@"
				foreach="$players$^$nums_1_to_20$" javaClass="RulesAttachment" type="player"&gt;
			&lt;option name="directPresenceTerritories" value="map" count="1"/&gt;
			&lt;option name="unitPresence" value="build_fleet" count="1"/&gt;
		&lt;/attachment&gt;
		&lt;attachment name="trigger_build_fleet_@players@_@nums_1_to_20@" attachTo="@players@"
				foreach="$players$^$nums_1_to_20$" javaClass="TriggerAttachment" type="player"&gt;
			&lt;option name="conditions" value="cond_build_fleet_@players@_@nums_1_to_20@"/&gt;
			&lt;option name="when" value="before:@players@Never"/&gt;
			&lt;option name="removeUnits" value="all:build_fleet" count="1"/&gt;
			&lt;option name="purchase" value="fleet" count="1"/&gt;
		&lt;/attachment&gt;
		&lt;attachment name="trigger_build_fleet_@players@" attachTo="@players@" foreach="$players$" javaClass="TriggerAttachment" type="player"&gt;
			&lt;option name="conditions" value="cond_build_fleet_@players@_1"/&gt;
			&lt;option name="when" value="before:@players@StructuresPlace"/&gt;
			&lt;!-- triggerName:numberOfTimes:useUses:testUses:testConditions:testChance, we want to test the cond. --&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_1:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_2:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_3:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_4:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_5:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_6:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_7:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_8:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_9:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_10:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_11:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_12:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_13:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_14:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_15:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_16:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_17:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_18:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_19:1:false:false:true:false"/&gt;
			&lt;option name="activateTrigger" value="trigger_build_fleet_@players@_20:1:false:false:true:false"/&gt;
		&lt;/attachment&gt;
</code></pre>
<p dir="auto">(In this case, I'm replacing all instances of "build_fleet" unit with "fleet" unit purchase.)</p>
]]></description><link>https://forums.triplea-game.org/topic/3212/is-it-possible-to-run-a-trigger-for-each-unit-found-via-unitpresence</link><generator>RSS for Node</generator><lastBuildDate>Thu, 21 May 2026 16:43:58 GMT</lastBuildDate><atom:link href="https://forums.triplea-game.org/topic/3212.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 May 2022 02:03:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Fri, 13 May 2022 18:53:52 GMT]]></title><description><![CDATA[<p dir="auto">I looked at the engine code around <code>createsUnitsList</code> and it doesn't look like it will work.</p>
<p dir="auto">The relevant code is in <code>EndTurnDelegate.java</code>.</p>
<pre><code>            } else if (!uaToCreate.getIsSea() &amp;&amp; !uaToCreate.getIsAir() &amp;&amp; t.isWater()) {
              toAddLand.addAll(ut.create(createsUnitsMap.getInt(ut), player));

...

        if (!toAddLand.isEmpty()) {
          final Predicate&lt;Territory&gt; myTerrs =
              Matches.isTerritoryOwnedBy(player).and(Matches.territoryIsLand());
          final Collection&lt;Territory&gt; landNeighbors = data.getMap().getNeighbors(t, myTerrs);
          if (!landNeighbors.isEmpty()) {
            final Territory location = getRandomTerritory(data, landNeighbors, bridge);
            createUnits(location, toAddLand, change, endTurnReport);
          }
        }
</code></pre>
<p dir="auto">So basically, for any land units that would be created at sea, we instead find a random neighboring land territory owned by the player and create the units there. No considerations for transports are given.</p>
<p dir="auto">I suppose engine changes could be done to support different semantics, but given this whole line of thinking is already trying to workaround a different engine limitation - perhaps that one could be addressed directly, i.e. making <code>unitPresence</code> support <code>each</code> (either as a multiplication on top of <code>each</code> on <code>directPresenceTerritories</code> if both are used, or not allowing multiple <code>each</code> values on different options).</p>
]]></description><link>https://forums.triplea-game.org/post/54934</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54934</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Fri, 13 May 2022 18:53:52 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Thu, 12 May 2022 11:57:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a> Ooh, that sounds promising. Let me try that! One thing I'm not sure about is whether placement of newly created land units at sea is possible at all - I seemed to recall some logic in the engine that tries to find a nearby land territory. Possibly something that can be treated as a bug to fix in the engine.</p>
]]></description><link>https://forums.triplea-game.org/post/54904</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54904</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Thu, 12 May 2022 11:57:00 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Thu, 12 May 2022 08:38:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/myrd" aria-label="Profile: Myrd">@<bdi>Myrd</bdi></a></p>
<p dir="auto">One problem at a time. Your first one "seems" undoable at present, with simple coding, but I'm still running thoughts through my head. With 'createUnitLists' a trigger could be run prior to 'endTurn' to reduce the "creating" units 'transportCost' to 0 thus allowing the other to be placed in the transport. After the "creating" units are removed, the 'transportCost' can be returned to normal.</p>
<p dir="auto">Trying to be helpful.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/54903</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54903</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Thu, 12 May 2022 08:38:55 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Thu, 12 May 2022 02:40:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a></p>
<p dir="auto"><code>createsUnitsList</code> doesn't work for me, since I'm converting the unit to a purchase (i.e. that can be placed in a different territory). The context is my map requires players to spent resources that need to be physically at factories (via consumes units) to build all units, including other factories. But those other factories are allowed to be placed elsewhere. Anyway...</p>
<p dir="auto">I tried using <code>createsUnitsList</code> for different, but still somewhat similar problem, where it also seemed like it could be a good solution - where I do want to convert all units of one type to another, in the location where they are. So I tried creates units and a trigger to remove the old one. One challenge with this is that it doesn't work when they're loaded on ships (you want the new units to take the same transport slots which doesn't work if the previous unit is still there.)</p>
<p dir="auto">Anyway, it sounds like without engine changes, these aren't really possible.</p>
]]></description><link>https://forums.triplea-game.org/post/54901</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54901</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Thu, 12 May 2022 02:40:19 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Thu, 12 May 2022 01:32:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/myrd" aria-label="Profile: Myrd">@<bdi>Myrd</bdi></a></p>
<p dir="auto">Sorry for taking so long to get back to you. You are right 'each' does not work for 'unitPresence', please accept my apologies for giving that bad information. Trying to account for multiple units in multiple territories has limited degrees of success within the TripleA engine.</p>
<p dir="auto">As to you latest problem. Have you tried 'createsUnitsList' as a possible answer?</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/54900</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54900</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Thu, 12 May 2022 01:32:19 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Sat, 07 May 2022 12:29:08 GMT]]></title><description><![CDATA[<p dir="auto">As an aside, I'm running into this again as I'd like to place a new unit next to each unit of a certain type via a trigger. Same problem.</p>
]]></description><link>https://forums.triplea-game.org/post/54871</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54871</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Sat, 07 May 2022 12:29:08 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Sat, 07 May 2022 12:20:55 GMT]]></title><description><![CDATA[<p dir="auto">Hmm, I think <code>each</code> is not supported on <code>unitPresence</code>?</p>
]]></description><link>https://forums.triplea-game.org/post/54870</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54870</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Sat, 07 May 2022 12:20:55 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Fri, 06 May 2022 14:32:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/myrd" aria-label="Profile: Myrd">@<bdi>Myrd</bdi></a></p>
<p dir="auto">Yes this will count the number of territories. If you need to count the number of units in a territory, you would have to specify the territory and use 'each' in 'unitPresence'.</p>
<p dir="auto">What can not be done is 'each' with both 'directPresenceTerritories' and 'unitPresence', nor can you create a condition for 1 as a 'conditions' for the other. The engine does not handle multiple 'each' statements.</p>
<p dir="auto">To count multiple units in multiple territories, a 'variable' list with territories as 'element' could be used to cycle through the territories to count the units.</p>
<p dir="auto">Just some food for thought.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/54859</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54859</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Fri, 06 May 2022 14:32:44 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Fri, 06 May 2022 10:52:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wc_sumpton" aria-label="Profile: wc_sumpton">@<bdi>wc_sumpton</bdi></a> said in <a href="/post/54857">Is it possible to run a trigger for each unit found via unitPresence?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/myrd" aria-label="Profile: Myrd">@<bdi>Myrd</bdi></a></p>
<p dir="auto">Try using 'each' as the "count" for 'directPresenceTerritories'. Then your trigger should assign the purchase for each territory. A trigger would still be needed to remove all the counted units.</p>
</blockquote>
<p dir="auto">Doesn't that count the number of territories and not units?</p>
]]></description><link>https://forums.triplea-game.org/post/54858</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54858</guid><dc:creator><![CDATA[Myrd]]></dc:creator><pubDate>Fri, 06 May 2022 10:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run a trigger for each unit found via unitPresence? on Fri, 06 May 2022 10:35:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/myrd" aria-label="Profile: Myrd">@<bdi>Myrd</bdi></a></p>
<p dir="auto">Try using 'each' as the "count" for 'directPresenceTerritories'. Then your trigger should assign the purchase for each territory. A trigger would still be needed to remove all the counted units.</p>
<p dir="auto">Hope this is helpful.</p>
<p dir="auto">Cheers...</p>
]]></description><link>https://forums.triplea-game.org/post/54857</link><guid isPermaLink="true">https://forums.triplea-game.org/post/54857</guid><dc:creator><![CDATA[wc_sumpton]]></dc:creator><pubDate>Fri, 06 May 2022 10:35:40 GMT</pubDate></item></channel></rss>