2014-12-16 13:12:54 +00:00
|
|
|
#ifndef _UNIT_H_
|
|
|
|
#define _UNIT_H_
|
|
|
|
|
|
|
|
#include <string>
|
2014-12-16 13:13:02 +00:00
|
|
|
#include <vector>
|
2014-12-16 13:12:54 +00:00
|
|
|
|
2014-12-16 13:12:58 +00:00
|
|
|
#include "gametypes.h"
|
2014-12-16 13:12:54 +00:00
|
|
|
#include "vector2.h"
|
|
|
|
|
2014-12-21 11:04:26 +00:00
|
|
|
#define UNIT_FORMATTER "UNIT:%u pl:%u vs:%c dr:%c ps:[%u,%u]"
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 22:35:56 +00:00
|
|
|
// force a reset of the unit ID value
|
2014-12-21 10:44:08 +00:00
|
|
|
void __forceResetCUnitID();
|
2014-12-16 22:35:56 +00:00
|
|
|
|
2014-12-16 13:12:54 +00:00
|
|
|
// Base unit type
|
|
|
|
class CUnit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Factory function for creating units from a visual
|
2014-12-21 10:45:08 +00:00
|
|
|
static CUnit GetUnitFromVis( unitvis_c vis );
|
2014-12-16 13:13:02 +00:00
|
|
|
|
|
|
|
// Unit <--> string conversion functions
|
2014-12-21 10:41:06 +00:00
|
|
|
static std::string GetStringFromUnit(const CUnit& unit );
|
|
|
|
static CUnit GetUnitFromString(const std::string& unit );
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Constructor
|
2014-12-16 13:13:01 +00:00
|
|
|
CUnit();
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Move constructor and move assignment. CUnit cannot be copied
|
2014-12-16 13:13:01 +00:00
|
|
|
CUnit(CUnit&& unit);
|
2014-12-21 10:41:06 +00:00
|
|
|
CUnit& operator=(CUnit&& unit);
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-21 10:41:06 +00:00
|
|
|
bool operator==(const CUnit& rhs);
|
|
|
|
bool operator!=(const CUnit& rhs) { return !(*this == rhs); }
|
2014-12-16 13:13:00 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Getters for all the members
|
2014-12-21 10:44:08 +00:00
|
|
|
inline const unit_id_t& GetID() const { return unit_id; }
|
2014-12-21 11:14:01 +00:00
|
|
|
inline const player_t & GetPlayer() const { return player_id; }
|
2014-12-21 11:04:26 +00:00
|
|
|
inline const unitvis_c & GetVisual() const { return unit_vis; }
|
2014-12-21 11:14:20 +00:00
|
|
|
inline const dir_c & GetDir() const { return dir; }
|
2014-12-21 10:44:08 +00:00
|
|
|
inline const uvector2& GetPos() const { return pos; }
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Set
|
2014-12-21 11:14:01 +00:00
|
|
|
inline player_t SetPlayer(const player_t &v) { return (player_id = v); }
|
2014-12-21 11:04:26 +00:00
|
|
|
inline unitvis_c SetVisual(const unitvis_c &v) { return (unit_vis = v); }
|
2014-12-21 11:14:20 +00:00
|
|
|
inline dir_c SetDir(const dir_c &v) { return (dir = v); }
|
2014-12-21 10:44:08 +00:00
|
|
|
inline void SetPos(const uvector2 &v) { pos = v; }
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Get the co-ordinate in front of the unit
|
2014-12-21 10:44:08 +00:00
|
|
|
uvector2 GetInFront() const;
|
2014-12-16 13:13:01 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
// Check unit is valid
|
2014-12-21 10:44:08 +00:00
|
|
|
inline bool Valid() const;
|
2014-12-16 13:13:00 +00:00
|
|
|
|
|
|
|
// Set a unit based solely on it's visual
|
2014-12-21 10:45:08 +00:00
|
|
|
bool SetFromVisual(const unitvis_c &vis);
|
2014-12-16 13:12:56 +00:00
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Orientation methods
|
2014-12-21 11:14:20 +00:00
|
|
|
dir_c TurnLeft();
|
|
|
|
dir_c TurnRight();
|
|
|
|
dir_c TurnAround();
|
2014-12-16 13:13:01 +00:00
|
|
|
|
2014-12-16 13:12:54 +00:00
|
|
|
private:
|
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Update my visual must be called when setting direction
|
2014-12-21 10:45:08 +00:00
|
|
|
unitvis_c UpdateMyVisual();
|
2014-12-16 13:13:01 +00:00
|
|
|
|
2014-12-16 13:12:58 +00:00
|
|
|
// Unit ID
|
2014-12-21 10:41:06 +00:00
|
|
|
unit_id_t unit_id;
|
2014-12-16 13:13:00 +00:00
|
|
|
|
|
|
|
// Visual
|
2014-12-21 11:04:26 +00:00
|
|
|
unitvis_c unit_vis;
|
2014-12-16 13:12:58 +00:00
|
|
|
|
2014-12-21 11:04:26 +00:00
|
|
|
// Player ID
|
2014-12-21 11:14:01 +00:00
|
|
|
player_t player_id;
|
2014-12-16 13:12:58 +00:00
|
|
|
|
2014-12-16 13:13:01 +00:00
|
|
|
// Direction
|
2014-12-21 11:14:20 +00:00
|
|
|
dir_c dir;
|
2014-12-16 13:12:58 +00:00
|
|
|
|
2014-12-16 13:13:01 +00:00
|
|
|
// Position
|
2014-12-21 10:41:06 +00:00
|
|
|
uvector2 pos;
|
2014-12-16 13:12:54 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 13:13:02 +00:00
|
|
|
// Typedef for a vector of units
|
2014-12-21 10:44:08 +00:00
|
|
|
typedef std::vector< CUnit > CUnitVector;
|
|
|
|
typedef std::vector< unit_id_t > CUnitIDVector;
|
2014-12-16 13:13:02 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
// Simple validation
|
2014-12-21 10:44:08 +00:00
|
|
|
inline bool CUnit::Valid() const
|
2014-12-16 13:13:00 +00:00
|
|
|
{
|
|
|
|
return (unit_id != unit_id_invalid )
|
2014-12-21 11:14:01 +00:00
|
|
|
&& (player_id != player_t::NUM_INVALID )
|
2014-12-21 10:45:08 +00:00
|
|
|
&& (unit_vis != unitvis_invalid);
|
2014-12-16 13:13:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 13:13:01 +00:00
|
|
|
#endif //_UNIT_H_
|