Remove hp

This commit is contained in:
Xavier Del Campo Romero 2024-01-27 13:54:57 +01:00
parent 69f753d26f
commit b4f904ecdc
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
8 changed files with 4 additions and 88 deletions

View File

@ -31,7 +31,6 @@ struct building_cfg
void building_create(const struct building_cfg *cfg, struct building *b);
void building_set_alive_cb(void (*f)(const struct util_rect *dim, bool alive, void *p), void *p);
int building_render(const struct building *b, const struct camera *cam, bool sel);
instance_hp building_maxhp(const struct building *b);
const char *building_str(const struct building *b);
extern struct sprite building_sprites[MAX_BUILDING_TYPES];

View File

@ -6,16 +6,6 @@
struct sprite building_sprites[MAX_BUILDING_TYPES];
instance_hp building_maxhp(const struct building *const b)
{
static const instance_hp hp[] =
{
[BUILDING_TYPE_BARRACKS] = 100
};
return hp[b->type];
}
int building_render(const struct building *const b,
const struct camera *const cam, const bool sel)
{
@ -33,8 +23,7 @@ int building_render(const struct building *const b,
.prim_type = INSTANCE_RENDER_CFG_SPRITE,
.prim = {.s = s},
.cam = cam,
.sel = sel,
.max_hp = building_maxhp(b)
.sel = sel
};
return instance_render(&cfg);
@ -69,7 +58,6 @@ void building_create(const struct building_cfg *const cfg,
i->r.x = cfg->x;
i->r.y = cfg->y;
i->alive = true;
i->hp = building_maxhp(b);
if (cb)
cb(&i->r, i->alive, op);

View File

@ -12,17 +12,12 @@ extern "C"
{
#endif
typedef unsigned int instance_hp;
struct instance
{
bool alive, dying;
unsigned int hp;
bool alive;
struct util_rect r;
};
typedef bool (*instance_attacked_cb)(struct instance *i, unsigned int ap);
typedef bool (*instance_sheltered_cb)(struct instance *self, struct instance *other);
typedef void (*instance_done_cb)(struct instance *i, void *op);
struct instance_render_cfg
@ -48,15 +43,12 @@ struct instance_render_cfg
} prim;
bool sel;
instance_hp max_hp;
const struct instance_render_off
{
short x, y;
} *off;
};
bool instance_attacked(struct instance *self, unsigned int ap);
void instance_clear_pools(void);
int instance_render(const struct instance_render_cfg *cfg);
int instance_render_target(const struct instance *const i, const struct camera *cam);
void instance_cyclic(void);

View File

@ -8,19 +8,6 @@
static unsigned char line_g;
static bool line_g_flip;
bool instance_attacked(struct instance *const self, const instance_hp ap)
{
if (self->hp > ap)
self->hp -= ap;
else
{
self->hp = 0;
self->alive = false;
}
return !self->alive;
}
void instance_cyclic(void)
{
if (!line_g_flip)

View File

@ -279,8 +279,8 @@ static void update_selected(struct human_player *const h)
{
struct sel_instance *const si = &h->sel[i];
if (si->d.i && (!si->d.i->alive || si->d.i->dying
|| si->type == INSTANCE_TYPE_UNIT))
if (si->d.i
&& (!si->d.i->alive || si->type == INSTANCE_TYPE_UNIT))
{
si->d.i = NULL;
h->n_sel--;

View File

@ -25,8 +25,6 @@ static int render_sel_single_building(const struct human_player *const h,
const struct sel_instance *const sel, struct gui_common *const r)
{
const struct building *const b = sel->d.b;
const struct instance *const in = &b->instance;
const instance_hp hp = in->hp, max_hp = building_maxhp(b);
struct gui_label bl;
gui_label_init(&bl);
@ -35,21 +33,6 @@ static int render_sel_single_building(const struct human_player *const h,
bl.text = building_str(b);
gui_add_child(r, &bl.common);
char hp_str[sizeof "65535/65535"];
const int rs = snprintf(hp_str, sizeof hp_str, "%u/%u", hp, max_hp);
if (rs < 0 || rs >= sizeof hp_str)
return -1;
struct gui_label hpl;
gui_label_init(&hpl);
hpl.common.x = X_OFF;
hpl.common.y = HP_Y;
hpl.text = hp_str;
gui_add_child(r, &hpl.common);
return gui_render(r);
}
@ -57,8 +40,6 @@ static int render_sel_single_unit(const struct human_player *const h,
const struct sel_instance *const sel, struct gui_common *const r)
{
const struct unit *const u = sel->d.u;
const struct instance *const in = &u->instance;
const instance_hp hp = in->hp, max_hp = unit_maxhp(u);
enum {CARRY_X = 96, CARRY_Y = 8};
struct gui_label ul;
@ -69,21 +50,6 @@ static int render_sel_single_unit(const struct human_player *const h,
ul.text = unit_str(u);
gui_add_child(r, &ul.common);
char hp_str[sizeof "65535/65535"];
const int rs = snprintf(hp_str, sizeof hp_str, "%u/%u", hp, max_hp);
if (rs < 0 || rs >= sizeof hp_str)
return -1;
struct gui_label hpl;
gui_label_init(&hpl);
hpl.common.x = X_OFF;
hpl.common.y = HP_Y;
hpl.text = hp_str;
gui_add_child(r, &hpl.common);
return gui_render(r);
}

View File

@ -25,8 +25,6 @@ struct unit_target
{
struct instance *ins;
enum unit_state state;
instance_sheltered_cb shelter;
instance_attacked_cb attack;
instance_done_cb done;
void *op;
};
@ -73,9 +71,7 @@ bool unit_can_harvest(const struct unit *u);
bool unit_target_valid(const struct unit *u, const struct unit_target *t);
void unit_set_target(struct unit *u, const struct unit_target *t);
void unit_move_to(struct unit *u, unsigned long x, unsigned long y);
bool unit_attacked(struct instance *, instance_hp ap);
void unit_update(struct unit *u);
instance_hp unit_maxhp(const struct unit *u);
const char *unit_str(const struct unit *u);
enum

View File

@ -216,16 +216,6 @@ void unit_move_to(struct unit *const u, const unsigned long x, const unsigned lo
u->ty = y > y_off ? fix16_from_int(y - y_off) : 0;
}
instance_hp unit_maxhp(const struct unit *const u)
{
static const instance_hp hp[] =
{
[UNIT_TYPE_PEASANT] = 25
};
return hp[u->type];
}
static int get_ux(const struct unit *const u)
{
switch (u->dir)
@ -416,7 +406,6 @@ int unit_render(const struct unit *const u, const struct camera *const cam,
.prim = {.quad = &rcfg.qcfg},
.cam = cam,
.sel = sel,
.max_hp = unit_maxhp(u),
.off = &rcfg.off
};
@ -448,7 +437,6 @@ void unit_create(const struct unit_cfg *const cfg, struct unit *const u)
.instance =
{
.alive = true,
.hp = unit_maxhp(u)
},
.type = cfg->type,