public void AttackMove(Vector2 target) { PathToFollow = gm.GetPath(controlledUnit.Position, target); fsm.ChangeState(FSMState.FSMStates.AttackMove, true); AttackMoving = true; AttackMoveDestination = target; }
public void FollowPath(Path path) { if (path == null) return; PathToFollow = path; fsm.ChangeState(FSMState.FSMStates.Move, true); //previousPathParam = 0; }
private Path ReconstructPath(Tile end) { List<Tile> reversePath = new List<Tile>(); Path p = new Path(); reversePath.Add(end); while (end.cameFrom != null) { end = end.cameFrom; reversePath.Add(end); } for (int i = reversePath.Count - 1; i >= 0; i--) { p.AddPoint(grid.GetWindowCenterPos(reversePath[i])); } return p; }
public Path FindPath(Tile start, Tile end, float goalTolerance = 0.0f) { if (!start.passable || (!end.passable && goalTolerance <= 0.0f)) { Path p1 = new Path(); p1.AddPoint(grid.GetWindowCenterPos(start)); return p1; } openSet.Clear(); closedSet.Clear(); start.g = 0; start.f = start.g + start.DistanceHeuristic(end); openSet.Add(start); while (openSet.Count > 0) { Tile current = openSet.First(); openSet.Remove(current); closedSet.Add(current); float dh = current.DistanceHeuristic(end); if (current == end || current.DistanceHeuristic(end) <= goalTolerance) return ReconstructPath(current); foreach (Tile t in current.neighbours) { if (closedSet.Contains(t)) { continue; } float tentative_g = current.g + 1; Tile newParent = current; if (current.cameFrom != null && grid.LineOfSight(current.cameFrom, t)) { float cost = (float)Math.Sqrt(Math.Pow(current.cameFrom.gridX - t.gridX, 2) + Math.Pow(current.cameFrom.gridY - t.gridY, 2)); tentative_g = current.cameFrom.g + cost; newParent = current.cameFrom; } if (!openSet.Contains(t)) { //t.cameFrom = current; //t.g = tentative_g; //t.f = t.g + t.ManhattanDistance(end); openSet.Add(t); } else if (tentative_g >= t.g) { continue; } t.cameFrom = newParent; t.g = tentative_g; t.f = t.g + t.DistanceHeuristic(end) - goalTolerance; } openSet.Sort(); } //If we get here, no path was found Path p2 = new Path(); p2.AddPoint(grid.GetWindowCenterPos(start)); return p2; }
public void Stop() { AttackTarget = null; PathToFollow = null; fsm.ChangeState(FSMState.FSMStates.Idle, true); }