fheroes2 icon indicating copy to clipboard operation
fheroes2 copied to clipboard

Support 8-directions of attack for wide creatures

Open usidedown opened this issue 7 months ago • 16 comments

Solves #3411 attacks

Adds mouse cursor for top/bottom attacks: vlcsnap-2025-05-26-08h54m27s175 vlcsnap-2025-05-26-08h53m34s489

Adds attacks originating from "tail" direction: vlcsnap-2025-05-26-08h54m32s402

usidedown avatar May 26 '25 06:05 usidedown

Hi @usidedown what worries me here is that two concepts are mixed up here: the concept of "vertical attack" in the battle UI (which is OK) and the concept of the "vertical direction of the neighboring cell", which doesn't really exist, because, if you take a look at the battlefield, there is in fact no neighboring cells with a strictly vertical direction. For instance, the Battle::Board::GetIndexDirection() will not be able to return anything sane for such a direction. We IMHO need to separate these concepts somehow, rather than create some kind of "fake" cell directions that nothing corresponds to.

oleg-derevenetz avatar May 26 '25 07:05 oleg-derevenetz

Also I suppose it is impossible to use the swipe mechanics (intended for relatively small touchscreen devices) with these additional directions, right?

oleg-derevenetz avatar May 26 '25 13:05 oleg-derevenetz

Hi @usidedown what worries me here is that two concepts are mixed up here: the concept of "vertical attack" in the battle UI (which is OK) and the concept of the "vertical direction of the neighboring cell", which doesn't really exist, because, if you take a look at the battlefield, there is in fact no neighboring cells with a strictly vertical direction. For instance, the Battle::Board::GetIndexDirection() will not be able to return anything sane for such a direction. We IMHO need to separate these concepts somehow, rather than create some kind of "fake" cell directions that nothing corresponds to.

Yes you're right, attack directions and cell directions are mixed all around. I'll take a look.

Also I suppose it is impossible to use the swipe mechanics (intended for relatively small touchscreen devices) with these additional directions, right?

Right again! You can attack in 6 directions using swipe. Top and bottom require a little bit more finesse. I'll see what I can do.

usidedown avatar May 26 '25 16:05 usidedown

@oleg-derevenetz I introduced CellDirection and AttackDirection types. They are similar but CellDirection includes only the 6 directions whereas AttackDirections allows for Top and Bottom attacks. Let me know what you think.

Swipe controls currently have trouble with Top/Bottom because they are hex based. Fixing this would require a fundamental change in the way swipe works. I think it should be done in a separate PR.

usidedown avatar May 28 '25 08:05 usidedown

@oleg-derevenetz Thank you so much for your fixes!

OK. It may not be possible to do this in a convenient way at all, because the hexes are relatively large and the space to indicate the top/bottom attack is relatively small.

I'm still thinking about it but instead of using source and destination Hexes we can use pixel coordinates. A source + dest points give a vector. It can then be compared to the 8 directions. This way I think it's possible to create 8 equal directions. It's all very preliminary though.

usidedown avatar May 28 '25 18:05 usidedown

A source + dest points give a vector. It can then be compared to the 8 directions. This way I think it's possible to create 8 equal directions.

There are difficulties with this - the hexes are at least visible on the screen, but these directions are somewhat imaginary, and they are smaller then the hexes (because there are 6 hexes but 8 directions). I'm not sure if this will be convenient.

oleg-derevenetz avatar May 28 '25 18:05 oleg-derevenetz

Hi @usidedown I just made a few more changes, mainly related to improving the clarity of the code by using more "descriptive" names and comments, and by streamlining the logic a bit in a few places. Could you please take a look when you have time?

oleg-derevenetz avatar May 29 '25 11:05 oleg-derevenetz

Hi @usidedown I just made a few more changes, mainly related to improving the clarity of the code by using more "descriptive" names and comments, and by streamlining the logic a bit in a few places. Could you please take a look when you have time?

