Huge refactor, pulling server and local out into their own binaries
This commit is contained in:
parent
1b2010faba
commit
0ead12c7dd
16 changed files with 165 additions and 247 deletions
62
source/local/local.cpp
Normal file
62
source/local/local.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include "game.h"
|
||||
#include "filesystem.h"
|
||||
#include "error.h"
|
||||
#include "net.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// =====================================================================================================================
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// must provide information
|
||||
if (argc < 2)
|
||||
fatal_error("Usage: ttrts-local MAPFILE");
|
||||
|
||||
std::string gamefile = argv[1];
|
||||
|
||||
std::cout<<"TTRTS: Launching with "<<gamefile<<std::endl;
|
||||
CTTRTSGame game = GetGameFromFile(gamefile);
|
||||
|
||||
// Grab the players involved
|
||||
auto players = game.GetPlayers();
|
||||
|
||||
// Default for games
|
||||
std::string ttrts_games_dir = getGamesDir();
|
||||
|
||||
// Empty the current game directory
|
||||
if ( CreateAndCleanGameDir(game.GetName()) < 0)
|
||||
return -1;
|
||||
|
||||
// While the game isn't finished
|
||||
while ( ! game.GameOver() )
|
||||
{
|
||||
std::cout<<"TTRTS: Starting turn "<<game.GetTurn()<<std::endl;
|
||||
|
||||
// Create a turn file
|
||||
if( !OutputGameStateFile(game))
|
||||
fatal_error("Error: Failed to output new turn file");
|
||||
|
||||
// Wait for order files
|
||||
for( player_t player : players)
|
||||
{
|
||||
// Construct the player order filename
|
||||
std::string orders = GetOrdersFromPlayerFile(game, player);
|
||||
|
||||
// Issue the orders to the game
|
||||
if( game.IssueOrders(player, orders) )
|
||||
std::cerr<<"Warning: Orders for player "<<(int) player <<" failed to correctly parse"<<std::endl;
|
||||
}
|
||||
|
||||
// Simulate turn
|
||||
std::cout<<"TTRTS: Simulating this turn!"<<std::endl;
|
||||
if ( game.SimulateToNextTurn() )
|
||||
fatal_error("Failed to simulate game turn");
|
||||
|
||||
}
|
||||
|
||||
// Output final gamestate
|
||||
OutputGameStateFile(game);
|
||||
|
||||
return OutputGameEnd( game );
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue