PocketEmpires/UnitOld.h

124 lines
2.8 KiB
C

#ifndef UNIT_H__
#define UNIT_H__
/* **************************************
* 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_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 UnitDrawShadow(TYPE_UNIT *ptrUnit, TYPE_CAMERA *ptrCamera);
/* Movement. */
void UnitMoveTo(TYPE_UNIT *ptrUnit, uint16_t x, uint16_t y);
/* Collision cheking. */
bool UnitCheckCollisionAgainstOtherUnits(TYPE_COLLISION_BLOCK* cb, TYPE_UNIT *ptrUnitArray, TYPE_UNIT* ptrCurrentUnit);
/* Selection index. */
const char* UnitGetActionString(UNIT_ACTION action);
#ifdef __cplusplus
}
#endif /* cplusplus. */
#endif /* UNIT_H__. */