Teleporting the AI...
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Teleporting the AI...
I have noticed the standard
But an even bigger problem is they don't know how to use them (that they have to step on them to go somewhere), even if those teleporters worked...
Now it happens I have a rather strange map where for the whole duration of the scenario I want to have random enemies pop up at random places all over the (biggish) map...
For obvious reasons I've rejected the idea of creating over 200 "name=turn" events and place several hundreds of "random" units by hand.
What seemed like a nice and resource-conscious solution would be to have an enemy leader in a hidden place recruit units, and those units step randomly on one of the dozens of teleporter tiles all around their birthing castle, and thus land somewhere on the map.
That should be random enough, both for the unit types as for the places they will pop up, but unfortunately it doesn't work...
Is there any solution?
For the record:
Note I've seen a
[teleport] doesn't work for the AI: They can land right on a teleporter tile and nothing happens.But an even bigger problem is they don't know how to use them (that they have to step on them to go somewhere), even if those teleporters worked...
Now it happens I have a rather strange map where for the whole duration of the scenario I want to have random enemies pop up at random places all over the (biggish) map...
For obvious reasons I've rejected the idea of creating over 200 "name=turn" events and place several hundreds of "random" units by hand.
What seemed like a nice and resource-conscious solution would be to have an enemy leader in a hidden place recruit units, and those units step randomly on one of the dozens of teleporter tiles all around their birthing castle, and thus land somewhere on the map.
That should be random enough, both for the unit types as for the places they will pop up, but unfortunately it doesn't work...
Is there any solution?
For the record:
- Teleporting AI controlled units somewhere on the map
- And for this to work, having the AI controlled units want to step on one of a dozen teleporter tiles (instead of just piling up in their castle because there is no obvious way out)
Note I've seen a
[tunnel] feature, but failed to see the light on the other side: What is this tunnel anyway? What's the difference between that and teleporting? Is there any code example somewhere so I can see what the WML is supposed to look like? The reference Wiki is once again very succinct, reading it only told me that this feature exists, and that it probably can solve my problem since apparently you have a vision of the arrival point, so the AI would have a motive to use it. Unless I totally misunderstood how it works. Re: Teleporting the AI...
[teleport] is direct action that you as addon author take to move units. [tunnel] is map feature to let faraway tiles connect to each other.
Re: Teleporting the AI...
Okay, thanks, that makes sense.
And how do I use it? Is there somewhere any code example I can look at?
The ReferenceWML is very light on examples...
And how do I use it? Is there somewhere any code example I can look at?
The ReferenceWML is very light on examples...
- Celtic_Minstrel
- Developer
- Posts: 2487
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Teleporting the AI...
You might have noticed that the AI has no problem using a Silver Mage, which can teleport. That's because the Silver Mage uses
That means the Silver Mage's teleport ability is another example of a
[tunnel], which modifies the graph of the map's hex connections used for pathfinding.That means the Silver Mage's teleport ability is another example of a
[tunnel] that you can look at.Re: Teleporting the AI...
Great, thanks.
Now pondering how to make the AI use different tunnels at random.
In the example Ravana gave me, it seems like there are three tunnels with the same departure hex.
What happens in this case when one unit steps on that departure hex? The unit arrives at one of the destinations at random? Three units arrive, one in each destination?
Now pondering how to make the AI use different tunnels at random.
In the example Ravana gave me, it seems like there are three tunnels with the same departure hex.
What happens in this case when one unit steps on that departure hex? The unit arrives at one of the destinations at random? Three units arrive, one in each destination?
Re: Teleporting the AI...
Nothing happens. Just because they are allowed to move though tunnel doesnt force them to.
Re: Teleporting the AI...
Yes, but if they do? That's what I'm asking for.
Re: Teleporting the AI...
They go where they want to go.
Re: Teleporting the AI...
So, in the case of several tunnels with one entry and several exits, you can chose which exit to use?
Hmm, that doesn't help. I don't want them to arrive all at the arrival point nearest to the player, I want them to arrive randomly all over the place, so they all attack from different directions. That's the whole point.
What happens if one of the castle hexes is a tunnel entry? Will units recruited there automatically land on the exit hex, or will they linger?
Because I could indeed give the castle 5-6 different tunnels and thus create some randomness. But it only work if the recruited units are teleported automatically. It won't work if they get to chose where to go.
What happens if one of the castle hexes is a tunnel entry? Will units recruited there automatically land on the exit hex, or will they linger?
Because I could indeed give the castle 5-6 different tunnels and thus create some randomness. But it only work if the recruited units are teleported automatically. It won't work if they get to chose where to go.
Re: Teleporting the AI...
If you want this kind of mechanic just move them after recruitment. No need for tunnels. Tunnel means tiles behave similarly as adjacent to each other.
Re: Teleporting the AI...
OK, that was the information I was missing, thanks.Ravana wrote: August 5th, 2026, 2:21 pm Tunnel means tiles behave similarly as adjacent to each other.
And how would I do that?...Ravana wrote: August 5th, 2026, 2:21 pm If you want this kind of mechanic just move them after recruitment. No need for tunnels.
I'm trying indeed to find a way to (automatically) move them, and the only way I know is teleporting, which doesn't work for AI units...
They all get recruited in the same castle, but the next turn (or so) they should be randomly dispersed all over the map.
Re: Teleporting the AI...
kurt751 wrote: August 5th, 2026, 2:37 pm They all get recruited in the same castle, but the next turn (or so) they should be randomly dispersed all over the map.
Code: Select all
[event]
name=recruit
first_time_only=no
[filter]
side=2
[/filter]
[modify_unit]
[filter]
id=$unit.id
[/filter]
[set_variable]
name=already_teleported
value=no
[/set_variable]
[/modify_unit]
[/event]
[event]
name=side 2 turn refresh
first_time_only=no
[store_unit]
variable=units_not_yet_teleported
[filter]
[filter_wml]
[variables]
already_teleported=no
[/variables]
[/filter_wml]
[/filter]
[/store_unit]
[foreach]
array=units_not_yet_teleported
[do]
[set_variable]
name=teleport_x
rand=1..10
[/set_variable]
[set_variable]
name=teleport_y
rand=1..10
[/set_variable]
{TELEPORT_UNIT (
id=$this_item.id
) $teleport_x $teleport_y}
[modify_unit]
[filter]
id=$this_item.id
[/filter]
[set_variable]
name=already_teleported
value=yes
[/set_variable]
[/modify_unit]
[/do]
[/foreach]
[/event]
Re: Teleporting the AI...
Wow, thanks a lot.gnombat wrote: August 5th, 2026, 3:17 pmCode: Select all
[event] name=recruit first_time_only=no [filter] side=2 [/filter] [modify_unit] [filter] id=$unit.id [/filter] [set_variable] name=already_teleported value=no [/set_variable] [/modify_unit] [/event] [event] name=side 2 turn refresh first_time_only=no [store_unit] variable=units_not_yet_teleported [filter] [filter_wml] [variables] already_teleported=no [/variables] [/filter_wml] [/filter] [/store_unit] [foreach] array=units_not_yet_teleported [do] [set_variable] name=teleport_x rand=1..10 [/set_variable] [set_variable] name=teleport_y rand=1..10 [/set_variable] {TELEPORT_UNIT ( id=$this_item.id ) $teleport_x $teleport_y} [modify_unit] [filter] id=$this_item.id [/filter] [set_variable] name=already_teleported value=yes [/set_variable] [/modify_unit] [/do] [/foreach] [/event]
I assume the "rand=1..10" part means "pick a random number between 1 and 10", isn't it. In my case it would be more like "rand=1..100"...
And what happens if their destination is unwalkable or solid wall? Does the teleport abort, does the unit gets placed on the nearest valid tile, or does the game crash...?