Framework for movement and action orders, plus some better organisation of the test code
This commit is contained in:
parent
008739dee6
commit
72b35dbc06
5 changed files with 115 additions and 44 deletions
|
@ -122,11 +122,31 @@ int CTTRTSGame::VerifyOrder( player_id_t player, const COrder& order )
|
|||
// Simulate all movements
|
||||
int CTTRTSGame::SimulateMovements()
|
||||
{
|
||||
// Grab all movement orders
|
||||
COrderVector movements;
|
||||
for ( COrderVector::const_iterator it = m_orders.begin(); it != m_orders.end(); it++ )
|
||||
{
|
||||
if( isMovementOrder(*it) )
|
||||
movements.push_back(*it);
|
||||
}
|
||||
|
||||
// Calculate movements
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Simulate all actions
|
||||
int CTTRTSGame::SimulateActions()
|
||||
{
|
||||
// Grab all action orders
|
||||
COrderVector actions;
|
||||
for ( COrderVector::const_iterator it = m_orders.begin(); it != m_orders.end(); it++ )
|
||||
{
|
||||
if( isActionOrder(*it) )
|
||||
actions.push_back(*it);
|
||||
}
|
||||
|
||||
// Calculate actions
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "orders.h"
|
||||
|
||||
#include "mathtypes.h"
|
||||
|
||||
// Convert an order to a string
|
||||
std::string GetStringFromOrder( COrder& order )
|
||||
std::string GetStringFromOrder(const COrder& order )
|
||||
{
|
||||
std::string ret;
|
||||
ret += std::to_string(order.unit);
|
||||
|
@ -12,8 +14,9 @@ std::string GetStringFromOrder( COrder& order )
|
|||
}
|
||||
|
||||
// Convert a string to an order
|
||||
COrder GetOrderFromString( std::string order )
|
||||
COrder GetOrderFromString( const std::string& _order )
|
||||
{
|
||||
std::string order = _order;
|
||||
COrder ret;
|
||||
|
||||
int pos = order.find(ORDER_DELIMITER);
|
||||
|
@ -31,4 +34,26 @@ COrder GetOrderFromString( 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;
|
||||
}
|
|
@ -11,6 +11,20 @@
|
|||
// Type for all orders ( as a char )
|
||||
typedef char order_c;
|
||||
|
||||
// Movement orders
|
||||
static const order_c sk_movementOrders[] =
|
||||
{
|
||||
'F', // Forward
|
||||
};
|
||||
|
||||
// Action orders
|
||||
static const order_c sk_actionOrders[] =
|
||||
{
|
||||
'L', // Left
|
||||
'R', // Right
|
||||
'A', // Attack
|
||||
};
|
||||
|
||||
// Container for an order
|
||||
struct COrder
|
||||
{
|
||||
|
@ -36,7 +50,10 @@ typedef std::vector<COrder> COrderVector;
|
|||
|
||||
// Order strings stored as simply "[unit id] [order char]"
|
||||
// string <--> order conversion functions
|
||||
std::string GetStringFromOrder( COrder& order );
|
||||
COrder GetOrderFromString( std::string order );
|
||||
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_
|
Loading…
Add table
Add a link
Reference in a new issue