COrder -> SOrder
This commit is contained in:
		
							parent
							
								
									755fe01bf5
								
							
						
					
					
						commit
						f63dc8462f
					
				
					 5 changed files with 26 additions and 26 deletions
				
			
		|  | @ -48,7 +48,7 @@ int CTTRTSGame::IssueOrders( Team team, const std::string& _orders ) | |||
| 		orders.erase(0,pos+1); | ||||
| 
 | ||||
|         // Create an order from the string and push it back
 | ||||
| 		COrder order = GetOrderFromString( sorder ); | ||||
| 		SOrder order = GetOrderFromString( sorder ); | ||||
| 		orderVector.push_back(order); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -71,7 +71,7 @@ int CTTRTSGame::IssueOrders( Team team, const COrderVector& orders ) | |||
| } | ||||
| 
 | ||||
| // Issue a single order
 | ||||
| int CTTRTSGame::IssueOrder( Team team, const COrder& order ) | ||||
| int CTTRTSGame::IssueOrder( Team team, const SOrder & order ) | ||||
| { | ||||
|     // Verify the order
 | ||||
| 	if ( VerifyOrder(team,order) ) | ||||
|  | @ -259,7 +259,7 @@ int CTTRTSGame::SimulateToNextTurn() | |||
| 
 | ||||
|     // Clear all orders
 | ||||
|     for ( SOrderUnitPair & pair : m_OrderUnitPairs ) | ||||
|         pair.order = COrder(); | ||||
|         pair.order = SOrder(); | ||||
| 
 | ||||
|     // Increment the current turn
 | ||||
|     turn++; | ||||
|  | @ -343,7 +343,7 @@ int CTTRTSGame::AddUnit( CUnit&& unit ) | |||
|     } | ||||
| 
 | ||||
|     // Add the unit with a blank order
 | ||||
|     m_OrderUnitPairs.push_back( SOrderUnitPair(std::move(unit), COrder()) ); | ||||
|     m_OrderUnitPairs.push_back( SOrderUnitPair(std::move(unit), SOrder()) ); | ||||
| 
 | ||||
| 
 | ||||
| 	return 0; | ||||
|  | @ -366,7 +366,7 @@ int CTTRTSGame::AddUnits( CUnitVector&& units ) | |||
| } | ||||
| 
 | ||||
| // Verify any order
 | ||||
| int CTTRTSGame::VerifyOrder( Team team, const COrder& order ) const | ||||
| int CTTRTSGame::VerifyOrder( Team team, const SOrder & order ) const | ||||
| { | ||||
|     int ret = 1; | ||||
| 
 | ||||
|  | @ -405,7 +405,7 @@ const CUnit& CTTRTSGame::GetUnitByIDConst( unit_id_t id ) const | |||
| } | ||||
| 
 | ||||
| // Get an order by unit ID
 | ||||
