16 #define GETTEXT_DOMAIN "wesnoth-lib"
32 #define ERR_CFG LOG_STREAM(err, log_config)
36 bool message_private_on =
false;
38 std::map<std::string, std::set<std::string>> completed_campaigns;
39 std::set<std::string> encountered_units_set;
40 std::set<t_translation::terrain_code> encountered_terrains_set;
42 std::map<std::string, std::vector<std::string>> history_map;
44 std::map<std::string, preferences::acquaintance> acquaintances;
46 std::vector<std::string> mp_modifications;
47 bool mp_modifications_initialized =
false;
48 std::vector<std::string> sp_modifications;
49 bool sp_modifications_initialized =
false;
52 bool options_initialized =
false;
54 void initialize_modifications(
bool mp =
true)
58 mp_modifications_initialized =
true;
61 sp_modifications_initialized =
true;
78 for(
const auto& elem : completed_campaigns) {
80 cmp[
"name"] = elem.first;
81 cmp[
"difficulty_levels"] =
utils::join(elem.second);
99 for(
const auto& history_id : history_map) {
101 for(
const std::string&
line : history_id.second) {
104 cfg[
"message"] =
line;
105 history_id_cfg.
add_child(
"line", std::move(cfg));
108 history.
add_child(history_id.first, history_id_cfg);
113 encountered_units_set.clear();
114 encountered_terrains_set.clear();
136 completed_campaigns[
c];
141 std::set<std::string>&
d = completed_campaigns[cc[
"name"]];
142 std::vector<std::string> nd =
utils::split(cc[
"difficulty_levels"]);
143 std::copy(nd.begin(), nd.end(), std::inserter(
d,
d.begin()));
150 encountered_terrains_set.insert(terrain.begin(), terrain.end());
161 for(
const config& l :
h.cfg.child_range(
"line")) {
162 history_map[
h.key].push_back(l[
"message"]);
170 if(acquaintances.empty()) {
183 for(
auto&
a : acquaintances) {
192 return acquaintances;
198 std::vector<std::string> ignored;
200 for(
const auto& person : acquaintances) {
201 if(person.second.get_status() ==
"ignore") {
202 ignored.push_back(person.second.get_nick());
213 std::map<std::string, std::string> ac_nice;
215 for(
const auto&
a : acquaintances) {
216 if(
a.second.get_status() == filter) {
217 ac_nice[
a.second.get_nick()] =
a.second.get_notes();
225 const std::string& nick,
const std::string& mode,
const std::string& notes)
228 return std::pair(
nullptr,
false);
232 auto [iter, added_new] = acquaintances.insert_or_assign(nick, new_entry);
235 return std::pair(&iter->second, added_new);
243 if(
i == acquaintances.end()) {
244 std::size_t pos = nick.find_first_of(
' ');
246 if(pos != std::string::npos) {
247 i = acquaintances.find(nick.substr(0, pos));
251 if(
i == acquaintances.end()) {
255 acquaintances.erase(
i);
264 const auto it = acquaintances.find(nick);
266 if(it == acquaintances.end()) {
269 return it->second.get_status() ==
"friend";
276 const auto it = acquaintances.find(nick);
278 if(it == acquaintances.end()) {
281 return it->second.get_status() ==
"ignore";
287 completed_campaigns[campaign_id].insert(difficulty_level);
292 return completed_campaigns.count(campaign_id) != 0;
297 const auto it = completed_campaigns.find(campaign_id);
298 return it == completed_campaigns.end() ? false : it->second.count(difficulty_level) != 0;
304 if(sender !=
"server") {
308 std::string::size_type pos = message.find(
" has logged into the lobby");
309 if(pos == std::string::npos) {
310 pos = message.find(
" has disconnected");
311 if(pos == std::string::npos) {
325 return is_friend(message.substr(0, pos));
331 if(pref ==
"friends") {
333 }
else if(pref ==
"all") {
335 }
else if(pref ==
"none") {
361 std::vector<game_config::server_info> pref_servers;
364 pref_servers.emplace_back();
365 pref_servers.back().name = server[
"name"].str();
366 pref_servers.back().address = server[
"address"].str();
375 prefs.clear_children(
"server");
377 for(
const auto& svinfo : value) {
379 sv_cfg[
"name"] = svinfo.name;
380 sv_cfg[
"address"] = svinfo.address;
404 return "add-ons.wesnoth.org";
490 return lexical_cast_default<int>(
preferences::get(
"mp_server_warning_disabled"), 0);
554 if(options_initialized) {
555 return option_values;
562 option_values.
clear();
567 options_initialized =
true;
569 return option_values;
575 options_initialized =
false;
610 return std::clamp<int>(lexical_cast_default<int>(
preferences::get(
"mp_countdown_init_time"), 240), 0, 1500);
620 return std::clamp<int>(lexical_cast_default<int>(
preferences::get(
"mp_countdown_reservoir_time"), 360), 30, 1500);
630 return std::clamp<int>(lexical_cast_default<int>(
preferences::get(
"mp_countdown_turn_bonus"), 240), 0, 300);
640 return std::clamp<int>(lexical_cast_default<int>(
preferences::get(
"mp_countdown_action_bonus"), 0), 0, 30);
710 if((!mp_modifications_initialized &&
mp) || (!sp_modifications_initialized && !
mp)) {
711 initialize_modifications(
mp);
714 return mp ? mp_modifications : sp_modifications;
721 mp_modifications_initialized =
false;
724 sp_modifications_initialized =
false;
801 static const std::string null_theme =
"null";
815 if(
theme !=
"null") {
832 return message_private_on;
837 message_private_on = value;
846 if(choice.empty() || choice ==
"gzip" || choice ==
"yes") {
848 }
else if(choice ==
"bzip2") {
850 }
else if(choice ==
"none" || choice ==
"no") {
900 return lexical_cast_default<int>(
preferences::get(
"chat_message_aging"), 20);
915 return encountered_units_set;
920 return encountered_terrains_set;
941 return &history_map[
id];
947 return confirmation ==
"green" || confirmation ==
"yes";
959 return confirmation ==
"no_moves" || confirmation.empty();
964 for(
const team& help_team : teams) {
965 help_team.log_recruitable();
966 encountered_units_set.insert(help_team.recruits().begin(), help_team.recruits().end());
972 for(
const auto& help_unit : units) {
973 encountered_units_set.insert(help_unit.type_id());
979 for(
const team&
t : teams) {
981 encountered_units_set.insert(u->type_id());
1007 nick_ = cfg[
"nick"].str();
1008 status_ = cfg[
"status"].str();
1009 notes_ = cfg[
"notes"].str();
A config object defines a single node in a WML file, with access to child nodes.
void clear_children(T... keys)
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
virtual const std::vector< team > & teams() const override
virtual const unit_map & units() const override
virtual const gamemap & map() const override
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void for_each_loc(const F &f) const
Encapsulates the map of the game.
const t_translation::ter_list & underlying_union_terrain(const map_location &loc) const
void load_from_config(const config &cfg)
std::string nick_
acquaintance's MP nick
std::string notes_
notes on the acquaintance
const std::string & get_nick() const
std::string status_
status (e.g., "friend", "ignore")
This class stores all the data for a single 'side' (in game nomenclature).
Container associating units to locations.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
New lexcical_cast header.
Standard logging facilities (interface).
General settings and defaults for scenarios.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
std::vector< server_info > server_list
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
std::pair< std::string, unsigned > item
std::string get_timestamp(const std::time_t &t, const std::string &format)
Main entry points of multiplayer mode.
Modify, read and display user preferences.
void set_village_support(int value)
void set_show_side_colors(bool value)
void set_campaign_server(const std::string &host)
void set_skip_ai_moves(bool value)
bool show_all_units_in_help()
void set_village_gold(int value)
bool show_floating_labels()
void set_era(const std::string &value)
void set_user_servers_list(const std::vector< game_config::server_info > &value)
void set_shuffle_sides(bool value)
void set_music_volume(int vol)
lobby_joins get_lobby_joins()
void set_allow_observers(bool value)
void set_skip_mp_replay(bool value)
void _set_lobby_joins(lobby_joins show)
std::string get_mp_server_program_name()
void clear(const std::string &key)
void set_message_private(bool value)
void set_mp_server_program_name(const std::string &path)
bool is_ignored(const std::string &nick)
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
void set_hide_whiteboard(bool value)
void set_sound_volume(int vol)
void set_shroud(bool value)
void set_custom_command(const std::string &command)
bool use_twelve_hour_clock_format()
static void load_acquaintances()
int countdown_init_time()
void set(const std::string &key, bool value)
bool interrupt_when_ally_sighted()
void set_random_faction_mode(const std::string &value)
const std::string get_ignored_delim()
void set_modifications(const std::vector< std::string > &value, bool mp)
void set_turns(int value)
std::string campaign_server()
bool is_campaign_completed(const std::string &campaign_id)
void set_blindfold_replay(bool value)
void set_mp_server_warning_disabled(int value)
std::set< std::string > & encountered_units()
compression::format save_compression_format()
std::string network_host()
void set_show_all_units_in_help(bool value)
void set_chat_lines(int lines)
void set_chat_message_aging(const int aging)
void encounter_all_content(const game_board &gameboard_)
std::vector< game_config::server_info > user_servers_list()
void set_network_host(const std::string &host)
void encounter_start_units(const unit_map &units)
void set_delete_saves(bool value)
void set_interrupt_when_ally_sighted(bool value)
void set_chat_timestamping(bool value)
void set_xp_modifier(int value)
void set_use_map_settings(bool value)
void set_level_type(int value)
static void encounter_recallable_units(const std::vector< team > &teams)
void set_countdown_reservoir_time(int value)
int countdown_turn_bonus()
int countdown_action_bonus()
std::set< t_translation::terrain_code > & encountered_terrains()
void set_countdown(bool value)
optional_const_config get_child(const std::string &key)
void encounter_recruitable_units(const std::vector< team > &teams)
std::string get_chat_timestamp(const std::time_t &t)
std::string custom_command()
void set_turn_dialog(bool ison)
int mp_server_warning_disabled()
static void save_acquaintances()
void set_child(const std::string &key, const config &val)
const std::vector< game_config::server_info > & builtin_servers_list()
void set_theme(const std::string &theme)
bool remove_acquaintance(const std::string &nick)
void encounter_map_terrain(const gamemap &map)
void set_countdown_init_time(int value)
void set_ask_delete_saves(bool value)
void set_countdown_action_bonus(int value)
void set_level(const std::string &value)
void set_show_floating_labels(bool value)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string ¬es)
void set_options(const config &values)
void set_save_replays(bool value)
void set_random_start_time(bool value)
void set_autosavemax(int value)
std::string get(const std::string &key)
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
std::vector< std::string > * get_history(const std::string &id)
Returns a pointer to the history vector associated with given id making a new one if it doesn't exist...
int countdown_reservoir_time()
void erase(const std::string &key)
bool enable_whiteboard_mode_on_start()
void set_countdown_turn_bonus(int value)
void set_enable_whiteboard_mode_on_start(bool value)
std::string random_faction_mode()
const std::map< std::string, acquaintance > & get_acquaintances()
bool is_friend(const std::string &nick)
const std::vector< std::string > & modifications(bool mp)
int get_village_support(const std::string &value)
Gets the village unit level support.
int get_turns(const std::string &value)
Gets the number of turns.
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
std::vector< terrain_code > ter_list
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
std::string write_list(const ter_list &list)
Writes a list of terrains to a string, only writes the new format.
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
bool headless()
The game is running headless.
std::string::const_iterator iterator
static lg::log_domain log_config("config")
std::shared_ptr< const unit > unit_const_ptr
Encapsulates the map of the game.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...