64 #include <boost/range/adaptors.hpp>
65 #include <boost/range/algorithm/copy.hpp>
69 #define ERR_NG LOG_STREAM(err, log_engine)
70 #define WRN_NG LOG_STREAM(warn, log_engine)
71 #define LOG_NG LOG_STREAM(info, log_engine)
72 #define DBG_NG LOG_STREAM(debug, log_engine)
75 : has_carryover_expanded_(false)
80 , starting_pos_type_(STARTINGPOS_NONE)
88 : has_carryover_expanded_(false)
91 , classification_(cfg)
93 , starting_pos_type_(STARTINGPOS_NONE)
102 : has_carryover_expanded_(state.has_carryover_expanded_)
103 , carryover_(state.carryover_)
104 , replay_start_(state.replay_start_)
105 , classification_(state.classification_)
106 , mp_settings_(state.mp_settings_)
107 , starting_pos_type_(state.starting_pos_type_)
108 , starting_pos_(state.starting_pos_)
109 , replay_data_(state.replay_data_)
171 static const std::vector<std::string> team_defaults = {
172 "carryover_percentage",
178 if(side[
"save_id"].empty())
180 side[
"save_id"] = side[
"id"];
182 if(!is_multiplayer_tag && side[
"side_name"].blank())
184 side[
"side_name"] = side[
"name"];
186 if(!is_loaded_game && !side[
"current_player"].empty())
188 ERR_NG <<
"Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using 'side_name' instead\n";
196 if(scenario_value && team_value.
empty())
198 team_value = *scenario_value;
219 if (!scenario[
"addon_id"].empty() && scenario[
"require_scenario"].to_bool(
false)) {
238 config_variable_set(
const config& cfg) : cfg_(cfg) {}
248 ERR_NG <<
"invalid variablename " <<
id <<
"\n";
257 return res ==
"true" || res ==
"yes" || res ==
"1";
261 struct modevents_entry
267 struct modevents_entry_for
270 typedef modevents_entry result_type;
272 modevents_entry operator()(
const std::string&
id)
const
274 return modevents_entry(type_,
id);
288 bool require_default = (type ==
"era");
289 if (!cfg[
"addon_id"].empty() && cfg[require_attr].to_bool(require_default)) {
296 if(modevent[
"enable_if"].empty() || variable_to_bool(
carryover_.
child_or_empty(
"variables"), modevent[
"enable_if"]))
315 ERR_NG <<
"Couldn't find [" << type<<
"] with id=" <<
id <<std::endl;
326 std::vector<modevents_entry> mods;
327 std::set<std::string> loaded_resources;
329 | boost::adaptors::transformed(modevents_entry_for(
"modification"))
330 , std::back_inserter(mods) );
338 for(modevents_entry& mod : mods)
345 if(loaded_resources.find(cfg[
"id"].str()) == loaded_resources.end()) {
346 mods.push_back(modevents_entry(
"resource", cfg[
"id"].str()));
347 loaded_resources.insert(cfg[
"id"].str());
351 }
while(!mods.empty());
360 std::vector<modevents_entry> mods;
363 | boost::adaptors::transformed(modevents_entry_for(
"modification"))
364 , std::back_inserter(mods) );
367 mods.push_back(modevents_entry(
"campaign",
classification().campaign));
370 for(modevents_entry& mod : mods)
376 variables[
option[
"id"]] = option[
"value"];
381 LOG_NG <<
"Couldn't find [" << mod.type<<
"] with id=" << mod.id <<
" for [option]s" << std::endl;
395 LOG_NG <<
"randomly generating scenario...\n";
419 LOG_NG <<
"randomly generating map...\n";
543 scenario_id =
carryover_[
"next_scenario"].str();
547 assert(!
"cannot figure out scenario_id");
548 throw "assertion ingnored";
550 return scenario_id ==
"null" ?
"" : scenario_id;
574 if (side[
"controller"] !=
"human" && side[
"controller"] !=
"network")
continue;
577 unit[
"goto_x"] = -999;
578 unit[
"goto_y"] = -999;
587 if (side[
"controller"] ==
"network")
588 side[
"controller"] =
"human";
589 if (side[
"controller"] ==
"network_ai")
590 side[
"controller"] =
"ai";
616 if(
config & caryover_sides = cfg.
child(
"carryover_sides"))
621 else if(
config & caryover_sides_start = cfg.
child(
"carryover_sides_start"))
665 if (
const config &stats = cfg.
child(
"statistics")) {
void rotate_random()
Resets the random to the 0 calls and the seed to the random this way we stay in the same sequence but...
child_itors child_range(const std::string &key)
config replay_start_
snapshot made before the start event.
std::string random_generate_map(const std::string &parms, const config &cfg)
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
void write(const config &cfg)
void write_starting_pos(config_writer &out) const
std::string label
Name of the game (e.g.
std::string get_tagname() const
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
void set_scenario(config scenario)
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine ...
GLuint GLuint GLsizei GLenum type
We failed to get a starting pos in expand_scenario.
There is no scenario stating pos data (start-of-scenario).
config & child_or_add(const std::string &key)
Returns a reference to the first child with the given key.
STARTING_POS_TYPE starting_pos_type_
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
void merge_old_carryover(const carryover_info &old_carryover)
config & set_snapshot(config snapshot)
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
void clear_children(const std::string &key)
void transfer_to(config &level)
bool empty() const
Tests for an attribute that either was never set or was set to "".
void write_general_info(config_writer &out) const
Definitions for the interface to Wesnoth Markup Language (WML).
Variant for storing WML attributes.
void write_config(config_writer &out) const
writes the config information into a stream (file)
void write_child(const std::string &key, const config &cfg)
void transfer_all_to(config &side_cfg)
std::vector< std::string > active_mods
static game_config_manager * get()
void load_mod(const std::string &type, const std::string &id)
helper for expand_mp_events();
void close_child(const std::string &key)
void set_random_seed()
sets the random seed if that didn't already happen.
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
Class for writing a config out to a file in pieces.
config random_generate_scenario(const std::string &parms, const config &cfg)
void open_child(const std::string &key)
void update_label()
sets classification().label to the correct value.
void update_addon_requirements(const config &addon_cfg)
void write(config_writer &out) const
config & add_child(const std::string &key)
We have a [snapshot] (mid-game-savefile).
void read_stats(const config &cfg)
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
const rand_rng::mt_rng & rng() const
std::string campaign
the campaign being played
config & get_starting_pos()
void set_data(config &cfg)
destroys the passed config.
Templates and utility-routines for strings and numbers.
std::string read_map(const std::string &name)
game_classification classification_
some general information of the game that doesn't change during the game
std::string abbrev
the campaign abbreviation
Game configuration data as global variables.
mp_game_settings mp_settings_
const config & game_config() const
config starting_pos_
The starting pos where the (non replay) game will be started from.
void append_config(const config &data)
Information on a WML variable.
#define log_scope(description)
std::string get_scenario_id()
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
GLdouble GLdouble GLdouble r
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
saved_game & operator=(saved_game other)
void swap(replay_recorder_base &other)
const attribute_value * get(const std::string &key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
void swap(saved_game &other)
replay_recorder_base replay_data_
virtual config::attribute_value get_variable_const(const std::string &id) const =0
void load_game_config_for_game(const game_classification &classification)
game_classification & classification()
void set_carryover_sides_start(config carryover_sides_start)
void swap(game_board &one, game_board &other)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Standard logging facilities (interface).
void convert_to_start_save()
converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next sce...
static lg::log_domain log_engine("engine")
Some information about savefiles: A saveile can contain: General information (toplevel atributes...
A config object defines a single node in a WML file, with access to child nodes.
void write_carryover(config_writer &out) const
bool has_carryover_expanded_
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
We have a [scenario] (start-of-scenario) savefile.
GLsizei const GLcharARB ** string
const config & get_replay_starting_pos()