From fa7aa15ccdce3e539e0f5509992a8c6142ed1ef5 Mon Sep 17 00:00:00 2001 From: mdiluzio Date: Sat, 20 Dec 2014 15:35:18 +0000 Subject: [PATCH] Fix some bugs Fix a case where game folder existed in verious forms Fix bug where game would not correctly end at draw state Fix bug where the team order file was looked for in the wrong directory Extract gamestate function and properly handle game ending scenarios Stop hitting yourselves Fixed bug where units would not move forward because they were hitting themselves --- source/game/game.cpp | 5 ++- source/ttrts/main.cpp | 89 ++++++++++++++++++++++++++++++++----------- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/source/game/game.cpp b/source/game/game.cpp index 0608415..3608f70 100644 --- a/source/game/game.cpp +++ b/source/game/game.cpp @@ -144,7 +144,10 @@ int CTTRTSGame::SimulateToNextTurn() // If any unit is in this spot, or moving unit moving to said spot, reject this for ( const OrderUnitPair& pair2 : m_OrderUnitPairs ) { - if( GetNewPosition(pair2) != newpos ) + // Skip myself + if( pair.unit.getID() == pair2.unit.getID() ) continue; + + if( GetNewPosition(pair2) == newpos ) { possible = false; break; diff --git a/source/ttrts/main.cpp b/source/ttrts/main.cpp index cbdbca7..7ecc424 100644 --- a/source/ttrts/main.cpp +++ b/source/ttrts/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "game.h" @@ -26,6 +27,25 @@ inline void WaitForFile( const std::string& name, const std::chrono::millisecond while( !FileExists(name) ) std::this_thread::sleep_for(time); } +bool OutputGameStateFile(CTTRTSGame &game, std::string &gameDir) +{ + char turnFileName[128]; + snprintf(turnFileName,128,"%s/Turn_%i.txt",gameDir.c_str(),game.GetTurn()); + std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists + + if ( turnFile.bad() ) + { + return false; + } + + // Output the turn description + std::string turnDescriptor = game.GetStateAsString(); + turnFile<>input; + if( !input.size() || std::tolower(input[0]) != 'y' ) + { + std::cerr<<"Aborting..."< 0 ) // We have no units left + { + std::cout<<"Starting turn "<