115 lines
2.2 KiB
C
115 lines
2.2 KiB
C
#ifndef __UNIT_HEADER__
|
|
#define __UNIT_HEADER__
|
|
|
|
/* **************************************
|
|
* Includes *
|
|
* **************************************/
|
|
|
|
#include "Global_Inc.h"
|
|
#include "Camera.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 struct t_Unit
|
|
{
|
|
uint16_t x;
|
|
uint16_t y;
|
|
uint16_t target_x;
|
|
uint16_t target_y;
|
|
uint8_t hp;
|
|
uint8_t 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 enum t_unitid
|
|
{
|
|
// Walking units
|
|
PEASANT = 0,
|
|
|
|
MAX_UNIT_ID,
|
|
|
|
// Buildings
|
|
BARRACKS,
|
|
TOWER,
|
|
|
|
MAX_BUILDING_ID,
|
|
|
|
MAX_UNITS_BUILDINGS,
|
|
|
|
FIRST_UNIT_ID = PEASANT,
|
|
FIRST_BUILDING_ID = BARRACKS
|
|
}TYPE_UNIT_ID;
|
|
|
|
typedef struct
|
|
{
|
|
const char* str;
|
|
void (*pAction)(TYPE_UNIT*);
|
|
}TYPE_UNIT_ACTION;
|
|
|
|
typedef enum t_availableactions
|
|
{
|
|
ACTION_BUILD,
|
|
ACTION_ATTACK,
|
|
ACTION_CREATE_UNIT
|
|
}UNIT_ACTION;
|
|
|
|
typedef struct t_Camera TYPE_CAMERA;
|
|
|
|
/* **************************************
|
|
* Global prototypes *
|
|
* **************************************/
|
|
|
|
// Initialization and handling
|
|
void UnitInit(void);
|
|
void UnitHandler(TYPE_UNIT* ptrUnit);
|
|
|
|
// Unit information
|
|
uint8_t UnitGetHpFromID(uint8_t id);
|
|
uint8_t UnitGetWidthFromID(uint8_t id);
|
|
uint8_t UnitGetHeightFromID(uint8_t id);
|
|
uint8_t UnitGetAvailableActions(TYPE_UNIT* ptrUnit);
|
|
|
|
// Rendering
|
|
void UnitDraw(TYPE_UNIT* ptrUnit, TYPE_CAMERA* ptrCamera, bool bHighlighted);
|
|
|
|
void UnitMoveTo(TYPE_UNIT* ptrUnit, uint16_t x, uint16_t y);
|
|
|
|
void UnitAcceptAction(TYPE_UNIT* ptrUnit);
|
|
void UnitResetMenuLevel(void);
|
|
|
|
// Selection index
|
|
const char* UnitGetActionString(UNIT_ACTION action);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif //__cplusplus
|
|
|
|
#endif //__UNIT_HEADER__
|