lots of initial design for the game, and unit data
This commit is contained in:
parent
6a17e4e4c1
commit
a17a9db2ad
5 changed files with 56 additions and 4 deletions
|
@ -1 +1,8 @@
|
|||
#include "game.h"
|
||||
|
||||
|
||||
// Initialise the game with default configuration
|
||||
void CTTRTSGame::Initialise()
|
||||
{
|
||||
|
||||
}
|
33
game/game.h
33
game/game.h
|
@ -2,6 +2,12 @@
|
|||
#define _GAME_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
|
||||
{
|
||||
|
@ -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_
|
|
@ -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<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 );
|
||||
|
||||
|
||||
#endif //_ORDERS_H_
|
|
@ -1,18 +1,19 @@
|
|||
#include "unit.h"
|
||||
|
||||
// Unit types
|
||||
#include "unitv.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
std::unique_ptr<CUnit> 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<CUnit> p = std::unique_ptr<CUnit>(new CUnitV);
|
||||
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));
|
||||
}
|
10
game/unit.h
10
game/unit.h
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue