From 0aef4f319caa2572d459b18e4e994122d53abcbe Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 27 Jan 2024 15:58:53 +0100 Subject: Remove resource, tech and old game resources --- src/resource/CMakeLists.txt | 3 - src/resource/inc/resource.h | 58 ------------- src/resource/inc/resource_type.h | 21 ----- src/resource/src/resource.c | 177 --------------------------------------- 4 files changed, 259 deletions(-) delete mode 100644 src/resource/CMakeLists.txt delete mode 100644 src/resource/inc/resource.h delete mode 100644 src/resource/inc/resource_type.h delete mode 100644 src/resource/src/resource.c (limited to 'src/resource') diff --git a/src/resource/CMakeLists.txt b/src/resource/CMakeLists.txt deleted file mode 100644 index 1591e58..0000000 --- a/src/resource/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_library(resource "src/resource.c") -target_include_directories(resource PUBLIC "inc") -target_link_libraries(resource PUBLIC camera gfx instance util) diff --git a/src/resource/inc/resource.h b/src/resource/inc/resource.h deleted file mode 100644 index aa7f1bd..0000000 --- a/src/resource/inc/resource.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef RESOURCE_H -#define RESOURCE_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -enum {RESOURCE_GOLD_CAPACITY = 2}; - -struct resource -{ - struct instance instance; - enum resource_type type; - - union - { - struct resource_gold - { - struct instance *miners[RESOURCE_GOLD_CAPACITY]; - size_t n_miners; - } gold; - } res; -}; - -UTIL_STATIC_ASSERT(!offsetof(struct resource, instance), "must be at offset zero"); - -struct resource_cfg -{ - enum resource_type type; - unsigned long x, y; -}; - -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); -bool resource_harvested(struct instance *i, instance_hp ap); -instance_hp resource_maxhp(const struct resource *res); -const char *resource_str(const struct resource *res); - -extern struct sprite resource_sprites[MAX_RESOURCE_TYPES]; - -#ifdef __cplusplus -} -#endif - -#endif /* RESOURCE_H */ diff --git a/src/resource/inc/resource_type.h b/src/resource/inc/resource_type.h deleted file mode 100644 index 8a41148..0000000 --- a/src/resource/inc/resource_type.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RESOURCE_TYPE_H -#define RESOURCE_TYPE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -enum resource_type -{ - RESOURCE_TYPE_WOOD, - RESOURCE_TYPE_GOLD, - - MAX_RESOURCE_TYPES -}; - -#ifdef __cplusplus -} -#endif - -#endif /* RESOURCE_TYPE_H */ diff --git a/src/resource/src/resource.c b/src/resource/src/resource.c deleted file mode 100644 index 91c9681..0000000 --- a/src/resource/src/resource.c +++ /dev/null @@ -1,177 +0,0 @@ -#include -#include -#include -#include -#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) -{ - struct resource *const res = (struct resource *)self; - struct resource_gold *const g = &res->res.gold; - - for (size_t i = 0; i < sizeof g->miners / sizeof *g->miners; i++) - { - struct instance **const ins = &g->miners[i]; - - if (!*ins) - { - *ins = other; - g->n_miners++; - return true; - } - } - - return false; -} - -instance_sheltered_cb resource_shelter(const struct resource *res) -{ - static const instance_sheltered_cb s[] = - { - [RESOURCE_TYPE_GOLD] = gold_shelter - }; - - return s[res->type]; -} - -bool resource_harvested(struct instance *const self, const instance_hp 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) -{ - static const instance_hp hp[] = - { - [RESOURCE_TYPE_GOLD] = 1000, - [RESOURCE_TYPE_WOOD] = 45 - }; - - return hp[res->type]; -} - -int resource_render(const struct resource *const res, - const struct camera *const cam, const bool sel) -{ - const struct instance *const in = &res->instance; - - if (!in->alive) - return 0; - - sprite_get_or_ret(s, -1); - - if (sprite_clone(&resource_sprites[res->type], s)) - return -1; - - const struct instance_render_off *off = NULL; - - switch (res->type) - { - case RESOURCE_TYPE_GOLD: - s->h = in->r.h; - - if (res->res.gold.n_miners) - s->v += s->h; - - break; - - case RESOURCE_TYPE_WOOD: - { - static const struct instance_render_off w_off = - { - .y = -30 - }; - - off = &w_off; - } - break; - - default: - break; - } - - const struct instance_render_cfg cfg = - { - .i = &res->instance, - .prim_type = INSTANCE_RENDER_CFG_SPRITE, - .prim = {.s = s}, - .cam = cam, - .sel = sel, - .max_hp = resource_maxhp(res), - .off = off - }; - - return instance_render(&cfg); -} - -static void get_dimensions(const enum resource_type type, short *const w, - short *const h) -{ - static const struct dim - { - short w, h; - } dim[] = - { - [RESOURCE_TYPE_GOLD] = {.w = 96, .h = 96}, - [RESOURCE_TYPE_WOOD] = {.w = 32, .h = 16} - }; - - const struct dim *const d = &dim[type]; - *w = d->w; - *h = d->h; -} - -int resource_create(const struct resource_cfg *const cfg, struct resource *const list, - const size_t n) -{ - for (size_t i = 0; i < n; i++) - { - struct resource *const r = &list[i]; - struct instance *const in = &r->instance; - - if (!in->alive) - { - get_dimensions(cfg->type, &in->r.w, &in->r.h); - r->type = cfg->type; - in->r.x = cfg->x; - in->r.y = cfg->y; - in->alive = true; - in->hp = resource_maxhp(r); - - if (cb) - cb(&in->r, in->alive, op); - - return 0; - } - } - - 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[] = - { - [RESOURCE_TYPE_GOLD] = "Gold mine", - [RESOURCE_TYPE_WOOD] = "Pine tree" - }; - - return str[res->type]; -} -- cgit v1.2.3