diff --git a/game/game.cpp b/game/game.cpp index 1ebb6d8..b52b671 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -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; } diff --git a/game/orders.cpp b/game/orders.cpp index 4cae3d2..5928f1f 100644 --- a/game/orders.cpp +++ b/game/orders.cpp @@ -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; } \ No newline at end of file diff --git a/game/orders.h b/game/orders.h index e90d3c7..a433235 100644 --- a/game/orders.h +++ b/game/orders.h @@ -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 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_ \ No newline at end of file diff --git a/maths/mathtypes.h b/maths/mathtypes.h index ab1e0eb..322f78f 100644 --- a/maths/mathtypes.h +++ b/maths/mathtypes.h @@ -3,6 +3,11 @@ #include // std::numeric_limits +#include "stdlib.h" // for size_t + +template +constexpr size_t _countof(T (&)[N]) { return N; } + // Coordinate types typedef short coord_t; typedef unsigned short ucoord_t; diff --git a/test/test.cpp b/test/test.cpp index c6e9272..29ccbbe 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -4,69 +4,73 @@ #include "board.h" #include "orders.h" - -// Namespace for testing functions -namespace tests +const char* tests() { - // print a board - void debug_print( CBoard& b ) - { - for ( unsigned int r = 0; r < b.rows; r++ ) - { - for ( unsigned int c = 0; c < b.cols; c++ ) - { - std::cout<<(char)(b.get(c,r)); - } - std::cout< myV = CUnit::getUnitFromVis('v'); if( myV->getVisual() != 'v' ) - std::cout<<"ERROR, failed to properly create V unit"<