The Battle for Wesnoth  1.17.0-dev
game.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
18 #include "preferences/game.hpp"
19 #include "game_board.hpp"
20 #include "game_display.hpp"
21 #include "gettext.hpp"
22 #include "lexical_cast.hpp"
23 #include "log.hpp"
24 #include "map/map.hpp"
25 #include "map_settings.hpp"
28 #include "units/map.hpp"
29 #include "units/unit.hpp"
30 #include "wml_exception.hpp"
31 
32 #include <cassert>
33 
34 static lg::log_domain log_config("config");
35 #define ERR_CFG LOG_STREAM(err, log_config)
36 
37 using acquaintances_map = std::map<std::string, preferences::acquaintance>;
38 
39 namespace
40 {
41 bool message_private_on = false;
42 
43 std::map<std::string, std::set<std::string>> completed_campaigns;
44 std::set<std::string> encountered_units_set;
45 std::set<t_translation::terrain_code> encountered_terrains_set;
46 
47 std::map<std::string, std::vector<std::string>> history_map;
48 
49 acquaintances_map acquaintances;
50 
51 std::vector<std::string> mp_modifications;
52 bool mp_modifications_initialized = false;
53 std::vector<std::string> sp_modifications;
54 bool sp_modifications_initialized = false;
55 
56 config option_values;
57 bool options_initialized = false;
58 
59 void initialize_modifications(bool mp = true)
60 {
61  if(mp) {
62  mp_modifications = utils::split(preferences::get("mp_modifications"), ',');
63  mp_modifications_initialized = true;
64  } else {
65  sp_modifications = utils::split(preferences::get("sp_modifications"), ',');
66  sp_modifications_initialized = true;
67  }
68 }
69 
70 } // namespace
71 
72 namespace preferences
73 {
75  : base()
76 {
78 }
79 
81 {
82  config campaigns;
83  for(const auto& elem : completed_campaigns) {
84  config cmp;
85  cmp["name"] = elem.first;
86  cmp["difficulty_levels"] = utils::join(elem.second);
87  campaigns.add_child("campaign", cmp);
88  }
89 
90  preferences::set_child("completed_campaigns", campaigns);
91 
92  preferences::set("encountered_units", utils::join(encountered_units_set));
93  t_translation::ter_list terrain(encountered_terrains_set.begin(), encountered_terrains_set.end());
94  preferences::set("encountered_terrain_list", t_translation::write_list(terrain));
95 
96  /* Structure of the history
97  [history]
98  [history_id]
99  [line]
100  message = foobar
101  [/line]
102  */
103  config history;
104  for(const auto& history_id : history_map) {
105  config history_id_cfg; // [history_id]
106  for(const std::string& line : history_id.second) {
107  config cfg; // [line]
108 
109  cfg["message"] = line;
110  history_id_cfg.add_child("line", std::move(cfg));
111  }
112 
113  history.add_child(history_id.first, history_id_cfg);
114  }
115  preferences::set_child("history", history);
116 
117  history_map.clear();
118  encountered_units_set.clear();
119  encountered_terrains_set.clear();
120 }
121 
123 {
126 
127  if(!preferences::get("remember_timer_settings", false)) {
128  preferences::erase("mp_countdown_init_time");
129  preferences::erase("mp_countdown_reservoir_time");
130  preferences::erase("mp_countdown_turn_bonus");
131  preferences::erase("mp_countdown_action_bonus");
132  }
133 
134  // We save the password encrypted now. Erase any saved passwords in the prefs file.
135  preferences::erase("password");
136  preferences::erase("password_is_wrapped");
137 
138  /*
139  completed_campaigns = "A,B,C"
140  [completed_campaigns]
141  [campaign]
142  name = "A"
143  difficulty_levels = "EASY,MEDIUM"
144  [/campaign]
145  [/completed_campaigns]
146  */
147  for(const std::string& c : utils::split(preferences::get("completed_campaigns"))) {
148  completed_campaigns[c]; // create the elements
149  }
150 
151  if(const config& ccc = preferences::get_child("completed_campaigns")) {
152  for(const config& cc : ccc.child_range("campaign")) {
153  std::set<std::string>& d = completed_campaigns[cc["name"]];
154  std::vector<std::string> nd = utils::split(cc["difficulty_levels"]);
155  std::copy(nd.begin(), nd.end(), std::inserter(d, d.begin()));
156  }
157  }
158 
159  encountered_units_set = utils::split_set(preferences::get("encountered_units"));
160 
161  const t_translation::ter_list terrain(t_translation::read_list(preferences::get("encountered_terrain_list")));
162  encountered_terrains_set.insert(terrain.begin(), terrain.end());
163 
164  if(const config& history = preferences::get_child("history")) {
165  /* Structure of the history
166  [history]
167  [history_id]
168  [line]
169  message = foobar
170  [/line]
171  */
172  for(const config::any_child h : history.all_children_range()) {
173  for(const config& l : h.cfg.child_range("line")) {
174  history_map[h.key].push_back(l["message"]);
175  }
176  }
177  }
178 }
179 
180 static void load_acquaintances()
181 {
182  if(acquaintances.empty()) {
183  for(const config& acfg : preferences::get_prefs()->child_range("acquaintance")) {
184  acquaintance ac = acquaintance(acfg);
185  acquaintances[ac.get_nick()] = ac;
186  }
187  }
188 }
189 
190 static void save_acquaintances()
191 {
193  cfg->clear_children("acquaintance");
194 
195  for(auto& a : acquaintances) {
196  config& item = cfg->add_child("acquaintance");
197  a.second.save(item);
198  }
199 }
200 
201 const std::map<std::string, acquaintance>& get_acquaintances()
202 {
204  return acquaintances;
205 }
206 
207 const std::string get_ignored_delim()
208 {
210  std::vector<std::string> ignored;
211 
212  for(const auto& person : acquaintances) {
213  if(person.second.get_status() == "ignore") {
214  ignored.push_back(person.second.get_nick());
215  }
216  }
217 
218  return utils::join(ignored);
219 }
220 
221 // returns acquaintances in the form nick => notes where the status = filter
222 std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter)
223 {
225  std::map<std::string, std::string> ac_nice;
226 
227  for(const auto& a : acquaintances) {
228  if(a.second.get_status() == filter) {
229  ac_nice[a.second.get_nick()] = a.second.get_notes();
230  }
231  }
232 
233  return ac_nice;
234 }
235 
236 std::pair<preferences::acquaintance*, bool> add_acquaintance(
237  const std::string& nick, const std::string& mode, const std::string& notes)
238 {
239  if(!utils::isvalid_wildcard(nick)) {
240  return std::pair(nullptr, false);
241  }
242 
243  preferences::acquaintance new_entry(nick, mode, notes);
244  auto [iter, success] = acquaintances.emplace(nick, new_entry);
245 
246  if(!success) {
247  iter->second = new_entry;
248  }
249 
251 
252  return std::pair(&iter->second, success);
253 }
254 
255 bool remove_acquaintance(const std::string& nick)
256 {
257  std::map<std::string, acquaintance>::iterator i = acquaintances.find(nick);
258 
259  // nick might include the notes, depending on how we're removing
260  if(i == acquaintances.end()) {
261  std::size_t pos = nick.find_first_of(' ');
262 
263  if(pos != std::string::npos) {
264  i = acquaintances.find(nick.substr(0, pos));
265  }
266  }
267 
268  if(i == acquaintances.end()) {
269  return false;
270  }
271 
272  acquaintances.erase(i);
274 
275  return true;
276 }
277 
278 bool is_friend(const std::string& nick)
279 {
281  const auto it = acquaintances.find(nick);
282 
283  if(it == acquaintances.end()) {
284  return false;
285  } else {
286  return it->second.get_status() == "friend";
287  }
288 }
289 
290 bool is_ignored(const std::string& nick)
291 {
293  const auto it = acquaintances.find(nick);
294 
295  if(it == acquaintances.end()) {
296  return false;
297  } else {
298  return it->second.get_status() == "ignore";
299  }
300 }
301 
302 void add_completed_campaign(const std::string& campaign_id, const std::string& difficulty_level)
303 {
304  completed_campaigns[campaign_id].insert(difficulty_level);
305 }
306 
307 bool is_campaign_completed(const std::string& campaign_id)
308 {
309  return completed_campaigns.count(campaign_id) != 0;
310 }
311 
312 bool is_campaign_completed(const std::string& campaign_id, const std::string& difficulty_level)
313 {
314  const auto it = completed_campaigns.find(campaign_id);
315  return it == completed_campaigns.end() ? false : it->second.count(difficulty_level) != 0;
316 }
317 
318 bool parse_should_show_lobby_join(const std::string& sender, const std::string& message)
319 {
320  // If it's actually not a lobby join or leave message return true (show it).
321  if(sender != "server") {
322  return true;
323  }
324 
325  std::string::size_type pos = message.find(" has logged into the lobby");
326  if(pos == std::string::npos) {
327  pos = message.find(" has disconnected");
328  if(pos == std::string::npos) {
329  return true;
330  }
331  }
332 
333  int lj = lobby_joins();
334  if(lj == SHOW_NONE) {
335  return false;
336  }
337 
338  if(lj == SHOW_ALL) {
339  return true;
340  }
341 
342  return is_friend(message.substr(0, pos));
343 }
344 
346 {
347  std::string pref = preferences::get("lobby_joins");
348  if(pref == "friends") {
349  return SHOW_FRIENDS;
350  } else if(pref == "all") {
351  return SHOW_ALL;
352  } else if(pref == "none") {
353  return SHOW_NONE;
354  } else {
355  return SHOW_FRIENDS;
356  }
357 }
358 
360 {
361  if(show == SHOW_FRIENDS) {
362  preferences::set("lobby_joins", "friends");
363  } else if(show == SHOW_ALL) {
364  preferences::set("lobby_joins", "all");
365  } else if(show == SHOW_NONE) {
366  preferences::set("lobby_joins", "none");
367  }
368 }
369 
370 const std::vector<game_config::server_info>& builtin_servers_list()
371 {
372  static std::vector<game_config::server_info> pref_servers = game_config::server_list;
373  return pref_servers;
374 }
375 
376 std::vector<game_config::server_info> user_servers_list()
377 {
378  std::vector<game_config::server_info> pref_servers;
379 
380  for(const config& server : get_prefs()->child_range("server")) {
381  pref_servers.emplace_back();
382  pref_servers.back().name = server["name"].str();
383  pref_servers.back().address = server["address"].str();
384  }
385 
386  return pref_servers;
387 }
388 
389 void set_user_servers_list(const std::vector<game_config::server_info>& value)
390 {
391  config& prefs = *get_prefs();
392  prefs.clear_children("server");
393 
394  for(const auto& svinfo : value) {
395  config& sv_cfg = prefs.add_child("server");
396  sv_cfg["name"] = svinfo.name;
397  sv_cfg["address"] = svinfo.address;
398  }
399 }
400 
401 std::string network_host()
402 {
403  const std::string res = preferences::get("host");
404  if(res.empty()) {
405  return builtin_servers_list().front().address;
406  } else {
407  return res;
408  }
409 }
410 
411 void set_network_host(const std::string& host)
412 {
413  preferences::set("host", host);
414 }
415 
416 std::string campaign_server()
417 {
418  if(!preferences::get("campaign_server").empty()) {
419  return preferences::get("campaign_server");
420  } else {
421  return "add-ons.wesnoth.org";
422  }
423 }
424 
425 void set_campaign_server(const std::string& host)
426 {
427  preferences::set("campaign_server", host);
428 }
429 
431 {
432  return preferences::get("turn_dialog", false);
433 }
434 
435 void set_turn_dialog(bool ison)
436 {
437  preferences::set("turn_dialog", ison);
438 }
439 
441 {
442  return preferences::get("enable_planning_mode_on_start", false);
443 }
444 
446 {
447  preferences::set("enable_planning_mode_on_start", value);
448 }
449 
451 {
452  return preferences::get("hide_whiteboard", false);
453 }
454 
455 void set_hide_whiteboard(bool value)
456 {
457  preferences::set("hide_whiteboard", value);
458 }
459 
461 {
462  return preferences::get("show_combat", true);
463 }
464 
466 {
467  return preferences::get("allow_observers", true);
468 }
469 
470 void set_allow_observers(bool value)
471 {
472  preferences::set("allow_observers", value);
473 }
474 
476 {
477  return preferences::get("shuffle_sides", false);
478 }
479 
480 void set_shuffle_sides(bool value)
481 {
482  preferences::set("shuffle_sides", value);
483 }
484 
485 std::string random_faction_mode()
486 {
487  return preferences::get("random_faction_mode");
488 }
489 
490 void set_random_faction_mode(const std::string& value)
491 {
492  preferences::set("random_faction_mode", value);
493 }
494 
496 {
497  return preferences::get("mp_use_map_settings", true);
498 }
499 
500 void set_use_map_settings(bool value)
501 {
502  preferences::set("mp_use_map_settings", value);
503 }
504 
506 {
507  return lexical_cast_default<int>(preferences::get("mp_server_warning_disabled"), 0);
508 }
509 
511 {
512  preferences::set("mp_server_warning_disabled", value);
513 }
514 
515 void set_mp_server_program_name(const std::string& path)
516 {
517  if(path.empty()) {
518  preferences::clear("mp_server_program_name");
519  } else {
520  preferences::set("mp_server_program_name", path);
521  }
522 }
523 
525 {
526  return preferences::get("mp_server_program_name");
527 }
528 
530 {
531  return preferences::get("mp_random_start_time", true);
532 }
533 
534 void set_random_start_time(bool value)
535 {
536  preferences::set("mp_random_start_time", value);
537 }
538 
539 bool fog()
540 {
541  return preferences::get("mp_fog", true);
542 }
543 
544 void set_fog(bool value)
545 {
546  preferences::set("mp_fog", value);
547 }
548 
549 bool shroud()
550 {
551  return preferences::get("mp_shroud", false);
552 }
553 
554 void set_shroud(bool value)
555 {
556  preferences::set("mp_shroud", value);
557 }
558 
559 int turns()
560 {
561  return settings::get_turns(preferences::get("mp_turns"));
562 }
563 
564 void set_turns(int value)
565 {
566  preferences::set("mp_turns", value);
567 }
568 
569 const config& options()
570 {
571  if(options_initialized) {
572  return option_values;
573  }
574 
575  if(!preferences::get_child("options")) {
576  // It may be an invalid config, which would cause problems in
577  // multiplayer_create, so let's replace it with an empty but valid
578  // config
579  option_values.clear();
580  } else {
581  option_values = preferences::get_child("options");
582  }
583 
584  options_initialized = true;
585 
586  return option_values;
587 }
588 
589 void set_options(const config& values)
590 {
591  preferences::set_child("options", values);
592  options_initialized = false;
593 }
594 
596 {
597  return preferences::get("skip_mp_replay", false);
598 }
599 
600 void set_skip_mp_replay(bool value)
601 {
602  preferences::set("skip_mp_replay", value);
603 }
604 
606 {
607  return preferences::get("blindfold_replay", false);
608 }
609 
610 void set_blindfold_replay(bool value)
611 {
612  preferences::set("blindfold_replay", value);
613 }
614 
615 bool countdown()
616 {
617  return preferences::get("mp_countdown", false);
618 }
619 
620 void set_countdown(bool value)
621 {
622  preferences::set("mp_countdown", value);
623 }
624 
626 {
627  return std::clamp<int>(lexical_cast_default<int>(preferences::get("mp_countdown_init_time"), 270), 0, 1500);
628 }
629 
630 void set_countdown_init_time(int value)
631 {
632  preferences::set("mp_countdown_init_time", value);
633 }
634 
636 {
637  return std::clamp<int>(lexical_cast_default<int>(preferences::get("mp_countdown_reservoir_time"), 330), 30, 1500);
638 }
639 
641 {
642  preferences::set("mp_countdown_reservoir_time", value);
643 }
644 
646 {
647  return std::clamp<int>(lexical_cast_default<int>(preferences::get("mp_countdown_turn_bonus"), 60), 0, 300);
648 }
649 
651 {
652  preferences::set("mp_countdown_turn_bonus", value);
653 }
654 
656 {
657  return std::clamp<int>(lexical_cast_default<int>(preferences::get("mp_countdown_action_bonus"), 13), 0, 30);
658 }
659 
661 {
662  preferences::set("mp_countdown_action_bonus", value);
663 }
664 
666 {
667  return settings::get_village_gold(preferences::get("mp_village_gold"));
668 }
669 
670 void set_village_gold(int value)
671 {
672  preferences::set("mp_village_gold", value);
673 }
674 
676 {
677  return settings::get_village_support(preferences::get("mp_village_support"));
678 }
679 
680 void set_village_support(int value)
681 {
682  preferences::set("mp_village_support", std::to_string(value));
683 }
684 
686 {
687  return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
688 }
689 
690 void set_xp_modifier(int value)
691 {
692  preferences::set("mp_xp_modifier", value);
693 }
694 
695 std::string era()
696 {
697  return preferences::get("mp_era");
698 }
699 
700 void set_era(const std::string& value)
701 {
702  preferences::set("mp_era", value);
703 }
704 
705 std::string level()
706 {
707  return preferences::get("mp_level");
708 }
709 
710 void set_level(const std::string& value)
711 {
712  preferences::set("mp_level", value);
713 }
714 
716 {
717  return lexical_cast_default<int>(preferences::get("mp_level_type"), 0);
718 }
719 
720 void set_level_type(int value)
721 {
722  preferences::set("mp_level_type", value);
723 }
724 
725 const std::vector<std::string>& modifications(bool mp)
726 {
727  if((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp)) {
728  initialize_modifications(mp);
729  }
730 
731  return mp ? mp_modifications : sp_modifications;
732 }
733 
734 void set_modifications(const std::vector<std::string>& value, bool mp)
735 {
736  if(mp) {
737  preferences::set("mp_modifications", utils::join(value, ","));
738  mp_modifications_initialized = false;
739  } else {
740  preferences::set("sp_modifications", utils::join(value, ","));
741  sp_modifications_initialized = false;
742  }
743 }
744 
746 {
747  return preferences::get("skip_ai_moves", false);
748 }
749 
750 void set_skip_ai_moves(bool value)
751 {
752  preferences::set("skip_ai_moves", value);
753 }
754 
755 void set_show_side_colors(bool value)
756 {
757  preferences::set("show_side_colors", value);
758 }
759 
761 {
762  return preferences::get("show_side_colors", true);
763 }
764 
765 void set_save_replays(bool value)
766 {
767  preferences::set("save_replays", value);
768 }
769 
771 {
772  return preferences::get("save_replays", true);
773 }
774 
775 void set_delete_saves(bool value)
776 {
777  preferences::set("delete_saves", value);
778 }
779 
781 {
782  return preferences::get("delete_saves", false);
783 }
784 
785 void set_ask_delete_saves(bool value)
786 {
787  preferences::set("ask_delete", value);
788 }
789 
791 {
792  return preferences::get("ask_delete", true);
793 }
794 
796 {
797  preferences::set("ally_sighted_interrupts", value);
798 }
799 
801 {
802  return preferences::get("ally_sighted_interrupts", true);
803 }
804 
806 {
807  return lexical_cast_default<int>(preferences::get("auto_save_max"), 10);
808 }
809 
810 void set_autosavemax(int value)
811 {
812  preferences::set("auto_save_max", value);
813 }
814 
815 std::string theme()
816 {
817  if(CVideo::get_singleton().non_interactive()) {
818  static const std::string null_theme = "null";
819  return null_theme;
820  }
821 
822  std::string res = preferences::get("theme");
823  if(res.empty()) {
824  return "Default";
825  }
826 
827  return res;
828 }
829 
830 void set_theme(const std::string& theme)
831 {
832  if(theme != "null") {
833  preferences::set("theme", theme);
834  }
835 }
836 
838 {
839  return preferences::get("floating_labels", true);
840 }
841 
842 void set_show_floating_labels(bool value)
843 {
844  preferences::set("floating_labels", value);
845 }
846 
848 {
849  return message_private_on;
850 }
851 
852 void set_message_private(bool value)
853 {
854  message_private_on = value;
855 }
856 
858 {
859  const std::string& choice = preferences::get("compress_saves");
860 
861  // "yes" was used in 1.11.7 and earlier; the compress_saves
862  // option used to be a toggle for gzip in those versions.
863  if(choice.empty() || choice == "gzip" || choice == "yes") {
864  return compression::GZIP;
865  } else if(choice == "bzip2") {
866  return compression::BZIP2;
867  } else if(choice == "none" || choice == "no") { // see above
868  return compression::NONE;
869  } /*else*/
870 
871  // In case the preferences file was created by a later version
872  // supporting some algorithm we don't; although why would anyone
873  // playing a game need more algorithms, really...
874  return compression::GZIP;
875 }
876 
877 std::string get_chat_timestamp(const std::time_t& t)
878 {
879  if(chat_timestamping()) {
881  return lg::get_timestamp(t, _("[%H:%M]")) + " ";
882  } else {
883  return lg::get_timestamp(t, _("[%I:%M %p]")) + " ";
884  }
885  }
886 
887  return "";
888 }
889 
891 {
892  return preferences::get("chat_timestamp", false);
893 }
894 
895 void set_chat_timestamping(bool value)
896 {
897  preferences::set("chat_timestamp", value);
898 }
899 
901 {
902  return lexical_cast_default<int>(preferences::get("chat_lines"), 6);
903 }
904 
905 void set_chat_lines(int lines)
906 {
907  preferences::set("chat_lines", lines);
908 }
909 
910 void set_chat_message_aging(const int aging)
911 {
912  preferences::set("chat_message_aging", aging);
913 }
914 
916 {
917  return lexical_cast_default<int>(preferences::get("chat_message_aging"), 20);
918 }
919 
921 {
922  return preferences::get("show_all_units_in_help", false);
923 }
924 
926 {
927  preferences::set("show_all_units_in_help", value);
928 }
929 
930 std::set<std::string>& encountered_units()
931 {
932  return encountered_units_set;
933 }
934 
935 std::set<t_translation::terrain_code>& encountered_terrains()
936 {
937  return encountered_terrains_set;
938 }
939 
940 std::string custom_command()
941 {
942  return preferences::get("custom_command");
943 }
944 
945 void set_custom_command(const std::string& command)
946 {
947  preferences::set("custom_command", command);
948 }
949 
950 /**
951  * Returns a pointer to the history vector associated with given id
952  * making a new one if it doesn't exist.
953  *
954  * @todo FIXME only used for gui2. Could be used for the above histories.
955  */
956 std::vector<std::string>* get_history(const std::string& id)
957 {
958  return &history_map[id];
959 }
960 
962 {
963  const std::string confirmation = preferences::get("confirm_end_turn");
964  return confirmation == "green" || confirmation == "yes";
965 }
966 
968 {
969  return preferences::get("confirm_end_turn") == "yellow";
970 }
971 
973 {
974  // This is very non-intrusive so it is on by default
975  const std::string confirmation = preferences::get("confirm_end_turn");
976  return confirmation == "no_moves" || confirmation.empty();
977 }
978 
979 void encounter_recruitable_units(const std::vector<team>& teams)
980 {
981  for(const team& help_team : teams) {
982  help_team.log_recruitable();
983  encountered_units_set.insert(help_team.recruits().begin(), help_team.recruits().end());
984  }
985 }
986 
987 void encounter_start_units(const unit_map& units)
988 {
989  for(const auto& help_unit : units) {
990  encountered_units_set.insert(help_unit.type_id());
991  }
992 }
993 
994 static void encounter_recallable_units(const std::vector<team>& teams)
995 {
996  for(const team& t : teams) {
997  for(const unit_const_ptr u : t.recall_list()) {
998  encountered_units_set.insert(u->type_id());
999  }
1000  }
1001 }
1002 
1004 {
1005  map.for_each_loc([&](const map_location& loc) {
1006  const t_translation::terrain_code terrain = map.get_terrain(loc);
1007  preferences::encountered_terrains().insert(terrain);
1010  }
1011  });
1012 }
1013 
1014 void encounter_all_content(const game_board& gameboard_)
1015 {
1020 }
1021 
1023 {
1024  nick_ = cfg["nick"].str();
1025  status_ = cfg["status"].str();
1026  notes_ = cfg["notes"].str();
1027 }
1028 
1030 {
1031  item["nick"] = nick_;
1032  item["status"] = status_;
1033  item["notes"] = notes_;
1034 }
1035 
1036 } // namespace preferences
Game board class.
Definition: game_board.hpp:51
void set_hide_whiteboard(bool value)
Definition: game.cpp:455
int autosavemax()
Definition: game.cpp:805
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
std::string get_timestamp(const std::time_t &t, const std::string &format)
Definition: log.cpp:174
void set_campaign_server(const std::string &host)
Definition: game.cpp:425
const t_translation::ter_list & underlying_union_terrain(const map_location &loc) const
Definition: map.cpp:59
void set_village_support(int value)
Definition: game.cpp:680
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:85
std::string random_faction_mode()
Definition: game.cpp:485
bool message_private()
Definition: game.cpp:847
static void encounter_recallable_units(const std::vector< team > &teams)
Definition: game.cpp:994
virtual const unit_map & units() const override
Definition: game_board.hpp:112
void clear_children(T... keys)
Definition: config.hpp:557
void set_countdown_action_bonus(int value)
Definition: game.cpp:660
void set_countdown_turn_bonus(int value)
Definition: game.cpp:650
std::string era()
Definition: game.cpp:695
void set_shroud(bool value)
Definition: game.cpp:554
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void set_countdown_init_time(int value)
Definition: game.cpp:630
int xp_modifier()
Definition: game.cpp:685
std::string campaign_server()
Definition: game.cpp:416
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:510
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
void set_show_floating_labels(bool value)
Definition: game.cpp:842
void set_options(const config &values)
Definition: game.cpp:589
int lobby_joins()
Definition: game.cpp:345
New lexcical_cast header.
#define a
const std::map< std::string, acquaintance > & get_acquaintances()
Definition: game.cpp:201
bool is_campaign_completed(const std::string &campaign_id)
Definition: game.cpp:307
const std::string get_ignored_delim()
Definition: game.cpp:207
child_itors child_range(config_key_type key)
Definition: config.cpp:344
bool shuffle_sides()
Definition: game.cpp:475
void set_show_side_colors(bool value)
Definition: game.cpp:755
std::string network_host()
Definition: game.cpp:401
void load_from_config(const config &cfg)
Definition: game.cpp:1022
bool hide_whiteboard()
Definition: game.cpp:450
void clear(const std::string &key)
Definition: general.cpp:186
void _set_lobby_joins(int show)
Definition: game.cpp:359
virtual const gamemap & map() const override
Definition: game_board.hpp:102
void set_chat_lines(int lines)
Definition: game.cpp:905
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
int chat_lines()
Definition: game.cpp:900
void for_each_loc(const F &f) const
Definition: map.hpp:136
void set_random_faction_mode(const std::string &value)
Definition: game.cpp:490
static CVideo & get_singleton()
Definition: video.hpp:49
static void load_acquaintances()
Definition: game.cpp:180
void set(const std::string &key, bool value)
Definition: general.cpp:161
#define h
void set_network_host(const std::string &host)
Definition: game.cpp:411
void clear()
Definition: config.cpp:920
#define d
void set_sound_volume(int vol)
Definition: general.cpp:595
static std::string _(const char *str)
Definition: gettext.hpp:93
static lg::log_domain log_config("config")
bool show_side_colors()
Definition: game.cpp:760
void set_countdown(bool value)
Definition: game.cpp:620
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:255
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:795
int countdown_init_time()
Definition: game.cpp:625
bool yellow_confirm()
Definition: game.cpp:967
int get_village_support(const std::string &value)
Gets the village unit level support.
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:515
bool fog()
Definition: game.cpp:539
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:52
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
bool confirm_no_moves()
Definition: game.cpp:972
void set_chat_message_aging(const int aging)
Definition: game.cpp:910
const config & options()
Definition: game.cpp:569
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
void set_turn_dialog(bool ison)
Definition: game.cpp:435
int countdown_turn_bonus()
Definition: game.cpp:645
void set_level_type(int value)
Definition: game.cpp:720
std::string get(const std::string &key)
Definition: general.cpp:209
void set_custom_command(const std::string &command)
Definition: game.cpp:945
const std::vector< game_config::server_info > & builtin_servers_list()
Definition: game.cpp:370
int village_support()
Definition: game.cpp:675
std::string level()
Definition: game.cpp:705
static void save_acquaintances()
Definition: game.cpp:190
void set_save_replays(bool value)
Definition: game.cpp:765
bool is_friend(const std::string &nick)
Definition: game.cpp:278
void set_theme(const std::string &theme)
Definition: game.cpp:830
void encounter_map_terrain(const gamemap &map)
Definition: game.cpp:1003
void encounter_start_units(const unit_map &units)
Definition: game.cpp:987
const std::string & get_nick() const
Definition: game.hpp:61
std::string theme()
Definition: game.cpp:815
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:302
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:236
int countdown_reservoir_time()
Definition: game.cpp:635
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:445
bool blindfold_replay()
Definition: game.cpp:605
void set_music_volume(int vol)
Definition: general.cpp:580
Encapsulates the map of the game.
Definition: map.hpp:171
void erase(const std::string &key)
Definition: general.cpp:201
void set_random_start_time(bool value)
Definition: game.cpp:534
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:935
void set_user_servers_list(const std::vector< game_config::server_info > &value)
Definition: game.cpp:389
std::string path
Definition: game_config.cpp:39
Modify, read and display user preferences.
bool show_combat()
Definition: game.cpp:460
void save(config &cfg)
Definition: game.cpp:1029
int village_gold()
Definition: game.cpp:665
bool show_all_units_in_help()
Definition: game.cpp:920
void set_blindfold_replay(bool value)
Definition: game.cpp:610
bool chat_timestamping()
Definition: game.cpp:890
void set_message_private(bool value)
Definition: game.cpp:852
General settings and defaults for scenarios.
bool is_ignored(const std::string &nick)
Definition: game.cpp:290
void set_chat_timestamping(bool value)
Definition: game.cpp:895
void set_level(const std::string &value)
Definition: game.cpp:710
Encapsulates the map of the game.
Definition: location.hpp:38
void set_child(const std::string &key, const config &val)
Definition: general.cpp:191
void set_allow_observers(bool value)
Definition: game.cpp:470
bool countdown()
Definition: game.cpp:615
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&#39;t exist...
Definition: game.cpp:956
bool shroud()
Definition: game.cpp:549
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
int mp_server_warning_disabled()
Definition: game.cpp:505
std::size_t i
Definition: function.cpp:967
std::string get_mp_server_program_name()
Definition: game.cpp:524
bool interrupt_when_ally_sighted()
Definition: game.cpp:800
void load_game_prefs()
Definition: game.cpp:122
void set_delete_saves(bool value)
Definition: game.cpp:775
Definition: theme.hpp:41
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
Definition: game.cpp:302
void encounter_all_content(const game_board &gameboard_)
Definition: game.cpp:1014
bool use_map_settings()
Definition: game.cpp:495
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
config * get_prefs()
Definition: general.cpp:231
std::string write_list(const ter_list &list)
Writes a list of terrains to a string, only writes the new format.
bool delete_saves()
Definition: game.cpp:780
void set_skip_mp_replay(bool value)
Definition: game.cpp:600
std::set< std::string > & encountered_units()
Definition: game.cpp:930
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:222
bool ask_delete_saves()
Definition: game.cpp:790
bool skip_mp_replay()
Definition: game.cpp:595
const config & get_child(const std::string &key)
Definition: general.cpp:196
config & add_child(config_key_type key)
Definition: config.cpp:514
void set_turns(int value)
Definition: game.cpp:564
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:877
void set_autosavemax(int value)
Definition: game.cpp:810
compression::format save_compression_format()
Definition: game.cpp:857
void set_show_all_units_in_help(bool value)
Definition: game.cpp:925
bool allow_observers()
Definition: game.cpp:465
bool green_confirm()
Definition: game.cpp:961
int turns()
Definition: game.cpp:559
int sound_volume()
Definition: general.cpp:590
bool show_floating_labels()
Definition: game.cpp:837
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:725
double t
Definition: astarsearch.cpp:65
std::vector< std::string > split(const config_attribute_value &val)
void set_modifications(const std::vector< std::string > &value, bool mp)
Definition: game.cpp:734
int chat_message_aging()
Definition: game.cpp:915
bool enable_whiteboard_mode_on_start()
Definition: game.cpp:440
Standard logging facilities (interface).
std::vector< terrain_code > ter_list
Definition: translation.hpp:78
int countdown_action_bonus()
Definition: game.cpp:655
Container associating units to locations.
Definition: map.hpp:98
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
Definition: game.cpp:318
void set_era(const std::string &value)
Definition: game.cpp:700
void set_shuffle_sides(bool value)
Definition: game.cpp:480
void set_fog(bool value)
Definition: game.cpp:544
void set_ask_delete_saves(bool value)
Definition: game.cpp:785
void encounter_recruitable_units(const std::vector< team > &teams)
Definition: game.cpp:979
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
mock_char c
void set_countdown_reservoir_time(int value)
Definition: game.cpp:640
bool random_start_time()
Definition: game.cpp:529
std::vector< game_config::server_info > user_servers_list()
Definition: game.cpp:376
void set_skip_ai_moves(bool value)
Definition: game.cpp:750
std::string custom_command()
Definition: game.cpp:940
void set_xp_modifier(int value)
Definition: game.cpp:690
bool turn_dialog()
Definition: game.cpp:430
int get_turns(const std::string &value)
Gets the number of turns.
bool use_twelve_hour_clock_format()
Definition: general.cpp:944
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
void set_village_gold(int value)
Definition: game.cpp:670
std::vector< server_info > server_list
Definition: game_config.cpp:95
void set_use_map_settings(bool value)
Definition: game.cpp:500
bool skip_ai_moves()
Definition: game.cpp:745
int music_volume()
Definition: general.cpp:575
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:410
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:140
std::map< std::string, preferences::acquaintance > acquaintances_map
Definition: game.cpp:37
bool save_replays()
Definition: game.cpp:770
int level_type()
Definition: game.cpp:715