Skip to content

Commit

Permalink
Spell: Tryfix trajectory distance calculation by using 2d distance
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jun 21, 2023
1 parent 6d84234 commit afc0f71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,23 @@ float Position::GetDistance(Position const& other) const
return distsq;
}

float Position::GetDistance2d(Position const& other) const
{
float dx = GetPositionX() - other.GetPositionX();
float dy = GetPositionY() - other.GetPositionY();
float distsq = dx * dx + dy * dy;

return distsq;
}

void Position::RelocateOffset(Position const& offset)
{
x = GetPositionX() + (offset.GetPositionX() * std::cos(GetPositionO()) + offset.GetPositionY() * std::sin(GetPositionO() + float(M_PI)));
y = GetPositionY() + (offset.GetPositionY() * std::cos(GetPositionO()) + offset.GetPositionX() * std::sin(GetPositionO()));
z = GetPositionZ() + offset.GetPositionZ();
o = GetPositionO() + offset.GetPositionO();
}

std::string Position::to_string() const
{
return "X: " + std::to_string(x) + " Y: " + std::to_string(y) + " Z: " + std::to_string(z) + " O: " + std::to_string(o);
Expand Down
2 changes: 2 additions & 0 deletions src/game/Entities/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ struct Position
bool IsEmpty() const { return x == 0.f && y == 0.f && z == 0.f; }
float GetAngle(const float x, const float y) const;
float GetDistance(Position const& other) const; // WARNING: Returns squared distance for performance reasons
float GetDistance2d(Position const& other) const; // WARNING: Returns squared distance for performance reasons
void RelocateOffset(Position const& offset);
std::string to_string() const;
};

Expand Down
1 change: 1 addition & 0 deletions src/game/Spells/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class SpellCastTargets
Position getDestination() const { return m_destPos; }
void getDestination(WorldLocation& loc) { loc.coord_x = m_destPos.x; loc.coord_y = m_destPos.y; loc.coord_z = m_destPos.z; }
void getSource(float& x, float& y, float& z) const { x = m_srcPos.x; y = m_srcPos.y; z = m_srcPos.z; }
Position getSource() const { return m_srcPos; }

void setGOTarget(GameObject* target);
ObjectGuid getGOTargetGuid() const { return m_GOTargetGUID; }
Expand Down

0 comments on commit afc0f71

Please sign in to comment.