From af0a6b73e16c959450ae206888e010d8deb02608 Mon Sep 17 00:00:00 2001 From: EricksOliveira Date: Thu, 14 Nov 2024 14:23:07 +0000 Subject: [PATCH] Fix Crashs Formation Arrow (#708) * Fix crash in formations * Crash fix: Arrow formation * Crash fix: Arrow formation looking for member information in different maps/instances. * Loop fix: arrow formation * Crash fix: Arrow formation when group isn't all in 1 place. * Fix Build --- src/strategy/values/Arrow.cpp | 23 +++++++++++++---------- src/strategy/values/Formations.cpp | 3 +++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/strategy/values/Arrow.cpp b/src/strategy/values/Arrow.cpp index 0a8afb50..b41f8b29 100644 --- a/src/strategy/values/Arrow.cpp +++ b/src/strategy/values/Arrow.cpp @@ -22,10 +22,9 @@ WorldLocation ArrowFormation::GetLocationInternal() float offset = 0.f; Player* master = botAI->GetMaster(); - if (!master) - { + if (!botAI->IsSafe(master)) return Formation::NullLocation; - } + float orientation = master->GetOrientation(); MultiLineUnitPlacer placer(orientation); @@ -43,6 +42,9 @@ WorldLocation ArrowFormation::GetLocationInternal() offset += rangedLines * sPlayerbotAIConfig->followDistance; healers.PlaceUnits(&placer); healers.Move(-cos(orientation) * offset, -sin(orientation) * offset); + + if (!masterUnit || !botUnit) + return Formation::NullLocation; float x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX(); float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); @@ -89,14 +91,15 @@ void ArrowFormation::FillSlotsExceptMaster() while (gref) { Player* member = gref->GetSource(); - - if (member == bot) - FindSlot(member)->AddLast(botUnit = new FormationUnit(index, false)); - else if (member != botAI->GetMaster()) - FindSlot(member)->AddLast(new FormationUnit(index, false)); - + if (botAI->IsSafe(member)) + { + if (member == bot) + FindSlot(member)->AddLast(botUnit = new FormationUnit(index, false)); + else if (member != botAI->GetMaster()) + FindSlot(member)->AddLast(new FormationUnit(index, false)); + ++index; + } gref = gref->next(); - ++index; } } diff --git a/src/strategy/values/Formations.cpp b/src/strategy/values/Formations.cpp index 2a38d9d1..77dc2264 100644 --- a/src/strategy/values/Formations.cpp +++ b/src/strategy/values/Formations.cpp @@ -437,6 +437,7 @@ float Formation::GetFollowAngle() { if (Player* member = ref->GetSource()) { + if (!member || member == bot || !member->IsAlive() || bot->GetMapId() != member->GetMapId()) continue; if (member != master && !botAI->IsTank(member) && !botAI->IsHeal(member)) { roster.insert(roster.begin() + roster.size() / 2, member); @@ -448,6 +449,7 @@ float Formation::GetFollowAngle() { if (Player* member = ref->GetSource()) { + if (!member || member == bot || !member->IsAlive() || bot->GetMapId() != member->GetMapId()) continue; if (member != master && botAI->IsHeal(member)) { roster.insert(roster.begin() + roster.size() / 2, member); @@ -460,6 +462,7 @@ float Formation::GetFollowAngle() { if (Player* member = ref->GetSource()) { + if (!member || member == bot || !member->IsAlive() || bot->GetMapId() != member->GetMapId()) continue; if (member != master && botAI->IsTank(member)) { if (left)