summaryrefslogtreecommitdiff
path: root/Unit.h
blob: 0f554c726e7d8f33f7f2f1b43978ffe7cfed6359 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
#ifndef __UNIT_HEADER__
#define __UNIT_HEADER__

/* **************************************
 * 	Includes							*
 * **************************************/

#include "Global_Inc.h"
#include "Camera.h"
#include "Player.h"

#ifdef __cplusplus
extern "C"
{
#endif //__cplusplus

/* **************************************
 * 	Defines								*
 * **************************************/

 /* **************************************
 * 	Structs and enums					*
 * **************************************/

typedef enum t_unitdirection
{
    DIRECTION_LEFT = 0,
    DIRECTION_RIGHT,
    DIRECTION_UP,
    DIRECTION_DOWN
}UNIT_DIRECTION;

typedef enum t_unitid
{
    // Walking units
	PEASANT,
    SOLDIER,

    MAX_UNIT_ID,

    // Buildings
    BARRACKS,
    TOWER,
    TOWN_CENTER,

    MAX_BUILDING_ID,

    MAX_UNITS_BUILDINGS,

    FIRST_UNIT_ID = PEASANT,
    FIRST_BUILDING_ID = BARRACKS
}TYPE_UNIT_ID;

typedef struct t_Unit
{
	uint16_t x;
	uint16_t y;
	uint16_t target_x;
	uint16_t target_y;
	uint8_t hp;
	TYPE_UNIT_ID id;
	UNIT_DIRECTION dir;
	bool mirror; // True = down or left; true = up or right
    bool building;
	bool walking;
	bool alive;
	bool selected;
    bool selecting_attack;
    bool attacking;
    uint8_t walk_counter;
}TYPE_UNIT;

typedef struct
{
	const char* str;
	void (*pAction)(TYPE_UNIT*);
}TYPE_UNIT_ACTION;

typedef enum t_availableactions
{
    ACTION_BUILD_BARRACKS,
    ACTION_ATTACK,
    ACTION_CREATE_PEASANT,
    ACTION_CREATE_SOLDIER,
    ACTION_BUILD_TOWER_CENTER,
    MAX_ACTIONS
}UNIT_ACTION;

typedef struct t_Camera TYPE_CAMERA;
typedef struct t_Resource TYPE_RESOURCES;

/* **************************************
 * 	Global prototypes					*
 * **************************************/

// Initialization and handling
void            UnitInit(void);
void            UnitHandler(TYPE_UNIT* unitArray, size_t sz);

// Unit information
uint8_t         UnitGetHpFromID(TYPE_UNIT_ID id);
uint8_t         UnitGetWidthFromID(TYPE_UNIT_ID id);
uint8_t         UnitGetHeightFromID(TYPE_UNIT_ID id);
uint8_t         UnitGetAvailableActions(TYPE_UNIT* ptrUnit);
TYPE_RESOURCES  UnitNeededResourcesFromID(TYPE_UNIT_ID id);

// Rendering
void            UnitDraw(TYPE_UNIT* ptrUnit, TYPE_CAMERA* ptrCamera, bool bHighlighted);

void            UnitMoveTo(TYPE_UNIT* ptrUnit, uint16_t x, uint16_t y);

// Selection index
const char*     UnitGetActionString(UNIT_ACTION action);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif //__UNIT_HEADER__