84 #define ERR_NG LOG_STREAM(err, log_engine)
85 #define WRN_NG LOG_STREAM(warn, log_engine)
86 #define LOG_NG LOG_STREAM(info, log_engine)
87 #define DBG_NG LOG_STREAM(debug, log_engine)
91 bool variable_to_bool(
const config& vars,
const std::string& expression)
94 return res ==
"true" || res ==
"yes" || res ==
"1";
98 struct modevents_entry
100 modevents_entry(
const std::string& _type,
const std::string& _id)
110 bool is_illegal_file_char(
char c)
112 return c ==
'/' ||
c ==
'\\' ||
c ==
':' || (
c >= 0x00 &&
c < 0x20)
114 ||
c ==
'?' ||
c ==
'|' ||
c ==
'<' ||
c ==
'>' ||
c ==
'*' ||
c ==
'"'
122 : has_carryover_expanded_(false)
136 : has_carryover_expanded_(false)
139 , classification_(cfg)
151 : has_carryover_expanded_(state.has_carryover_expanded_)
152 , carryover_(state.carryover_)
153 , replay_start_(state.replay_start_)
154 , classification_(state.classification_)
155 , mp_settings_(state.mp_settings_)
156 , starting_point_type_(state.starting_point_type_)
157 , starting_point_(state.starting_point_)
158 , replay_data_(state.replay_data_)
159 , statistics_(state.statistics_)
160 , skip_story_(state.skip_story_)
176 std::stringstream stream;
227 static const std::vector<std::string> team_defaults {
228 "carryover_percentage",
236 bool require_campaign = campaign[
"require_campaign"].to_bool(
true);
244 if(side[
"no_leader"].to_bool()) {
245 side[
"leader_lock"] =
true;
249 if(side[
"save_id"].empty()) {
250 side[
"save_id"] = side[
"id"];
252 if(side[
"save_id"].empty()) {
253 side[
"save_id"] = side.child_or_empty(
"leader")[
"id"];
256 if(!is_multiplayer_tag) {
257 if(side[
"name"].
blank()) {
258 side[
"name"] = side.child_or_empty(
"leader")[
"name"];
260 if(side[
"side_name"].
blank()) {
261 side[
"side_name"] = side[
"name"];
265 if(!is_loaded_game && !side[
"current_player"].empty()) {
266 ERR_NG <<
"Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using "
267 "'side_name' instead";
273 for(
const std::string& att_name : team_defaults) {
277 if(scenario_value && team_value.
empty()) {
278 team_value = *scenario_value;
318 scenario[
"version"] =
starting_point_[
"addon_version"].str(version_default);
320 scenario[
"required"] =
starting_point_[
"require_scenario"].to_bool(
false);
325 content[
"type"] =
"scenario";
335 std::string require_attr =
"require_" +
type;
341 non_scenario[
"id"] = cfg[
"addon_id"].str(
"mainline");
342 non_scenario[
"name"] = cfg[
"addon_title"].str(
"mainline");
343 non_scenario[
"version"] = cfg[
"addon_version"].str(version_default);
344 non_scenario[
"min_version"] = cfg[
"addon_min_version"];
345 non_scenario[
"required"] = cfg[require_attr].to_bool(!cfg[
"addon_id"].empty());
348 content[
"name"] = cfg[
"addon_title"].str(cfg[
"name"].str(
""));
349 content[
"type"] =
type;
355 if(modevent[
"enable_if"].empty()
378 ERR_NG <<
"Couldn't find [" <<
type <<
"] with id=" <<
id;
391 std::vector<modevents_entry> mods;
392 std::set<std::string> loaded_resources;
395 [](
const std::string&
id) { return modevents_entry(
"modification", id); }
407 for(modevents_entry& mod : mods) {
417 if(loaded_resources.find(
id) == loaded_resources.end()) {
418 loaded_resources.insert(
id);
430 std::vector<modevents_entry> mods;
433 [](
const std::string&
id) { return modevents_entry(
"modification", id); }
442 for(modevents_entry& mod : mods) {
443 if(
auto cfg =
mp_settings().options.find_child(mod.type,
"id", mod.id)) {
448 ERR_NG <<
"variable " << option[
"id"] <<
"cannot be set to " << option[
"value"];
452 LOG_NG <<
"Couldn't find [" << mod.type <<
"] with id=" << mod.id <<
" for [option]s";
466 auto side_to = scenario.
find_child(
"side",
"side", side_from[
"side"]);
468 side_to->inherit_attributes(side_from);
469 side_to->append_children(side_from);
478 if(!scenario[
"include_file"].empty()) {
480 if(!include_data.empty()) {
482 read(include_data_cfg, include_data);
487 scenario[
"include_file"] =
"";
490 if(scenario[
"map_data"].empty() && !scenario[
"map_file"].empty()) {
492 if(map_data.find(
"map_data") != std::string::npos) {
496 read(map_data_cfg, map_data);
500 scenario[
"map_data"] = map_data;
512 LOG_NG <<
"randomly generating scenario...";
530 LOG_NG <<
"randomly generating map...";
541 static const std::vector<std::string> attributes_to_copy {
553 for(
const auto& str : attributes_to_copy) {
554 generated_scenario[str] = old_scenario[str];
561 generated_scenario.
add_child(
"story", story);
681 std::string scenario_id;
686 scenario_id =
carryover_[
"next_scenario"].str();
690 assert(!
"cannot figure out scenario_id");
691 throw "assertion ignored";
694 return scenario_id ==
"null" ?
"" : scenario_id;
713 std::replace(
label.begin(),
label.end(),
'_',
' ');
722 if(side[
"controller"] != side_controller::human) {
726 for(
config&
unit : side.child_range(
"unit")) {
727 unit[
"goto_x"] = -999;
728 unit[
"goto_y"] = -999;
736 side.remove_attribute(
"is_local");
768 }
else if(
auto caryover_sides_start = cfg.
optional_child(
"carryover_sides_start")) {
void merge_old_carryover(const carryover_info &old_carryover)
void transfer_to(config &level)
void transfer_all_to(config &side_cfg)
const randomness::mt_rng & rng() const
Variant for storing WML attributes.
bool empty() const
Tests for an attribute that either was never set or was set to "".
Class for writing a config out to a file in pieces.
void close_child(const std::string &key)
void write(const config &cfg)
void write_child(const std::string &key, const config &cfg)
void open_child(const std::string &key)
A config object defines a single node in a WML file, with access to child nodes.
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 & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
void remove_child(config_key_type key, std::size_t index)
config_attribute_value attribute_value
Variant for storing WML attributes.
std::size_t child_count(config_key_type key) const
optional_config_impl< 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.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
std::size_t all_children_count() const
config & add_child_at_total(config_key_type key, const config &val, std::size_t pos)
void remove_attribute(config_key_type key)
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
std::size_t find_total_first_of(config_key_type key, std::size_t start=0)
void append_children(const config &cfg)
Adds children from cfg.
void splice_children(config &src, config_key_type key)
Moves all the children with tag key from src to this.
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.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
std::vector< std::string > active_mods
std::string label
Name of the game (e.g.
std::string get_tagname() const
std::string campaign
The id of the campaign being played.
std::string abbrev
the campaign abbreviation
static game_config_manager * get()
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
const game_config_view & game_config() const
A class grating read only view to a vector of config objects, viewed as one config with all children ...
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...
int get_random_int(int min, int max)
void write(config_writer &out) const
void append_config(const config &data)
void swap(replay_recorder_base &other)
game_classification & classification()
saved_game & operator=(const saved_game &other)=delete
void set_random_seed()
sets the random seed if that didn't already happen.
config replay_start_
snapshot made before the start event.
void swap(saved_game &other)
void write_config(config_writer &out) const
writes the config information into a stream (file)
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
void set_carryover_sides_start(config carryover_sides_start)
starting_point starting_point_type_
std::string get_scenario_id() const
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_ge...
replay_recorder_base replay_data_
void load_non_scenario(const std::string &type, const std::string &id, size_t pos)
helper for expand_mp_events();
void update_label()
sets classification().label to the correct value.
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
statistics_record::campaign_stats_t statistics_
void set_scenario(config scenario)
bool has_carryover_expanded_
static void expand_map_file(config &scenario)
reads scenario["map_file"]
config & get_starting_point()
config starting_point_
The starting pos where the (non replay) game will be started from.
const config & get_replay_starting_point()
void check_require_scenario()
Add addon_id information if needed.
void write_starting_point(config_writer &out) const
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
mp_game_settings mp_settings_
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
@ SNAPSHOT
We have a [snapshot] (mid-game-savefile).
@ SCENARIO
We have a [scenario] (start-of-scenario) savefile.
@ NONE
There is no scenario stating pos data (start-of-scenario).
@ INVALID
We failed to get a starting pos in expand_scenario.
statistics_record::campaign_stats_t & statistics()
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...
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine
void write_general_info(config_writer &out) const
game_classification classification_
some general information of the game that doesn't change during the game
void set_data(config &cfg)
destroys the passed config.
config & set_snapshot(config snapshot)
void write_carryover(config_writer &out) const
This class represents a single unit of a specific type.
std::string str() const
Serializes the version number into string form.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
std::string label
What to show in the filter's drop-down list.
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
#define log_scope(description)
std::string random_generate_map(const std::string &name, const config &cfg, const config *vars)
config random_generate_scenario(const std::string &name, const config &cfg, const config *vars)
std::string read_scenario(const std::string &name)
std::string read_map(const std::string &name)
Game configuration data as global variables.
const version_info wesnoth_version(VERSION)
@ NONE
Default, unset return value.
rng * generator
This generator is automatically synced during synced context.
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 erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void swap(saved_game &lhs, saved_game &rhs)
Implement non-member swap function for std::swap (calls saved_game::swap).
static lg::log_domain log_engine("engine")
static void inherit_scenario(config &scenario, config &map_scen)
void read(config &cfg, std::istream &in, abstract_validator *validator)
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 new_scenario(const std::string &scenario_name)
Adds an entry for anew scenario to wrte to.
void read(const config &cfg, bool append=false)
void write(config_writer &out) const
variable_info_mutable< variable_info_implementation::vi_policy_create > variable_access_create
'Create if nonexistent' access.