85 #define ERR_NG LOG_STREAM(err, log_engine) 86 #define WRN_NG LOG_STREAM(warn, log_engine) 87 #define LOG_NG LOG_STREAM(info, log_engine) 88 #define DBG_NG LOG_STREAM(debug, log_engine) 92 bool variable_to_bool(
const config& vars,
const std::string& expression)
95 return res ==
"true" || res ==
"yes" || res ==
"1";
99 struct modevents_entry
101 modevents_entry(
const std::string& _type,
const std::string& _id)
111 bool is_illegal_file_char(
char c)
113 return c ==
'/' || c ==
'\\' || c ==
':' || (c >= 0x00 && c < 0x20)
115 || c ==
'?' || c ==
'|' || c ==
'<' || c ==
'>' || c ==
'*' || c ==
'"' 123 : has_carryover_expanded_(false)
174 std::stringstream stream;
223 static const std::vector<std::string> team_defaults {
224 "carryover_percentage",
229 bool require_campaign = campaign[
"require_campaign"].to_bool(
true);
237 if(side[
"no_leader"].to_bool()) {
238 side[
"leader_lock"] =
true;
242 if(side[
"save_id"].empty()) {
243 side[
"save_id"] = side[
"id"];
246 if(!is_multiplayer_tag && side[
"side_name"].
blank()) {
247 side[
"side_name"] = side[
"name"];
250 if(!is_loaded_game && !side[
"current_player"].empty()) {
251 ERR_NG <<
"Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using " 252 "'side_name' instead";
258 for(
const std::string& att_name : team_defaults) {
262 if(scenario_value && team_value.
empty()) {
263 team_value = *scenario_value;
303 scenario[
"version"] =
starting_point_[
"addon_version"].str(version_default);
305 scenario[
"required"] =
starting_point_[
"require_scenario"].to_bool(
false);
309 content[
"type"] =
"scenario";
319 std::string require_attr =
"require_" +
type;
323 const bool require_default = cfg[
"addon_id"].empty() ? false : type ==
"era";
327 non_scenario[
"id"] = cfg[
"addon_id"].str(
"mainline");
328 non_scenario[
"name"] = cfg[
"addon_title"].str(
"mainline");
329 non_scenario[
"version"] = cfg[
"addon_version"].str(version_default);
330 non_scenario[
"min_version"] = cfg[
"addon_min_version"];
331 non_scenario[
"required"] = cfg[require_attr].to_bool(require_default);
334 content[
"name"] = cfg[
"addon_title"].str(cfg[
"name"].str(
""));
335 content[
"type"] =
type;
341 if(modevent[
"enable_if"].empty()
364 ERR_NG <<
"Couldn't find [" << type <<
"] with id=" <<
id;
377 std::vector<modevents_entry> mods;
378 std::set<std::string> loaded_resources;
381 [](
const std::string&
id) {
return modevents_entry(
"modification",
id); }
393 for(modevents_entry& mod : mods) {
403 if(loaded_resources.find(
id) == loaded_resources.end()) {
404 loaded_resources.insert(
id);
416 std::vector<modevents_entry> mods;
419 [](
const std::string&
id) {
return modevents_entry(
"modification",
id); }
428 for(modevents_entry& mod : mods) {
434 ERR_NG <<
"variable " << option[
"id"] <<
"cannot be set to " << option[
"value"];
438 LOG_NG <<
"Couldn't find [" << mod.type <<
"] with id=" << mod.id <<
" for [option]s";
463 if(scenario[
"map_data"].empty() && !scenario[
"map_file"].empty()) {
465 if(map_data.find(
"map_data") != std::string::npos) {
468 read(map_data_cfg, map_data);
472 scenario[
"map_data"] = map_data;
484 LOG_NG <<
"randomly generating scenario...";
502 LOG_NG <<
"randomly generating map...";
513 static const std::vector<std::string> attributes_to_copy {
525 for(
const auto& str : attributes_to_copy) {
526 generated_scenario[str] = old_scenario[str];
533 generated_scenario.
add_child(
"story", story);
651 std::string scenario_id;
656 scenario_id =
carryover_[
"next_scenario"].str();
660 assert(!
"cannot figure out scenario_id");
661 throw "assertion ignored";
664 return scenario_id ==
"null" ?
"" : scenario_id;
682 label.
erase(std::remove_if(label.begin(), label.end(), is_illegal_file_char), label.end());
683 std::replace(label.begin(), label.end(),
'_',
' ');
692 if(side[
"controller"] != side_controller::human) {
696 for(
config&
unit : side.child_range(
"unit")) {
697 unit[
"goto_x"] = -999;
698 unit[
"goto_y"] = -999;
706 side.remove_attribute(
"is_local");
735 if(
config& caryover_sides = cfg.
child(
"carryover_sides")) {
738 }
else if(
config& caryover_sides_start = cfg.
child(
"carryover_sides_start")) {
764 }
else if(
config& scenario = cfg.
child(
"scenario")) {
774 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)
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)
Returns a reference to the first child with the given 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)
std::string label
What to show in the filter's drop-down list.
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
std::string id
Text to match against addon_info.tags()
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