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