Ability with relative facing
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
Ability with relative facing
Hi,
Woking on some custom abilities;
How to check if unit is attacked from the face/right-face/left-face side before combat in formula?
(I'd like to increase unit's resistance/damage if it's attacked from the front)
FACE HEXES: those pikemans are on
BACK HEXES: those Assassins are on
Woking on some custom abilities;
How to check if unit is attacked from the face/right-face/left-face side before combat in formula?
(I'd like to increase unit's resistance/damage if it's attacked from the front)
FACE HEXES: those pikemans are on
BACK HEXES: those Assassins are on
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Ability with relative facing
I'm sure there's a more elegant way to do this, but...
You dwarf is facing NE. Therefore, if (enemy.x>unit.x) or (enemy.x==unit.x and enemy.y>unit.y) then front=true.
I assume there will be special cases due to the hex coordinate system, but you can still brute force it easy enough if you think through them.
EDIT: Ignore this. You can do it with WFL. Looks like it would be pretty easy once you figure it out. See https://wiki.wesnoth.org/Wesnoth_Formul ... _Functions
You dwarf is facing NE. Therefore, if (enemy.x>unit.x) or (enemy.x==unit.x and enemy.y>unit.y) then front=true.
I assume there will be special cases due to the hex coordinate system, but you can still brute force it easy enough if you think through them.
EDIT: Ignore this. You can do it with WFL. Looks like it would be pretty easy once you figure it out. See https://wiki.wesnoth.org/Wesnoth_Formul ... _Functions
Last edited by white_haired_uncle on June 20th, 2024, 8:34 pm, edited 2 times in total.
Speak softly, and carry Doombringer.
Re: Ability with relative facing
Face hex means n,ne,se, so you could check if relative position between units is one of them.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Ability with relative facing
Thanks I can use direction_from to get the faced hex and then tiles that are adjacent to both the unit and the faced hex are face-hexes and rest are back hexes.white_haired_uncle wrote: ↑June 20th, 2024, 8:19 pm EDIT: Ignore this. You can do it with WFL. Looks like it would be pretty easy once you figure it out. See https://wiki.wesnoth.org/Wesnoth_Formul ... _Functions
But how to put it into weapon special/ability?
Since facing of the defender changes when the fight begins.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Ability with relative facing
I was thinking about using direction_from to get the faced hex, then using direction_from with rotate_loc_around +1 and -1 on facing to get the others, but adjacent sounds like it would work too.ZombieKnight wrote: ↑June 21st, 2024, 4:49 amThanks I can use direction_from to get the faced hex and then tiles that are adjacent to both the unit and the faced hex are face-hexes and rest are back hexes.white_haired_uncle wrote: ↑June 20th, 2024, 8:19 pm EDIT: Ignore this. You can do it with WFL. Looks like it would be pretty easy once you figure it out. See https://wiki.wesnoth.org/Wesnoth_Formul ... _Functions
But how to put it into weapon special/ability?
Since facing of the defender changes when the fight begins.
Here's an example of a weapon special that uses WFL and direction_from that might help...
https://github.com/Dugy/Legend_of_the_I ... #L569-L600
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Ability with relative facing
Thats something else.white_haired_uncle wrote: ↑June 21st, 2024, 11:13 am Here's an example of a weapon special that uses WFL and direction_from that might help...
https://github.com/Dugy/Legend_of_the_I ... #L569-L600
I t only checks if theres a unit on the other side of the target.
It doesn't work with the defenders unit facing.
And I don't know how to filter that...
Any ideas?
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Ability with relative facing
Yes, it's something else. It's just an example meant to show using facing and direction_from in a weapon special.
I assume to get defender's unit facing you'd move other.facing into [filter_self], or use self.facing in [filter_opponent].
I assume to get defender's unit facing you'd move other.facing into [filter_self], or use self.facing in [filter_opponent].
Speak softly, and carry Doombringer.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Ability with relative facing
But won't that relative facing set to face the attacker at the very start of the fight?white_haired_uncle wrote: ↑June 21st, 2024, 3:24 pm Yes, it's something else. It's just an example meant to show using facing and direction_from in a weapon special.
I assume to get defender's unit facing you'd move other.facing into [filter_self], or use self.facing in [filter_opponent].
...
So you can't filter if he was attacked from his back side.