Spawn unit in passable terrains
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.
- hermestrismi
- Posts: 471
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Spawn unit in passable terrains
In my campaigns, I use a lot of spawning events but I always have the problem of spawning units in closed unwalkable areas (like in a cave road surronded by walls )
I am sure there is a way to avoid that but I didnt found it.
Can someone help?
I am sure there is a way to avoid that but I didnt found it.
Can someone help?
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
Re: Spawn unit in passable terrains
There is one sloppy work around. You can also teleport the unit to the spot after spawning it, this will place it in the next possible spot.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Spawn unit in passable terrains
One important thing to note here is that the name of the relevant key is different depending on whether you're placing the unit with SingleUnitWML or
[unstore_unit]
; it's passable=yes
with the former, but find_vacant=yes
with the latter. The validator will warn you if you mix the two up, if you're using that.Wesnoth-related GitHub repos:
General mods collection, SotBEEE, AToTBWaTD, The Earth's Gut, A Little Adventure, FtF
Social media: Mastodon: @egallager@treehouse.systems, Steam: egallager
General mods collection, SotBEEE, AToTBWaTD, The Earth's Gut, A Little Adventure, FtF
Social media: Mastodon: @egallager@treehouse.systems, Steam: egallager
Re: Spawn unit in passable terrains
Concern was about maps that have passable hex that is fully surrounded by impassable.
- beetlenaut
- Developer
- Posts: 2792
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Spawn unit in passable terrains
I don't think you can avoid this, but you could redo the spawn if it's in a bad place. You can use [find_path] to find the distance to a known valid hex (like a village or the leader's position). If $path.hexes = 0, then no path could be found. Use a [while] loop to repeatedly spawn and kill the unit while a path is not found. Make sure you allow multi-turn paths, and cap the number of tries so you don't end up in an infinite loop. (Actually, WML loops aren't allowed to be infinite, but it can still take them a long time to exit.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide