WFL get adjecent units
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.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
WFL get adjecent units
Hi,
I'm new to WFL.
Do you know how to get all adjacent units, fulfilling certain conditions(enemy=yes)?
(I don't really need to store them, I need sum(count)of them)
I'm new to WFL.
Do you know how to get all adjacent units, fulfilling certain conditions(enemy=yes)?
(I don't really need to store them, I need sum(count)of them)
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: WFL get adjecent units
WFL? You couldn't just use [store_unit] and a filter to store them to an array and then take its length?
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: WFL get adjecent units
Yes,...white_haired_uncle wrote: ↑May 24th, 2024, 9:07 pm WFL? You couldn't just use [store_unit] and a filter to store them to an array and then take its length?
But not inside [ability][damage]
Maybe I could use lua somehow?
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: WFL get adjecent units
inside [abilities][damage] ? (not [ability]).
You MIGHT be able to use [filter_adjacent] https://wiki.wesnoth.org/AbilitiesWML#C ... on_special if you're looking to do something specific like unit is adjacent to exactly one enemy.
I don't know what you're trying to do, but I suspect you'll end up creating attacker_hits/defender_hits events filtering on ability= and using [harm_unit].
You MIGHT be able to use [filter_adjacent] https://wiki.wesnoth.org/AbilitiesWML#C ... on_special if you're looking to do something specific like unit is adjacent to exactly one enemy.
I don't know what you're trying to do, but I suspect you'll end up creating attacker_hits/defender_hits events filtering on ability= and using [harm_unit].
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: WFL get adjecent units
I'd like to [damage] add = $($number_of_adjacent-enemies - 1)white_haired_uncle wrote: ↑May 25th, 2024, 6:47 am You MIGHT be able to use [filter_adjacent] https://wiki.wesnoth.org/AbilitiesWML#C ... on_special if you're looking to do something specific like unit is adjacent to exactly one enemy.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: WFL get adjecent units
This works but only for max +1 damage
Code: Select all
[damage]
id=battle_frenzy
name= _ "battle frenzy"
female_name= _ "female^battle frenzy"
description=_ "When in the heat of battle, this unit enters a state of frenzy, significantly increasing its attack power.
"
special_note=_ "TODO"
add=1
affect_self=yes
apply_to=self
[filter_self]
[filter_adjacent]
is_enemy=yes
count=2-6
[/filter_adjacent]
[/filter_self]
[/damage]
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: WFL get adjecent units
At the beginning of the attack and every attacker_hits/defender_hits, check the number of adjacent units and adjust the damage accordingly.
(or something close to that)
Code: Select all
$stored_unit.abilities.damage[$i].add, where $stored_unit.abilities.damage$[i].id=="battle_frenzy"
Speak softly, and carry Doombringer.
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: WFL get adjecent units
If you need to do this all in a single formula, I think something like the following should work (untested):ZombieKnight wrote: ↑May 24th, 2024, 6:30 pm Do you know how to get all adjacent units, fulfilling certain conditions(enemy=yes)?
Code: Select all
size( filter( filter( map( adjacent_locs(loc(x,y)), 'loc', unit_at(loc)), 'maybe_unit', maybe_unit != null()), hitpoints < max_hitpoints / 2))
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: WFL get adjecent units
Poor, there's no easy formula for it...
Since there's a max of 6 adjacent units, I've made a workaround with 5 abilities, each for count 2,3,4,5, or 6.
Thanks...
1 Could you explain me how is that supposed to work.
2 Why you count hitpoints there?
Thanks
Since there's a max of 6 adjacent units, I've made a workaround with 5 abilities, each for count 2,3,4,5, or 6.
Thanks...
Out of curiosity (and I'd really like to learn WFL),Celtic_Minstrel wrote: ↑May 27th, 2024, 12:34 amCode: Select all
size( filter( filter( map( adjacent_locs(loc(x,y)), 'loc', unit_at(loc)), 'maybe_unit', maybe_unit != null()), hitpoints < max_hitpoints / 2))
1 Could you explain me how is that supposed to work.
2 Why you count hitpoints there?
Thanks
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: WFL get adjecent units
ZombieKnight wrote: ↑May 27th, 2024, 5:39 am Out of curiosity (and I'd really like to learn WFL),
1 Could you explain me how is that supposed to work.
adjacent_locs(loc(x,y)
gets all the locations adjacent to the unit under consideration (x,y is equivalent to self.x,self.y here).map(..., 'loc', unit_at(loc))
converts the list of locations to a list of the units on those locations (with a null for empty hexes).filter(..., 'maybe_unit', maybe_unit != null())
removes all the nulls from the list so you have only units remaining.filter(..., hitpoints < max_hitpoints / 2)
filters the list down to units with less than half their hitpoints.size(...)
returns the length of the resulting list.
That was just a random condition I threw in. It could be replaced with pretty much anything you want. I think you originally said you wanted to filter for enemies, so that would probably look like
'unit', enemy_of(self, unit)
instead of hitpoints < max_hitpoints / 2
.- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: WFL get adjecent units
Interesting!
Had no idea it can work like this. ^^
Had no idea it can work like this. ^^
-
- Posts: 581
- Joined: August 4th, 2019, 5:27 pm
- Contact:
Re: WFL get adjecent units
Seems like WFL is a functional programming language inside Wesnoth. Haven't really thought about it that way beforeCeltic_Minstrel wrote: ↑May 27th, 2024, 12:34 am If you need to do this all in a single formula, I think something like the following should work (untested):
Code: Select all
size( filter( filter( map( adjacent_locs(loc(x,y)), 'loc', unit_at(loc)), 'maybe_unit', maybe_unit != null()), hitpoints < max_hitpoints / 2))
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: WFL get adjecent units
Yes, it's a pure functional language inside Wesnoth (pure meaning that there are no functions with side-effects).