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