lots of initial design for the game, and unit data

This commit is contained in:
Marc Di Luzio 2014-12-16 13:12:58 +00:00
parent 6a17e4e4c1
commit a17a9db2ad
5 changed files with 56 additions and 4 deletions

View file

@ -1 +1,8 @@
#include "game.h" #include "game.h"
// Initialise the game with default configuration
void CTTRTSGame::Initialise()
{
}

View file

@ -2,6 +2,12 @@
#define _GAME_H_ #define _GAME_H_
#include "board.h" #include "board.h"
#include "gametypes.h"
#include "orders.h"
#include <memory> // unique_ptr and shared_ptr
typedef std::vector< std::shared_ptr<CUnit> > sharedUnitVector_t;
class CTTRTSGame class CTTRTSGame
{ {
@ -10,8 +16,35 @@ public:
CTTRTSGame(); CTTRTSGame();
~CTTRTSGame() = default; ~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: 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_ #endif //_GAME_H_

View file

@ -20,10 +20,12 @@ struct COrder
// Order command issued // Order command issued
order_c order; order_c order;
// Basic operators
inline bool operator==( const COrder& rhs ) const; inline bool operator==( const COrder& rhs ) const;
inline bool operator!=( const COrder& rhs ) const { return !(*this==rhs); } inline bool operator!=( const COrder& rhs ) const { return !(*this==rhs); }
}; };
// Simple == operator
inline bool COrder::operator== ( const COrder& rhs ) const inline bool COrder::operator== ( const COrder& rhs ) const
{ {
return ( unit == rhs.unit ) && ( order == rhs.order ); return ( unit == rhs.unit ) && ( order == rhs.order );
@ -33,10 +35,8 @@ inline bool COrder::operator== ( const COrder& rhs ) const
typedef std::vector<COrder> COrderVector; typedef std::vector<COrder> COrderVector;
// Order strings stored as simply "[unit id] [order char]" // Order strings stored as simply "[unit id] [order char]"
// string <--> order conversion functions // string <--> order conversion functions
std::string GetStringFromOrder( COrder& order ); std::string GetStringFromOrder( COrder& order );
COrder GetOrderFromString( std::string order ); COrder GetOrderFromString( std::string order );
#endif //_ORDERS_H_ #endif //_ORDERS_H_

View file

@ -1,18 +1,19 @@
#include "unit.h" #include "unit.h"
// Unit types
#include "unitv.h" #include "unitv.h"
#include <memory>
std::unique_ptr<CUnit> CUnit::getUnitFromVis( unitVis_c vis ) std::unique_ptr<CUnit> CUnit::getUnitFromVis( unitVis_c vis )
{ {
switch( vis ) switch( vis )
{ {
// Match with any image for a V
case '^': case '^':
case '>': case '>':
case 'v': case 'v':
case '<': case '<':
{ {
// Create a V
std::unique_ptr<CUnit> p = std::unique_ptr<CUnit>(new CUnitV); std::unique_ptr<CUnit> p = std::unique_ptr<CUnit>(new CUnitV);
if( (bool)p && p->setFromVisual(vis) ) if( (bool)p && p->setFromVisual(vis) )
{ {
@ -22,5 +23,6 @@ std::unique_ptr<CUnit> CUnit::getUnitFromVis( unitVis_c vis )
} }
} }
// No unit found, return nullptr
return std::move(std::unique_ptr<CUnit>(nullptr)); return std::move(std::unique_ptr<CUnit>(nullptr));
} }

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include "gametypes.h"
#include "vector2.h" #include "vector2.h"
// Type for the unit type-id // Type for the unit type-id
@ -28,6 +29,15 @@ protected:
private: 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 // All units must have position
uvector2 pos; uvector2 pos;
}; };