Beispiel #1
0
        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);
        }
Beispiel #2
0
 public PatherCallback(Pather parent)
 {
     _parent = parent;
 }
        public void TestFlightpathes()
        {
            System.Collections.Generic.List<Hop> roadHops;
            Pather.Filter.ExcludeFlags = (ushort) (PolyFlag.FlightMaster);
            TryPath(new Vector3(-9447.5f, 55.4f, 56.2f), new Vector3(-8957.4f, 517.3f, 96.3f), out roadHops, false);

            Pather = new Pather("S:\\meshReader\\Meshes\\Azeroth", MockConnectionHandler);
            System.Collections.Generic.List<Hop> flightHops;
            TryPath(new Vector3(-9447.5f, 55.4f, 56.2f), new Vector3(-8957.4f, 517.3f, 96.3f), out flightHops, false);

            Console.WriteLine("Ground path: " + roadHops.Count + " hops, Flight path: " + flightHops.Count + " hops");
            Assert.Less(flightHops.Count, roadHops.Count);
            Assert.IsTrue(flightHops.Any(hop => hop.Type == HopType.Flightmaster && hop.FlightTarget != null));
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
 public PatherCallback(Pather parent)
 {
     _parent = parent;
 }
Beispiel #6
0
 protected void Initialize(string continent)
 {
     Pather = new Pather(continent);
     Assert.IsFalse(Pather.IsDungeon);
 }
Beispiel #7
0
        private void UpdateBackground()
        {
            if (_startX == 0 && _startY == 0)
            {
                var files = Directory.GetFiles("S:\\meshReader\\Meshes\\" + _world + "\\");
                var best =
                    files.Where(f => f.EndsWith(".tile")).OrderByDescending(f => new FileInfo(f).Length).FirstOrDefault();
                best = best.Substring(best.LastIndexOf('\\') + 1);
                var tokens = best.Split('_');
                _startX = int.Parse(tokens[1]);
                _startY = int.Parse(tokens[2].Substring(0, tokens[2].IndexOf('.')));
            }

            originTileLabel.Content = OriginTileX + ", " + OriginTileY;
            _pather = new Pather("S:\\meshReader\\Meshes\\" + _world);

            var wdt = new WDT("World\\Maps\\" + _world + "\\" + _world + ".wdt");
            if (!wdt.IsValid || wdt.IsGlobalModel)
                return;                   

            const int totalX = 3;
            const int totalY = 3;

            const int tileSize = 256;
            var result = new Bitmap(totalX * tileSize, totalY * tileSize);
            for (int y = _startY - 1; y <= _startY+1; y++)
            {
                for (int x = _startX - 1; x <= _startX+1; x++)
                {
                    if (!wdt.HasTile(x, y))
                        continue;

                    try
                    {
                        var path = GetMinimapFileByCoords(_world, x, y);
                        var xBegin = (x-(_startX-1))*tileSize;
                        var yBegin = (y-(_startY-1))*tileSize;

                        var image = new Blp(path).GetImage(0);
                        var bitmap = new Bitmap(image);
                        for (int i = 0; i < tileSize; i++)
                        {
                            for (int j = 0; j < tileSize; j++)
                                result.SetPixel(xBegin + i, yBegin + j, bitmap.GetPixel(i, j));
                        }
                    }
                    catch (FileNotFoundException)
                    {

                    }
                }
            }

            // somebody needs to kill WPF developers for this bullshit
            var ms = new MemoryStream();
            result.Save(ms, ImageFormat.Bmp);
            ms.Seek(0, SeekOrigin.Begin);
            var bi = new BitmapImage();
            bi.BeginInit();
            bi.StreamSource = ms;
            bi.EndInit();

            canvas1.Background = new ImageBrush(bi);
        }
 protected void Initialize(string dungeon)
 {
     Pather = new Pather(dungeon);
     Assert.IsTrue(Pather.IsDungeon);
 }