public void OnMapObstacleBreak(int mapX, int mapY) { int startX = WorldToGrid(mapX); int startY = WorldToGrid(mapY); int endX = startX + resolution; int endY = startY + resolution; NodeType type = Node.TypeFromMapTile(TileType.Ground); int breakWallsPenalty = Node.GetPenalty(TileType.Ground, true); int driveAroundPenalty = Node.GetPenalty(TileType.Ground, false); for (int y = startY; y < endY; y++) { for (int x = startX; x < endX; x++) { nodes[x, y] = new Node(x, y, type, breakWallsPenalty, driveAroundPenalty); } } BlurNodeWeights(); }
public Grid(Map map) { // Add nodes to edges to prevent navigation there, these will be of NodeType.Impassable size = map.size * resolution + 2 * edgeNodesNumber; nodes = new Node[size, size]; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { int mapX = Mathf.FloorToInt((x - edgeNodesNumber) / (float)resolution); int mapY = Mathf.FloorToInt((y - edgeNodesNumber) / (float)resolution); bool outOfMap = mapX < 0 || mapX >= map.size || mapY < 0 || mapY >= map.size; int breakWallsPenalty; int driveAroundPenalty; NodeType type; if (outOfMap) { breakWallsPenalty = Node.maxMovePenalty; driveAroundPenalty = Node.maxMovePenalty; type = NodeType.Impassable; } else { TileType tile = map.tiles[mapX, mapY]; breakWallsPenalty = Node.GetPenalty(tile, true); driveAroundPenalty = Node.GetPenalty(tile, false); type = Node.TypeFromMapTile(tile); } nodes[x, y] = new Node(x, y, type, breakWallsPenalty, driveAroundPenalty); } } BlurNodeWeights(); }