From 49303ba6adc3025dea1a210e45e40100fd0a1965 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Tue, 23 Jul 2024 18:06:42 +0200 Subject: [PATCH] =?UTF-8?q?npc=20:=20ajout=20des=20d=C3=A9clarations=20des?= =?UTF-8?q?=20nouvelles=20fonctions,=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/npc.c | 3 +-- src/npc.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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! */