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; }