/*
 * $Id: wp_info.h,v 2.8 89/12/03 13:59:43 tynor Exp $
 *----------------------------------------------------------------------------
 *	FPLAN - Flight Planner
 *	Steve Tynor
 *	tynor@prism.gatech.edu
 *
 *	This program is in the public domain. Permission to copy,
 * distribute, modify this program is hearby given as long as this header
 * remains. If you redistribute this program after modifying it, please
 * document your changes so that I do not take the blame (or credit) for
 * those changes.  If you fix bugs or add features, please send me a
 * patch so that I can keep the 'official' version up-to-date.
 *
 *	Bug reports are welcome and I'll make an attempt to fix those
 * that are reported.
 *
 *	USE AT YOUR OWN RISK! I assume no responsibility for any
 * errors in this program, its database or documentation. I will make an
 * effort to fix bugs, but if you crash and burn because, for example,
 * fuel estimates in this program were inaccurate, it's your own fault
 * for trusting somebody else's code! Remember, as PIC, it's _your_
 * responsibility to do complete preflight planning. Use this program as
 * a flight planning aid, but verify its results before using them.
 *----------------------------------------------------------------------------
 */

typedef int BOOLEAN;
#define FALSE ((BOOLEAN)0)
#define TRUE  ((BOOLEAN)1)

#define MI_PER_NM 1.1507575757	/* statute miles per natutical miles */

typedef enum {WP_FROM, WP_VIA, WP_TO} WAYPOINT_KIND;

typedef enum {WP_VOR, WP_AIRPORT, WP_NAMED_INTERSECTION, 
		 WP_INTERSECTION, WP_INCREMENTAL, WP_LAT_LONG,
		 WP_NDB, WP_DME, WP_TAC, WP_ILS, WP_WPT, WP_LOM, WP_LMM, WP_UNK
		 } WAYPOINT_MODE;

#define MAX_NUM_WAYPOINTS 100
#define MAX_NUM_VOR_FIXES 6

typedef enum {FROM, TO} FROM_TO;

typedef struct {
   BOOLEAN valid;
   double  value;
} OPTIONAL_DBL;

typedef struct {
   WAYPOINT_MODE       	mode;
   double		latitude;  /* stored in decimal - not degrees/min/sec */
   double		longitude;   
   char 		*desig;
   char 		*city;
   char 		*name;
   char 		*comment;
   OPTIONAL_DBL		freq;
   OPTIONAL_DBL		altitude;
   double		mag_variation;
   union {
      /* when wp_mode == WP_INCREMENTAL */
      double	dist_since_last_wp;
   } u;
} DATABASE_INFO;

typedef struct {
   BOOLEAN valid;
   DATABASE_INFO *db;
   double  heading;
   double  distance;
   FROM_TO from_to;
} VOR_FIX;

/*
 * NOTE: ALL VALUES STORED INTERNALLY IN KNOTS AND NAUTICAL MILES
 */
typedef struct {
   WAYPOINT_KIND       	wp_kind;
   DATABASE_INFO	*db;
   OPTIONAL_DBL 	tc;
   OPTIONAL_DBL 	mc;
   OPTIONAL_DBL 	mh;
   OPTIONAL_DBL 	wind_speed; 
   OPTIONAL_DBL 	wind_direction;
   OPTIONAL_DBL 	dist_leg;
   OPTIONAL_DBL 	dist;
   OPTIONAL_DBL 	dist_remain;
   OPTIONAL_DBL 	eta_leg;
   OPTIONAL_DBL 	eta;
   BOOLEAN		refuel;
   OPTIONAL_DBL		extra_fuel_burn;
   OPTIONAL_DBL 	fuel_amt;
   OPTIONAL_DBL 	fuel_rate;
   OPTIONAL_DBL 	fuel_leg;
   OPTIONAL_DBL 	altitude;
   OPTIONAL_DBL 	tas;
   OPTIONAL_DBL 	egs;
   VOR_FIX		vor_fix [MAX_NUM_VOR_FIXES];
} WAYPOINT_INFO;


WAYPOINT_INFO waypoints[MAX_NUM_WAYPOINTS];

int num_waypoints;

#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define ABS(x) (((x) < 0) ? -(x) : (x))


#define PI ((double) 3.14159265358979323846)

#define DEG2RAD(x) ((x)*PI/180.0)
#define RAD2DEG(x) ((x)*180.0/PI)

int max_nav;

#define CACHE_SIZE MAX_NUM_WAYPOINTS
DATABASE_INFO *cache [CACHE_SIZE];
int num_cached;

