The Battle for Wesnoth  1.15.4+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("registered_users_only", false);
490 }
491 
493 {
494  preferences::set("registered_users_only", value);
495 }
496 
498 {
499  return preferences::get("shuffle_sides", false);
500 }
501 
502 void set_shuffle_sides(bool value)
503 {
504  preferences::set("shuffle_sides", value);
505 }
506 
508  return preferences::get("random_faction_mode");
509 }
510 
512  preferences::set("random_faction_mode", value);
513 }
514 
516 {
517  return preferences::get("mp_use_map_settings", true);
518 }
519 
520 void set_use_map_settings(bool value)
521 {
522  preferences::set("mp_use_map_settings", value);
523 }
524 
526 {
527  return lexical_cast_default<int>(preferences::get("mp_server_warning_disabled"), 0);
528 }
529 
531 {
532  preferences::set("mp_server_warning_disabled", value);
533 }
534 
536 {
537  if (path.empty())
538  {
539  preferences::clear("mp_server_program_name");
540  }
541  else
542  {
543  preferences::set("mp_server_program_name", path);
544  }
545 }
546 
548 {
549  return preferences::get("mp_server_program_name");
550 }
551 
553 {
554  return preferences::get("mp_random_start_time", true);
555 }
556 
557 void set_random_start_time(bool value)
558 {
559  preferences::set("mp_random_start_time", value);
560 }
561 
562 bool fog()
563 {
564  return preferences::get("mp_fog", true);
565 }
566 
567 void set_fog(bool value)
568 {
569  preferences::set("mp_fog", value);
570 }
571 
572 bool shroud()
573 {
574  return preferences::get("mp_shroud", false);
575 }
576 
577 void set_shroud(bool value)
578 {
579  preferences::set("mp_shroud", value);
580 }
581 
582 int turns()
583 {
584  return settings::get_turns(preferences::get("mp_turns"));
585 }
586 
587 void set_turns(int value)
588 {
589  preferences::set("mp_turns", value);
590 }
591 
592 const config& options()
593 {
594  if (options_initialized) {
595  return option_values;
596  }
597 
598  if (!preferences::get_child("options")) {
599  // It may be an invalid config, which would cause problems in
600  // multiplayer_create, so let's replace it with an empty but valid
601  // config
602  option_values.clear();
603  } else {
604  option_values = preferences::get_child("options");
605  }
606 
607  options_initialized = true;
608 
609  return option_values;
610 }
611 
612 void set_options(const config& values)
613 {
614  preferences::set_child("options", values);
615  options_initialized = false;
616 }
617 
619 {
620  return preferences::get("skip_mp_replay", false);
621 }
622 
623 void set_skip_mp_replay(bool value)
624 {
625  preferences::set("skip_mp_replay", value);
626 }
627 
629 {
630  return preferences::get("blindfold_replay", false);
631 }
632 
633 void set_blindfold_replay(bool value)
634 {
635  preferences::set("blindfold_replay", value);
636 }
637 
638 bool countdown()
639 {
640  return preferences::get("mp_countdown", false);
641 }
642 
643 void set_countdown(bool value)
644 {
645  preferences::set("mp_countdown", value);
646 }
647 
649 {
650  return utils::clamp<int>(
651  lexical_cast_default<int>(preferences::get("mp_countdown_init_time"), 270), 0, 1500);
652 }
653 
654 void set_countdown_init_time(int value)
655 {
656  preferences::set("mp_countdown_init_time", value);
657 }
658 
660 {
661  return utils::clamp<int>(
662  lexical_cast_default<int>(preferences::get("mp_countdown_reservoir_time"), 330), 30, 1500);
663 }
664 
666 {
667  preferences::set("mp_countdown_reservoir_time", value);
668 }
669 
671 {
672  return utils::clamp<int>(
673  lexical_cast_default<int>(preferences::get("mp_countdown_turn_bonus"), 60), 0, 300);
674 }
675 
677 {
678  preferences::set("mp_countdown_turn_bonus", value);
679 }
680 
682 {
683  return utils::clamp<int>(
684  lexical_cast_default<int>(preferences::get("mp_countdown_action_bonus"), 13), 0, 30);
685 }
686 
688 {
689  preferences::set("mp_countdown_action_bonus", value);
690 }
691 
693 {
694  return settings::get_village_gold(preferences::get("mp_village_gold"));
695 }
696 
697 void set_village_gold(int value)
698 {
699  preferences::set("mp_village_gold", value);
700 }
701 
703 {
704  return settings::get_village_support(preferences::get("mp_village_support"));
705 }
706 
707 void set_village_support(int value)
708 {
709  preferences::set("mp_village_support", std::to_string(value));
710 }
711 
713 {
714  return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
715 }
716 
717 void set_xp_modifier(int value)
718 {
719  preferences::set("mp_xp_modifier", value);
720 }
721 
723 {
724  return preferences::get("mp_era");
725 }
726 
727 void set_era(const std::string& value)
728 {
729  preferences::set("mp_era", value);
730 }
731 
733 {
734  return preferences::get("mp_level");
735 }
736 
737 void set_level(const std::string& value)
738 {
739  preferences::set("mp_level", value);
740 }
741 
743 {
744  return lexical_cast_default<int>(preferences::get("mp_level_type"), 0);
745 }
746 
747 void set_level_type(int value)
748 {
749  preferences::set("mp_level_type", value);
750 }
751 
752 const std::vector<std::string>& modifications(bool mp)
753 {
754  if ((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp))
755  initialize_modifications(mp);
756 
757  return mp ? mp_modifications : sp_modifications;
758 }
759 
760 void set_modifications(const std::vector<std::string>& value, bool mp)
761 {
762  if (mp) {
763  preferences::set("mp_modifications", utils::join(value, ","));
764  mp_modifications_initialized = false;
765  } else {
766  preferences::set("sp_modifications", utils::join(value, ","));
767  sp_modifications_initialized = false;
768  }
769 
770 }
771 
773 {
774  return preferences::get("skip_ai_moves", false);
775 }
776 
777 void set_skip_ai_moves(bool value)
778 {
779  preferences::set("skip_ai_moves", value);
780 }
781 
782 void set_show_side_colors(bool value)
783 {
784  preferences::set("show_side_colors", value);
785 }
786 
788 {
789  return preferences::get("show_side_colors", true);
790 }
791 
792 void set_save_replays(bool value)
793 {
794  preferences::set("save_replays", value);
795 }
796 
798 {
799  return preferences::get("save_replays", true);
800 }
801 
802 void set_delete_saves(bool value)
803 {
804  preferences::set("delete_saves", value);
805 }
806 
808 {
809  return preferences::get("delete_saves", false);
810 }
811 
812 void set_ask_delete_saves(bool value)
813 {
814  preferences::set("ask_delete", value);
815 }
816 
818 {
819  return preferences::get("ask_delete", true);
820 }
821 
823 {
824  preferences::set("ally_sighted_interrupts", value);
825 }
826 
828 {
829  return preferences::get("ally_sighted_interrupts", true);
830 }
831 
833 {
834  return lexical_cast_default<int>(preferences::get("auto_save_max"), 10);
835 }
836 
837 void set_autosavemax(int value)
838 {
839  preferences::set("auto_save_max", value);
840 }
841 
843 {
844  if(CVideo::get_singleton().non_interactive()) {
845  static const std::string null_theme = "null";
846  return null_theme;
847  }
848 
849  std::string res = preferences::get("theme");
850  if(res.empty()) {
851  return "Default";
852  }
853 
854  return res;
855 }
856 
858 {
859  if(theme != "null") {
860  preferences::set("theme", theme);
861  }
862 }
863 
865 {
866  return preferences::get("floating_labels", true);
867 }
868 
869 void set_show_floating_labels(bool value)
870 {
871  preferences::set("floating_labels", value);
872 }
873 
875 {
876  return message_private_on;
877 }
878 
879 void set_message_private(bool value)
880 {
881  message_private_on = value;
882 }
883 
885 {
886  const std::string& choice =
887  preferences::get("compress_saves");
888 
889  // "yes" was used in 1.11.7 and earlier; the compress_saves
890  // option used to be a toggle for gzip in those versions.
891  if(choice.empty() || choice == "gzip" || choice == "yes") {
892  return compression::GZIP;
893  } else if(choice == "bzip2") {
894  return compression::BZIP2;
895  } else if(choice == "none" || choice == "no") { // see above
896  return compression::NONE;
897  } /*else*/
898 
899  // In case the preferences file was created by a later version
900  // supporting some algorithm we don't; although why would anyone
901  // playing a game need more algorithms, really...
902  return compression::GZIP;
903 }
904 
905 std::string get_chat_timestamp(const std::time_t& t) {
906  if (chat_timestamping()) {
908  return lg::get_timestamp(t, _("[%H:%M]")) + " ";
909  }
910  else {
911  return lg::get_timestamp(t, _("[%I:%M %p]")) + " ";
912  }
913  }
914  return "";
915 }
916 
918  return preferences::get("chat_timestamp", false);
919 }
920 
921 void set_chat_timestamping(bool value) {
922  preferences::set("chat_timestamp", value);
923 }
924 
926 {
927  return lexical_cast_default<int>(preferences::get("chat_lines"), 6);
928 }
929 
930 void set_chat_lines(int lines)
931 {
932  preferences::set("chat_lines", lines);
933 }
934 
935 void set_chat_message_aging(const int aging)
936 {
937  preferences::set("chat_message_aging", aging);
938 }
939 
941 {
942  return lexical_cast_default<int>(preferences::get("chat_message_aging"), 20);
943 }
944 
946  return preferences::get("show_all_units_in_help", false);
947 }
948 
949 void set_show_all_units_in_help(bool value) {
950  preferences::set("show_all_units_in_help", value);
951 }
952 
953 std::set<std::string> &encountered_units() {
954  return encountered_units_set;
955 }
956 
957 std::set<t_translation::terrain_code> &encountered_terrains() {
958  return encountered_terrains_set;
959 }
960 
962  return preferences::get("custom_command");
963 }
964 
965 void set_custom_command(const std::string& command) {
966  preferences::set("custom_command", command);
967 }
968 
969 /**
970  * Returns a pointer to the history vector associated with given id
971  * making a new one if it doesn't exist.
972  *
973  * @todo FIXME only used for gui2. Could be used for the above histories.
974  */
975 std::vector<std::string>* get_history(const std::string& id) {
976  return &history_map[id];
977 }
978 
980 {
981  std::string confirmation = preferences::get("confirm_end_turn");
982 
983  if (confirmation == "green" || confirmation == "yes")
984  return true;
985  return false;
986 }
987 
989 {
990  return preferences::get("confirm_end_turn") == "yellow";
991 }
992 
994 {
995  //This is very non-intrusive so it is on by default
996  const std::string confirmation = preferences::get("confirm_end_turn");
997  return confirmation == "no_moves" || confirmation.empty();
998 }
999 
1000 
1001 void encounter_recruitable_units(const std::vector<team>& teams){
1002  for (std::vector<team>::const_iterator help_team_it = teams.begin();
1003  help_team_it != teams.end(); ++help_team_it) {
1004  help_team_it->log_recruitable();
1005  encountered_units_set.insert(help_team_it->recruits().begin(), help_team_it->recruits().end());
1006  }
1007 }
1008 
1009 void encounter_start_units(const unit_map& units){
1010  for (unit_map::const_iterator help_unit_it = units.begin();
1011  help_unit_it != units.end(); ++help_unit_it) {
1012  encountered_units_set.insert(help_unit_it->type_id());
1013  }
1014 }
1015 
1016 static void encounter_recallable_units(const std::vector<team>& teams){
1017  for (const team& t : teams) {
1018  for (const unit_const_ptr u : t.recall_list()) {
1019  encountered_units_set.insert(u->type_id());
1020  }
1021  }
1022 }
1023 
1025 {
1026  map.for_each_loc([&](const map_location& loc) {
1028  preferences::encountered_terrains().insert(terrain);
1031  }
1032  });
1033 }
1034 
1035 void encounter_all_content(const game_board & gameboard_) {
1040 }
1041 
1043 {
1044  nick_ = cfg["nick"].str();
1045  status_ = cfg["status"].str();
1046  notes_ = cfg["notes"].str();
1047 }
1048 
1050 {
1051  item["nick"] = nick_;
1052  item["status"] = status_;
1053  item["notes"] = notes_;
1054 }
1055 
1056 } // 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:832
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:175
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:707
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:92
std::string random_faction_mode()
Definition: game.cpp:507
bool message_private()
Definition: game.cpp:874
static void encounter_recallable_units(const std::vector< team > &teams)
Definition: game.cpp:1016
virtual const unit_map & units() const override
Definition: game_board.hpp:114
void clear_children(T... keys)
Definition: config.hpp:479
void set_countdown_action_bonus(int value)
Definition: game.cpp:687
void set_countdown_turn_bonus(int value)
Definition: game.cpp:676
std::string era()
Definition: game.cpp:722
void set_shroud(bool value)
Definition: game.cpp:577
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:654
bool is_authenticated()
Definition: game.cpp:180
int xp_modifier()
Definition: game.cpp:712
std::string campaign_server()
Definition: game.cpp:428
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:530
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:869
void set_options(const config &values)
Definition: game.cpp:612
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:497
void set_show_side_colors(bool value)
Definition: game.cpp:782
std::string network_host()
Definition: game.cpp:413
void load_from_config(const config &cfg)
Definition: game.cpp:1042
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:206
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:930
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:925
void set_random_faction_mode(const std::string &value)
Definition: game.cpp:511
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:181
#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:566
static lg::log_domain log_config("config")
bool show_side_colors()
Definition: game.cpp:787
void set_countdown(bool value)
Definition: game.cpp:643
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:280
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:822
int countdown_init_time()
Definition: game.cpp:648
bool yellow_confirm()
Definition: game.cpp:988
void set_registered_users_only(bool value)
Definition: game.cpp:492
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:535
bool fog()
Definition: game.cpp:562
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:993
void set_chat_message_aging(const int aging)
Definition: game.cpp:935
const config & options()
Definition: game.cpp:592
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:670
void set_level_type(int value)
Definition: game.cpp:747
std::string get(const std::string &key)
Definition: general.cpp:229
void set_custom_command(const std::string &command)
Definition: game.cpp:965
const std::vector< game_config::server_info > & builtin_servers_list()
Definition: game.cpp:382
int village_support()
Definition: game.cpp:702
std::string level()
Definition: game.cpp:732
static void save_acquaintances()
Definition: game.cpp:211
void set_save_replays(bool value)
Definition: game.cpp:792
bool is_friend(const std::string &nick)
Definition: game.cpp:302
void set_theme(const std::string &theme)
Definition: game.cpp:857
void encounter_map_terrain(const gamemap &map)
Definition: game.cpp:1024
void encounter_start_units(const unit_map &units)
Definition: game.cpp:1009
const std::string & get_nick() const
Definition: game.hpp:272
std::string theme()
Definition: game.cpp:842
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:659
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:457
bool blindfold_replay()
Definition: game.cpp:628
void set_music_volume(int vol)
Definition: general.cpp:551
Encapsulates the map of the game.
Definition: map.hpp:36
void erase(const std::string &key)
Definition: general.cpp:221
void set_random_start_time(bool value)
Definition: game.cpp:557
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:957
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
bool registered_users_only()
Definition: game.cpp:487
void save(config &cfg)
Definition: game.cpp:1049
int village_gold()
Definition: game.cpp:692
bool show_all_units_in_help()
Definition: game.cpp:945
void set_blindfold_replay(bool value)
Definition: game.cpp:633
bool chat_timestamping()
Definition: game.cpp:917
void set_message_private(bool value)
Definition: game.cpp:879
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:921
void set_level(const std::string &value)
Definition: game.cpp:737
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:211
void set_allow_observers(bool value)
Definition: game.cpp:482
bool countdown()
Definition: game.cpp:638
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:975
bool shroud()
Definition: game.cpp:572
int mp_server_warning_disabled()
Definition: game.cpp:525
std::size_t i
Definition: function.cpp:933
std::string get_mp_server_program_name()
Definition: game.cpp:547
bool interrupt_when_ally_sighted()
Definition: game.cpp:827
void set_delete_saves(bool value)
Definition: game.cpp:802
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:1035
bool use_map_settings()
Definition: game.cpp:515
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
config * get_prefs()
Definition: general.cpp:251
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:807
void set_skip_mp_replay(bool value)
Definition: game.cpp:623
std::set< std::string > & encountered_units()
Definition: game.cpp:953
const std::string & get_status() const
Definition: game.hpp:273
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:244
bool ask_delete_saves()
Definition: game.cpp:817
bool skip_mp_replay()
Definition: game.cpp:618
const config & get_child(const std::string &key)
Definition: general.cpp:216
config & add_child(config_key_type key)
Definition: config.cpp:476
void set_turns(int value)
Definition: game.cpp:587
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:905
void set_autosavemax(int value)
Definition: game.cpp:837
compression::format save_compression_format()
Definition: game.cpp:884
void set_show_all_units_in_help(bool value)
Definition: game.cpp:949
bool allow_observers()
Definition: game.cpp:477
bool green_confirm()
Definition: game.cpp:979
int turns()
Definition: game.cpp:582
int sound_volume()
Definition: general.cpp:561
bool show_floating_labels()
Definition: game.cpp:864
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:752
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:760
int chat_message_aging()
Definition: game.cpp:940
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:681
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:727
void set_shuffle_sides(bool value)
Definition: game.cpp:502
void set_fog(bool value)
Definition: game.cpp:567
void set_ask_delete_saves(bool value)
Definition: game.cpp:812
void encounter_recruitable_units(const std::vector< team > &teams)
Definition: game.cpp:1001
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:665
bool random_start_time()
Definition: game.cpp:552
std::vector< game_config::server_info > user_servers_list()
Definition: game.cpp:388
void set_skip_ai_moves(bool value)
Definition: game.cpp:777
std::string custom_command()
Definition: game.cpp:961
void set_xp_modifier(int value)
Definition: game.cpp:717
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:915
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
void set_village_gold(int value)
Definition: game.cpp:697
std::vector< server_info > server_list
Definition: game_config.cpp:94
void set_use_map_settings(bool value)
Definition: game.cpp:520
bool skip_ai_moves()
Definition: game.cpp:772
int music_volume()
Definition: general.cpp:546
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:797
int level_type()
Definition: game.cpp:742