Ejemplo n.º 1
0
        public virtual void Initilize()
        {
            if (initialized)
            {
                Exception err = new Exception("ERROR: AIPathfinder.Initialize() - Can't initialize more then once!");
            }

            if (map == null)
            {
                Exception err = new Exception("ERROR: AIPathfinder.Initialize() - Set map before calling this method!");
            }

            if (character == null)
            {
                Exception err = new Exception("ERROR: AIPathfinder.Initilize() - Set character before calling this method!");
            }

            openQueue = new PriorityQueueB <AIPathfinderNode>(new AINodeComparer());
            closeList = new List <AIPathfinderNode>();
            if (grid == null)
            {
                grid = new byte[map.Width, map.Height];


                // get the cost of each node as seend from character's perspective
                for (int w = 0; w < map.Width; w++)
                {
                    for (int h = 0; h < map.Height; h++)
                    {
                        grid[w, h] = character.TypeToCost(
                            map.Node(w, h).Type
                            );
                    }
                }
            }

            parentNode    = new AIPathfinderNode();
            parentNode.G  = 0;
            parentNode.H  = heuristicEstimateValue;
            parentNode.F  = parentNode.G + parentNode.H;
            parentNode.X  = startNode.X;
            parentNode.Y  = startNode.Y;
            parentNode.PX = parentNode.X;
            parentNode.PY = parentNode.Y;

            initialized = true;

            this.state = AIPathfinderState.Idle;
        }
Ejemplo n.º 2
0
        public void FillMapForAvoidDemo(ref AIMap mapToFill)
        {
            if (mapToFill == null)
            {
                return;
            }

            int X = mapToFill.Width / 2;
            int Y = mapToFill.Height / 2;

            mapToFill.Node(X, Y).Type     = 0;
            mapToFill.Node(X + 1, Y).Type = 0;
            mapToFill.Node(X - 1, Y).Type = 0;
            mapToFill.Node(X, Y + 1).Type = 0;
            mapToFill.Node(X, Y - 1).Type = 0;
        }
Ejemplo n.º 3
0
        public void FillMap(ref AIMap mapToFill)
        {
            if (mapToFill == null)
            {
                return;
            }

            // node types:
            // 0 - can't cross
            // 1 - crossabe

            Random rnd = new Random();

            for (int index = 0; index < 1000; index++)
            {
                int X = (int)rnd.Next(mapToFill.Width - 1);
                int Y = (int)rnd.Next(mapToFill.Height - 1);

                mapToFill.Node(X, Y).Type = 0;
            }
        }