Compare commits
3 Commits
afc554167e
...
e869bfd0f6
Author | SHA1 | Date |
---|---|---|
Xavier Del Campo Romero | e869bfd0f6 | |
Xavier Del Campo Romero | 4305732e0a | |
Xavier Del Campo Romero | 7196c6a0cc |
|
@ -52,7 +52,7 @@ struct human_player
|
|||
} d;
|
||||
} sel[MAX_SELECTED_INSTANCES];
|
||||
|
||||
struct
|
||||
struct human_player_target
|
||||
{
|
||||
const struct instance *ins;
|
||||
unsigned char t, n;
|
||||
|
|
|
@ -59,6 +59,9 @@ static bool select_units(struct human_player *const h, const short x,
|
|||
{
|
||||
sel = h->sel;
|
||||
h->n_sel = 1;
|
||||
|
||||
for (size_t i = 1; i < sizeof h->sel / sizeof *h->sel; i++)
|
||||
h->sel[i].d.u = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -123,6 +126,9 @@ static bool select_buildings(struct human_player *const h, const short x,
|
|||
{
|
||||
sel = h->sel;
|
||||
h->n_sel = 1;
|
||||
|
||||
for (size_t i = 1; i < sizeof h->sel / sizeof *h->sel; i++)
|
||||
h->sel[i].d.b = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -176,6 +182,9 @@ static bool select_resources(struct human_player *const h, const short x,
|
|||
{
|
||||
sel = h->sel;
|
||||
h->n_sel = 1;
|
||||
|
||||
for (size_t i = 1; i < sizeof h->sel / sizeof *h->sel; i++)
|
||||
h->sel[i].d.r = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -421,9 +430,12 @@ static void set_target(struct human_player *const h, struct unit *const u,
|
|||
const struct unit_target *const t)
|
||||
{
|
||||
unit_set_target(u, t);
|
||||
memset(&h->target, 0, sizeof h->target);
|
||||
h->target.ins = t->ins;
|
||||
h->target.render = true;
|
||||
|
||||
h->target = (const struct human_player_target)
|
||||
{
|
||||
.ins = t->ins,
|
||||
.render = true
|
||||
};
|
||||
}
|
||||
|
||||
static void target_from_pos(struct player *const p,
|
||||
|
@ -478,7 +490,9 @@ static void move_units(struct human_player *const h,
|
|||
|
||||
static void deselect_instances(struct human_player *const h)
|
||||
{
|
||||
memset(h->sel, 0, sizeof h->sel);
|
||||
for (size_t i = 0; i < sizeof h->sel / sizeof *h->sel; i++)
|
||||
h->sel[i] = (const struct sel_instance){0};
|
||||
|
||||
h->n_sel = 0;
|
||||
}
|
||||
|
||||
|
@ -511,7 +525,7 @@ static void update_target(struct human_player *const h)
|
|||
enum {TOGGLE = 10};
|
||||
|
||||
if (!i->alive)
|
||||
memset(&h->target, 0, sizeof h->target);
|
||||
h->target = (const struct human_player_target){0};
|
||||
else if (++h->target.t >= TOGGLE)
|
||||
{
|
||||
enum {TIMES = 5};
|
||||
|
@ -520,7 +534,7 @@ static void update_target(struct human_player *const h)
|
|||
h->target.t = 0;
|
||||
|
||||
if (++h->target.n >= TIMES)
|
||||
memset(&h->target, 0, sizeof h->target);
|
||||
h->target = (const struct human_player_target){0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,26 +143,25 @@ static int render_sel_single_unit(const struct human_player *const h,
|
|||
hpl.text = hp_str;
|
||||
gui_add_child(r, &hpl.common);
|
||||
|
||||
char c_str[sizeof "255"];
|
||||
struct gui_label cl;
|
||||
|
||||
if (unit_can_harvest(u))
|
||||
{
|
||||
const struct unit_harvester *const uh = &u->us.harvester;
|
||||
|
||||
if (uh->carry)
|
||||
{
|
||||
char c_str[sizeof "255"];
|
||||
const int rs = snprintf(c_str, sizeof c_str, "%hhu", uh->carry);
|
||||
struct gui_label cl;
|
||||
|
||||
if (rs < 0 || rs >= sizeof c_str)
|
||||
return -1;
|
||||
|
||||
gui_label_init(&cl);
|
||||
cl.common.x = CARRY_X;
|
||||
cl.common.y = CARRY_Y;
|
||||
cl.text = c_str;
|
||||
gui_add_child(r, &cl.common);
|
||||
|
||||
if (rs < 0 || rs >= sizeof c_str)
|
||||
return -1;
|
||||
|
||||
return gui_render(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue