void CheckGridPoint(Vector3 target) { //check if out of bounds //first check if own side var b = map.AreaOwnerAtPoint(Utility.GetNearestPointOnGrid(target)); //check if there is a wall var w = Physics.OverlapBox(target, (Vector3.one * 0.1f), Quaternion.identity, walls); // check if there is a turret var t = Physics.OverlapBox(target, (Vector3.one * 0.1f), Quaternion.identity, turret); // checkk if there is the castle var c = Physics.OverlapBox(target, (Vector3.one * 0.1f), Quaternion.identity, castle); if ((w.Length > 0) || (t.Length > 0) || (c.Length > 0) || (b != pm.id)) { clear = false; } else { clear = true; } }
public bool FloodFillPlayerArea(Vector2Int startingPoint, int playerID) { // This is where we store the found points that we'll fill HashSet <Vector2Int> filled = new HashSet <Vector2Int>(); // This is where we store the places that still need to be // checked for expanding the floodfill var fringe = new List <Vector2Int>(); fringe.Add(startingPoint); var dirOffsets = new Vector2Int[] { Vector2Int.left, Vector2Int.up, Vector2Int.right, Vector2Int.down }; // process remaining points as long as there are any while (fringe.Count > 0) { // we always take out the last one first (more efficient) var point = fringe[fringe.Count - 1]; fringe.RemoveAt(fringe.Count - 1); // check if this point should be disqualified for fill for any reason: // if this was already filled, move on to checking the next point if (filled.Contains(point)) { continue; } // if this is outside the grid or in unusable space, also disqualified if (map.AreaOwnerAtPoint(point) == -1) { return(false); } var checkForWalls = Physics.OverlapBox(new Vector3(point.x, 0, point.y), boxsize, Quaternion.identity, walls); if (checkForWalls.Length > 0) { continue; } // add point to filled, then queue up the next points to try to expand filled.Add(point); for (int i = 0; i < 4; i++) { var neighbor = point + dirOffsets[i]; fringe.Add(neighbor); } } // now we can do whatever with the points we found foreach (var point in filled) { var checkForIndicator = Physics.OverlapBox(new Vector3(point.x, 0, point.y), boxsize, Quaternion.identity, indicators); if (checkForIndicator.Length > 0) { continue; } else { var indi = Instantiate(indicator, new Vector3(point.x, 0, point.y), Quaternion.identity); } } //foreach (var script in pms) { // var id = script.id; // if (id == playerID) { // script.loosing = false; // }continue; //} return(true); }