

#ifndef __ROUTE_H__
#define __ROUTE_H__

#define BFF_ROUTEFIND_ID (('R'<<0) | ('O'<<8) | ('U'<<16) | (0<<24))

//#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)


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;

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

// 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