| const COrder& CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const | ||||
| const SOrder & CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const | ||||
| { | ||||
|     for ( const SOrderUnitPair & pair : m_OrderUnitPairs ) | ||||
|     { | ||||
|  | @ -415,7 +415,7 @@ const COrder& CTTRTSGame::GetOrderByIDConst( unit_id_t id ) const | |||
|     } | ||||
| 
 | ||||
|     // Return an invalid unit
 | ||||
|     static COrder invalid_order; | ||||
|     static SOrder invalid_order; | ||||
|     return invalid_order; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -41,7 +41,7 @@ public: | |||
| 	// Issue orders to the game, returns non-zero if orders are incorrect
 | ||||
| 	int                     IssueOrders( Team team, const std::string& orders ); | ||||
| 	int                     IssueOrders( Team team, const COrderVector& orders ); | ||||
| 	int                     IssueOrder( Team team, const COrder& order ); | ||||
| 	int                     IssueOrder( Team team, const SOrder & order ); | ||||
| 
 | ||||
| 	// Add a units to the game, nonzero return value indicates error
 | ||||
| 	int                     AddUnit( CUnit&& unit ); | ||||
|  | @ -52,11 +52,11 @@ public: | |||
| 
 | ||||
| 	// Get unit and orderby index as above (not unit ID)
 | ||||
|     inline const CUnit&     GetUnitByIndex( unsigned int i ) const      { return m_OrderUnitPairs[i].unit; } | ||||
|     inline const COrder&    GetOrdersByIndex( unsigned int i ) const   { return m_OrderUnitPairs[i].order; } | ||||
|     inline const SOrder &    GetOrdersByIndex( unsigned int i ) const   { return m_OrderUnitPairs[i].order; } | ||||
| 
 | ||||
|     // Get a unit by it's ID
 | ||||
|     const CUnit&            GetUnitByIDConst( unit_id_t id ) const; | ||||
|     const COrder&           GetOrderByIDConst( unit_id_t id ) const; | ||||
|     const SOrder &           GetOrderByIDConst( unit_id_t id ) const; | ||||
| 
 | ||||
|     // Get dimensions
 | ||||
|     inline const uvector2&  GetDimensions() const { return dimensions; } | ||||
|  | @ -79,7 +79,7 @@ private: | |||
|     static bool             CheckForPassThrough( const CUnit& one, const CUnit& two ); | ||||
| 
 | ||||
|     // Verify any order or position - non-zero is error
 | ||||
|     int                     VerifyOrder( Team team, const COrder& order ) const; | ||||
|     int                     VerifyOrder( Team team, const SOrder & order ) const; | ||||
|     int                     VerifyPos( uvector2 vec ) const; | ||||
| 
 | ||||
|     // Get a units new position after an order
 | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ | |||
| #include "order.h" | ||||
| 
 | ||||
| // Convert an order to a string
 | ||||
| std::string GetStringFromOrder(const COrder& order ) | ||||
| std::string GetStringFromOrder(const SOrder & order ) | ||||
| { | ||||
| 	static char buff[128]; | ||||
| 	memset(buff,0,sizeof(buff)); | ||||
|  | @ -15,9 +15,9 @@ std::string GetStringFromOrder(const COrder& order ) | |||
| } | ||||
| 
 | ||||
| // Convert a string to an order
 | ||||
| COrder GetOrderFromString( const std::string& order ) | ||||
| SOrder GetOrderFromString( const std::string& order ) | ||||
| { | ||||
| 	COrder ret; | ||||
| 	SOrder ret; | ||||
| 
 | ||||
| 	char corder; | ||||
| 	unsigned int unit; | ||||
|  |  | |||
|  | @ -19,10 +19,10 @@ enum class command_c : char | |||
| }; | ||||
| 
 | ||||
| // Container for an order
 | ||||
| struct COrder | ||||
| struct SOrder | ||||
| { | ||||
|     // Base constructor makes invalid order
 | ||||
|     COrder() | ||||
|     SOrder() | ||||
|         : unit ( unit_id_invalid ) | ||||
|         , command( command_c::NUM_INVALID ) | ||||
|     {} | ||||
|  | @ -34,21 +34,21 @@ struct COrder | |||
|     command_c command; | ||||
| 
 | ||||
| 	// Basic operators
 | ||||
| 	inline bool operator==( const COrder& rhs ) const; | ||||
| 	inline bool operator!=( const COrder& rhs ) const { return !(*this==rhs); } | ||||
| 	inline bool operator==( const SOrder & rhs ) const; | ||||
| 	inline bool operator!=( const SOrder & rhs ) const { return !(*this==rhs); } | ||||
| }; | ||||
| 
 | ||||
| // Simple == operator
 | ||||
| inline bool COrder::operator== ( const COrder& rhs ) const | ||||
| inline bool SOrder::operator== ( const SOrder & rhs ) const | ||||
| { | ||||
| 	return ( unit == rhs.unit ) && ( command == rhs.command); | ||||
| } | ||||
| 
 | ||||
| // Typedef a vector of orders
 | ||||
| typedef std::vector<COrder> COrderVector; | ||||
| typedef std::vector<SOrder> COrderVector; | ||||
| 
 | ||||
| // string <--> order conversion functions
 | ||||
| std::string GetStringFromOrder(const COrder& order ); | ||||
| COrder GetOrderFromString( const std::string& order ); | ||||
| std::string GetStringFromOrder(const SOrder & order ); | ||||
| SOrder GetOrderFromString( const std::string& order ); | ||||
| 
 | ||||
| #endif //_ORDERS_H_
 | ||||
|  |  | |||
|  | @ -55,11 +55,11 @@ const char* tests() | |||
| 
 | ||||
|     // Test if we can successfully convert orders back and forth
 | ||||
| 	{ | ||||
| 		COrder order; | ||||
| 		SOrder order; | ||||
|         order.command = command_c::F; | ||||
| 		order.unit = 10; | ||||
| 		std::string order_string = GetStringFromOrder(order); | ||||
| 		COrder order2 = GetOrderFromString(order_string); | ||||
| 		SOrder order2 = GetOrderFromString(order_string); | ||||
| 
 | ||||
| 		if ( order2 != order ) | ||||
| 			return "failed order string conversion test"; | ||||
|  | @ -106,7 +106,7 @@ const char* tests() | |||
| 
 | ||||
|         CUnit unit = CUnit::GetUnitFromVis('>'); | ||||
|         const unit_id_t id = unit.getID(); | ||||
|         COrder order; | ||||
|         SOrder order; | ||||
| 
 | ||||
|         unit.setPos( {2,2} ); | ||||
|         unit.setTeam(Team::Red); | ||||
|  | @ -137,7 +137,7 @@ const char* tests() | |||
|         { | ||||
|             CUnit unit = CUnit::GetUnitFromVis('>'); | ||||
|             id = unit.getID(); | ||||
|             COrder order; | ||||
|             SOrder order; | ||||
| 
 | ||||
|             unit.setPos( {0,0} ); | ||||
|             unit.setTeam(Team::Blue); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue