Skip to content

Commit

Permalink
-Crash fix: When looking at random-teleport locations beyond 200000 y…
Browse files Browse the repository at this point in the history
…ards.
  • Loading branch information
mostlikely4r committed Feb 9, 2024
1 parent aa487fc commit b4702eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 11 additions & 0 deletions playerbot/TravelMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,17 @@ vector<WorldPosition*> TravelMgr::getNextPoint(WorldPosition* center, vector<Wor

std::transform(retVec.begin(), retVec.end(), std::back_inserter(weights), [center](WorldPosition* point) { return 200000 / (1 + point->distance(*center)); });

//If any weight is 0 add 1 to all weights.
for (auto& w : weights)
{
if (w > 0)
continue;

std::for_each(weights.begin(), weights.end(), [](uint32& d) { d += 1; });
break;

}

std::mt19937 gen(time(0));

weighted_shuffle(retVec.begin(), retVec.end(), weights.begin(), weights.end(), gen);
Expand Down
8 changes: 0 additions & 8 deletions playerbot/TravelMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,6 @@ namespace ai
, W first_weight, W last_weight
, URBG&& g)
{
//Only shuffle if there is atleast 1 non-zero value.
W check_weight = first_weight;
while (check_weight != last_weight && !*check_weight)
++check_weight;

if (check_weight == last_weight)
return;

while (first != last && first_weight != last_weight)
{
std::discrete_distribution<int> dd(first_weight, last_weight);
Expand Down

0 comments on commit b4702eb

Please sign in to comment.