Nearly impassably terrain

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
white_haired_uncle
Posts: 1244
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Nearly impassably terrain

Post by white_haired_uncle »

For the final battle, I want to place an impassable shield around the enemy leader so that the player cannot approach unit he has met certain objectives. But I want the enemy units to be able to pass through (preferably without messing with teleports).

First, I gave them movement_cost=2 on impassable, which works but they end up walking in walls which is not what I want.

Then I speculated I might be able to create a terrain and give it my own movement restraint. For example, if I set it to 'impenetrable' and gave enemy units movement on that type then only they could move on that terrain (since the player wouldn't have any, hopefully it would default to 0/nil), if I was lucky. I don't think that will work, since it doesn't look like you can specify movement for a terrain_type, only inherit.

Then I noticed every unit has a Fake Shroud movement cost. I've seen fake shroud in the map editor. This should work! I set my terrain to Xu^_s (hmm, fake shroud is an overlay, not a good sign) and movement_cost fake_shroud=2 (which I made up, based on for example Deep Water = deep_water)... and my units still show movement Fake Shroud=-.

I could probably get away with taking away flying from any of the player's units for this specific instance. Or I could set the enemy's impassable movement type back to 0 when they were at radius > X from starting location. But I'm looking for a better general solution.

Thoughts? Answers? Taunts?

P.S. I'm also a bit confused why I can make a custom terrain type, but I can't configure the "movement type" on it. Probably wouldn't help me here, but that just seems like something that would be part of a terrain type, it has to be stored somewhere and I can't think of a better place.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3040
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Nearly impassably terrain

Post by Ravana »

You can add impassable overlay during player turns.
white_haired_uncle
Posts: 1244
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Nearly impassably terrain

Post by white_haired_uncle »

Oh, very good.
Speak softly, and carry Doombringer.
User avatar
Celtic_Minstrel
Developer
Posts: 2258
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Nearly impassably terrain

Post by Celtic_Minstrel »

white_haired_uncle wrote: April 28th, 2024, 1:19 am P.S. I'm also a bit confused why I can make a custom terrain type, but I can't configure the "movement type" on it. Probably wouldn't help me here, but that just seems like something that would be part of a terrain type, it has to be stored somewhere and I can't think of a better place.
A terrain type's movement type is determined by its movement alias, which is generally set to another terrain type. (For cases where there are multiple aliases, this means the movement type on that terrain type may be different for different units.)

So basically, when determining the terrain type's movement type for a particular unit, the engine looks at the terrain's aliases – the mvt_alias key if present, otherwise the aliasof key. I won't get into the details of how it chooses one when there's a comma-separated list – that's documented in TerrainWML in any case. (It's possible it needs to consider every possibility in order to determine which one to apply, but I'm not sure.) The chosen alias is then the ID of another terrain type, so it looks up that terrain type and repeats the process. Eventually, it reaches a terrain type that has no aliases at all. We call this the "archetype" terrain. That terrain type's ID is the movement type for that unit on that terrain – in other words, it's the key used to look up movement cost, defense, etc in the movement type structure for that unit.

I think most of the mainline terrain types alias an archetype directly, but I don't think that's required for the system to work.

So, basically, in order to make your custom "impenetrable" terrain work with a custom movement cost, I believe all you need to do is not put an alias in the terrain type, and then it'll be an archetype that you can use in [movement_costs]. Or, if for whatever reason you need an alias, make a second terrain type as the archetype and alias to it in addition to whatever other terrain type you need to alias.

I haven't tested any of this recently. I believe I last had it working for a custom "lava" type in 1.14.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply