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