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