diff --git a/src/npc.c b/src/npc.c index 1002936..752aad6 100644 --- a/src/npc.c +++ b/src/npc.c @@ -44,7 +44,6 @@ int npc_clear_path(NPC *npc) return 0; } -//Won't work on static NPCs, use npc_clear_path before or make them on the heap int npc_append_path(uint16_t x, uint16_t y, NPC *npc) { npc->path_length++; @@ -66,7 +65,7 @@ void as_clean(uint8_t *visited, uint8_t *gscore, uint8_t *fscore) int as_reconstruct_path(int16_t *came_from, int w, int h, int16_t spos, int16_t dest, NPC *npc) { - if(npc_clear_path(npc) goto as_recons_fail; + if(npc_clear_path(npc)) goto as_recons_fail; int16_t next = came_from[dest]; diff --git a/src/npc.h b/src/npc.h index b32f485..29aa22c 100644 --- a/src/npc.h +++ b/src/npc.h @@ -46,7 +46,18 @@ typedef struct bool paused; } NPC; +//Frees then malloc()s a new path to npc +//Useful if you want to safely edit a path +int npc_clear_path(NPC *npc); +//Adds point x,y to the path of npc +//Won't work on static NPCs, use npc_clear_path before or make them on the heap +int npc_append_path(uint16_t x, uint16_t y, NPC *npc); + +//Clears the NPCs path and creates a new one going to dest, +//avoiding non-walkable tiles +//Returns non-zero on failure +int npc_pathfind(int dest_x, int dest_y, Map *full_map, NPC *npc); /* Draws the player player. This function should be called after drawing the * map! */