OrderUnitPair -> SOrderUnitPair

This commit is contained in:
mdiluzio 2014-12-21 10:31:00 +00:00
parent d71983dcb1
commit 9551560bc0
2 changed files with 26 additions and 26 deletions

View file

@ -78,7 +78,7 @@ int CTTRTSGame::IssueOrder( Team team, const COrder& order )
return 1; return 1;
// Get the right unit for the order // Get the right unit for the order
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
if ( pair.unit.getID() == order.unit ) if ( pair.unit.getID() == order.unit )
{ {
@ -106,7 +106,7 @@ int CTTRTSGame::VerifyPos(uvector2 vec) const
// Get a units new position // Get a units new position
uvector2 CTTRTSGame::GetNewPosition( const OrderUnitPair& pair ) const uvector2 CTTRTSGame::GetNewPosition( const SOrderUnitPair & pair ) const
{ {
// Grab the order // Grab the order
switch ( pair.order.command) switch ( pair.order.command)
@ -127,7 +127,7 @@ int CTTRTSGame::SimulateToNextTurn()
int error = 0; int error = 0;
// Attempt all movement orders // Attempt all movement orders
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
switch ( pair.order.command) switch ( pair.order.command)
{ {
@ -142,7 +142,7 @@ int CTTRTSGame::SimulateToNextTurn()
if ( possible ) if ( possible )
{ {
// If any unit is in this spot, or moving unit moving to said spot, reject this // If any unit is in this spot, or moving unit moving to said spot, reject this
for ( const OrderUnitPair& pair2 : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair2 : m_OrderUnitPairs )
{ {
// Skip myself // Skip myself
if( pair.unit.getID() == pair2.unit.getID() ) continue; if( pair.unit.getID() == pair2.unit.getID() ) continue;
@ -168,7 +168,7 @@ int CTTRTSGame::SimulateToNextTurn()
} }
// Turn all units that need turning // Turn all units that need turning
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
switch ( pair.order.command) switch ( pair.order.command)
{ {
@ -196,7 +196,7 @@ int CTTRTSGame::SimulateToNextTurn()
// Assume no more charging // Assume no more charging
charging = false; charging = false;
// Initially move all units // Initially move all units
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
if ( pair.order.command == command_c::A ) if ( pair.order.command == command_c::A )
{ {
@ -215,9 +215,9 @@ int CTTRTSGame::SimulateToNextTurn()
std::vector< unit_id_t > toKill; // Vector to store which units to kill std::vector< unit_id_t > toKill; // Vector to store which units to kill
// Initially move all units to check for pass through // Initially move all units to check for pass through
for ( OrderUnitPair& pair1 : m_OrderUnitPairs ) for ( SOrderUnitPair & pair1 : m_OrderUnitPairs )
if ( pair1.order.command == command_c::A ) if ( pair1.order.command == command_c::A )
for ( OrderUnitPair& pair2 : m_OrderUnitPairs ) for ( SOrderUnitPair & pair2 : m_OrderUnitPairs )
if ( pair1.unit.getID() != pair2.unit.getID() // Don't check the same units if ( pair1.unit.getID() != pair2.unit.getID() // Don't check the same units
&& pair2.order.command == command_c::A ) && pair2.order.command == command_c::A )
{ {
@ -233,8 +233,8 @@ int CTTRTSGame::SimulateToNextTurn()
toKill.clear(); toKill.clear();
// Check for all matching spots // Check for all matching spots
for ( OrderUnitPair& pair1 : m_OrderUnitPairs ) for ( SOrderUnitPair & pair1 : m_OrderUnitPairs )
for ( OrderUnitPair& pair2 : m_OrderUnitPairs ) for ( SOrderUnitPair & pair2 : m_OrderUnitPairs )
{ {
if( pair1.unit.getID() == pair2.unit.getID() ) continue; // Don't check the same units if( pair1.unit.getID() == pair2.unit.getID() ) continue; // Don't check the same units
@ -258,7 +258,7 @@ int CTTRTSGame::SimulateToNextTurn()
} }
// Clear all orders // Clear all orders
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
pair.order = COrder(); pair.order = COrder();
// Increment the current turn // Increment the current turn
@ -336,14 +336,14 @@ int CTTRTSGame::AddUnit( CUnit&& unit )
return 2; return 2;
// If any unit's position matches, reject this // If any unit's position matches, reject this
for ( const OrderUnitPair& pair: m_OrderUnitPairs ) for ( const SOrderUnitPair & pair: m_OrderUnitPairs )
{ {
if( pair.unit.getPos() == unit.getPos() ) if( pair.unit.getPos() == unit.getPos() )
return 3; return 3;
} }
// Add the unit with a blank order // Add the unit with a blank order
m_OrderUnitPairs.push_back( OrderUnitPair(std::move(unit), COrder()) ); m_OrderUnitPairs.push_back( SOrderUnitPair(std::move(unit), COrder()) );
return 0; return 0;
@ -374,7 +374,7 @@ int CTTRTSGame::VerifyOrder( Team team, const COrder& order ) const
const unit_id_t unitID = order.unit; const unit_id_t unitID = order.unit;
// Attempt to find the unit // Attempt to find the unit
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
// Accept if we have the unit // Accept if we have the unit
if ( pair.unit.getID() == unitID if ( pair.unit.getID() == unitID
@ -392,7 +392,7 @@ int CTTRTSGame::VerifyOrder( Team team, const COrder& order ) const
// Get unit by unit ID // Get unit by unit ID
const CUnit& CTTRTSGame::GetUnitByIDConst( unit_id_t id ) const const CUnit& CTTRTSGame::GetUnitByIDConst( unit_id_t id ) const
{ {
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
// Attempt the unit add // Attempt the unit add
if ( pair.unit.getID() == id ) if ( pair.unit.getID() == id )
@ -407,7 +407,7 @@ const CUnit& CTTRTSGame::GetUnitByIDConst( unit_id_t id ) const
// Get an order by unit ID // Get an order by unit ID
const COrder& CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const const COrder& CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const
{ {
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
// Attempt the unit add // Attempt the unit add
if ( pair.unit.getID() == id ) if ( pair.unit.getID() == id )
@ -422,7 +422,7 @@ const COrder& CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const
// Get unit by unit ID // Get unit by unit ID
CUnit& CTTRTSGame::GetUnitByID( unit_id_t id ) CUnit& CTTRTSGame::GetUnitByID( unit_id_t id )
{ {
for ( OrderUnitPair& pair : m_OrderUnitPairs ) for ( SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
// Attempt the unit add // Attempt the unit add
if ( pair.unit.getID() == id ) if ( pair.unit.getID() == id )
@ -441,7 +441,7 @@ std::vector<Team> CTTRTSGame::GetTeams() const
teams.reserve(GetNumUnits()); teams.reserve(GetNumUnits());
// Grab all teams // Grab all teams
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
teams.push_back(pair.unit.getTeam()); teams.push_back(pair.unit.getTeam());
} }
@ -461,7 +461,7 @@ Team CTTRTSGame::CheckForWin() const
memset(units,0,sizeof(units)); memset(units,0,sizeof(units));
// Count up all the units for each Team // Count up all the units for each Team
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
const int team = (int)pair.unit.getTeam(); const int team = (int)pair.unit.getTeam();
units[team] += 1; units[team] += 1;
@ -499,7 +499,7 @@ std::string CTTRTSGame::GetStateAsString() const
// Gather unit information // Gather unit information
std::string units; std::string units;
for ( const OrderUnitPair& pair : m_OrderUnitPairs ) for ( const SOrderUnitPair & pair : m_OrderUnitPairs )
{ {
units += CUnit::GetStringFromUnit(pair.unit); units += CUnit::GetStringFromUnit(pair.unit);
units += '\n'; units += '\n';

View file

@ -9,22 +9,22 @@
#define GAME_HEADER_DELIMITER "~~~~\n" #define GAME_HEADER_DELIMITER "~~~~\n"
// Type for order and unit pairs // Type for order and unit pairs
struct OrderUnitPair struct SOrderUnitPair
{ {
// Straight up move constructor // Straight up move constructor
OrderUnitPair( OrderUnitPair&& other ) SOrderUnitPair( SOrderUnitPair && other )
: unit ( std::move(other.unit) ) : unit ( std::move(other.unit) )
, order ( other.order ) , order ( other.order )
{} {}
// Multi parameter constructor // Multi parameter constructor
OrderUnitPair( CUnit&& u, COrder o ) SOrderUnitPair( CUnit&& u, COrder o )
: unit ( std::move(u) ) : unit ( std::move(u) )
, order ( o ) , order ( o )
{} {}
// Move assignment operator // Move assignment operator
inline OrderUnitPair& operator=( OrderUnitPair&& rhs ) inline SOrderUnitPair & operator=( SOrderUnitPair && rhs )
{ {
this->unit = std::move(rhs.unit); this->unit = std::move(rhs.unit);
this->order = std::move(rhs.order); this->order = std::move(rhs.order);
@ -36,7 +36,7 @@ struct OrderUnitPair
}; };
// Typedef for a vector of these unit pairs // Typedef for a vector of these unit pairs
typedef std::vector< OrderUnitPair > OrderUnitPairVector; typedef std::vector<SOrderUnitPair> OrderUnitPairVector;
// Full TTRTS Game class // Full TTRTS Game class
// Stores information about the game // Stores information about the game
@ -109,7 +109,7 @@ private:
int VerifyPos( uvector2 vec ) const; int VerifyPos( uvector2 vec ) const;
// Get a units new position after an order // Get a units new position after an order
uvector2 GetNewPosition( const OrderUnitPair& pair ) const; uvector2 GetNewPosition( const SOrderUnitPair & pair ) const;
// Check for a pass through // Check for a pass through
static bool CheckForPassThrough( const CUnit& one, const CUnit& two ); static bool CheckForPassThrough( const CUnit& one, const CUnit& two );