private void GenerateWorld(bool useRSeed) { if (useRSeed) { seed = System.DateTime.Now.ToString(); } GameTiles.BuildTilesDict(groundTilemap); Random.InitState(seed.GetHashCode()); var env = ScriptableObject.CreateInstance <EnvironmentBuilder>(); env.wallObject = wallObject; env.numWalls = numWalls; env.SpawnWalls(); var spawner = ScriptableObject.CreateInstance <Spawner>(); spawner.playerObject = playerObject; spawner.enemyObject = enemyObject; spawner.numEnemies = numEnemies; spawner.SpawnPlayer(); spawner.SpawnEnemies(); PathGrid.BuildGrid(); }
public PathNode(PathGrid <PathNode> grid, int x, int y) { this.grid = grid; this.x = x; this.y = y; isWalkable = true; //gonna have to manipulate this with collision stuff to get the true thing }
public PathfindingNode(PathGrid <PathfindingNode> _grid, int _x, int _y) { grid = _grid; x = _x; y = _y; isWalkable = true; }
private void Awake() { //gets the scene's pathgrid pathGrid = GameObject.Find("PathManager").GetComponent <PathGrid>(); //add this formation ot the list of formations participating in the battle army.AddFormation(this); }
private void btn_findPath_Click(object sender, EventArgs e) { if (points.Count != 2) { MessageBox.Show("Please select start point and end point!"); return; } var start = points[0]; var end = points[1]; Stopwatch stopwatch = new Stopwatch(); PathGrid pathGrid = new PathGrid(readMap.Width, readMap.Height, readMap.Maze); stopwatch.Start(); var tempPoints = pathGrid.FindPath(start, end); stopwatch.Stop(); if (tempPoints == null || tempPoints.Count == 0) { lbl_info.Text = "Can't find the path!"; return; } lbl_info.Text = $"times:{stopwatch.ElapsedMilliseconds}\r\nDistance:{tempPoints.Count}"; var newBitmap = (Bitmap)readMap.clippingZone.Clone(); pic_map.Image = newBitmap; foreach (var item in tempPoints) { newBitmap.SetPixel(item.X, item.Y, Color.Red); } pic_map.Image = newBitmap; }
private void StepForward(PathData pathData, PathGrid grid, float deltaTime, float totalTime) { OccupyPhysicalPosition(pathData.currentPosition, pathData.drone); if (pathData.complete) { return; } Vector3Int newGridPos = GetTargetPosition(pathData, grid, deltaTime, totalTime); if (newGridPos == grid.GetGridPosition(pathData.currentPosition)) { //Debug.Log("CHECK 2 | not moving during this time step, couldn't find valid position!!"); } if (newGridPos == pathData.targetGridPos) { pathData.complete = true; AddPositionToPath(pathData, pathData.target, totalTime); return; } else { AddNodeToPath(pathData, newGridPos, totalTime); } }
// Start is called before the first frame update void Awake() { requestManager = GetComponent <PathRequestManager>(); tilemap = GetComponent <Tilemap>(); pathGrid = GetComponent <PathGrid>(); tilemap.CompressBounds(); BoundsInt bounds = tilemap.cellBounds; // tileArray = tilemap.GetTilesBlock(bounds); // Debug.Log("bound x: " + bounds.size.x + " bound y: " + bounds.size.y); #region //for (int x = 0; x < bounds.size.x; ++x) //{ // for (int y = 0; y < bounds.size.y; ++y) // { // TileBase tile = tileArray[x + y];// * bounds.size.x]; // if (tile != null) // { // Debug.Log("x: " + x + " y: " + y + " tile: " + tile.name); // var placehoderPosition = grid.WorldToCell(new Vector3(y, x, 0)); // var placehoderPosition2 = grid.CellToWorld(new Vector3Int(x, y, 0)); // Instantiate(placeholderPrefab, placehoderPosition2, Quaternion.identity); // // Debug. // // Gizmos.DrawCube(new Vector3(y, x, 0), tilemap.cellSize); // } // else // { // // Debug.Log("x: " + x + "y: " + y + " tile: (null)"); // } // } //} #endregion }
/// <summary> /// Ends a path grid update and marks the entry as authoritative in the reachability /// monitor, allowing removed cells to be processed. /// </summary> /// <param name="grid">The path grid to update.</param> /// <param name="isComplete">true if the probing is complete.</param> /// <param name="prober">The path prober making the update.</param> private static void EndUpdate(PathGrid grid, bool isComplete, PathProber prober) { grid.isUpdating = false; int sn = grid.serialNo; var gp = grid.groupProber; var inst = SensorPatches.FastGroupProber.Instance; if (gp != null) { var cells = grid.freshlyOccupiedCells; if (inst != null && ReferenceEquals(gp, MinionGroupProber.Instance)) { inst.Occupy(grid, cells, isComplete); } else { gp.Occupy(grid, sn, cells); } } if (isComplete) { // There is no need to do this on the minion group prober, but in case another // one appears later gp?.SetValidSerialNos(grid, grid.previousSerialNo, sn); grid.previousSerialNo = sn; } if (isComplete && FastTrackOptions.Instance.CachePaths) { PathCacher.SetValid(prober, true); } }
private static List <Node> GetNeighbours(Node node) { List <Node> neighbours = new List <Node>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } int checkX = node.X + x; int checkY = node.Y + y; Node n = PathGrid.NodeAt(checkX, checkY); if (n != null && n.IsTraversable) { neighbours.Add(n); } } } return(neighbours); }
void Start() { //Check if in a study session if (GameObject.Find("Player Prefab test (2)(Clone)").GetComponent <Client>().isStudy) { isStudy = true; spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint1"); agentTrainer = GameObject.Find("Player Prefab test (2)(Clone)"); target = agentTrainer; pathGrid = GameObject.Find("PathGrid").GetComponent <PathGrid>(); } else { Destroy(GameObject.Find("PathGrid").GetComponent <PathGrid>()); } //Initialise all booleans not set //in inspector to false as default justRespawned = false; actionMode = false; canShoot = false; pathCompleted = false; //Initialise stats health = 100; //Initialise pathing variables idleTimer = 1.0f; idleTarget = new Vector3(0, 0, 0); pathPosition = 0; pathSize = 0; }
public void FindPaths() { grid = new PathGrid(Drones, Targets); pathData.Sort((a, b) => a.distance.CompareTo(b.distance)); totalTime = 0.0f; foreach (PathData path in pathData) { StartPath(path, grid); } totalTime += TIMESTEP; grid.ClearOccupancy(); int completeCount = 0; int iterationCount = 0; while (completeCount < pathData.Count) { completeCount = StepPathfinding(); iterationCount += 1; if (iterationCount >= MaxIterations) { break; } } MergeNodes(); Debug.Log("Complete count: " + completeCount + " / " + pathData.Count); EditorApplication.QueuePlayerLoopUpdate(); }
public void Initialize() { //Called from Game Control script during scene initialization //PathGrid() pulls data for tiles from DataController on Awake() and creates grid for pathfinding use pathGrid = new PathGrid(); gameController = GameController.Instance; }
void Start() { animator = this.GetComponent <Animator>(); walkSpeedId = Animator.StringToHash("WalkSpeed"); grid = GameObject.FindGameObjectWithTag("A*").GetComponent <PathGrid>(); renderer = transform.Find("Human").GetComponent <Renderer>(); }
/// <summary> /// 几何估价法(Euclidian heuristic) /// 它计算出两点之间的直线距离,本质公式为勾股定理 /// </summary> private float onEuclidian(PathGrid node) { int dx = node.col - m_end_node.col; int dy = node.row - m_end_node.row; return(Mathf.Sqrt(dx * dx + dy * dy) * m_straight_cost); }
private static List <Subregion> CreateSubregionAt(int X, int Y) { int subregionStartX = ((int)(X / _subregionSize)) * _subregionSize; int subregionStartY = ((int)(Y / _subregionSize)) * _subregionSize; //Deleting any subregions that existed on 10x10 chunk for (int x = subregionStartX; x < subregionStartX + _subregionSize; x++) { for (int y = subregionStartY; y < subregionStartY + _subregionSize; y++) { PathGrid.NodeAt(x, y)?.subregion?.Reset(); } } //Creating new subregions on named chunk List <Subregion> createdSubregions = new List <Subregion>(); for (int x = subregionStartX; x < subregionStartX + _subregionSize; x++) { for (int y = subregionStartY; y < subregionStartY + _subregionSize; y++) { Subregion newSubregion = FillSubregionFrom(PathGrid.NodeAt(x, y)); if (newSubregion != null) { newSubregion.CalculateAverageCoordinates(); createdSubregions.Add(newSubregion); } } } return(createdSubregions); }
private void Step(PathGrid grid, float deltaTime, float time) { pathData.Sort((x, y) => x.currentDistance.CompareTo(y.currentDistance)); foreach (PathData path in pathData) { StepForward(path, grid, deltaTime, time); } }
public uint getColor(PathGrid node) { if (node == null || !node.walkable) { return(0); } return(0xffffff); }
public void SetWalkable(bool value, PathGrid grid) { UpdateSpanPos(); foreach (Vector3 v in m_spanPosArray) { grid.SetWalkable(Mathf.FloorToInt(v.x / size), Mathf.FloorToInt(v.z / size), value); } }
public static List <Node> GetDefaultPathfinding(Vector2Int startPosition, Vector2Int targetPosition) { var startNode = PathGrid.NodeAt(startPosition.x, startPosition.y); var targetNode = PathGrid.NodeAt(targetPosition.x, targetPosition.y); var path = DefaultPathfinding.AStarSearch.GetPath(startNode, targetNode); return(path); }
public static void Initialize(int mapWidth, int mapHeight, ITraversable[,] tileGrid) { MapWidth = mapWidth; MapHeight = mapHeight; PathGrid.CreateGrid(tileGrid); RegionSystem.Initialize(); }
public static List <Node> GetPathWithoutRegionSearch(Vector2Int startPosition, Vector2Int targetPosition) { var startNode = PathGrid.NodeAt(startPosition.x, startPosition.y); var targetNode = PathGrid.NodeAt(targetPosition.x, targetPosition.y); var path = AStarSearch.GetPathWithoutRegionSearch(startNode, targetNode); return(path); }
public void Init() { //初始化路径网格 PathGrid pathGrid = new PathGrid(leftDownTransform.position, rightUpTransform.position); EveryFunction.InitPathFinding(pathGrid); cameraController = GameObject.FindWithTag("MainCamera").GetComponent <CameraController> (); }
public void setStartNode(int row, int col) { if (!isValidRowCol(row, col)) { return; } m_startNode = m_nodes[row, col] as PathGrid; }
// Start is called before the first frame update public static Stack <WorldTile> FindPath(Vector3 start, Vector3 end) { var nodes = PathGrid.nodes; Node startNode = nodes[start]; Node endNode = nodes[end]; List <Node> openSet = new List <Node>(); HashSet <Node> closedSet = new HashSet <Node>(); openSet.Add(startNode); while (openSet.Count > 0) { Node node = openSet[0]; for (int i = 1; i < openSet.Count; i++) { if (openSet[i].fCost < node.fCost || openSet[i].fCost == node.fCost) { if (openSet[i].hCost < node.hCost) { node = openSet[i]; } } } openSet.Remove(node); closedSet.Add(node); if (node == endNode) { return(RetracePath(startNode, endNode)); } var neighbors = PathGrid.GetNeighbours(node); foreach (Node neighbour in neighbors) { if (!neighbour.walkable || closedSet.Contains(neighbour)) { continue; } int newCostToNeighbour = node.gCost + GetDistance(node, neighbour); if (newCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) { neighbour.gCost = newCostToNeighbour; neighbour.hCost = GetDistance(neighbour, endNode); neighbour.parent = node; node.child = neighbour; if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } return(new Stack <WorldTile>()); }
// Start is called before the first frame update private void Awake() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); gameWorld = GameObject.Find("GameWorld").GetComponent <GameWorld>(); boundEntity = GetComponent <Entity>(); grid = GameObject.Find("GameWorld").GetComponent <PathGrid>(); aiDirector = gameManager.GetComponent <WorldAIDirector>(); battleEntryScreen = GameObject.Find("BattleEntry").GetComponent <BattleEntryScript>(); }
private void StartPath(PathData path, PathGrid grid) { GameObject drone = path.drone; path.currentPosition = drone.transform.position; path.currentDistance = Vector3.Distance(path.currentPosition, path.target); path.targetGridPos = grid.GetGridPosition(path.target); AddPositionToPath(path, drone.transform.position, 0.0f); }
public override void Destroy() { if (m_PathGrid != null) { m_PathGrid.removeObject(this); m_PathGrid = null; } base.Destroy(); }
public PawnPath findPath(Map map, IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode, ByteGrid avoidGrid, Area allowedArea, int costsCardinal, int costsDiagonal) { this.map = map; this.cellIndices = this.map.cellIndices; this.edificeGrid = map.edificeGrid; this.traverseParms = traverseParms; this.dest = dest; this.peMode = peMode; this.costPerMoveCardinal = costsCardinal; this.costPerMoveDiagonal = costsDiagonal; this.avoidGrid = avoidGrid; this.allowedArea = allowedArea; this.pathGridArray = map.pathGrid.pathGrid; this.pathGrid = map.pathGrid; this.topGrid = map.terrainGrid.topGrid; this.pawn = traverseParms.pawn; this.drafted = pawn != null && pawn.Drafted; this.blueprintGrid = map.blueprintGrid.InnerArray; //Only colonists and tamed animals should respect restrictions. //Drafted pawns move unrestricted. //Some job types like firefighting should exclude the restrictions. List <string> exceptions = QOLMod.getSettings().pfRestrictionExcemptions; if (this.pawn.Faction != null && this.pawn.Faction.IsPlayer && !this.pawn.Drafted && (exceptions == null || pawn.jobs.curJob == null || !exceptions.Contains(pawn.jobs.curJob.def.defName))) { this.pathfinderDirections = map.GetComponent <MapComponent_PathfinderDirections>(); } else { this.pathfinderDirections = null; } this.drawPath = DebugViewSettings.drawPaths; this.mapSizeX = map.Size.x; this.mapSizeZ = map.Size.z; this.dontPassWater = traverseParms.mode == TraverseMode.NoPassClosedDoorsOrWater || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater; this.collidesWithPawns = pawn != null && PawnUtility.ShouldCollideWithPawns(pawn); Step step = astar(start); if (step == null) { return(PawnPath.NotFound); } PawnPath emptyPawnPath = map.pawnPathPool.GetEmptyPawnPath(); int costs = step.costToReachThis; while (step != null) { emptyPawnPath.AddNode(step.current); step = step.predecessor; } emptyPawnPath.SetupFound((float)costs, false); return(emptyPawnPath); }
/// <summary> /// 对角线估价法 /// </summary> /// <param name="node"></param> /// <returns></returns> private float onDiagonal(PathGrid node) { int dx = Mathf.Abs(node.col - m_end_node.col); int dy = Mathf.Abs(node.row - m_end_node.row); int diag = Mathf.Min(dx, dy); int straight = dx + dy; return(m_diag_cost * diag + m_straight_cost * (straight - 2 * diag)); }
public PathGrid PathGridImporting() { PathGridReader.Position = 0; var pathGrid = new PathGrid(FormKey.Null); PathGridBinaryCreateTranslation.FillBinaryPointToPointConnections( new Binary.MutagenFrame(PathGridReader), pathGrid); return(pathGrid); }