83 #define ERR_NG LOG_STREAM(err, log_engine) 84 #define WRN_NG LOG_STREAM(warn, log_engine) 85 #define LOG_NG LOG_STREAM(info, log_engine) 86 #define DBG_NG LOG_STREAM(debug, log_engine) 90 bool variable_to_bool(
const config& vars,
const std::string& expression)
93 return res ==
"true" || res ==
"yes" || res ==
"1";
97 struct modevents_entry
99 modevents_entry(
const std::string& _type,
const std::string& _id)
109 bool is_illegal_file_char(
char c)
111 return c ==
'/' || c ==
'\\' || c ==
':' || (c >= 0x00 && c < 0x20)
113 || c ==
'?' || c ==
'|' || c ==
'<' || c ==
'>' || c ==
'*' || c ==
'"' 121 : has_carryover_expanded_(false)
172 std::stringstream stream;
221 static const std::vector<std::string> team_defaults {
222 "carryover_percentage",
227 bool require_campaign = campaign[
"require_campaign"].to_bool(
true);
235 if(side[
"no_leader"].to_bool()) {
236 side[
"leader_lock"] =
true;
240 if(side[
"save_id"].empty()) {
241 side[
"save_id"] = side[
"id"];
244 if(!is_multiplayer_tag && side[
"side_name"].blank()) {
245 side[
"side_name"] = side[
"name"];
248 if(!is_loaded_game && !side[
"current_player"].empty()) {
249 ERR_NG <<
"Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using " 250 "'side_name' instead\n";
256 for(
const std::string& att_name : team_defaults) {
260 if(scenario_value && team_value.
empty()) {
261 team_value = *scenario_value;
301 scenario[
"version"] =
starting_point_[
"addon_version"].str(version_default);
303 scenario[
"required"] =
starting_point_[
"require_scenario"].to_bool(
false);
307 content[
"type"] =
"scenario";
317 std::string require_attr =
"require_" +
type;
321 const bool require_default = cfg[
"addon_id"].empty() ? false : type ==
"era";
325 non_scenario[
"id"] = cfg[
"addon_id"].str(
"mainline");
326 non_scenario[
"name"] = cfg[
"addon_title"].str(
"mainline");
327 non_scenario[
"version"] = cfg[
"addon_version"].str(version_default);
328 non_scenario[
"min_version"] = cfg[
"addon_min_version"];
329 non_scenario[
"required"] = cfg[require_attr].to_bool(require_default);
332 content[
"name"] = cfg[
"addon_title"].str(cfg[
"name"].str(
""));
333 content[
"type"] =
type;
339 if(modevent[
"enable_if"].empty()
362 ERR_NG <<
"Couldn't find [" << type <<
"] with id=" <<
id << std::endl;
375 std::vector<modevents_entry> mods;
376 std::set<std::string> loaded_resources;
379 [](
const std::string& id) {
return modevents_entry(
"modification",
id); }
391 for(modevents_entry& mod : mods) {
401 if(loaded_resources.find(
id) == loaded_resources.end()) {
402 loaded_resources.insert(
id);
414 std::vector<modevents_entry> mods;
417 [](
const std::string& id) {
return modevents_entry(
"modification",
id); }
426 for(modevents_entry& mod : mods) {
432 ERR_NG <<
"variable " << option[
"id"] <<
"cannot be set to " << option[
"value"] << std::endl;
436 LOG_NG <<
"Couldn't find [" << mod.type <<
"] with id=" << mod.id <<
" for [option]s" << std::endl;
461 if(scenario[
"map_data"].empty() && !scenario[
"map_file"].empty()) {
463 if(map_data.find(
"map_data") != std::string::npos) {
466 read(map_data_cfg, map_data);
470 scenario[
"map_data"] = map_data;
482 LOG_NG <<
"randomly generating scenario...\n";
500 LOG_NG <<
"randomly generating map...\n";
511 static const std::vector<std::string> attributes_to_copy {
523 for(
const auto& str : attributes_to_copy) {
524 generated_scenario[str] = old_scenario[str];
531 generated_scenario.
add_child(
"story", story);
649 std::string scenario_id;
654 scenario_id =
carryover_[
"next_scenario"].str();
658 assert(!
"cannot figure out scenario_id");
659 throw "assertion ignored";
662 return scenario_id ==
"null" ?
"" : scenario_id;
680 label.
erase(std::remove_if(label.begin(), label.end(), is_illegal_file_char), label.end());
681 std::replace(label.begin(), label.end(),
'_',
' ');
690 if(side[
"controller"] !=
"human" && side[
"controller"] !=
"network") {
694 for(
config&
unit : side.child_range(
"unit")) {
695 unit[
"goto_x"] = -999;
696 unit[
"goto_y"] = -999;
704 side.remove_attribute(
"is_local");
706 if(side[
"controller"] ==
"network") {
707 side[
"controller"] =
"human";
710 if(side[
"controller"] ==
"network_ai") {
711 side[
"controller"] =
"ai";
741 if(
config& caryover_sides = cfg.
child(
"carryover_sides")) {
744 }
else if(
config& caryover_sides_start = cfg.
child(
"carryover_sides_start")) {
770 }
else if(
config& scenario = cfg.
child(
"scenario")) {
780 if(
const config& stats = cfg.
child(
"statistics")) {
void check_require_scenario()
Add addon_id information if needed.
bool empty() const
Tests for an attribute that either was never set or was set to "".
config replay_start_
snapshot made before the start event.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void write_general_info(config_writer &out) const
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)
std::string label
Name of the game (e.g.
This class represents a single unit of a specific type.
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Variant for storing WML attributes.
void set_scenario(config scenario)
void write_starting_point(config_writer &out) const
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine ...
void write_config(config_writer &out) const
writes the config information into a stream (file)
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
unsigned child_count(config_key_type key) const
void write_carryover(config_writer &out) const
config & add_child_at_total(config_key_type key, const config &val, size_t pos)
child_itors child_range(config_key_type key)
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
void merge_old_carryover(const carryover_info &old_carryover)
size_t find_total_first_of(config_key_type key, size_t start=0)
config & child_or_add(config_key_type key)
config starting_point_
The starting pos where the (non replay) game will be started from.
config & set_snapshot(config snapshot)
static void post_scenario_generation(const config &old_scenario, config &generated_scenario)
copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_genera...
void append_children(const config &cfg)
Adds children from cfg.
void transfer_to(config &level)
void remove_attribute(config_key_type key)
Definitions for the interface to Wesnoth Markup Language (WML).
std::string get_scenario_id() const
std::string random_generate_map(const std::string &name, const config &cfg, const config *vars)
We failed to get a starting pos in expand_scenario.
void write_child(const std::string &key, const config &cfg)
void transfer_all_to(config &side_cfg)
static game_config_manager * get()
static void expand_map_file(config &scenario)
reads scenario["map_file"]
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
const randomness::mt_rng & rng() const
void close_child(const std::string &key)
void set_random_seed()
sets the random seed if that didn't already happen.
std::vector< std::string > active_mods
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
void read(config &cfg, std::istream &in, abstract_validator *validator)
Class for writing a config out to a file in pieces.
unsigned all_children_count() const
const game_config_view & game_config() const
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)
Takes a config with addon metadata (id, name, version, min_version) and adds it as a requirement for ...
void swap(saved_game &lhs, saved_game &rhs)
Implement non-member swap function for std::swap (calls saved_game::swap).
void read_stats(const config &cfg)
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
config & get_starting_point()
void write(config_writer &out) const
void load_non_scenario(const std::string &type, const std::string &id, size_t pos)
helper for expand_mp_events();
starting_point starting_point_type_
std::string campaign
The id of the campaign being played.
void set_data(config &cfg)
destroys the passed config.
all_children_iterator erase(const all_children_iterator &i)
std::string read_map(const std::string &name)
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
static void inherit_scenario(config &scenario, config &map_scenario)
game_classification classification_
some general information of the game that doesn't change during the game
std::string abbrev
the campaign abbreviation
const config & get_replay_starting_point()
There is no scenario stating pos data (start-of-scenario).
Default, unset return value.
We have a [scenario] (start-of-scenario) savefile.
Game configuration data as global variables.
mp_game_settings mp_settings_
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...
void append_config(const config &data)
#define log_scope(description)
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
int get_random_int(int min, int max)
This helper method provides a random int from the underlying generator, using results of next_random...
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
const version_info wesnoth_version(VERSION)
rng * generator
This generator is automatically synced during synced context.
variable_info_mutable< variable_info_implementation::vi_policy_create > variable_access_create
'Create if nonexistent' access.
config & add_child(config_key_type key)
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
void swap(replay_recorder_base &other)
void swap(saved_game &other)
replay_recorder_base replay_data_
config random_generate_scenario(const std::string &name, const config &cfg, const config *vars)
game_classification & classification()
void set_carryover_sides_start(config carryover_sides_start)
saved_game & operator=(const saved_game &other)=delete
Standard logging facilities (interface).
std::string str() const
Serializes the version number into string form.
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...
We have a [snapshot] (mid-game-savefile).
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
config_attribute_value attribute_value
Variant for storing WML attributes.
static lg::log_domain log_engine("engine")
Some information about savefiles:
A config object defines a single node in a WML file, with access to child nodes.
bool has_carryover_expanded_
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
void remove_child(config_key_type key, unsigned index)
std::string get_tagname() const