From 2756664b7733b4b360faada7449f17cadedfbbef Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 24 Sep 2024 20:34:18 +0800 Subject: [PATCH] [Tank face] Improve angle calculation --- src/strategy/actions/MovementActions.cpp | 18 +++++++++++++----- src/strategy/values/IsFacingValue.cpp | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index f8600b63..9b5214e5 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -2242,7 +2242,9 @@ float CombatFormationMoveAction::AverageGroupAngle(Unit* from, bool ranged, bool { return 0.0f; } - float average = 0.0f; + // float average = 0.0f; + float sumX = 0.0f; + float sumY = 0.0f; int cnt = 0; Group::MemberSlotList const& groupSlot = group->GetMemberSlots(); for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++) @@ -2262,11 +2264,17 @@ float CombatFormationMoveAction::AverageGroupAngle(Unit* from, bool ranged, bool continue; cnt++; - average += from->GetAngle(member); + sumX += member->GetPositionX() - from->GetPositionX(); + sumY += member->GetPositionY() - from->GetPositionY(); } - if (cnt) - average /= cnt; - return average; + if (cnt == 0) + return 0.0f; + + // unnecessary division + // sumX /= cnt; + // sumY /= cnt; + + return atan2(sumY, sumX); } Position CombatFormationMoveAction::GetNearestPosition(const std::vector& positions) diff --git a/src/strategy/values/IsFacingValue.cpp b/src/strategy/values/IsFacingValue.cpp index 9ac841d6..c3e62586 100644 --- a/src/strategy/values/IsFacingValue.cpp +++ b/src/strategy/values/IsFacingValue.cpp @@ -4,6 +4,7 @@ */ #include "IsFacingValue.h" +#include #include "Playerbots.h" @@ -13,5 +14,5 @@ bool IsFacingValue::Calculate() if (!target) return false; - return bot->HasInArc(CAST_ANGLE_IN_FRONT, target); + return bot->HasInArc(M_PI_2, target); }