X-Git-Url: https://pd.if.org/git/?p=hexagon;a=blobdiff_plain;f=hexmap.h;h=50665d058f87c05faaa42e11838688892485d86c;hp=10586538067fca7ed15d34bd8b4badd551276c9d;hb=5c48a06bc8649958e69013c53e925b83398ebc74;hpb=67fdcec57ab31e7a972ed624ab5f6df866313206 diff --git a/hexmap.h b/hexmap.h index 1058653..50665d0 100644 --- a/hexmap.h +++ b/hexmap.h @@ -79,6 +79,10 @@ int HL_hexcenter(int cantor, double *x, double *y); /* how far is it on the hex grid */ int HL_distance(int from_cantor, int to_cantor); +/* returns 0 for <0 or >5 */ +int HL_adjacent_hex(int start, int dir); + +/* module direction */ int HL_adjhex(int start, int dir); int HL_hexes_at_range(int hex, int range, int *list, int size); int HL_hexes_within_range(int hex, int range, int *list, int size); @@ -105,4 +109,37 @@ struct HL_hex { int x,y; /* hmm. would be nice to be able to just point to a generic */ }; +/* + * Pathfinding + */ + +struct HL_astar_hex { + int hex; + double f, g, h; + struct HL_astar_hex *parent; + int open; + struct HL_astar_hex *next; + struct HL_astar_hex *prev; +}; + +struct HL_astar { + int start, goal; + int pathlen; + double (*metric)(int,int); + double (*heuristic)(int,int); + int (*neighbor)(int,int); + int nodes, allocated; + struct HL_astar_hex *sets; + struct HL_astar_hex *open; + struct HL_astar_hex *closed; + struct HL_astar_hex *from, *to; + int known, index; + int error, malloced; +}; + +int HL_findpath(struct HL_astar *s, int loops); +void HL_astar_free(struct HL_astar *s); +struct HL_astar *HL_astar_clear(struct HL_astar *s); +struct HL_astar *HL_astar_init(struct HL_astar *s); + #endif