[Tank face] Improve angle calculation

This commit is contained in:
Yunfan Li
2024-09-24 20:34:18 +08:00
parent eea652f5d5
commit 2756664b77
2 changed files with 15 additions and 6 deletions

View File

@@ -2242,7 +2242,9 @@ float CombatFormationMoveAction::AverageGroupAngle(Unit* from, bool ranged, bool
{ {
return 0.0f; return 0.0f;
} }
float average = 0.0f; // float average = 0.0f;
float sumX = 0.0f;
float sumY = 0.0f;
int cnt = 0; int cnt = 0;
Group::MemberSlotList const& groupSlot = group->GetMemberSlots(); Group::MemberSlotList const& groupSlot = group->GetMemberSlots();
for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++) for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++)
@@ -2262,11 +2264,17 @@ float CombatFormationMoveAction::AverageGroupAngle(Unit* from, bool ranged, bool
continue; continue;
cnt++; cnt++;
average += from->GetAngle(member); sumX += member->GetPositionX() - from->GetPositionX();
sumY += member->GetPositionY() - from->GetPositionY();
} }
if (cnt) if (cnt == 0)
average /= cnt; return 0.0f;
return average;
// unnecessary division
// sumX /= cnt;
// sumY /= cnt;
return atan2(sumY, sumX);
} }
Position CombatFormationMoveAction::GetNearestPosition(const std::vector<Position>& positions) Position CombatFormationMoveAction::GetNearestPosition(const std::vector<Position>& positions)

View File

@@ -4,6 +4,7 @@
*/ */
#include "IsFacingValue.h" #include "IsFacingValue.h"
#include <cmath>
#include "Playerbots.h" #include "Playerbots.h"
@@ -13,5 +14,5 @@ bool IsFacingValue::Calculate()
if (!target) if (!target)
return false; return false;
return bot->HasInArc(CAST_ANGLE_IN_FRONT, target); return bot->HasInArc(M_PI_2, target);
} }