Fix filesystem game method

This commit is contained in:
mdiluzio 2015-01-03 19:31:42 +00:00
parent b532f1c9c8
commit 61c012370d
3 changed files with 7 additions and 7 deletions

View file

@ -116,7 +116,7 @@ int runClient(int argc, char* argv[])
// Output the gamestate file for this game
CTTRTSGame thisGame = GetGameFromString(gamestate);
OutputGameStateFile(thisGame, getGamesDir());
OutputGameStateFile(thisGame);
// Get the order file for this turn
std::string orders = GetOrdersFromPlayerFile(thisGame,myPlayer);

View file

@ -30,10 +30,10 @@ void WaitForFile( const std::string& name, const std::chrono::milliseconds& time
while( !FileExists(name) ) std::this_thread::sleep_for(time);
}
bool OutputGameStateFile(CTTRTSGame &game, const std::string &gameDir)
bool OutputGameStateFile(CTTRTSGame &game)
{
char turnFileName[128];
snprintf(turnFileName,128,"%s/%s/Turn_%i.txt",gameDir.c_str(),game.GetName().c_str(),game.GetTurn());
snprintf(turnFileName,128,"%s%s/Turn_%i.txt", getGamesDir().c_str(),game.GetName().c_str(),game.GetTurn());
std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists
if ( turnFile.bad() )
@ -127,7 +127,7 @@ std::string GetOrdersFromPlayerFile(const CTTRTSGame &game, player_t &player)
std::string gameDir = getGamesDir();
char playerOrderFileName[128];
snprintf(playerOrderFileName, 128, "%s/%s/Player_%i_Turn_%i.txt", gameDir.c_str(),game.GetName().c_str(),(int) player, game.GetTurn());
snprintf(playerOrderFileName, 128, "%s%s/Player_%i_Turn_%i.txt", gameDir.c_str(),game.GetName().c_str(),(int) player, game.GetTurn());
// Wait for the player order file to be created
std::cout<<"Waiting for "<< playerOrderFileName << std::endl;
@ -249,7 +249,7 @@ int runFromFilesystem(int argc, char* argv[])
std::cout<<"Starting turn "<<game.GetTurn()<<std::endl;
// Create a turn file
if( !OutputGameStateFile(game, gameDir))
if( !OutputGameStateFile(game))
{
std::cerr<<"Error: Failed to output new turn file" << std::endl;
return 1;
@ -277,7 +277,7 @@ int runFromFilesystem(int argc, char* argv[])
}
// Output final gamestate
OutputGameStateFile(game, gameDir);
OutputGameStateFile(game);
// Get the winning player
player_t winningPlayer = game.GetWinningPlayer();

View file

@ -13,7 +13,7 @@ bool FileExists( const std::string& name );
void WaitForFile( const std::string& name, const std::chrono::milliseconds& time );
bool OutputGameStateFile(CTTRTSGame &game, const std::string &gameDir);
bool OutputGameStateFile(CTTRTSGame &game);
std::string GetOrdersFromPlayerFile(const CTTRTSGame &game, player_t &player);