StandardUnitFilter, adjacent to tile

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

StandardUnitFilter, adjacent to tile

Post by white_haired_uncle »

I'm firing a catapult in the general direction of a hero, though it actually hits somewhere within a small radius. This means there's no guarantee that there is a unit where it hits. Wherever it actually hits, I want any unit on that tile to take 12 damage, and any unit on an adjacent TILE to take 6. The second harm_unit in the following doesn't seem to work when $hit_locs[$i].x,$hit_locs[$i].y does not contain a unit.

I'm wondering what [filter_adjacent] means. I now think it means "adjacent to the unit at...", while I was originally hoping it meant "adjacent to the tile at ...". If I'm correct, is there a simple solution, or do I just have to iterate over [store_location] x,y... radius=1 ?

Code: Select all

                [harm_unit]
                    [filter]
                        x,y=$hit_locs[$i].x,$hit_locs[$i].y
                    [/filter]
                    damage_type=impact
                    amount=12
                    posioned=yes
                    animate=yes
                [/harm_unit]
                [harm_unit]
                    [filter]
                        [filter_adjacent]
                            x,y=$hit_locs[$i].x,$hit_locs[$i].y
                        [/filter_adjacent]
                    [/filter]
                    damage_type=impact
                    amount=6
                    posioned=yes
                    animate=yes
                [/harm_unit]
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3057
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: StandardUnitFilter, adjacent to tile

Post by Ravana »

filter_adjacent -> filter_location+radius should work.
white_haired_uncle
Posts: 1258
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: StandardUnitFilter, adjacent to tile

Post by white_haired_uncle »

Thanks, I think I see what's up now.

I assume if I wanted to match ONLY adjacent I'd do something like:

Code: Select all

[harm_unit]
    [filter]
         [filter_location]
              x,y=$hit_locs[$i].x,$hit_locs[$i].y
              radius=1
              [not]
                  radius=0
              [/not]
         [/filter_location]
    [/filter]
or

Code: Select all

[harm_unit]
    [filter]
         [filter_location]
              x,y=$hit_locs[$i].x,$hit_locs[$i].y
              radius=1
         [/filter_location]
         [filter_location]
         [not]
                x,y=$hit_locs[$i].x,$hit_locs[$i].y  
         [/not]
    [/filter]
or

Code: Select all

[harm_unit]
    [filter]
         [filter_location]
              x,y=$hit_locs[$i].x,$hit_locs[$i].y
              radius=1
         [/filter_location]
         [not]
              [filter_location]
                  x,y=$hit_locs[$i].x,$hit_locs[$i].y 
              [filter_location] 
         [/not]
    [/filter]
Obviously I struggle with the syntax a bit, especially when radius is involved.

The first example is of particular interest to me (in the general case, not necessarily for this example). As I understand it, radius=N actually means radius<=N, so if I want (the correct) radius=N I'd need to do 'radius=N and not radius=N-1'.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3057
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: StandardUnitFilter, adjacent to tile

Post by Ravana »

I would avoid multiple radius.

Code: Select all

[harm_unit]
    [filter]
              [not]
                  x,y=$hit_locs[$i].x,$hit_locs[$i].y
              [/not]
         [filter_location]
              x,y=$hit_locs[$i].x,$hit_locs[$i].y
              radius=1
         [/filter_location]
    [/filter]
There is also filter_adjacent_location, but you would have to consult documentation to know if it fits use case.
User avatar
Celtic_Minstrel
Developer
Posts: 2260
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: StandardUnitFilter, adjacent to tile

Post by Celtic_Minstrel »

I think I would suggest using [filter_adjacent_location] instead of [filter_adjacent]. As you suspected, [filter_adjacent] requires a unit to be present (it is, after all, part of StandardUnitFilter).

Something like this (untested):

Code: Select all

[harm_unit]
	[filter_location]
		[filter_adjacent_location]
			x,y=$hit_locs[$i].x,$hit_locs[$i].y
		[/filter_adjacent_location]
	[/filter_location]
[/harm_unit]
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply