예제 #1
0
파일: Pather.cs 프로젝트: zneel/TheNoobBot
        public Point GetClosestPointOnTile(Point position, out bool success)
        {
            lock (_threadLocker)
            {
                float[] extents = new Point(20.0f, 2000.0f, 20.0f).ToFloatArray();
                float[] center  = position.ToRecast().ToFloatArray();

                float tx, ty;
                GetTileByLocation(position, out tx, out ty);
                int x = (int)Math.Floor(tx);
                int y = (int)Math.Floor(ty);
                LoadTile(x, y);

                dtPolyRef startRef = _query.FindNearestPolygon(center, extents, Filter);
                if (startRef == 0)
                {
                    success = false;
                    return(new Point());
                }
                float[]      result;
                DetourStatus status = _query.closestPointOnPolyBoundary(startRef, center, out result);
                if (status.HasFailed())
                {
                    success = false;
                    return(new Point());
                }
                success = true;
                return(new Point(result.ToWoW()));
            }
        }
예제 #2
0
파일: Pather.cs 프로젝트: zneel/TheNoobBot
        public float GetZ(Point position, bool strict = false)
        {
            lock (_threadLocker)
            {
                float[] extents = strict ? new Point(0.5f, 2000.0f, 0.5f).ToFloatArray() : new Point(1.5f, 2000.0f, 1.5f).ToFloatArray();
                float[] center  = position.ToRecast().ToFloatArray();

                float tx, ty;
                GetTileByLocation(position, out tx, out ty);
                int x = (int)Math.Floor(tx);
                int y = (int)Math.Floor(ty);
                LoadTile(x, y);

                dtPolyRef startRef = _query.FindNearestPolygon(center, extents, Filter);
                if (startRef == 0)
                {
                    Logging.WriteDebug("There is no polygon in this location (Tile " + x + "," + y + "), coord: X:" +
                                       position.X + ", Y:" + position.Y);
                    return(0);
                }
                float z = _query.GetPolyHeight(startRef, center);
                if (z == 0 && !strict) // it failed but we are not strict, then search around
                {
                    float[]      result;
                    DetourStatus status = _query.closestPointOnPolyBoundary(startRef, center, out result);
                    z = status.HasFailed() ? 0 : result[1];
                }
                return(z);
            }
        }
예제 #3
0
파일: Pather.cs 프로젝트: zneel/TheNoobBot
        public bool LoadTile(byte[] data)
        {
            lock (_threadLocker)
            {
                try
                {
                    if (CheckDungeon())
                    {
                        return(false);
                    }

                    MeshTile     tile;
                    DetourStatus ret = _mesh.AddTile(data, out tile);
                    if (ret.IsWrongVersion())
                    {
                        Logging.WriteNavigator("This mesh tile is outdated.");
                        return(false);
                    }
                    if (ret.HasFailed())
                    {
                        Logging.WriteNavigator("This mesh tile is corrupted.");
                        return(false);
                    }
                    AddMemoryPressure(data.LongLength);
                    // HandleConnections(tile);
                    return(true);
                }
                catch (Exception exception)
                {
                    Logging.WriteError("LoadTile(byte[] data): " + exception);
                    return(false);
                }
            }
        }
예제 #4
0
파일: Pather.cs 프로젝트: zneel/TheNoobBot
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     try
     {
         Status = status;
     }
     catch (Exception exception)
     {
         Logging.WriteError("NavMeshException(DetourStatus status, string text): " + exception);
     }
 }
예제 #5
0
파일: Pather.cs 프로젝트: zneel/TheNoobBot
        public Pather(string continent, ConnectionHandlerDelegate connectionHandler)
        {
            lock (_threadLocker)
            {
                try
                {
                    ConnectionHandler = connectionHandler;

                    Continent = continent.Substring(continent.LastIndexOf('\\') + 1);

                    string dir = Application.StartupPath;
                    _meshPath = dir + "\\Meshes"; // + continent;


                    if (!Directory.Exists(_meshPath))
                    {
                        Logging.WriteNavigator(DetourStatus.Failure + " No mesh for " + continent + " (Path: " + _meshPath +
                                               ")");
                    }

                    _mesh        = new NavMesh();
                    _loadedTiles = new Dictionary <Tuple <int, int>, int>();
                    _failedTiles = new Dictionary <Tuple <int, int>, int>();
                    if (_loadTileCheck == null)
                    {
                        _loadTileCheck = new Helpful.Timer(60 * 1000); // 1 min
                    }
                    DetourStatus status;

                    // check if this is a dungeon and initialize our mesh accordingly
                    WoWMap map = WoWMap.FromMPQName(continent);
                    if (map.Record.MapType == WoWMap.MapType.WDTOnlyType || continent == "AllianceGunship")
                    {
                        string dungeonPath = GetDungeonPath();
                        if (!File.Exists(_meshPath + "\\" + dungeonPath))
                        {
                            downloadTile(dungeonPath);
                        }
                        byte[] data = File.ReadAllBytes(_meshPath + "\\" + dungeonPath);
                        status = _mesh.Initialize(data);
                        AddMemoryPressure(data.LongLength);
                        IsDungeon = true;
                    }
                    else //                       20bits 28bits
                    {
                        status = _mesh.Initialize(1048576, 2048 * Division * Division, Utility.Origin, Utility.TileSize / Division, Utility.TileSize / Division);
                    }
                    // maxPolys = 1 << polyBits (20) = 1048576
                    // maxTiles = is 8192 (was 4096), Travel loads tons of tile in quester.
                    // I have logs with over 6000 .tile files loaded.

                    if (status.HasFailed())
                    {
                        Logging.WriteNavigator(status + " Failed to initialize the mesh");
                    }

                    _query = new NavMeshQuery(new PatherCallback(this));
                    DetourStatus t = _query.Initialize(_mesh, 524287); // 20bits - 1
                    //Logging.WriteDebug("NavMeshQuery initialized with status: " + t);
                    Filter = new QueryFilter {
                        IncludeFlags = 0xFFFF, ExcludeFlags = 0x0
                    };
                    // Add the costs
                    Filter.SetAreaCost((int)PolyArea.Water, 4);
                    Filter.SetAreaCost((int)PolyArea.Terrain, 1);
                    Filter.SetAreaCost((int)PolyArea.Road, 1);  // This is the Taxi system, not in tiles yet
                    Filter.SetAreaCost((int)PolyArea.Danger, 25);
                    if (nManagerSetting.DangerousZones.Count > 0)
                    {
                        int addedDangers = ReportDanger(nManagerSetting.DangerousZones, true);
                        if (addedDangers > 0)
                        {
                            Logging.WriteNavigator(addedDangers + " dangers added.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Logging.WriteError("Pather(string continent, ConnectionHandlerDelegate connectionHandler): " + exception);
                }
            }
        }
예제 #6
0
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     Status = status;
 }
예제 #7
0
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     Status = status;
 }
예제 #8
0
 public static bool HasSucceeded(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.Success));
 }
예제 #9
0
 public static bool IsPartialResult(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.PartialResult));
 }
예제 #10
0
 public static bool IsInProgress(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.InProgress));
 }
예제 #11
0
 public static bool IsWrongVersion(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.WrongVersion));
 }
예제 #12
0
 public static bool HasFailed(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.Failure));
 }