Fix for IndexOutOfRange exceptions during map generation caused by very large wall cells near the entrance of the level (example seed: i1qecA7V)

This commit is contained in:
Joonas Rikkonen
2017-06-20 21:19:04 +03:00
parent d2ab71b07d
commit db9a77fb25

View File

@@ -257,8 +257,20 @@ namespace Barotrauma
var targetCells = new List<VoronoiCell>();
for (int i = 0; i < pathNodes.Count; i++)
{
int cellIndex = FindCellIndex(pathNodes[i], cells, cellGrid, gridCellSize, 2, gridOffset);
targetCells.Add(cells[cellIndex]);
//a search depth of 2 is large enough to find a cell in almost all maps, but in case it fails, we increase the depth
int searchDepth = 2;
while (searchDepth < 5)
{
int cellIndex = FindCellIndex(pathNodes[i], cells, cellGrid, gridCellSize, searchDepth, gridOffset);
if (cellIndex > -1)
{
targetCells.Add(cells[cellIndex]);
break;
}
searchDepth++;
}
}
return GeneratePath(targetCells, cells, cellGrid, gridCellSize, limits, wanderAmount, mirror);