1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#ifndef UNIT_H
#define UNIT_H
#include <camera.h>
#include <gfx.h>
#include <sfx.h>
#include <instance.h>
#include <unit_type.h>
#include <util.h>
#include <fixmath.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
enum unit_state
{
UNIT_STATE_IDLE_MOVING
};
struct unit_target
{
struct instance *ins;
enum unit_state state;
instance_sheltered_cb shelter;
instance_attacked_cb attack;
instance_done_cb done;
void *op;
};
struct unit
{
struct instance instance;
enum unit_type type;
enum unit_dir
{
UNIT_DIR_N,
UNIT_DIR_NE,
UNIT_DIR_E,
UNIT_DIR_SE,
UNIT_DIR_S,
UNIT_DIR_SW,
UNIT_DIR_W,
UNIT_DIR_NW
} dir;
enum unit_state state;
struct
{
unsigned char t, i;
} frame;
fix16_t rx, ry, tx, ty;
struct unit_target target;
};
UTIL_STATIC_ASSERT(!offsetof(struct unit, instance), "must be at offset zero");
struct unit_cfg
{
enum unit_type type;
unsigned long x, y;
};
void unit_create(const struct unit_cfg *cfg, struct unit *u);
int unit_render(const struct unit *u, const struct camera *cam, bool sel);
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
{
UNIT_SPRITE_N,
UNIT_SPRITE_NE,
UNIT_SPRITE_E,
UNIT_SPRITE_SE,
UNIT_SPRITE_S,
MAX_UNIT_SPRIES
};
extern struct sprite unit_sprites[MAX_UNIT_SPRIES];
enum unit_sound
{
UNIT_SOUND_SELECTED,
UNIT_SOUND_MOVE,
UNIT_SOUND_MOVE_2,
MAX_UNIT_SOUNDS
};
extern struct sound unit_sounds[MAX_UNIT_SOUNDS];
#ifdef __cplusplus
}
#endif
#endif /* UNIT_H */
|