Ability with relative facing

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
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Ability with relative facing

Post by ZombieKnight »

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
Screenshot_20240620_194858.png
Screenshot_20240620_194858.png (139.11 KiB) Viewed 1180 times
white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Ability with relative facing

Post by white_haired_uncle »

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
Last edited by white_haired_uncle on June 20th, 2024, 8:34 pm, edited 2 times in total.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3314
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Ability with relative facing

Post by Ravana »

Face hex means n,ne,se, so you could check if relative position between units is one of them.
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Ability with relative facing

Post by ZombieKnight »

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
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.

But how to put it into weapon special/ability?
Since facing of the defender changes when the fight begins.
white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Ability with relative facing

Post by white_haired_uncle »

ZombieKnight wrote: June 21st, 2024, 4:49 am
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
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.

But how to put it into weapon special/ability?
Since facing of the defender changes when the fight begins.
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.

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.
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Ability with relative facing

Post by ZombieKnight »

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

Re: Ability with relative facing

Post by white_haired_uncle »

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].
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Ability with relative facing

Post by ZombieKnight »

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].
But won't that relative facing set to face the attacker at the very start of the fight?
...
So you can't filter if he was attacked from his back side.
Post Reply