Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magiclysm: replace spell_effect_line #35345

Merged
merged 8 commits into from
Nov 23, 2019

Conversation

OrenAudeles
Copy link
Contributor

Summary

SUMMARY: Bugfixes "Fix holes in spell_effect::spell_effect_line"

Purpose of change

Previous implementation occasionally misses tiles that should be hit in some orientations.

Describe the solution

Currently does not work outside of 2D space. Allowing 3D line spells is work for the future.

  1. Get 2D delta vector
  2. Calculate square distance, if zero we can quit early. We are targeting self.
  3. Calculate clockwise perpendicular vector from delta vector
  4. Find primary axis (north, east, south, west) of delta vector, and from that its clockwise perpendicular axis
  5. Calculate clockwise and counter/anti-clockwise axis leg lengths, modify further if distance metric is non-circular
  6. Get orientation of delta vector relative to primary axis. This signifies which leg is behind or in front of the clockwise perpendicular axis
  7. Get a canonical tile path along delta vector, pop off the endpoint and insert the origin at the beginning. This is done so that we can walk along the path easily.
  8. Fill tile path between the source and target points using the line walker
  9. Dependant on the orientation found in (6), fill paths for clockwise and counter clockwise legs.

Testing

Tossed around some Megablast spells in a group of zombies, did not see holes where there shouldn't be holes.

Additional context

All targeting a tile diagonally away from the Player to most easily demonstrate holes in current implementation

  • Current Implementation: Without Circular Distance metric
    cropped-master-circdist-false
  • Current Implementation: With Circular Distance Metric
    cropped-master-circdist-true
  • PR Implementation: Without Circular Distance Metric
    cropped-pr-circdist-false
  • PR Implementation: With Circular Distance Metric
    cropped-pr-circdist-true

@KorGgenT KorGgenT added [C++] Changes (can be) made in C++. Previously named `Code` Mods: Magiclysm Anything to do with the Magiclysm mod labels Nov 6, 2019
@KorGgenT KorGgenT self-assigned this Nov 6, 2019
@OrenAudeles
Copy link
Contributor Author

@KorGgenT I think the blah & name stuff was the result of astyle being weird with lambda. Issue disappeared when I converted the lambda into functions.

// Orientation of point C relative to line AB
static int side_of( const point &a, const point &b, const point &c )
{
int cross = ( ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int cross = ( ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x ) );
const int cross = ( ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x ) );

@KorGgenT KorGgenT removed their assignment Nov 9, 2019
@KorGgenT KorGgenT merged commit efbacc3 into CleverRaven:master Nov 23, 2019
@OrenAudeles OrenAudeles deleted the magiclysm_spell_line branch January 10, 2023 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Mods: Magiclysm Anything to do with the Magiclysm mod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants