private void Initialize(int[,] g, int[] s, int[] e, AstarMoveMode f = AstarMoveMode.Diagonal) { this.grid = g; this.from = s; this.to = e; this.find = f; }
public void Store(List <Vector2> i, Grill tg, int[] t, AstarMoveMode m) { this.indexes = i; this.togrill = tg; this.to = t; this.mode = m; }
public void FindPathNonAlloc(List <Vector2> res, int[,] g, int[] s, int[] e, AstarMoveMode f = AstarMoveMode.Diagonal) { Initialize(g, s, e, f); res.Clear(); this.result = res; this.CalculatePath(); }
public List <Vector2> FindPath(int[,] g, int[] s, int[] e, AstarMoveMode f = AstarMoveMode.Diagonal) { Initialize(g, s, e, f); this.result = new List <Vector2>(); this.CalculatePath(); return(this.result); }
/* ---------------------------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------------------------*/ /* ------------------------------------- PUBLIC FUNCTIONS --------------------------------------*/ /* ---------------------------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------------------------*/ public List <Step> GetPathTo(Cellable e, Vector3 dest, Vector3 normal, AstarMoveMode mode = AstarMoveMode.Diagonal) { List <Step> steps; PlanetPathfinding pathfinder; if (!pathfinders.ContainsKey(e.currentSurface)) { Debug.LogError($"ERROR : Could not find the pathfinder associated with the surface of {e} !"); return(null); } pathfinder = pathfinders[e.currentSurface]; steps = pathfinder.GetPath(e, dest, normal, mode); return(steps); }
public List <Step> GetPath(Cellable e, Vector3 target, Vector3 targetNormal, AstarMoveMode mode = AstarMoveMode.Diagonal) { Path path; int[] from, to; List <Vector2> indexes; Grill fromgrill, togrill; List <Step> steps; if (!paths.ContainsKey(e)) { path = new Path(); this.paths.Add(e, path); indexes = new List <Vector2>(); } else { path = this.paths[e]; indexes = path.indexes; } fromgrill = e.currentCell.grill; togrill = this.surface.GetGrillOf(target, targetNormal); from = fromgrill.GetIndexInGrill(e.currentCell.position); to = togrill.GetIndexInGrill(target); // store data path.Store(indexes, togrill, to, mode); if (fromgrill == togrill) { steps = this.FindPath(indexes, fromgrill, from, to, mode); } else { Debug.LogWarning("WARNING : Pathfinding among several faces is not yet implemented and may never be..."); steps = null; // steps = this.FindPathAmongGrill(indexes, fromgrill, togrill, from, to, mode); } path.steps = steps; return(steps); }
/* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* ---------------------------- UTIL FUNCTION NOT YET IMPLEMENTED -----------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ private List <Step> FindPathAmongGrill(List <Vector2> indexes, Grill fromgrill, Grill togrill, int[] from, int[] to, AstarMoveMode mode) { // not yet implemented return(null); /*List<Grill> grills; * List<Step> steps; * int[][] mids; * Grill g; * int count; * * steps = new List<Step>(); * * grills = this.surface.GetPathAmongGrill(fromgrill, togrill); * count = grills.Count; * * mids = this.GetIndexesTransitionBetweenGrills(fromgrill, grills[1]); * this.astar.FindPathNonAlloc(indexes, this.grids[fromgrill], from, mids[0], mode); * this.ConvertIndexesToStepsAmongGrill(steps, indexes, fromgrill); * * for(int i = 1; i < count - 1; ++i) { * g = grills[i]; * mids = this.GetIndexesTransitionBetweenGrills(g, grills[i+1]); * this.astar.FindPathNonAlloc(indexes, this.grids[g], mids[0], mids[1], mode); * this.ConvertIndexesToStepsAmongGrill(steps, indexes, g); * } * * mids = this.GetIndexesTransitionBetweenGrills(grills[count-2], togrill); * this.astar.FindPathNonAlloc(indexes, this.grids[togrill], mids[1], to, mode); * this.ConvertIndexesToStepsAmongGrill(steps, indexes, togrill); * * return steps;*/ }
private List <Step> FindPath(List <Vector2> indexes, Grill grill, int[] from, int[] to, AstarMoveMode mode, List <Step> steps = null) { List <Step> result; this.astar.FindPathNonAlloc(indexes, this.grids[grill], from, to, mode); result = this.ConvertIndexesToStepsOnGrill(indexes, grill, steps); return(result); }