From 1950fe7b0679c6b6486cc7b25bef813db2b1bb4e Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 30 Mar 2022 08:28:47 +0200 Subject: Implement sub-tile collboxes These will be later used by the pathfinding algorithm. --- src/resource/inc/resource.h | 1 + src/resource/src/resource.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/resource') diff --git a/src/resource/inc/resource.h b/src/resource/inc/resource.h index 56da45e..aa7f1bd 100644 --- a/src/resource/inc/resource.h +++ b/src/resource/inc/resource.h @@ -41,6 +41,7 @@ struct resource_cfg }; const struct container_list *resource_res(void); +void resource_set_alive_cb(void (*f)(const struct util_rect *dim, bool alive, void *p), void *p); int resource_create(const struct resource_cfg *cfg, struct resource *list, size_t n); int resource_render(const struct resource *res, const struct camera *cam, bool sel); instance_sheltered_cb resource_shelter(const struct resource *res); diff --git a/src/resource/src/resource.c b/src/resource/src/resource.c index ae0b528..40f2301 100644 --- a/src/resource/src/resource.c +++ b/src/resource/src/resource.c @@ -5,6 +5,8 @@ #include struct sprite resource_sprites[MAX_RESOURCE_TYPES]; +static void (*cb)(const struct util_rect *, bool, void *); +static void *op; static bool gold_shelter(struct instance *const self, struct instance *const other) @@ -39,7 +41,12 @@ instance_sheltered_cb resource_shelter(const struct resource *res) bool resource_harvested(struct instance *const self, const instance_hp ap) { - return instance_attacked(self, ap); + const bool ret = instance_attacked(self, ap); + + if (ret && cb) + cb(&self->r, self->alive, op); + + return ret; } instance_hp resource_maxhp(const struct resource *const res) @@ -120,6 +127,10 @@ int resource_create(const struct resource_cfg *const cfg, struct resource *const in->r.y = cfg->y; in->alive = true; in->hp = resource_maxhp(r); + + if (cb) + cb(&in->r, in->alive, op); + return 0; } } @@ -127,6 +138,13 @@ int resource_create(const struct resource_cfg *const cfg, struct resource *const return -1; } +void resource_set_alive_cb(void (*const f)(const struct util_rect *, bool, void *), + void *const p) +{ + cb = f; + op = p; +} + const char *resource_str(const struct resource *const res) { static const char *const str[] = -- cgit v1.2.3