Example #1
0
File: Program.cs Project: ipo/AGBA
 static void Main(string[] args)
 {
     Console.Write("test");
     //CachedMap map = new CachedMap("E:\\Games\\d3advanced\\demonbuddy\\demonbuddy_180_leveling\\eu1_apollo_tr_agbact222\\atGuard");
     CachedMap map = new CachedMap("E:\\Games\\d3advanced\\demonbuddy\\demonbuddy_180_leveling\\eu1_apollo_tr_agbact222\\atQueen");
     AStarPathing pathing = new AStarPathing(map);
     MapWindow.Instance(new MapDrawer(map), false).Visible = true;
     MapWindow.Instance().GetDrawer().SetPathing(pathing);
     MapWindow.Instance().Redraw();
     //Console.ReadKey();
 }
Example #2
0
 public MapDrawer(CachedMap cachedMap = null)
 {
     if (cachedMap != null)
     {
         this.CachedMap = cachedMap;
     }
     else
     {
         this.CachedMap = new CachedMap();
     }
 }
Example #3
0
        public static List<AStarNode> GenerateNodes(CachedMap map)
        {
            Dictionary<int, Dictionary<int, AStarNode>> validNodes = new Dictionary<int, Dictionary<int, AStarNode>>();

            lock (map.Cache)
            {
                foreach (var scene in map.Cache.Values)
                {
                    foreach (var cell in scene.Cells)
                    {
                        for (int x = NODE_DISTANCE * (int)Math.Ceiling((cell.Min.X + scene.ZoneMin.X) / NODE_DISTANCE); x <= (cell.Max.X + scene.ZoneMin.X); x += NODE_DISTANCE)
                        {
                            Dictionary<int, AStarNode> xSet = null;
                            if (!validNodes.TryGetValue(x, out xSet))
                            {
                                xSet = new Dictionary<int, AStarNode>();
                                validNodes.Add(x, xSet);
                            }
                            for (int y = NODE_DISTANCE * (int)Math.Ceiling((cell.Min.Y + scene.ZoneMin.Y) / NODE_DISTANCE); y <= (cell.Max.Y + scene.ZoneMin.Y); y += NODE_DISTANCE)
                            {
                                if (!xSet.ContainsKey(y))
                                {
                                    xSet.Add(y, new AStarNode(new Vector2(x, y)));
                                }
                            }
                        }
                    }
                }
            }

            List<AStarNode> result = new List<AStarNode>();
            List<int> offsets = new List<int>(){
                NODE_DISTANCE, 0,
                -NODE_DISTANCE, 0,
                0, NODE_DISTANCE,
                0, -NODE_DISTANCE
            };
            if (ALLOW_DIAGONALS)
            {
                offsets.AddRange(
                new int[]{
                    NODE_DISTANCE, NODE_DISTANCE,
                    -NODE_DISTANCE, NODE_DISTANCE,
                    -NODE_DISTANCE, -NODE_DISTANCE,
                    NODE_DISTANCE, -NODE_DISTANCE
                }
            );
            }
            foreach (var xEntry in validNodes)
            {
                foreach (var yEntry in xEntry.Value)
                {
                    var node = yEntry.Value;

                    // find all neighbours
                    for (int i = 0;  i < offsets.Count;  i += 2)
                    {
                        int xNear = xEntry.Key + offsets[i];
                        int yNear = yEntry.Key + offsets[i+1];

                        Dictionary<int, AStarNode> xSet = null;
                        AStarNode neighbour = null;
                        if (validNodes.TryGetValue(xNear, out xSet) && xSet.TryGetValue(yNear, out neighbour))
                        {
                            // TODO ensure there is a valid path between the two points
                            node.Neighbours.Add(neighbour);
                        }
                    }

                    result.Add(node);
                }
            }
            return result;
        }
Example #4
0
        public AStarPathingUnused(CachedMap map)
        {
            this.map = map;

            this.Points = GenerateNodes(map);
        }