[terrain] and nested filter_location query *SOLVED*

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
Spannerbag
Posts: 491
Joined: December 18th, 2016, 6:14 pm
Location: Yes

[terrain] and nested filter_location query *SOLVED*

Post by Spannerbag »

Edit: changed subject to indicate query answered

Hi,

I'm struggling to get [terrain] to work and would like some help please.

What I'm trying to achieve is when a waterborne enemy leader dies to remove all their castle and keep overlays (atop water terrain).
I do this sort of thing quite often but there are a few wrinkles here that are making life interesting.
Originally I simply removed all overlays that were radius=1 around the leader's keep, including the keep location itself.
This worked fine but due to other stuff that's going on it broke something else in special circumstances.
So I decided to use a nested [filter_location] to extract the hexes of interest... but this nested filter seems to be always ignored?

The wiki says:
terrain: the character of the terrain to use. See TerrainCodesWML to see what letter a type of terrain uses.
StandardLocationFilter. This StandardLocationFilter's terrain= key is used for the new terrain, filtering by terrain can be done with a nested StandardLocationFilter: [and]terrain=terrain_string_to_be_filtered_for.

However I can't get it to work.

Both these versions nuke all overlays ({SIDE} is 2 and {FILTER} is x,y=2,3 ):

Code: Select all

#define REMOVE_KEEP_DIE_EVENT SIDE FILTER
  [event]
    name=die
    [filter]
      side={SIDE}
      canrecruit=yes
    [/filter]
    [terrain]
      [and]
        {FILTER}
        radius=1
      [/and]
      [filter_location]
        terrain="W*^Cov,W*^Kov"
      [/filter_location]
      terrain="^"
      layer=overlay
    [/terrain]
  [/event]#enddef
and

Code: Select all

#define REMOVE_KEEP_DIE_EVENT SIDE FILTER
  [event]
    name=die
    [filter]
      side={SIDE}
      canrecruit=yes
    [/filter]
    [terrain]
      [and]
        {FILTER}
        [filter_location]
          terrain="W*^Cov,W*^Kov"
        [/filter_location]
        radius=1
      [/and]
      terrain="^"
      layer=overlay
    [/terrain]
  [/event]#enddef
yet this alternate logic version - with exactly the same {SIDE} and {FILTER} values - works as expected (or at least doesn't break anything):

Code: Select all

#define REMOVE_KEEP_DIE_EVENT SIDE FILTER
  [event]
    name=die
    [filter]
      side={SIDE}
      canrecruit=yes
    [/filter]
    [store_locations]
      [and]
        {FILTER}
        radius=1
      [/and]
      variable=remkeep_temp
      include_borders=no
    [/store_locations]
    [foreach]
      array=remkeep_temp
      [do]
        [if]
          [have_location]
            x,y=$this_item.x,$this_item.y
            terrain="W*^Cov,W*^Kov"
          [/have_location]
        [then]
          [terrain]
            x,y=$this_item.x,$this_item.y
            terrain="^"
            layer=overlay
          [/terrain]
        [/then]
        [/if]
      [/do]
    [/foreach]
    {CLEAR_VARIABLE remkeep_temp}
  [/event]#enddef
I'd much prefer to use the more elegant former version but am struggling to see how to get the nested filter to work.
I suspect my old nemesis radius might also be contributing to my problem?
Trouble is, whilst removing radius correctly nukes the keep it doesn't allow me to test if the nested filter works or not...

Any help or suggestions gratefully received!

Cheers!
-- Spannerbag
Last edited by Spannerbag on February 2nd, 2023, 12:30 pm, edited 1 time in total.
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
gnombat
Posts: 669
Joined: June 10th, 2010, 8:49 pm

Re: [terrain] and nested filter_location query

Post by gnombat »

Shouldn't the code look like the example in the wiki ([and]terrain=terrain_string_to_be_filtered_for)?

There are some examples in mainline campaigns which are similar to what you want (though not exactly the same), e.g., Sceptre of Fire here and here.
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [terrain] and nested filter_location query

Post by Celtic_Minstrel »

The [terrain] tag expects a StandardLocationFilter. [filter_location] is not documented as one of the tags that are valid inside a StandardLocationFilter, so the game is simply ignoring it.

As gnombat said, I think just using [and] alone should do the trick.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Spannerbag
Posts: 491
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [terrain] and nested filter_location query

Post by Spannerbag »

gnombat wrote: February 2nd, 2023, 1:59 am Shouldn't the code look like the example in the wiki ([and]terrain=terrain_string_to_be_filtered_for)?

There are some examples in mainline campaigns...
Many thanks for that - I did wonder if there were examples somewhere but had no idea where to look...

Celtic_Minstrel wrote: February 2nd, 2023, 7:20 am The [terrain] tag expects a StandardLocationFilter. [filter_location] is not documented as one of the tags that are valid inside a StandardLocationFilter, so the game is simply ignoring it.

As gnombat said, I think just using [and] alone should do the trick.
Yeah didn't seem right to me but what mislead me was the wiki phrase:
...filtering by terrain can be done with a nested StandardLocationFilter...

Got it working, the code needed two [and]s though, one each for [terrain] and radius.

Code: Select all

#define REMOVE_KEEP_DIE_EVENT SIDE FILTER
  [event]
    name=die
    [filter]
      side={SIDE}
      canrecruit=yes
    [/filter]
    [terrain]
      [and]
        [and]
          {FILTER}
          radius=1
        [/and]
        terrain="W*^Cov,W*^Kov"
      [/and]
      terrain="^"
      layer=overlay
    [/terrain]
  [/event]#enddef
Thanks ever so much for your help, it really helped!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply