[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;
}
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<Position>& positions)