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