The Battle for Wesnoth  1.15.0-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 bool haloes = true;
43 
44 std::map<std::string, std::set<std::string>> completed_campaigns;
45 std::set<std::string> encountered_units_set;
46 std::set<t_translation::terrain_code> encountered_terrains_set;
47 
48 std::map<std::string, std::vector<std::string>> history_map;
49 
50 acquaintances_map acquaintances;
51 
52 std::vector<std::string> mp_modifications;
53 bool mp_modifications_initialized = false;
54 std::vector<std::string> sp_modifications;
55 bool sp_modifications_initialized = false;
56 
57 config option_values;
58 bool options_initialized = false;
59 
60 bool authenticated = false;
61 
62 void initialize_modifications(bool mp = true)
63 {
64  if (mp) {
65  mp_modifications = utils::split(preferences::get("mp_modifications"), ',');
66  mp_modifications_initialized = true;
67  } else {
68  sp_modifications = utils::split(preferences::get("sp_modifications"), ',');
69  sp_modifications_initialized = true;
70  }
71 }
72 
73 } // anon namespace
74 
75 namespace preferences {
76 
77 
79  base()
80 {
83 
84  set_show_haloes(preferences::get("show_haloes", true));
85  if (!preferences::get("remember_timer_settings", false)) {
86  preferences::erase("mp_countdown_init_time");
87  preferences::erase("mp_countdown_reservoir_time");
88  preferences::erase("mp_countdown_turn_bonus");
89  preferences::erase("mp_countdown_action_bonus");
90  }
91 
92  // We save the password encrypted now. Erase any saved passwords in the prefs file.
93  preferences::erase("password");
94  preferences::erase("password_is_wrapped");
95 
96  /*
97  completed_campaigns = "A,B,C"
98  [completed_campaigns]
99  [campaign]
100  name = "A"
101  difficulty_levels = "EASY,MEDIUM"
102  [/campaign]
103  [/completed_campaigns]
104  */
105  for (const std::string &c : utils::split(preferences::get("completed_campaigns"))) {
106  completed_campaigns[c]; // create the elements
107  }
108  if (const config &ccc = preferences::get_child("completed_campaigns")) {
109  for (const config &cc : ccc.child_range("campaign")) {
110  std::set<std::string> &d = completed_campaigns[cc["name"]];
111  std::vector<std::string> nd = utils::split(cc["difficulty_levels"]);
112  std::copy(nd.begin(), nd.end(), std::inserter(d, d.begin()));
113  }
114  }
115 
116  const std::vector<std::string> v (utils::split(preferences::get("encountered_units")));
117  encountered_units_set.insert(v.begin(), v.end());
118 
119  const t_translation::ter_list terrain (t_translation::read_list(preferences::get("encountered_terrain_list")));
120  encountered_terrains_set.insert(terrain.begin(), terrain.end());
121 
122  if (const config &history = preferences::get_child("history"))
123  {
124 /* Structure of the history
125  [history]
126  [history_id]
127  [line]
128  message = foobar
129  [/line]
130 */
131  for (const config::any_child &h : history.all_children_range())
132  {
133  for (const config &l : h.cfg.child_range("line")) {
134  history_map[h.key].push_back(l["message"]);
135  }
136  }
137  }
138 }
139 
141 {
142  config campaigns;
143  typedef const std::pair<std::string, std::set<std::string>> cc_elem;
144  for (cc_elem &elem : completed_campaigns) {
145  config cmp;
146  cmp["name"] = elem.first;
147  cmp["difficulty_levels"] = utils::join(elem.second);
148  campaigns.add_child("campaign", cmp);
149  }
150  preferences::set_child("completed_campaigns", campaigns);
151  std::vector<std::string> v (encountered_units_set.begin(), encountered_units_set.end());
152  preferences::set("encountered_units", utils::join(v));
153  t_translation::ter_list terrain (encountered_terrains_set.begin(), encountered_terrains_set.end());
154  preferences::set("encountered_terrain_list", t_translation::write_list(terrain));
155 
156 /* Structure of the history
157  [history]
158  [history_id]
159  [line]
160  message = foobar
161  [/line]
162 */
163  config history;
164  typedef std::pair<std::string, std::vector<std::string>> hack;
165  for (const hack& history_id : history_map) {
166 
167  config history_id_cfg; // [history_id]
168  for (const std::string& line : history_id.second) {
169  config cfg; // [line]
170 
171  cfg["message"] = line;
172  history_id_cfg.add_child("line", std::move(cfg));
173  }
174 
175  history.add_child(history_id.first, history_id_cfg);
176  }
177  preferences::set_child("history", history);
178 
179  history_map.clear();
180  encountered_units_set.clear();
181  encountered_terrains_set.clear();
182 }
183 
185  return authenticated;
186 }
187 
188 void parse_admin_authentication(const std::string& sender, const std::string& message) {
189  if(sender != "server") return;
190  if(message.compare(0, 43, "You are now recognized as an administrator.") == 0) {
191  authenticated = true;
192  } else if(message.compare(0, 50, "You are no longer recognized as an administrator.") == 0) {
193  authenticated = false;
194  }
195 }
196 
198 {
199 }
200 
202 {
203  authenticated = false;
204 }
205 
206 static void load_acquaintances() {
207  if(acquaintances.empty()) {
208  for (const config &acfg : preferences::get_prefs()->child_range("acquaintance")) {
209  acquaintance ac = acquaintance(acfg);
210  acquaintances[ac.get_nick()] = ac;
211  }
212  }
213 }
214 
215 static void save_acquaintances()
216 {
218  cfg->clear_children("acquaintance");
219 
220  for(std::map<std::string, acquaintance>::iterator i = acquaintances.begin();
221  i != acquaintances.end(); ++i)
222  {
223  config& item = cfg->add_child("acquaintance");
224  i->second.save(item);
225  }
226 }
227 
228 const std::map<std::string, acquaintance> & get_acquaintances() {
230  return acquaintances;
231 }
232 
233 //returns acquaintances in the form nick => notes where the status = filter
234 std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter) {
236  std::map<std::string, std::string> ac_nice;
237 
238  for(std::map<std::string, acquaintance>::iterator i = acquaintances.begin(); i != acquaintances.end(); ++i)
239  {
240  if(i->second.get_status() == filter) {
241  ac_nice[i->second.get_nick()] = i->second.get_notes();
242  }
243  }
244 
245  return ac_nice;
246 }
247 
248 std::pair<preferences::acquaintance*, bool> add_acquaintance(const std::string& nick, const std::string& mode, const std::string& notes)
249 {
250  if(!utils::isvalid_wildcard(nick)) {
251  return std::make_pair(nullptr, false);
252  }
253 
254  preferences::acquaintance new_entry(nick, mode, notes);
255 
257  bool success;
258 
259  std::tie(iter, success) = acquaintances.emplace(nick, new_entry);
260 
261  if(!success) {
262  iter->second = new_entry;
263  }
264 
266 
267  return std::make_pair(&iter->second, success);
268 }
269 
270 bool remove_acquaintance(const std::string& nick) {
271  std::map<std::string, acquaintance>::iterator i = acquaintances.find(nick);
272 
273  //nick might include the notes, depending on how we're removing
274  if(i == acquaintances.end()) {
275  std::size_t pos = nick.find_first_of(' ');
276 
277  if(pos != std::string::npos) {
278  i = acquaintances.find(nick.substr(0, pos));
279  }
280  }
281 
282  if(i == acquaintances.end()) {
283  return false;
284  }
285 
286  acquaintances.erase(i);
288 
289  return true;
290 }
291 
292 bool is_friend(const std::string& nick)
293 {
295  const std::map<std::string, acquaintance
296  >::const_iterator it = acquaintances.find(nick);
297 
298  if(it == acquaintances.end()) {
299  return false;
300  } else {
301  return it->second.get_status() == "friend";
302  }
303 }
304 
305 bool is_ignored(const std::string& nick)
306 {
308  const std::map<std::string, acquaintance
309  >::const_iterator it = acquaintances.find(nick);
310 
311  if(it == acquaintances.end()) {
312  return false;
313  } else {
314  return it->second.get_status() == "ignore";
315  }
316 }
317 
318 void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level) {
319  completed_campaigns[campaign_id].insert(difficulty_level);
320 }
321 
322 bool is_campaign_completed(const std::string& campaign_id) {
323  return completed_campaigns.count(campaign_id) != 0;
324 }
325 
326 bool is_campaign_completed(const std::string& campaign_id, const std::string &difficulty_level) {
327  std::map<std::string, std::set<std::string>>::iterator it = completed_campaigns.find(campaign_id);
328  return it == completed_campaigns.end() ? false : it->second.count(difficulty_level) != 0;
329 }
330 
331 bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
332 {
333  // If it's actually not a lobby join or leave message return true (show it).
334  if (sender != "server") return true;
335  std::string::size_type pos = message.find(" has logged into the lobby");
336  if (pos == std::string::npos){
337  pos = message.find(" has disconnected");
338  if (pos == std::string::npos) return true;
339  }
340  int lj = lobby_joins();
341  if (lj == SHOW_NONE) return false;
342  if (lj == SHOW_ALL) return true;
343  return is_friend(message.substr(0, pos));
344 }
345 
347 {
348  std::string pref = preferences::get("lobby_joins");
349  if (pref == "friends") {
350  return SHOW_FRIENDS;
351  } else if (pref == "all") {
352  return SHOW_ALL;
353  } else if (pref == "none") {
354  return SHOW_NONE;
355  } else {
356  return SHOW_FRIENDS;
357  }
358 }
359 
360 
362 {
363  if (show == SHOW_FRIENDS) {
364  preferences::set("lobby_joins", "friends");
365  } else if (show == SHOW_ALL) {
366  preferences::set("lobby_joins", "all");
367  } else if (show == SHOW_NONE) {
368  preferences::set("lobby_joins", "none");
369  }
370 }
371 
372 const std::vector<game_config::server_info>& server_list()
373 {
374  static std::vector<game_config::server_info> pref_servers;
375  if(pref_servers.empty()) {
376  std::vector<game_config::server_info> &game_servers = game_config::server_list;
377  VALIDATE(!game_servers.empty(), _("No server has been defined."));
378  pref_servers.insert(pref_servers.begin(), game_servers.begin(), game_servers.end());
379  for(const config &server : get_prefs()->child_range("server")) {
381  sinf.name = server["name"].str();
382  sinf.address = server["address"].str();
383  pref_servers.push_back(sinf);
384  }
385  }
386  return pref_servers;
387 }
388 
389 std::string network_host()
390 {
391  const std::string res = preferences::get("host");
392  if(res.empty()) {
393  return server_list().front().address;
394  } else {
395  return res;
396  }
397 }
398 
399 void set_network_host(const std::string& host)
400 {
401  preferences::set("host", host);
402 }
403 
404 std::string campaign_server()
405 {
406  if(!preferences::get("campaign_server").empty()) {
407  return preferences::get("campaign_server");
408  } else {
409  return "add-ons.wesnoth.org";
410  }
411 }
412 
413 void set_campaign_server(const std::string& host)
414 {
415  preferences::set("campaign_server", host);
416 }
417 
419 {
420  return preferences::get("turn_dialog", false);
421 }
422 
423 void set_turn_dialog(bool ison)
424 {
425  preferences::set("turn_dialog", ison);
426 }
427 
429 {
430  return preferences::get("enable_planning_mode_on_start", false);
431 }
432 
434 {
435  preferences::set("enable_planning_mode_on_start", value);
436 }
437 
439 {
440  return preferences::get("hide_whiteboard", false);
441 }
442 
443 void set_hide_whiteboard(bool value)
444 {
445  preferences::set("hide_whiteboard", value);
446 }
447 
449 {
450  return preferences::get("show_combat", true);
451 }
452 
454 {
455  return preferences::get("allow_observers", true);
456 }
457 
458 void set_allow_observers(bool value)
459 {
460  preferences::set("allow_observers", value);
461 }
462 
464 {
465  return preferences::get("registered_users_only", false);
466 }
467 
469 {
470  preferences::set("registered_users_only", value);
471 }
472 
474 {
475  return preferences::get("shuffle_sides", false);
476 }
477 
478 void set_shuffle_sides(bool value)
479 {
480  preferences::set("shuffle_sides", value);
481 }
482 
483 std::string random_faction_mode(){
484  return preferences::get("random_faction_mode");
485 }
486 
487 void set_random_faction_mode(const std::string & value) {
488  preferences::set("random_faction_mode", value);
489 }
490 
492 {
493  return preferences::get("mp_use_map_settings", true);
494 }
495 
496 void set_use_map_settings(bool value)
497 {
498  preferences::set("mp_use_map_settings", value);
499 }
500 
502 {
503  return lexical_cast_default<int>(preferences::get("mp_server_warning_disabled"), 0);
504 }
505 
507 {
508  preferences::set("mp_server_warning_disabled", value);
509 }
510 
511 void set_mp_server_program_name(const std::string& path)
512 {
513  if (path.empty())
514  {
515  preferences::clear("mp_server_program_name");
516  }
517  else
518  {
519  preferences::set("mp_server_program_name", path);
520  }
521 }
522 
524 {
525  return preferences::get("mp_server_program_name");
526 }
527 
529 {
530  return preferences::get("mp_random_start_time", true);
531 }
532 
533 void set_random_start_time(bool value)
534 {
535  preferences::set("mp_random_start_time", value);
536 }
537 
538 bool fog()
539 {
540  return preferences::get("mp_fog", true);
541 }
542 
543 void set_fog(bool value)
544 {
545  preferences::set("mp_fog", value);
546 }
547 
548 bool shroud()
549 {
550  return preferences::get("mp_shroud", false);
551 }
552 
553 void set_shroud(bool value)
554 {
555  preferences::set("mp_shroud", value);
556 }
557 
558 int turns()
559 {
560  return settings::get_turns(preferences::get("mp_turns"));
561 }
562 
563 void set_turns(int value)
564 {
565  preferences::set("mp_turns", value);
566 }
567 
568 const config& options()
569 {
570  if (options_initialized) {
571  return option_values;
572  }
573 
574  if (!preferences::get_child("options")) {
575  // It may be an invalid config, which would cause problems in
576  // multiplayer_create, so let's replace it with an empty but valid
577  // config
578  option_values.clear();
579  } else {
580  option_values = preferences::get_child("options");
581  }
582 
583  options_initialized = true;
584 
585  return option_values;
586 }
587 
588 void set_options(const config& values)
589 {
590  preferences::set_child("options", values);
591  options_initialized = false;
592 }
593 
595 {
596  return preferences::get("skip_mp_replay", false);
597 }
598 
599 void set_skip_mp_replay(bool value)
600 {
601  preferences::set("skip_mp_replay", value);
602 }
603 
605 {
606  return preferences::get("blindfold_replay", false);
607 }
608 
609 void set_blindfold_replay(bool value)
610 {
611  preferences::set("blindfold_replay", value);
612 }
613 
614 bool countdown()
615 {
616  return preferences::get("mp_countdown", false);
617 }
618 
619 void set_countdown(bool value)
620 {
621  preferences::set("mp_countdown", value);
622 }
623 
625 {
626  return utils::clamp<int>(
627  lexical_cast_default<int>(preferences::get("mp_countdown_init_time"), 270), 0, 1500);
628 }
629 
630 void set_countdown_init_time(int value)
631 {
632  preferences::set("mp_countdown_init_time", value);
633 }
634 
636 {
637  return utils::clamp<int>(
638  lexical_cast_default<int>(preferences::get("mp_countdown_reservoir_time"), 330), 30, 1500);
639 }
640 
642 {
643  preferences::set("mp_countdown_reservoir_time", value);
644 }
645 
647 {
648  return utils::clamp<int>(
649  lexical_cast_default<int>(preferences::get("mp_countdown_turn_bonus"), 60), 0, 300);
650 }
651 
653 {
654  preferences::set("mp_countdown_turn_bonus", value);
655 }
656 
658 {
659  return utils::clamp<int>(
660  lexical_cast_default<int>(preferences::get("mp_countdown_action_bonus"), 13), 0, 30);
661 }
662 
664 {
665  preferences::set("mp_countdown_action_bonus", value);
666 }
667 
669 {
670  return settings::get_village_gold(preferences::get("mp_village_gold"));
671 }
672 
673 void set_village_gold(int value)
674 {
675  preferences::set("mp_village_gold", value);
676 }
677 
679 {
680  return settings::get_village_support(preferences::get("mp_village_support"));
681 }
682 
683 void set_village_support(int value)
684 {
685  preferences::set("mp_village_support", std::to_string(value));
686 }
687 
689 {
690  return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
691 }
692 
693 void set_xp_modifier(int value)
694 {
695  preferences::set("mp_xp_modifier", value);
696 }
697 
698 std::string era()
699 {
700  return preferences::get("mp_era");
701 }
702 
703 void set_era(const std::string& value)
704 {
705  preferences::set("mp_era", value);
706 }
707 
708 std::string level()
709 {
710  return preferences::get("mp_level");
711 }
712 
713 void set_level(const std::string& value)
714 {
715  preferences::set("mp_level", value);
716 }
717 
719 {
720  return lexical_cast_default<int>(preferences::get("mp_level_type"), 0);
721 }
722 
723 void set_level_type(int value)
724 {
725  preferences::set("mp_level_type", value);
726 }
727 
728 const std::vector<std::string>& modifications(bool mp)
729 {
730  if ((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp))
731  initialize_modifications(mp);
732 
733  return mp ? mp_modifications : sp_modifications;
734 }
735 
736 void set_modifications(const std::vector<std::string>& value, bool mp)
737 {
738  if (mp) {
739  preferences::set("mp_modifications", utils::join(value, ","));
740  mp_modifications_initialized = false;
741  } else {
742  preferences::set("sp_modifications", utils::join(value, ","));
743  sp_modifications_initialized = false;
744  }
745 
746 }
747 
749 {
750  return preferences::get("skip_ai_moves", false);
751 }
752 
753 void set_skip_ai_moves(bool value)
754 {
755  preferences::set("skip_ai_moves", value);
756 }
757 
758 void set_show_side_colors(bool value)
759 {
760  preferences::set("show_side_colors", value);
761 }
762 
764 {
765  return preferences::get("show_side_colors", true);
766 }
767 
768 void set_save_replays(bool value)
769 {
770  preferences::set("save_replays", value);
771 }
772 
774 {
775  return preferences::get("save_replays", true);
776 }
777 
778 void set_delete_saves(bool value)
779 {
780  preferences::set("delete_saves", value);
781 }
782 
784 {
785  return preferences::get("delete_saves", false);
786 }
787 
788 void set_ask_delete_saves(bool value)
789 {
790  preferences::set("ask_delete", value);
791 }
792 
794 {
795  return preferences::get("ask_delete", true);
796 }
797 
799 {
800  preferences::set("ally_sighted_interrupts", value);
801 }
802 
804 {
805  return preferences::get("ally_sighted_interrupts", true);
806 }
807 
809 {
810  return lexical_cast_default<int>(preferences::get("auto_save_max"), 10);
811 }
812 
813 void set_autosavemax(int value)
814 {
815  preferences::set("auto_save_max", value);
816 }
817 
818 std::string theme()
819 {
820  if(CVideo::get_singleton().non_interactive()) {
821  static const std::string null_theme = "null";
822  return null_theme;
823  }
824 
825  std::string res = preferences::get("theme");
826  if(res.empty()) {
827  return "Default";
828  }
829 
830  return res;
831 }
832 
833 void set_theme(const std::string& theme)
834 {
835  if(theme != "null") {
836  preferences::set("theme", theme);
837  }
838 }
839 
841 {
842  return preferences::get("floating_labels", true);
843 }
844 
845 void set_show_floating_labels(bool value)
846 {
847  preferences::set("floating_labels", value);
848 }
849 
851 {
852  return message_private_on;
853 }
854 
855 void set_message_private(bool value)
856 {
857  message_private_on = value;
858 }
859 
861 {
862  return haloes;
863 }
864 
865 void set_show_haloes(bool value)
866 {
867  haloes = value;
868  preferences::set("show_haloes", 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:443
int autosavemax()
Definition: game.cpp:808
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:413
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:683
void set_show_haloes(bool value)
Definition: game.cpp:865
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:92
std::string random_faction_mode()
Definition: game.cpp:483
bool message_private()
Definition: game.cpp:850
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:509
void set_countdown_action_bonus(int value)
Definition: game.cpp:663
void set_countdown_turn_bonus(int value)
Definition: game.cpp:652
std::string era()
Definition: game.cpp:698
void set_shroud(bool value)
Definition: game.cpp:553
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void set_countdown_init_time(int value)
Definition: game.cpp:630
bool is_authenticated()
Definition: game.cpp:184
int xp_modifier()
Definition: game.cpp:688
std::string campaign_server()
Definition: game.cpp:404
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:506
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:845
void set_options(const config &values)
Definition: game.cpp:588
int lobby_joins()
Definition: game.cpp:346
New lexcical_cast header.
const std::map< std::string, acquaintance > & get_acquaintances()
Definition: game.cpp:228
bool is_campaign_completed(const std::string &campaign_id)
Definition: game.cpp:322
child_itors child_range(config_key_type key)
Definition: config.cpp:366
bool shuffle_sides()
Definition: game.cpp:473
void set_show_side_colors(bool value)
Definition: game.cpp:758
std::string network_host()
Definition: game.cpp:389
void load_from_config(const config &cfg)
Definition: game.cpp:1029
bool hide_whiteboard()
Definition: game.cpp:438
void parse_admin_authentication(const std::string &sender, const std::string &message)
Definition: game.cpp:188
void clear(const std::string &key)
Definition: general.cpp:205
void _set_lobby_joins(int show)
Definition: game.cpp:361
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:487
static CVideo & get_singleton()
Definition: video.hpp:43
static void load_acquaintances()
Definition: game.cpp:206
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:399
void clear()
Definition: config.cpp:865
#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:763
void set_countdown(bool value)
Definition: game.cpp:619
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:270
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:798
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:624
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:468
t_translation::terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:309
bool show_haloes()
Definition: game.cpp:860
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:511
bool fog()
Definition: game.cpp:538
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:49
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:568
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:423
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
int countdown_turn_bonus()
Definition: game.cpp:646
void set_level_type(int value)
Definition: game.cpp:723
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:678
std::string level()
Definition: game.cpp:708
static void save_acquaintances()
Definition: game.cpp:215
void set_save_replays(bool value)
Definition: game.cpp:768
bool is_friend(const std::string &nick)
Definition: game.cpp:292
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void set_theme(const std::string &theme)
Definition: game.cpp:833
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:273
std::string theme()
Definition: game.cpp:818
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:248
int countdown_reservoir_time()
Definition: game.cpp:635
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:433
bool blindfold_replay()
Definition: game.cpp:604
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:372
void erase(const std::string &key)
Definition: general.cpp:220
void set_random_start_time(bool value)
Definition: game.cpp:533
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:448
bool registered_users_only()
Definition: game.cpp:463
void save(config &cfg)
Definition: game.cpp:1036
int village_gold()
Definition: game.cpp:668
bool show_all_units_in_help()
Definition: game.cpp:932
void set_blindfold_replay(bool value)
Definition: game.cpp:609
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:855
General settings and defaults for scenarios.
bool is_ignored(const std::string &nick)
Definition: game.cpp:305
void set_chat_timestamping(bool value)
Definition: game.cpp:908
void set_level(const std::string &value)
Definition: game.cpp:713
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:197
void set_child(const std::string &key, const config &val)
Definition: general.cpp:210
void set_allow_observers(bool value)
Definition: game.cpp:458
bool countdown()
Definition: game.cpp:614
std::vector< std::string > * get_history(const std::string &id)
Returns a pointer to the history vector associated with given id making a new one if it doesn&#39;t exist...
Definition: game.cpp:962
bool shroud()
Definition: game.cpp:548
int mp_server_warning_disabled()
Definition: game.cpp:501
std::size_t i
Definition: function.cpp:933
std::string get_mp_server_program_name()
Definition: game.cpp:523
bool interrupt_when_ally_sighted()
Definition: game.cpp:803
void set_delete_saves(bool value)
Definition: game.cpp:778
Definition: theme.hpp:38
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
Definition: game.cpp:318
void encounter_all_content(const game_board &gameboard_)
Definition: game.cpp:1022
bool use_map_settings()
Definition: game.cpp:491
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:783
void set_skip_mp_replay(bool value)
Definition: game.cpp:599
std::set< std::string > & encountered_units()
Definition: game.cpp:940
const std::string & get_status() const
Definition: game.hpp:274
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:234
bool ask_delete_saves()
Definition: game.cpp:793
bool skip_mp_replay()
Definition: game.cpp:594
const config & get_child(const std::string &key)
Definition: general.cpp:215
config & add_child(config_key_type key)
Definition: config.cpp:479
void set_turns(int value)
Definition: game.cpp:563
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:892
void set_autosavemax(int value)
Definition: game.cpp:813
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:453
bool green_confirm()
Definition: game.cpp:966
int turns()
Definition: game.cpp:558
int sound_volume()
Definition: general.cpp:560
bool show_floating_labels()
Definition: game.cpp:840
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:728
double t
Definition: astarsearch.cpp:64
void set_modifications(const std::vector< std::string > &value, bool mp)
Definition: game.cpp:736
int chat_message_aging()
Definition: game.cpp:927
bool enable_whiteboard_mode_on_start()
Definition: game.cpp:428
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:657
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:331
void set_era(const std::string &value)
Definition: game.cpp:703
void set_shuffle_sides(bool value)
Definition: game.cpp:478
void set_fog(bool value)
Definition: game.cpp:543
void set_ask_delete_saves(bool value)
Definition: game.cpp:788
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:92
mock_char c
void set_countdown_reservoir_time(int value)
Definition: game.cpp:641
bool random_start_time()
Definition: game.cpp:528
void set_skip_ai_moves(bool value)
Definition: game.cpp:753
std::string custom_command()
Definition: game.cpp:948
void set_xp_modifier(int value)
Definition: game.cpp:693
bool turn_dialog()
Definition: game.cpp:418
int get_turns(const std::string &value)
Gets the number of turns.
bool use_twelve_hour_clock_format()
Definition: general.cpp:1042
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
void set_village_gold(int value)
Definition: game.cpp:673
std::vector< server_info > server_list
Definition: game_config.cpp:94
void set_use_map_settings(bool value)
Definition: game.cpp:496
bool skip_ai_moves()
Definition: game.cpp:748
int music_volume()
Definition: general.cpp:545
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:773
int level_type()
Definition: game.cpp:718