Add stubs for game
This commit is contained in:
parent
e9308b839c
commit
270036c925
3 changed files with 117 additions and 5 deletions
108
game/game.cpp
108
game/game.cpp
|
@ -1 +1,109 @@
|
|||
#include "game.h"
|
||||
|
||||
|
||||
// Interpret a string of orders
|
||||
int CTTRTSGame::IssueOrders( player_id_t player, const std::string& _orders )
|
||||
{
|
||||
COrderVector orderVector;
|
||||
std::string orders = _orders;
|
||||
|
||||
size_t pos;
|
||||
while ( (pos = orders.find("\n")) != std::string::npos )
|
||||
{
|
||||
const std::string sorder = orders.substr(0, pos);
|
||||
orders.erase(0,pos+1);
|
||||
|
||||
COrder order = GetOrderFromString( sorder );
|
||||
|
||||
orderVector.push_back(order);
|
||||
}
|
||||
|
||||
return IssueOrders(player,orderVector);
|
||||
}
|
||||
|
||||
// Issue orders by vector to the game
|
||||
int CTTRTSGame::IssueOrders( player_id_t player, const COrderVector& orders )
|
||||
{
|
||||
// verify all the orders
|
||||
for ( COrderVector::const_iterator it = orders.begin(); it != orders.end(); it++ )
|
||||
{
|
||||
if ( IssueOrder(player,*it) )
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Issue a single order
|
||||
int CTTRTSGame::IssueOrder( player_id_t player, const COrder& order )
|
||||
{
|
||||
if ( VerifyOrder(player,order) )
|
||||
return 1;
|
||||
|
||||
m_orders.push_back(order);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Simulate and progress to the next turn
|
||||
// Returns non-zero if simulation failed
|
||||
int CTTRTSGame::SimulateToNextTurn()
|
||||
{
|
||||
int error;
|
||||
|
||||
// Simulate all movements first
|
||||
error = SimulateMovements();
|
||||
|
||||
// Simulate all the actions
|
||||
error = SimulateActions();
|
||||
|
||||
// Clear all orders
|
||||
m_orders.resize(0);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
// Add a unit, nonzero return value indicates error
|
||||
int CTTRTSGame::AddUnit( std::shared_ptr<CUnit> unit )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a units, nonzero return value indicates error
|
||||
int CTTRTSGame::AddUnits( sharedUnitVector_t units )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Simulate all movements
|
||||
int CTTRTSGame::SimulateMovements()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Simulate all actions
|
||||
int CTTRTSGame::SimulateActions()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Verify any order
|
||||
int CTTRTSGame::VerifyOrder( player_id_t player, const COrder& order )
|
||||
{
|
||||
// Grab the unit ID
|
||||
const unit_id_t unitID = order.unit;
|
||||
|
||||
// Attempt to find the unit
|
||||
bool unitFound = false;
|
||||
for ( sharedUnitVector_t::const_iterator it = m_allUnits.begin(); it != m_allUnits.end(); it++ )
|
||||
{
|
||||
if ( (*it)->getID() == unitID )
|
||||
{
|
||||
unitFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for now, as long as the unit exists we can attempt the order
|
||||
return unitFound;
|
||||
}
|
12
game/game.h
12
game/game.h
|
@ -24,8 +24,10 @@ public:
|
|||
~CTTRTSGame() = default;
|
||||
|
||||
// Issue orders to the game, returns non-zero if orders are incorrect
|
||||
int IssueOrders( player_id_t player, std::string orders );
|
||||
int IssueOrders( player_id_t player, COrderVector orders );
|
||||
int IssueOrders( player_id_t player, const std::string& orders );
|
||||
int IssueOrders( player_id_t player, const COrderVector& orders );
|
||||
|
||||
int IssueOrder( player_id_t player, const COrder& order );
|
||||
|
||||
// Simulate and progress to the next turn
|
||||
// Returns non-zero if simulation failed
|
||||
|
@ -52,13 +54,13 @@ public:
|
|||
private:
|
||||
|
||||
// Simulate all movements
|
||||
bool SimulateMovements();
|
||||
int SimulateMovements();
|
||||
|
||||
// Simulate all actions
|
||||
bool SimulateActions();
|
||||
int SimulateActions();
|
||||
|
||||
// Verify any order
|
||||
bool VerifyOrder( player_id_t player, COrder& order );
|
||||
int VerifyOrder( player_id_t player, const COrder& order );
|
||||
|
||||
// Vector to store points to all units
|
||||
sharedUnitVector_t m_allUnits;
|
||||
|
|
|
@ -18,6 +18,8 @@ public:
|
|||
|
||||
static std::unique_ptr<CUnit> getUnitFromVis( unitVis_c vis );
|
||||
|
||||
inline unit_id_t getID() const { return id; }
|
||||
|
||||
protected:
|
||||
CUnit() = default;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue