-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathmain.cpp
124 lines (107 loc) · 4.11 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later
#include "GlobalGameSettings.h"
#include "HeadlessGame.h"
#include "QuickStartGame.h"
#include "RTTR_Version.h"
#include "RttrConfig.h"
#include "files.h"
#include "random/Random.h"
#include "s25util/System.h"
#include <boost/filesystem.hpp>
#include <boost/nowide/args.hpp>
#include <boost/nowide/filesystem.hpp>
#include <boost/nowide/iostream.hpp>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
namespace bnw = boost::nowide;
namespace bfs = boost::filesystem;
namespace po = boost::program_options;
int main(int argc, char** argv)
{
bnw::nowide_filesystem();
bnw::args _(argc, argv);
boost::optional<std::string> replay_path;
boost::optional<std::string> savegame_path;
unsigned random_init = static_cast<unsigned>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
po::options_description desc("Allowed options");
// clang-format off
desc.add_options()
("help,h", "Show help")
("map,m", po::value<std::string>()->required(),"Map to load")
("ai", po::value<std::vector<std::string>>()->required(),"AI player(s) to add")
("objective", po::value<std::string>()->default_value("domination"),"domination(default)|conquer")
("replay", po::value(&replay_path),"Filename to write replay to (optional)")
("save", po::value(&savegame_path),"Filename to write savegame to (optional)")
("random_init", po::value(&random_init),"Seed value for the random number generator (optional)")
("maxGF", po::value<unsigned>()->default_value(std::numeric_limits<unsigned>::max()),"Maximum number of game frames to run (optional)")
("version", "Show version information and exit")
;
// clang-format on
if(argc == 1)
{
bnw::cerr << desc << std::endl;
return 1;
}
po::variables_map options;
try
{
po::store(po::command_line_parser(argc, argv).options(desc).run(), options);
if(options.count("help"))
{
bnw::cout << desc << std::endl;
return 0;
}
if(options.count("version"))
{
bnw::cout << rttr::version::GetTitle() << " v" << rttr::version::GetVersion() << "-"
<< rttr::version::GetRevision() << std::endl
<< "Compiled with " << System::getCompilerName() << " for " << System::getOSName() << std::endl;
return 0;
}
po::notify(options);
} catch(const std::exception& e)
{
bnw::cerr << "Error: " << e.what() << std::endl;
bnw::cerr << desc << std::endl;
return 1;
}
try
{
// We print arguments and seed in order to be able to reproduce crashes.
for(int i = 0; i < argc; ++i)
bnw::cout << argv[i] << " ";
bnw::cout << std::endl;
bnw::cout << "random_init: " << random_init << std::endl;
bnw::cout << std::endl;
RTTRCONFIG.Init();
RANDOM.Init(random_init);
const bfs::path mapPath = RTTRCONFIG.ExpandPath(options["map"].as<std::string>());
const std::vector<AI::Info> ais = ParseAIOptions(options["ai"].as<std::vector<std::string>>());
GlobalGameSettings ggs;
const auto objective = options["objective"].as<std::string>();
if(objective == "domination")
ggs.objective = GameObjective::TotalDomination;
else if(objective == "conquer")
ggs.objective = GameObjective::Conquer3_4;
else
{
bnw::cerr << "unknown objective: " << objective << std::endl;
return 1;
}
ggs.objective = GameObjective::TotalDomination;
HeadlessGame game(ggs, mapPath, ais);
if(replay_path)
game.RecordReplay(*replay_path, random_init);
game.Run(options["maxGF"].as<unsigned>());
game.Close();
if(savegame_path)
game.SaveGame(*savegame_path);
} catch(const std::exception& e)
{
bnw::cerr << e.what() << std::endl;
return 1;
}
return 0;
}