@oleg-derevenetz Thank you so much for your improvements! Looks good to me.

usidedown avatar May 29 '25 15:05 usidedown

Hi @Districh-ru. Thank you for taking the time to test this!

I'm afraid I didn't understand the problem, the behavior I see in the video isn't changed from the master branch. The only difference is the cursor which is now pointing upwards instead of top-left.

You can see that with the (new) tail attack the behavior is also as expected:

https://github.com/user-attachments/assets/446ad37d-a904-458d-98c5-4aa653bb3f90

And also a wishlist for the future (not this PR :) ): It'll be good if we can choose the direction of the 2-cell up/down attack: to attack the upper(lower) cell and left or right cell.

I noticed these 2 extra directions, but AFAIK the original game does not allow them.

usidedown avatar May 29 '25 15:05 usidedown

@usidedown, in the master branch the Phoenix flies to the cell (form left to right), then turns around (changes direction from right to left) and performs diagonal attack from left to right. In this PR Phoenix does not turn around before attacking so by the animation he performs diagonal attack from left to right (burns the bushes) while the damage is applied to the Archers that are not under the fire of Phoenix (by the shown animation).

Districh-ru avatar May 29 '25 16:05 Districh-ru

@Districh-ru Perhaps I am missing something? This is the behavior I get with 1.1.8 release:

https://github.com/user-attachments/assets/95d16807-0216-4425-b558-04552eb5da10

usidedown avatar May 29 '25 16:05 usidedown

изображение

The animation shows that the Phoenix attacks from bottom-left to top-right (the arrow) and the damage is applied to the Archers that are in the top-left direction from the Phoenix and are not under the drawn fire. ~The rotation of wide creature before such attack is missing now. :(~

I'll check the code later..

Districh-ru avatar May 29 '25 16:05 Districh-ru

@usidedown, you are right, we have this issue in the master build including v.1.1.8 release. I did more tests of the master build and this PR and the behavior for two-cells attack is almost the same. My bad. Previously I did not pay so much attention to this animation.

This issue is outside of the scope of this PR and it can be fixed later.

Districh-ru avatar May 30 '25 06:05 Districh-ru

@Districh-ru thank you so much for taking the time to review this

usidedown avatar May 30 '25 07:05 usidedown

Hi @usidedown , could you please resolve merge conflicts for this pull request?

ihhub avatar Jun 06 '25 07:06 ihhub

I am moving this pull request to the next release as we made code freeze for any features for the upcoming release.

ihhub avatar Jun 07 '25 15:06 ihhub

Hi @ihhub, could you take a look at this PR when you have the time? Is there more work to be done here?

usidedown avatar Jun 21 '25 08:06 usidedown

@usidedown , huge thanks for this feature!

ihhub avatar Jun 21 '25 16:06 ihhub

@usidedown and @oleg-derevenetz a user reported a bug that 2 hex creatures can't attack in the down left direction if a creature is standing to their left. The user says it's version 1.1.9 but I suppose it's a snapshot build from after this PR got merged because you can see a sword pointing straight downwards (?).

https://youtu.be/ZBNs2IPo1zc?si=4Kp0lspH9ZMZYVus

No save is provided but I can request one if needed.

Edit: They've confirmed that this is a snapshot build.

zenseii avatar Jun 24 '25 08:06 zenseii

a user reported a bug that 2 hex creatures can't attack in the down left direction if a creature is standing to their left. The user says it's version 1.1.9 but I suppose it's a snapshot build from after this PR got merged because you can see a sword pointing straight downwards (?).

https://youtu.be/ZBNs2IPo1zc?si=4Kp0lspH9ZMZYVus

No save is provided but I can request one if needed.

Edit: They've confirmed that this is a snapshot build.

Yeah, there would be an assertion failure in debug build. In regular build, the attack just won't work :)

oleg-derevenetz avatar Jun 24 '25 10:06 oleg-derevenetz