public void CrossingTest() { MpqManager.Initialize("S:\\WoW"); byte[] dataA, dataB; // Build tile A { var builder = new TileBuilder("Azeroth", 31, 49); dataA = builder.Build(new ConsoleLog()); Assert.IsNotNull(dataA); } // Build tile B { var builder = new TileBuilder("Azeroth", 32, 49); dataB = builder.Build(new ConsoleLog()); Assert.IsNotNull(dataB); } // Load into mesh var pather = new Pather("Azeroth"); Assert.IsTrue(pather.LoadTile(dataA)); Assert.IsTrue(pather.LoadTile(dataB)); // and try pathing, coords from AzerothMeshTest -> TileCrossing which is a non-building version of this var start = new Vector3(-9467.8f, 64.2f, 55.9f); var end = new Vector3(-9248.9f, -93.35f, 70.3f); var path = pather.FindPath(start, end); // check result Assert.IsNotNull(path); Assert.Greater(path.Count, 0); Assert.Less((end - path[path.Count-1].Location).Length(), 3f); }
public static bool PathTo(Location from, Location to, bool preferRoads = true) { try { // Reinstate the pather with our current continent/dungeon _Pather = new Pather(WoWWorld.CurrentMap); if (_Pather == null) { Log.WriteLine("Unable to instantiate the pather on map {0} (#{1})", WoWWorld.CurrentMap, WoWWorld.CurrentMapId); return false; } if (preferRoads) { // Use only water if necessary _Pather.Filter.SetAreaCost((int) PolyArea.Water, 10); // Roads and terrain keeps their priority _Pather.Filter.SetAreaCost((int) PolyArea.Road, 1); _Pather.Filter.SetAreaCost((int) PolyArea.Terrain, 1); // Exclude flightmasters as they arent properly implemented (yet) // Remember that they are implemented in the mesh, just not into the pather! _Pather.Filter.ExcludeFlags = (int) PolyFlag.FlightMaster; // Eventually add (int)PolyFlag.Swim } // Convert our locations to XNA and request a path var hops = _Pather.FindPath(from.ToXNA(), to.ToXNA()); if (hops == null) { Log.WriteLine("Unable to generate path to {0}", to); return false; } // Since we now know that we're ready to move, we can let the rest of the both know that we have a destination Destination = to; _lastLocation = from; stuckCheckTimer = DateTime.Now + TimeSpan.FromMilliseconds(5000); if (_GeneratedPath == null) _GeneratedPath = new Queue<Location>(); _GeneratedPath.Clear(); foreach (var hop in hops) _GeneratedPath.Enqueue(new Location(hop.Location.X, hop.Location.Y, hop.Location.Z)); } catch (NavMeshException ex) { Log.WriteLine("Exception in NavMesh (Status: {0}):", ex.Status); Log.WriteLine(ex.Message); Exception inner; while ((inner = ex.InnerException) != null) { Log.WriteLine(inner.Message); } Status = MovementStatus.Error; return false; } catch(Exception ex) { return false; } return true; }