diff --git a/source/game/game.cpp b/source/game/game.cpp index 1f811e5..8e01b2e 100644 --- a/source/game/game.cpp +++ b/source/game/game.cpp @@ -342,6 +342,25 @@ CUnit& CTTRTSGame::GetUnitByID( unit_id_t id ) return invalid_unit; } +// Get a vector of the teams in the current game +std::vector CTTRTSGame::GetTeams() const +{ + std::vector teams; + teams.reserve(GetNumUnits()); + + // Grab all teams + for ( const OrderUnitPair& pair : m_OrderUnitPairs ) + { + teams.push_back(pair.unit.getTeam()); + } + + // Remove dupes + std::sort( teams.begin(), teams.end() ); + teams.erase( std::unique( teams.begin(), teams.end() ), teams.end() ); + + return teams; +} + // Check if we have a win state Team CTTRTSGame::CheckForWin() const { diff --git a/source/game/game.h b/source/game/game.h index b0c3fad..b763071 100644 --- a/source/game/game.h +++ b/source/game/game.h @@ -96,6 +96,10 @@ public: // Set the turn of the game inline int SetTurn( int in ) { return (turn = in); } + inline int GetTurn() const { return turn; } + + // Get a vector of the teams in the current game + std::vector GetTeams() const; private: diff --git a/source/ttrts/CMakeLists.txt b/source/ttrts/CMakeLists.txt index 8258be5..08af9fb 100644 --- a/source/ttrts/CMakeLists.txt +++ b/source/ttrts/CMakeLists.txt @@ -2,10 +2,17 @@ # Project name project( ttrts ) +include_directories( + ../maths + ../game +) + # Add the sources set( SOURCES main.cpp ) # Add the executable -add_executable( ttrts ${SOURCES} ) \ No newline at end of file +add_executable( ttrts ${SOURCES} ) + +target_link_libraries( ttrts game ) \ No newline at end of file diff --git a/source/ttrts/main.cpp b/source/ttrts/main.cpp index 02fcc4c..6b1740e 100644 --- a/source/ttrts/main.cpp +++ b/source/ttrts/main.cpp @@ -1,5 +1,156 @@ -// Main program entry point -int main() +#include +#include +#include +#include +#include + +#include "game.h" + +static const char* sk_usage = "NAME\n" + "\tttrts - Tiny Terminal RTS\n" + "\n" + "SYNOPSYS\n" + "\tttrts [OPTIONS...] infile\n" + "\n" + "DESCRIPTION\n" + "\tWhen invoked, ttrts will set up a full game and output a single file representing\n" + "\tthe current game state.\n" + "\tThis file can be read in and interpretted by human, robot, or cat.\n" + "\tttrts will wait for orders files to be placed in it's current working directory.\n" + "\tOnce orders have been set for each player taking part, ttrts consumes order files,\n" + "\tcalculates new game state and outputs a new file.\n" + "\n" + "\tThis process repeats until a winner is chosen!\n"; + +// time for waiting between file stats +static const std::chrono::milliseconds sk_waitTime = std::chrono::milliseconds(100); + +// Check if a file exists +inline bool FileExists( const std::string& name ) { + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0); +} + +// Wait for a file to exist +inline void WaitForFile( const std::string& name, const std::chrono::milliseconds& time ) +{ + while( !FileExists(name) ) std::this_thread::sleep_for(time); +} + +// Main program entry point +int main(int argc, char* argv[]) +{ + // If no args, print usage + if ( argc == 1 ) + { + std::cerr<(file)),std::istreambuf_iterator()); + + if( gameDescriptor.size() == 0 ) + { + std::cerr<<"Error: failed to read in any information from "<(turnFile)),std::istreambuf_iterator()); + + // Issue the orders to the game + if( game.IssueOrders(team, orders) ) + std::cerr<<"Warning: Orders for team "<<(int)team<<" failed to correctly parse"<