public bool IsShorterThan(Path path) { if (GoalSameAsStart == true) return true; if (path.GoalSameAsStart == true) return false; if (PathPoints.Count <= path.PathPoints.Count) return true; return false; }
public void SetMovePath(Path path) { _prevMovePath = path; MovePath.Clear(); for (int i = path.PathPoints.Count - 1; i >= 0; i--) { MovePath.Push(path.PathPoints[i]); } }
public bool start(int Sx, int Sy, int Gx, int Gy) { pathBuffer = new List<Point>(); if ((Math.Abs(Sx - Gx) == 1 && Math.Abs(Sy - Gy) == 0) || (Math.Abs(Sx - Gx) == 0 && Math.Abs(Sy - Gy) == 1) || (Math.Abs(Sx - Gx) == 1 && Math.Abs(Sy - Gy) == 1) || (Sx == Gx && Sy == Gy)) { List<Point> p = new List<Point>(); p.Add(new Point(Gx, Gy)); Path = new Path(p); if (Sx == Gx && Sy == Gy) Path.GoalSameAsStart = true; return true; } pathAvailable = false; goalX = Gx; goalY = Gy; startX = Sx; startY = Sy; openList.Clear(); list.Clear(); bool noPath = false; if ((Gx - 1 < 0 || _colMap[Gx - 1, Gy].tileType == TileInfo.TileType.Wall) && (Gx + 1 > Width || _colMap[Gx + 1, Gy].tileType == TileInfo.TileType.Wall) && (Gy - 1 < 0 || _colMap[Gx, Gy - 1].tileType == TileInfo.TileType.Wall) && (Gy + 1 > Width || _colMap[Gx, Gy + 1].tileType == TileInfo.TileType.Wall)) noPath = true; if (!(Sx == Gx && Sy == Gy) && _colMap[Gx, Gy].tileType != TileInfo.TileType.Wall && !noPath) { list.Add(new Point(Sx, Sy), new listitem(Sx, Sy)); list.Add(new Point(Gx, Gy), new listitem(Gx, Gy)); openList.Add(new listitem(Sx, Sy)); setOpenOnLowestF(Sx, Sy, Gx, Gy); if (pathAvailable) { makePath(Gx, Gy, Sx, Sy); } else if (_colMap[Gx, Gy].unitOnTile != null && _colMap[Gx, Gy].unitOnTile.isPlayer && Math.Abs(goalX - startX) < 2 && Math.Abs(goalY - startY) < 2) { // If the player is on the goal tile then return true so we can attack him pathBuffer.Add(new Point(Gx, Gy)); return true; } } // TODO: Bug, det er lidt et problem at det her nogen gange sker if (pathBuffer.Count == 0) { } Path = new Path(pathBuffer); //Console.WriteLine(Path.ToString); return pathAvailable; }
public bool start(int Sx, int Sy, int Gx, int Gy) { Stopwatch s = new Stopwatch(); s.Start(); bool openUpGoal = false; pathBuffer = new List<Point>(); if ((Math.Abs(Sx - Gx) == 1 && Math.Abs(Sy - Gy) == 0) || (Math.Abs(Sx - Gx) == 0 && Math.Abs(Sy - Gy) == 1) || (Math.Abs(Sx - Gx) == 1 && Math.Abs(Sy - Gy) == 1) || (Sx == Gx && Sy == Gy)) { List<Point> p = new List<Point>(); p.Add(new Point(Gx, Gy)); Path = new Path(p); if (Sx == Gx && Sy == Gy) Path.GoalSameAsStart = true; return true; } pathAvailable = false; goalX = Gx; goalY = Gy; startX = Sx; startY = Sy; openList.Clear(); list.Clear(); bool noPath = false; if ((Gx - 1 < 0 || _colMap[Gx - 1, Gy].tileType == TileInfo.TileType.Wall) && (Gx + 1 > Width || _colMap[Gx + 1, Gy].tileType == TileInfo.TileType.Wall) && (Gy - 1 < 0 || _colMap[Gx, Gy - 1].tileType == TileInfo.TileType.Wall) && (Gy + 1 > Width || _colMap[Gx, Gy + 1].tileType == TileInfo.TileType.Wall)) noPath = true; if (_colMap[Gx, Gy].tileType == TileInfo.TileType.Wall) { openUpGoal = true; _colMap[Gx, Gy].tileType = TileInfo.TileType.Floor; //throw new Exception("Destination is a wall"); } if (!(Sx == Gx && Sy == Gy) && _colMap[Gx, Gy].tileType != TileInfo.TileType.Wall && !noPath) { list.Add(new Point(Sx, Sy), new listitem(Sx, Sy)); list.Add(new Point(Gx, Gy), new listitem(Gx, Gy)); openList.Add(new listitem(Sx, Sy)); setOpenOnLowestF(Sx, Sy, Gx, Gy); if (pathAvailable) { makePath(Gx, Gy, Sx, Sy); } else if (_colMap[Gx, Gy].unitOnTile != null && _colMap[Gx, Gy].unitOnTile.isPlayer && Math.Abs(goalX - startX) < 2 && Math.Abs(goalY - startY) < 2) { // If the player is on the goal tile then return true so we can attack him pathBuffer.Add(new Point(Gx, Gy)); return true; } } if (openUpGoal) _colMap[Gx, Gy].tileType = TileInfo.TileType.Wall; // TODO: Bug, det er lidt et problem at det her nogen gange sker if (pathBuffer.Count == 0) { } Path = new Path(pathBuffer); if (s.Elapsed.TotalMilliseconds >= 100) DwarfConsole.WriteLine("Path calculation time: " + s.Elapsed.TotalMilliseconds, ConsoleColor.Red); //Console.WriteLine(Path.ToString); return pathAvailable; }
private void StartMoving(Path path) { _movePath.Clear(); for (int i = path.PathPoints.Count - 1; i >= 0; i--) { _movePath.Push(path.PathPoints[i]); } }