

#ifndef __ROUTE_H__
#define __ROUTE_H__

//#define USE_BEVEL_ROUTES

//#define DOG_ROUTEFIND_MARGIN (110)
//#define DOG_ROUTEFIND_MARGIN (200)
// make to match the dog's coll-radius, otherwise it won't stop and bark when you're out of reach
#define DOG_ROUTEFIND_MARGIN (310)

#define DOG_POSITION_MARGIN    (DOG_ROUTEFIND_MARGIN - 10)
#define DOG_ROUTELINE_MARGIN  (DOG_ROUTEFIND_MARGIN  + 10)
#define DOG_ROUTEPOINT_MARGIN  (DOG_ROUTEFIND_MARGIN + 50)
#define DOG_ROUTELINE_SCHMITT	(10)

#ifndef USE_BEVEL_ROUTES
	#define BFF_ROUTEFIND_ID (('R'<<0) | ('O'<<8) | ('U'<<16) | (0<<24))
	typedef struct
	{
		int vx;
		int vz;
	}ROUTEBOX_VECTOR;
	typedef struct ROUTEBOX
	{
		ROUTEBOX_VECTOR *vecs;

		int n_vecs;
		int minx,maxx;
		int minz,maxz;

	}ROUTEBOX;



	typedef struct ROUTEFIND_STR
	{
		unsigned long id;		// Standard BFF header
		unsigned long len;
		unsigned long crc;

		int n_boxes;
		ROUTEBOX *boxes;
	}ROUTEFIND_STR;
#else
	#define BFF_ROUTEFIND_ID (('R'<<0) | ('O'<<8) | ('U'<<16) | (1<<24))
	typedef struct
	{
		int vx;
		int vz;
	}ROUTEBOX_VECTOR;
	typedef struct ROUTEBOX
	{
		ROUTEBOX_VECTOR *vecs;

		int n_vecs;
		int minx,maxx;
		int minz,maxz;

	}ROUTEBOX;



	typedef struct ROUTEFIND_STR
	{
		unsigned long id;		// Standard BFF header
		unsigned long len;
		unsigned long crc;

		int n_boxes;
		ROUTEBOX *boxes;
		ROUTEBOX *bevel_boxes;

	}ROUTEFIND_STR;
#endif




void routefindPreBFF();
void routefindLinkBFF(ROUTEFIND_STR *routes);

int routeFindRoute(VECTOR *src, VECTOR *dest, ROUTEBOX_VECTOR *route, int max_len);
void routeShowRoute(VECTOR *src, ROUTEBOX_VECTOR *route, int route_len);

// returns 1 if it needed pushing
int routeKeepOutOfRouteboxes(int *vx, int *vz, int margin);
int routeKeepOutOfRouteboxes2(int *vx, int *vz, int margin);

// For use when returning an enemy to patrolling
// Returns point number at start of the nearest line-segment and (optionally) closest vector target

typedef struct tagENEMYPOINT * ENEMYPOINTPOINTER;

int routeFindNearestPoint(VECTOR *src, ENEMYPOINTPOINTER path, int n_points, VECTOR *out);

void routeDraw(void);

#endif
