/* Copyright (C) 2017 G. Michael Barnes The file NavNode.cs is part of AGMGSKv8 a port and update of AGXNASKv7 from MonoGames 3.4 to MonoGames 3.5 AGMGSKv8 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #region Using Statements using System; using System.IO; // needed for trace()'s fout using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; #endregion namespace AGMGSKv8 { /// /// A WayPoint or Marker to be used in path following or path finding. /// Five types of WAYPOINT: /// VERTEX, a non-navigatable terrain vertex /// WAYPOINT, a navigatable terrain vertex /// PATH, a node in a path (could be the result of A*) /// OPEN, a possible node to follow in an A*path /// CLOSED, a node that has been evaluated by A* /// /// 2/14/2012 last update /// public class NavNode : IComparable { public enum NavNodeEnum { VERTEX, WAYPOINT, PATH, OPEN, CLOSED }; private double distance; // can be used with A* path finding. private Vector3 translation; private NavNodeEnum navigatable; private Vector3 nodeColor; // constructors /// /// Make a VERTEX NavNode /// /// location of vertex public NavNode(Vector3 pos) { translation = pos; Navigatable = NavNodeEnum.VERTEX; } /// /// Make a NavNode and set its Navigational type /// /// location of WAYPOINT /// Navigational type {VERTEX, WAYPOINT, PATH, OPEN, CLOSED} public NavNode(Vector3 pos, NavNodeEnum nType) { translation = pos; Navigatable = nType; } // properties public Vector3 NodeColor { get { return nodeColor; }} public Double Distance { get { return distance; } set { distance = value; } } /// /// When changing the Navigatable type the WAYPOINT's nodeColor is /// also updated. /// public NavNodeEnum Navigatable { get { return navigatable; } set { navigatable = value; switch (navigatable) { case NavNodeEnum.VERTEX : nodeColor = Color.Black.ToVector3(); break; // black case NavNodeEnum.WAYPOINT : nodeColor = Color.Yellow.ToVector3(); break; // yellow case NavNodeEnum.PATH : nodeColor = Color.Blue.ToVector3(); break; // blue case NavNodeEnum.OPEN : nodeColor = Color.White.ToVector3(); break; // white case NavNodeEnum.CLOSED : nodeColor = Color.Red.ToVector3(); break; // red } }} public Vector3 Translation { get { return translation; } } // methods /// /// Useful in A* path finding /// when inserting into an min priority queue open set ordered on distance /// /// goal node /// usual comparison values: -1, 0, 1 public int CompareTo(NavNode n) { if (distance < n.Distance) return -1; else if (distance > n.Distance) return 1; else return 0; } } }