More cleanup and remove of unneeded functions
This commit is contained in:
parent
005896b13c
commit
4c439a383e
6 changed files with 27 additions and 84 deletions
18
game/game.h
18
game/game.h
|
@ -5,10 +5,6 @@
|
|||
#include "gametypes.h"
|
||||
#include "orders.h"
|
||||
|
||||
#include <memory> // unique_ptr and shared_ptr
|
||||
|
||||
typedef std::vector< CUnit > CUnitVector;
|
||||
|
||||
// Type for order and unit pairs
|
||||
struct OrderUnitPair
|
||||
{
|
||||
|
@ -16,25 +12,22 @@ struct OrderUnitPair
|
|||
OrderUnitPair( OrderUnitPair&& other )
|
||||
: unit ( std::move(other.unit) )
|
||||
, order ( other.order )
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
// Multi parameter constructor
|
||||
OrderUnitPair( CUnit&& u, COrder o )
|
||||
: unit ( std::move(u) )
|
||||
, order ( o )
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
// Move asignment operator
|
||||
inline OrderUnitPair& operator=( OrderUnitPair&& rhs ) { this->unit = std::move(rhs.unit);this->order = rhs.order;rhs.order = COrder(); return *this; }
|
||||
|
||||
CUnit unit;
|
||||
COrder order;
|
||||
CUnit unit; // The unit
|
||||
COrder order; // Order for this unit from this turn
|
||||
};
|
||||
|
||||
// Typedef for a vector of these unit pairs
|
||||
typedef std::vector< OrderUnitPair > OrderUnitPairVector;
|
||||
|
||||
class CTTRTSGame
|
||||
|
@ -54,6 +47,7 @@ public:
|
|||
int IssueOrders( player_id_t player, const std::string& orders );
|
||||
int IssueOrders( player_id_t player, const COrderVector& orders );
|
||||
|
||||
// Issue a single order, returns non-zero for rejection
|
||||
int IssueOrder( player_id_t player, const COrder& order );
|
||||
|
||||
// Simulate and progress to the next turn
|
||||
|
|
|
@ -35,25 +35,3 @@ COrder GetOrderFromString( const std::string& _order )
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool isMovementOrder( const COrder& order )
|
||||
{
|
||||
const order_c c = order.order;
|
||||
for ( unsigned int i = 0; i < _countof(sk_movementOrders); i++ )
|
||||
{
|
||||
if ( c == sk_movementOrders[i] )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isActionOrder( const COrder& order )
|
||||
{
|
||||
const order_c c = order.order;
|
||||
for ( unsigned int i = 0; i < _countof(sk_actionOrders); i++ )
|
||||
{
|
||||
if ( c == sk_actionOrders[i] )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,29 +18,14 @@ enum class order_c : char
|
|||
INVALID
|
||||
};
|
||||
|
||||
// Movement orders
|
||||
static const order_c sk_movementOrders[] =
|
||||
{
|
||||
order_c::F, // Forward
|
||||
};
|
||||
|
||||
// Action orders
|
||||
static const order_c sk_actionOrders[] =
|
||||
{
|
||||
order_c::L, // Left
|
||||
order_c::R, // Right
|
||||
order_c::A, // Attack
|
||||
};
|
||||
|
||||
// Container for an order
|
||||
struct COrder
|
||||
{
|
||||
// Base constructor makes invalid order
|
||||
COrder()
|
||||
: unit ( unit_id_invalid )
|
||||
, order ( order_c::INVALID )
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
// Unit order is for
|
||||
unit_id_t unit;
|
||||
|
@ -67,7 +52,4 @@ typedef std::vector<COrder> COrderVector;
|
|||
std::string GetStringFromOrder(const COrder& order );
|
||||
COrder GetOrderFromString( const std::string& order );
|
||||
|
||||
bool isMovementOrder( const COrder& order );
|
||||
bool isActionOrder( const COrder& order );
|
||||
|
||||
#endif //_ORDERS_H_
|
||||
|
|
|
@ -39,7 +39,7 @@ CUnit::CUnit()
|
|||
, pos ( { ucoord_invalid, ucoord_invalid } )
|
||||
{
|
||||
updateMyVisual();
|
||||
};
|
||||
}
|
||||
|
||||
// Move constructor
|
||||
CUnit::CUnit(CUnit&& unit)
|
||||
|
@ -54,6 +54,7 @@ CUnit::CUnit(CUnit&& unit)
|
|||
}
|
||||
|
||||
|
||||
// Move asignment operator
|
||||
CUnit& CUnit::operator=(CUnit&& unit)
|
||||
{
|
||||
unit_id = std::move(unit.unit_id) ;
|
||||
|
@ -65,6 +66,7 @@ CUnit& CUnit::operator=(CUnit&& unit)
|
|||
return *this;
|
||||
}
|
||||
|
||||
// Get a unit from a visual
|
||||
CUnit CUnit::getUnitFromVis( unitVis_c vis )
|
||||
{
|
||||
CUnit unit;
|
||||
|
@ -87,6 +89,7 @@ unitVis_c CUnit::updateMyVisual()
|
|||
return getVisual();
|
||||
}
|
||||
|
||||
// Set the unit from visual
|
||||
bool CUnit::setFromVisual( const unitVis_c& vis )
|
||||
{
|
||||
dir_to_vis_map::const_iterator it;
|
||||
|
|
20
game/unit.h
20
game/unit.h
|
@ -2,7 +2,7 @@
|
|||
#define _UNIT_H_
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "gametypes.h"
|
||||
#include "vector2.h"
|
||||
|
@ -12,11 +12,17 @@ class CUnit
|
|||
{
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
CUnit();
|
||||
|
||||
// Move constructor and move asignement. CUnit cannot be copied
|
||||
CUnit(CUnit&& unit);
|
||||
CUnit& operator=(CUnit&& unit);
|
||||
|
||||
// Default dtor
|
||||
~CUnit() = default;
|
||||
|
||||
// Getters for all the members
|
||||
inline const unit_id_t& getID() const { return unit_id; }
|
||||
inline const team_id_t& getTeam() const { return team_id; }
|
||||
inline const player_id_t& getPlayer() const { return player_id; }
|
||||
|
@ -27,6 +33,8 @@ public:
|
|||
inline int setTeam(const team_id_t& v) { return (v == team_id_invalid) ? -1 : (( team_id = v ), 0); }
|
||||
inline int setPlayer(const player_id_t& v) { return (v == player_id_invalid) ? -1 : (( player_id = v ), 0); }
|
||||
inline int setVisual(const unitVis_c& v) { return (v == unitVis_invalid) ? -1 : (( unit_vis = v ), 0); }
|
||||
|
||||
// Set unit direction
|
||||
inline dir_t setDir(const dir_t& v) { return (dir = v); }
|
||||
|
||||
inline const uvector2& getPos() const { return pos; }
|
||||
|
@ -44,17 +52,14 @@ public:
|
|||
// Factory function for creating units from a visual
|
||||
static CUnit getUnitFromVis( unitVis_c vis );
|
||||
|
||||
// Orientation methods
|
||||
dir_t turnLeft();
|
||||
dir_t turnRight();
|
||||
dir_t turnAround();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Update the visual of V
|
||||
// Update my visual must be called when setting direction
|
||||
unitVis_c updateMyVisual();
|
||||
|
||||
// Unit ID
|
||||
|
@ -76,6 +81,9 @@ private:
|
|||
uvector2 pos;
|
||||
};
|
||||
|
||||
// Typedef for a vector of units
|
||||
typedef std::vector< CUnit > CUnitVector;
|
||||
|
||||
// Simple validation
|
||||
inline bool CUnit::valid() const
|
||||
{
|
||||
|
|
|
@ -41,28 +41,6 @@ const char* tests()
|
|||
return "failed order string conversion test";
|
||||
}
|
||||
|
||||
// Test if movement order is correctly recognised
|
||||
{
|
||||
COrder order;
|
||||
order.order = order_c::F;
|
||||
if (!isMovementOrder(order) )
|
||||
return "Failed to detect a movement order";
|
||||
|
||||
if (isActionOrder(order) )
|
||||
return "Wrongly detected an action order";
|
||||
}
|
||||
|
||||
// Test if Attack order is correctly recognised
|
||||
{
|
||||
COrder order;
|
||||
order.order = order_c::A;
|
||||
if (! isActionOrder(order) )
|
||||
return "Failed to detect a action order";
|
||||
|
||||
if (isMovementOrder(order) )
|
||||
return "Wrongly detected an movement order";
|
||||
}
|
||||
|
||||
// Test of the game can logically handle a blank game
|
||||
{
|
||||
CTTRTSGame game( 15, 10 );
|
||||
|
|
Loading…
Add table
Reference in a new issue