Spawn unit in passable terrains

The place to post your WML questions and answers.

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.
Post Reply
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Spawn unit in passable terrains

Post by hermestrismi »

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?
gnombat
Posts: 710
Joined: June 10th, 2010, 8:49 pm

Re: Spawn unit in passable terrains

Post by gnombat »

User avatar
Heindal
Posts: 1361
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Spawn unit in passable terrains

Post by Heindal »

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
User avatar
egallager
Posts: 586
Joined: November 19th, 2020, 7:27 pm
Location: Concord, New Hampshire
Contact:

Re: Spawn unit in passable terrains

Post by egallager »

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.
User avatar
Ravana
Forum Moderator
Posts: 3027
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Spawn unit in passable terrains

Post by Ravana »

Concern was about maps that have passable hex that is fully surrounded by impassable.
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Spawn unit in passable terrains

Post by beetlenaut »

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
Post Reply