From a17a9db2add24af980b268f90f5d09098ee8c83b Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 16 Dec 2014 13:12:58 +0000 Subject: [PATCH] lots of initial design for the game, and unit data --- game/game.cpp | 7 +++++++ game/game.h | 33 +++++++++++++++++++++++++++++++++ game/orders.h | 4 ++-- game/unit.cpp | 6 ++++-- game/unit.h | 10 ++++++++++ 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 7bb61ba..b014a7b 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -1 +1,8 @@ #include "game.h" + + +// Initialise the game with default configuration +void CTTRTSGame::Initialise() +{ + +} \ No newline at end of file diff --git a/game/game.h b/game/game.h index 8a4e184..a14b74f 100644 --- a/game/game.h +++ b/game/game.h @@ -2,6 +2,12 @@ #define _GAME_H_ #include "board.h" +#include "gametypes.h" +#include "orders.h" + +#include // unique_ptr and shared_ptr + +typedef std::vector< std::shared_ptr > sharedUnitVector_t; class CTTRTSGame { @@ -10,8 +16,35 @@ public: CTTRTSGame(); ~CTTRTSGame() = default; + // Initialise the game with default configuration + void Initialise(); + + // Issue orders to the game + bool IssueOrders( std::string orders ); + bool IssueOrders( COrderVector orders ); + + // Simulate and progress to the next turn + bool NextTurn(); + + // Get the number of units + inline unsigned int GetNumUnits() const { return m_orders.size(); } + + // Get unit by index as above (not unit ID) + inline const CUnit& GetUnitByIndex( unsigned int i ) const { return *m_orders[i]; } + private: + // Simulate all movements + bool SimulateMovements(); + + // Simulate all actions + bool SimulateActions(); + + // Vector to store points to all units + sharedUnitVector_t m_allUnits; + + // Orders to execute this turn + COrderVector m_orders; }; #endif //_GAME_H_ \ No newline at end of file diff --git a/game/orders.h b/game/orders.h index d737935..e90d3c7 100644 --- a/game/orders.h +++ b/game/orders.h @@ -20,10 +20,12 @@ struct COrder // Order command issued order_c order; + // Basic operators inline bool operator==( const COrder& rhs ) const; inline bool operator!=( const COrder& rhs ) const { return !(*this==rhs); } }; +// Simple == operator inline bool COrder::operator== ( const COrder& rhs ) const { return ( unit == rhs.unit ) && ( order == rhs.order ); @@ -33,10 +35,8 @@ inline bool COrder::operator== ( const COrder& rhs ) const 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 ); - #endif //_ORDERS_H_ \ No newline at end of file diff --git a/game/unit.cpp b/game/unit.cpp index 14d517e..517c239 100644 --- a/game/unit.cpp +++ b/game/unit.cpp @@ -1,18 +1,19 @@ #include "unit.h" +// Unit types #include "unitv.h" -#include - std::unique_ptr CUnit::getUnitFromVis( unitVis_c vis ) { switch( vis ) { + // Match with any image for a V case '^': case '>': case 'v': case '<': { + // Create a V std::unique_ptr p = std::unique_ptr(new CUnitV); if( (bool)p && p->setFromVisual(vis) ) { @@ -22,5 +23,6 @@ std::unique_ptr CUnit::getUnitFromVis( unitVis_c vis ) } } + // No unit found, return nullptr return std::move(std::unique_ptr(nullptr)); } \ No newline at end of file diff --git a/game/unit.h b/game/unit.h index e71a96f..585c6c7 100644 --- a/game/unit.h +++ b/game/unit.h @@ -4,6 +4,7 @@ #include #include +#include "gametypes.h" #include "vector2.h" // Type for the unit type-id @@ -28,6 +29,15 @@ protected: private: + // Unit ID + unit_id_t id; + + // Team ID + team_id_t team_id; + + // Owner ID + player_id_t owner_id; + // All units must have position uvector2 pos; };