public IList <Vector2Int> GetFirstLongestNaturalLine(IList <Vector2Int> jumpPoints, Func <Vector2Int, bool> isWalkable) { if (jumpPoints.Count == 1) { return(jumpPoints); } IList <Vector2Int> naturalJumpPoints = GetNaturalJumpPoints(jumpPoints); if (naturalJumpPoints.Count == 2) { return(_bresenhamLineCreator.GetBresenhamLine(jumpPoints[0].x, jumpPoints[0].y, jumpPoints[1].x, jumpPoints[1].y, -1, isWalkable, false)); } IList <Vector2Int> firstThreeNaturalJumpPoints = naturalJumpPoints.Take(3).ToList(); Vector2Int firstJumpPoint = firstThreeNaturalJumpPoints[0]; Vector2Int rangeCheckBeginning = firstThreeNaturalJumpPoints[1]; Vector2Int rangeCheckEnd = firstThreeNaturalJumpPoints[2]; IList <Vector2Int> rangeToCheck = // note that it's going from range end to range beginning _bresenhamLineCreator.GetBresenhamLine(rangeCheckEnd.x, rangeCheckEnd.y, rangeCheckBeginning.x, rangeCheckBeginning.y, -1, position => true); IList <Vector2Int> naturalWay = null; foreach (Vector2Int checkedPosition in rangeToCheck) { IList <Vector2Int> bresenhamLineToChecked = _bresenhamLineCreator.GetBresenhamLine(firstJumpPoint.x, firstJumpPoint.y, checkedPosition.x, checkedPosition.y, -1, isWalkable, false); bool clearWayToThirdExists = bresenhamLineToChecked.Any() && bresenhamLineToChecked.Last() == checkedPosition; if (clearWayToThirdExists) { naturalWay = bresenhamLineToChecked; break; } } return(naturalWay); }
public HashSet <Vector2Int> CalculateFov(Vector2Int fovCenter, int rayLength, Func <Vector2Int, bool> isWalkable) { var visibleTiles = new HashSet <Vector2Int>(); HashSet <Vector2Int> outlineToCastRaysOn = _fovSquareOutlineCreator.CreateSquareOutline(fovCenter, rayLength); foreach (Vector2Int point in outlineToCastRaysOn) { IList <Vector2Int> bresenhamLineTiles = _bresenhamLineCreator.GetBresenhamLine(fovCenter.x, fovCenter.y, point.x, point.y, rayLength, isWalkable); visibleTiles.UnionWith(bresenhamLineTiles); } IEnumerable <Vector2Int> visibleTilesFromPostProcessing = _basicFovPostprocessor.PostprocessBasicFov(visibleTiles, fovCenter, rayLength, isWalkable); visibleTiles.UnionWith(visibleTilesFromPostProcessing); return(visibleTiles); }
public bool ClearWayExistsLongDistanceNoBLockingActors(Vector2Int from, Vector2Int to) { IList <Vector2Int> line = _bresenhamLineCreator.GetBresenhamLine(from.x, from.y, to.x, to.y, -1, _gridInfoProvider.IsWalkable); return(line.Last() == to); }