mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 23:10:02 +00:00
Added scenario, side options to commandline_options.
Also changed and documented the helper functions in this class a bit.
This commit is contained in:
parent
25f8bcaefc
commit
126ffaf2e2
@ -174,6 +174,8 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
||||
("ai-config", po::value<std::vector<std::string> >()->composing(), "arg should have format side:value\nselects a configuration file to load for this side.")
|
||||
("exit-at-end", "exit Wesnoth at the end of the scenario.")
|
||||
("nogui", "runs the game without the GUI.")
|
||||
("scenario", po::value<std::string>(), "selects a multiplayer scenario. The default scenario is \"multiplayer_The_Freelands\".")
|
||||
("side", po::value<std::vector<std::string> >()->composing(), "<arg> should have format side:value. selects a faction of the current era for this side by id.")
|
||||
("turns", po::value<std::string>(), "sets the number of turns. The default is \"50\".")
|
||||
;
|
||||
|
||||
@ -210,7 +212,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
||||
po::store(po::command_line_parser(argc_,argv_).options(all_).positional(positional).style(parsing_style).run(),vm);
|
||||
|
||||
if (vm.count("ai-config"))
|
||||
multiplayer_ai_config = parse_to_int_string_tuples_(vm["ai-config"].as<std::vector<std::string> >());
|
||||
multiplayer_ai_config = parse_to_uint_string_tuples_(vm["ai-config"].as<std::vector<std::string> >());
|
||||
if (vm.count("bpp"))
|
||||
bpp = vm["bpp"].as<int>();
|
||||
if (vm.count("campaign"))
|
||||
@ -309,6 +311,8 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
||||
parse_resolution_(vm["resolution"].as<std::string>());
|
||||
if (vm.count("rng-seed"))
|
||||
rng_seed = vm["rng-seed"].as<unsigned int>();
|
||||
if (vm.count("scenario"))
|
||||
multiplayer_scenario = vm["scenario"].as<std::string>();
|
||||
if (vm.count("screenshot"))
|
||||
{
|
||||
screenshot = true;
|
||||
@ -317,6 +321,8 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
||||
}
|
||||
if (vm.count("server"))
|
||||
server = vm["server"].as<std::string>();
|
||||
if (vm.count("side"))
|
||||
multiplayer_side = parse_to_uint_string_tuples_(vm["side"].as<std::vector<std::string> >());
|
||||
if (vm.count("test"))
|
||||
test = vm["test"].as<std::string>();
|
||||
if (vm.count("turns"))
|
||||
@ -354,18 +360,18 @@ void commandline_options::parse_resolution_ ( const std::string& resolution_stri
|
||||
resolution = boost::tuple<int,int>(xres,yres);
|
||||
}
|
||||
|
||||
std::vector<boost::tuple<int,std::string> > commandline_options::parse_to_int_string_tuples_(const std::vector<std::string> &strings)
|
||||
std::vector<boost::tuple<unsigned int,std::string> > commandline_options::parse_to_uint_string_tuples_(const std::vector<std::string> &strings, char separator)
|
||||
{
|
||||
std::vector<boost::tuple<int,std::string> > vec;
|
||||
boost::tuple<int,std::string> elem;
|
||||
std::vector<boost::tuple<unsigned int,std::string> > vec;
|
||||
boost::tuple<unsigned int,std::string> elem;
|
||||
foreach(const std::string &s, strings)
|
||||
{
|
||||
const std::vector<std::string> tokens = utils::split(s, ':');
|
||||
const std::vector<std::string> tokens = utils::split(s, separator);
|
||||
if (tokens.size()!=2)
|
||||
{
|
||||
//TODO throw a meaningful exception
|
||||
}
|
||||
elem.get<0>() = lexical_cast<int>(tokens[0]);
|
||||
elem.get<0>() = lexical_cast<unsigned int>(tokens[0]);
|
||||
//TODO catch exception and pack in meaningful something
|
||||
elem.get<1>() = tokens[1];
|
||||
vec.push_back(elem);
|
||||
@ -373,6 +379,26 @@ std::vector<boost::tuple<int,std::string> > commandline_options::parse_to_int_st
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<boost::tuple<unsigned int,std::string,std::string> > commandline_options::parse_to_uint_string_string_tuples_(const std::vector<std::string> &strings, char separator)
|
||||
{
|
||||
std::vector<boost::tuple<unsigned int,std::string,std::string> > vec;
|
||||
boost::tuple<unsigned int,std::string,std::string> elem;
|
||||
foreach(const std::string &s, strings)
|
||||
{
|
||||
const std::vector<std::string> tokens = utils::split(s, separator);
|
||||
if (tokens.size()!=3)
|
||||
{
|
||||
//TODO throw a meaningful exception
|
||||
}
|
||||
elem.get<0>() = lexical_cast<unsigned int>(tokens[0]);
|
||||
//TODO catch exception and pack in meaningful something
|
||||
elem.get<1>() = tokens[1];
|
||||
elem.get<2>() = tokens[2];
|
||||
vec.push_back(elem);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &os, const commandline_options& cmdline_opts)
|
||||
{
|
||||
os << "Usage: " << cmdline_opts.argv_[0] << " [<options>] [<data-directory>]\n";
|
||||
|
@ -77,11 +77,11 @@ public:
|
||||
/// True if --multiplayer was given on the command line. Goes directly into multiplayer mode.
|
||||
bool multiplayer;
|
||||
/// Non-empty if --ai-config was given on the command line. Vector of pairs (side number, value). Dependant on --multiplayer.
|
||||
boost::optional<std::vector<boost::tuple<int, std::string> > > multiplayer_ai_config;
|
||||
boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_ai_config;
|
||||
/// Non-empty if --algorithm was given on the command line. Vector of pairs (side number, value). Dependant on --multiplayer.
|
||||
boost::optional<std::vector<boost::tuple<int, std::string> > > multiplayer_algorithm;
|
||||
boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_algorithm;
|
||||
/// Non-empty if --controller was given on the command line. Vector of pairs (side number, controller). Dependant on --multiplayer.
|
||||
boost::optional<std::vector<boost::tuple<int, std::string> > > multiplayer_controller;
|
||||
boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_controller;
|
||||
/// Non-empty if --era was given on the command line. Dependant on --multiplayer.
|
||||
boost::optional<std::string> multiplayer_era;
|
||||
/// True if --exit-at-and was given on the command line. Dependant on --multiplayer.
|
||||
@ -89,11 +89,11 @@ public:
|
||||
/// Non-empty if --label was given on the command line. Dependant on --multiplayer.
|
||||
boost::optional<std::string> multiplayer_label;
|
||||
/// Non-empty if --parm was given on the command line. Vector of pairs (side number, parm name, parm value). Dependant on --multiplayer.
|
||||
boost::optional<std::vector<boost::tuple<int, std::string, std::string> > > multiplayer_parm;
|
||||
boost::optional<std::vector<boost::tuple<unsigned int, std::string, std::string> > > multiplayer_parm;
|
||||
/// Non-empty if --scenario was given on the command line. Dependant on --multiplayer.
|
||||
boost::optional<std::string> multiplayer_scenario;
|
||||
/// Non-empty if --side was given on the command line. Vector of pairs (side number, faction id). Dependant on --multiplayer.
|
||||
boost::optional<std::vector<boost::tuple<int, std::string> > > multiplayer_side;
|
||||
boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_side;
|
||||
/// Non-empty if --turns was given on the command line. Dependant on --multiplayer.
|
||||
boost::optional<std::string> multiplayer_turns;
|
||||
/// Max FPS specified by --max-fps option.
|
||||
@ -165,7 +165,10 @@ public:
|
||||
private:
|
||||
void parse_log_domains_(const std::string &domains_string, const int severity);
|
||||
void parse_resolution_ (const std::string &resolution_string);
|
||||
std::vector<boost::tuple<int,std::string> > parse_to_int_string_tuples_(const std::vector<std::string> &strings);
|
||||
/// A helper function splitting vector of strings of format unsigned int:string to vector of tuples (unsigned int,string)
|
||||
std::vector<boost::tuple<unsigned int,std::string> > parse_to_uint_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
|
||||
/// A helper function splitting vector of strings of format unsigned int:string:string to vector of tuples (unsigned int,string,string)
|
||||
std::vector<boost::tuple<unsigned int,std::string,std::string> > parse_to_uint_string_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
|
||||
int argc_;
|
||||
char **argv_;
|
||||
boost::program_options::options_description all_;
|
||||
|
@ -464,8 +464,38 @@ bool game_controller::play_multiplayer_mode()
|
||||
|
||||
size_t sides_counted = 0;
|
||||
|
||||
if (cmdline_opts_.multiplayer_ai_config)
|
||||
{
|
||||
for(std::vector<boost::tuple<unsigned int, std::string> >::const_iterator it=cmdline_opts_.multiplayer_ai_config->begin(); it!=cmdline_opts_.multiplayer_ai_config->end(); ++it)
|
||||
{
|
||||
const unsigned int side = it->get<0>();
|
||||
const std::string ai_cfg_name = it->get<1>();
|
||||
if (side > sides_counted)
|
||||
{
|
||||
std::cerr << "counted sides: " << side << "\n";
|
||||
sides_counted = side;
|
||||
}
|
||||
side_ai_configs[side] = ai_cfg_name;
|
||||
}
|
||||
}
|
||||
if (cmdline_opts_.multiplayer_exit_at_end)
|
||||
game_config::exit_at_end = true;
|
||||
if (cmdline_opts_.multiplayer_scenario)
|
||||
scenario = *cmdline_opts_.multiplayer_scenario;
|
||||
if (cmdline_opts_.multiplayer_side)
|
||||
{
|
||||
for(std::vector<boost::tuple<unsigned int, std::string> >::const_iterator it=cmdline_opts_.multiplayer_side->begin(); it!=cmdline_opts_.multiplayer_side->end(); ++it)
|
||||
{
|
||||
const unsigned int side = it->get<0>();
|
||||
const std::string faction_id = it->get<1>();
|
||||
if (side > sides_counted)
|
||||
{
|
||||
std::cerr << "counted sides: " << side << "\n";
|
||||
sides_counted = side;
|
||||
}
|
||||
side_types[side] = faction_id;
|
||||
}
|
||||
}
|
||||
if (cmdline_opts_.multiplayer_turns)
|
||||
turns = *cmdline_opts_.multiplayer_turns;
|
||||
|
||||
@ -488,25 +518,14 @@ bool game_controller::play_multiplayer_mode()
|
||||
const bool last_digit = isdigit(name_tail) ? true:false;
|
||||
const size_t side = name_tail - '0';
|
||||
|
||||
if(last_digit && side > sides_counted) {
|
||||
std::cerr << "counted sides: " << side << "\n";
|
||||
sides_counted = side;
|
||||
}
|
||||
|
||||
if(name == "--scenario") {
|
||||
scenario = value;
|
||||
} else if(name == "--era") {
|
||||
if(name == "--era") {
|
||||
era = value;
|
||||
} else if(name == "--label") {
|
||||
label = value;
|
||||
} else if(last_digit && name_head == "--controller") {
|
||||
side_controllers[side] = value;
|
||||
} else if(last_digit && name_head == "--ai_config") {
|
||||
side_ai_configs[side] = value;
|
||||
} else if(last_digit && name_head == "--algorithm") {
|
||||
side_algorithms[side] = value;
|
||||
} else if(last_digit && name_head == "--side") {
|
||||
side_types[side] = value;
|
||||
} else if(last_digit && name_head == "--parm") {
|
||||
const std::vector<std::string> name_value = utils::split(value, ':');
|
||||
if(name_value.size() != 2) {
|
||||
|
@ -232,7 +232,10 @@ BOOST_AUTO_TEST_CASE (test_full_options)
|
||||
"--proxy-user=userfoo",
|
||||
"--resolution=800x600",
|
||||
"--rng-seed=1234",
|
||||
"--scenario=scenfoo",
|
||||
"--screenshot", "mapfoo", "outssfoo",
|
||||
"--side=1:sidefoo",
|
||||
"--side=2:sidebar",
|
||||
"--server=servfoo",
|
||||
"--smallgui",
|
||||
"--test=testfoo",
|
||||
@ -287,8 +290,11 @@ BOOST_AUTO_TEST_CASE (test_full_options)
|
||||
BOOST_CHECK(co.multiplayer_exit_at_end);
|
||||
BOOST_CHECK(!co.multiplayer_label);
|
||||
BOOST_CHECK(!co.multiplayer_parm);
|
||||
BOOST_CHECK(!co.multiplayer_scenario);
|
||||
BOOST_CHECK(!co.multiplayer_side);
|
||||
BOOST_CHECK(co.multiplayer_scenario && *co.multiplayer_scenario == "scenfoo");
|
||||
BOOST_CHECK(co.multiplayer_side);
|
||||
BOOST_CHECK(co.multiplayer_side->size() == 2);
|
||||
BOOST_CHECK(co.multiplayer_side->at(0).get<0>() == 1 && co.multiplayer_side->at(0).get<1>() == "sidefoo");
|
||||
BOOST_CHECK(co.multiplayer_side->at(1).get<0>() == 2 && co.multiplayer_side->at(1).get<1>() == "sidebar");
|
||||
BOOST_CHECK(co.multiplayer_turns && *co.multiplayer_turns == "42");
|
||||
BOOST_CHECK(co.max_fps && *co.max_fps == 100);
|
||||
BOOST_CHECK(co.nocache);
|
||||
|
Loading…
x
Reference in New Issue
Block a user