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>& builtin_servers_list()
384 {
385  static std::vector<game_config::server_info> pref_servers = game_config::server_list;
386  return pref_servers;
387 }
388 
389 std::vector<game_config::server_info> user_servers_list()
390 {
391  std::vector<game_config::server_info> pref_servers;
392 
393  for(const config &server : get_prefs()->child_range("server")) {
394  pref_servers.emplace_back();
395  pref_servers.back().name = server["name"].str();
396  pref_servers.back().address = server["address"].str();
397  }
398 
399  return pref_servers;
400 }
401 
402 void set_user_servers_list(const std::vector<game_config::server_info>& value)
403 {
404  config& prefs = *get_prefs();
405  prefs.clear_children("server");
406 
407  for(const auto& svinfo : value) {
408  config& sv_cfg = prefs.add_child("server");
409  sv_cfg["name"] = svinfo.name;
410  sv_cfg["address"] = svinfo.address;
411  }
412 }
413 
414 std::string network_host()
415 {
416  const std::string res = preferences::get("host");
417  if(res.empty()) {
418  return builtin_servers_list().front().address;
419  } else {
420  return res;
421  }
422 }
423 
424 void set_network_host(const std::string& host)
425 {
426  preferences::set("host", host);
427 }
428 
429 std::string campaign_server()
430 {
431  if(!preferences::get("campaign_server").empty()) {
432  return preferences::get("campaign_server");
433  } else {
434  return "add-ons.wesnoth.org";
435  }
436 }
437 
438 void set_campaign_server(const std::string& host)
439 {
440  preferences::set("campaign_server", host);
441 }
442 
444 {
445  return preferences::get("turn_dialog", false);
446 }
447 
448 void set_turn_dialog(bool ison)
449 {
450  preferences::set("turn_dialog", ison);
451 }
452 
454 {
455  return preferences::get("enable_planning_mode_on_start", false);
456 }
457 
459 {
460  preferences::set("enable_planning_mode_on_start", value);
461 }
462 
464 {
465  return preferences::get("hide_whiteboard", false);
466 }
467 
468 void set_hide_whiteboard(bool value)
469 {
470  preferences::set("hide_whiteboard", value);
471 }
472 
474 {
475  return preferences::get("show_combat", true);
476 }
477 
479 {
480  return preferences::get("allow_observers", true);
481 }
482 
483 void set_allow_observers(bool value)
484 {
485  preferences::set("allow_observers", value);
486 }
487 
489 {
490  return preferences::get("registered_users_only", false);
491 }
492 
494 {
495  preferences::set("registered_users_only", value);
496 }
497 
499 {
500  return preferences::get("shuffle_sides", false);
501 }
502 
503 void set_shuffle_sides(bool value)
504 {
505  preferences::set("shuffle_sides", value);
506 }
507 
508 std::string random_faction_mode(){
509  return preferences::get("random_faction_mode");
510 }
511 
512 void set_random_faction_mode(const std::string & value) {
513  preferences::set("random_faction_mode", value);
514 }
515 
517 {
518  return preferences::get("mp_use_map_settings", true);
519 }
520 
521 void set_use_map_settings(bool value)
522 {
523  preferences::set("mp_use_map_settings", value);
524 }
525 
527 {
528  return lexical_cast_default<int>(preferences::get("mp_server_warning_disabled"), 0);
529 }
530 
532 {
533  preferences::set("mp_server_warning_disabled", value);
534 }
535 
536 void set_mp_server_program_name(const std::string& path)
537 {
538  if (path.empty())
539  {
540  preferences::clear("mp_server_program_name");
541  }
542  else
543  {
544  preferences::set("mp_server_program_name", path);
545  }
546 }
547 
549 {
550  return preferences::get("mp_server_program_name");
551 }
552 
554 {
555  return preferences::get("mp_random_start_time", true);
556 }
557 
558 void set_random_start_time(bool value)
559 {
560  preferences::set("mp_random_start_time", value);
561 }
562 
563 bool fog()
564 {
565  return preferences::get("mp_fog", true);
566 }
567 
568 void set_fog(bool value)
569 {
570  preferences::set("mp_fog", value);
571 }
572 
573 bool shroud()
574 {
575  return preferences::get("mp_shroud", false);
576 }
577 
578 void set_shroud(bool value)
579 {
580  preferences::set("mp_shroud", value);
581 }
582 
583 int turns()
584 {
585  return settings::get_turns(preferences::get("mp_turns"));
586 }
587 
588 void set_turns(int value)
589 {
590  preferences::set("mp_turns", value);
591 }
592 
593 const config& options()
594 {
595  if (options_initialized) {
596  return option_values;
597  }
598 
599  if (!preferences::get_child("options")) {
600  // It may be an invalid config, which would cause problems in
601  // multiplayer_create, so let's replace it with an empty but valid
602  // config
603  option_values.clear();
604  } else {
605  option_values = preferences::get_child("options");
606  }
607 
608  options_initialized = true;
609 
610  return option_values;
611 }
612 
613 void set_options(const config& values)
614 {
615  preferences::set_child("options", values);
616  options_initialized = false;
617 }
618 
620 {
621  return preferences::get("skip_mp_replay", false);
622 }
623 
624 void set_skip_mp_replay(bool value)
625 {
626  preferences::set("skip_mp_replay", value);
627 }
628 
630 {
631  return preferences::get("blindfold_replay", false);
632 }
633 
634 void set_blindfold_replay(bool value)
635 {
636  preferences::set("blindfold_replay", value);
637 }
638 
639 bool countdown()
640 {
641  return preferences::get("mp_countdown", false);
642 }
643 
644 void set_countdown(bool value)
645 {
646  preferences::set("mp_countdown", value);
647 }
648 
650 {
651  return utils::clamp<int>(
652  lexical_cast_default<int>(preferences::get("mp_countdown_init_time"), 270), 0, 1500);
653 }
654 
655 void set_countdown_init_time(int value)
656 {
657  preferences::set("mp_countdown_init_time", value);
658 }
659 
661 {
662  return utils::clamp<int>(
663  lexical_cast_default<int>(preferences::get("mp_countdown_reservoir_time"), 330), 30, 1500);
664 }
665 
667 {
668  preferences::set("mp_countdown_reservoir_time", value);
669 }
670 
672 {
673  return utils::clamp<int>(
674  lexical_cast_default<int>(preferences::get("mp_countdown_turn_bonus"), 60), 0, 300);
675 }
676 
678 {
679  preferences::set("mp_countdown_turn_bonus", value);
680 }
681 
683 {
684  return utils::clamp<int>(
685  lexical_cast_default<int>(preferences::get("mp_countdown_action_bonus"), 13), 0, 30);
686 }
687 
689 {
690  preferences::set("mp_countdown_action_bonus", value);
691 }
692 
694 {
695  return settings::get_village_gold(preferences::get("mp_village_gold"));
696 }
697 
698 void set_village_gold(int value)
699 {
700  preferences::set("mp_village_gold", value);
701 }
702 
704 {
705  return settings::get_village_support(preferences::get("mp_village_support"));
706 }
707 
708 void set_village_support(int value)
709 {
710  preferences::set("mp_village_support", std::to_string(value));
711 }
712 
714 {
715  return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
716 }
717 
718 void set_xp_modifier(int value)
719 {
720  preferences::set("mp_xp_modifier", value);
721 }
722 
723 std::string era()
724 {
725  return preferences::get("mp_era");
726 }
727 
728 void set_era(const std::string& value)
729 {
730  preferences::set("mp_era", value);
731 }
732 
733 std::string level()
734 {
735  return preferences::get("mp_level");
736 }
737 
738 void set_level(const std::string& value)
739 {
740  preferences::set("mp_level", value);
741 }
742 
744 {
745  return lexical_cast_default<int>(preferences::get("mp_level_type"), 0);
746 }
747 
748 void set_level_type(int value)
749 {
750  preferences::set("mp_level_type", value);
751 }
752 
753 const std::vector<std::string>& modifications(bool mp)
754 {
755  if ((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp))
756  initialize_modifications(mp);
757 
758  return mp ? mp_modifications : sp_modifications;
759 }
760 
761 void set_modifications(const std::vector<std::string>& value, bool mp)
762 {
763  if (mp) {
764  preferences::set("mp_modifications", utils::join(value, ","));
765  mp_modifications_initialized = false;
766  } else {
767  preferences::set("sp_modifications", utils::join(value, ","));
768  sp_modifications_initialized = false;
769  }
770 
771 }
772 
774 {
775  return preferences::get("skip_ai_moves", false);
776 }
777 
778 void set_skip_ai_moves(bool value)
779 {
780  preferences::set("skip_ai_moves", value);
781 }
782 
783 void set_show_side_colors(bool value)
784 {
785  preferences::set("show_side_colors", value);
786 }
787 
789 {
790  return preferences::get("show_side_colors", true);
791 }
792 
793 void set_save_replays(bool value)
794 {
795  preferences::set("save_replays", value);
796 }
797 
799 {
800  return preferences::get("save_replays", true);
801 }
802 
803 void set_delete_saves(bool value)
804 {
805  preferences::set("delete_saves", value);
806 }
807 
809 {
810  return preferences::get("delete_saves", false);
811 }
812 
813 void set_ask_delete_saves(bool value)
814 {
815  preferences::set("ask_delete", value);
816 }
817 
819 {
820  return preferences::get("ask_delete", true);
821 }
822 
824 {
825  preferences::set("ally_sighted_interrupts", value);
826 }
827 
829 {
830  return preferences::get("ally_sighted_interrupts", true);
831 }
832 
834 {
835  return lexical_cast_default<int>(preferences::get("auto_save_max"), 10);
836 }
837 
838 void set_autosavemax(int value)
839 {
840  preferences::set("auto_save_max", value);
841 }
842 
843 std::string theme()
844 {
845  if(CVideo::get_singleton().non_interactive()) {
846  static const std::string null_theme = "null";
847  return null_theme;
848  }
849 
850  std::string res = preferences::get("theme");
851  if(res.empty()) {
852  return "Default";
853  }
854 
855  return res;
856 }
857 
858 void set_theme(const std::string& theme)
859 {
860  if(theme != "null") {
861  preferences::set("theme", theme);
862  }
863 }
864 
866 {
867  return preferences::get("floating_labels", true);
868 }
869 
870 void set_show_floating_labels(bool value)
871 {
872  preferences::set("floating_labels", value);
873 }
874 
876 {
877  return message_private_on;
878 }
879 
880 void set_message_private(bool value)
881 {
882  message_private_on = 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:468
int autosavemax()
Definition: game.cpp:833
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:438
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:708
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:92
std::string random_faction_mode()
Definition: game.cpp:508
bool message_private()
Definition: game.cpp:875
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:479
void set_countdown_action_bonus(int value)
Definition: game.cpp:688
void set_countdown_turn_bonus(int value)
Definition: game.cpp:677
std::string era()
Definition: game.cpp:723
void set_shroud(bool value)
Definition: game.cpp:578
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:655
bool is_authenticated()
Definition: game.cpp:181
int xp_modifier()
Definition: game.cpp:713
std::string campaign_server()
Definition: game.cpp:429
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:531
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:870
void set_options(const config &values)
Definition: game.cpp:613
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:498
void set_show_side_colors(bool value)
Definition: game.cpp:783
std::string network_host()
Definition: game.cpp:414
void load_from_config(const config &cfg)
Definition: game.cpp:1043
bool hide_whiteboard()
Definition: game.cpp:463
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: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:512
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:424
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:788
void set_countdown(bool value)
Definition: game.cpp:644
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:281
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:823
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:649
bool yellow_confirm()
Definition: game.cpp:989
void set_registered_users_only(bool value)
Definition: game.cpp:493
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:536
bool fog()
Definition: game.cpp:563
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:50
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:593
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:448
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
int countdown_turn_bonus()
Definition: game.cpp:671
void set_level_type(int value)
Definition: game.cpp:748
std::string get(const std::string &key)
Definition: general.cpp:228
void set_custom_command(const std::string &command)
Definition: game.cpp:966
const std::vector< game_config::server_info > & builtin_servers_list()
Definition: game.cpp:383
int village_support()
Definition: game.cpp:703
std::string level()
Definition: game.cpp:733
static void save_acquaintances()
Definition: game.cpp:212
void set_save_replays(bool value)
Definition: game.cpp:793
bool is_friend(const std::string &nick)
Definition: game.cpp:303
void set_theme(const std::string &theme)
Definition: game.cpp:858
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:272
std::string theme()
Definition: game.cpp:843
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:660
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:458
bool blindfold_replay()
Definition: game.cpp:629
void set_music_volume(int vol)
Definition: general.cpp:550
Encapsulates the map of the game.
Definition: map.hpp:36
void erase(const std::string &key)
Definition: general.cpp:220
void set_random_start_time(bool value)
Definition: game.cpp:558
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:958
void set_user_servers_list(const std::vector< game_config::server_info > &value)
Definition: game.cpp:402
std::string path
Definition: game_config.cpp:39
Modify, read and display user preferences.
bool show_combat()
Definition: game.cpp:473
bool registered_users_only()
Definition: game.cpp:488
void save(config &cfg)
Definition: game.cpp:1050
int village_gold()
Definition: game.cpp:693
bool show_all_units_in_help()
Definition: game.cpp:946
void set_blindfold_replay(bool value)
Definition: game.cpp:634
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:880
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:922
void set_level(const std::string &value)
Definition: game.cpp:738
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:483
bool countdown()
Definition: game.cpp:639
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:573
int mp_server_warning_disabled()
Definition: game.cpp:526
std::size_t i
Definition: function.cpp:933
std::string get_mp_server_program_name()
Definition: game.cpp:548
bool interrupt_when_ally_sighted()
Definition: game.cpp:828
void set_delete_saves(bool value)
Definition: game.cpp:803
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:1036
bool use_map_settings()
Definition: game.cpp:516
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:808
void set_skip_mp_replay(bool value)
Definition: game.cpp:624
std::set< std::string > & encountered_units()
Definition: game.cpp:954
const std::string & get_status() const
Definition: game.hpp:273
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:245
bool ask_delete_saves()
Definition: game.cpp:818
bool skip_mp_replay()
Definition: game.cpp:619
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:588
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:906
void set_autosavemax(int value)
Definition: game.cpp:838
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:478
bool green_confirm()
Definition: game.cpp:980
int turns()
Definition: game.cpp:583
int sound_volume()
Definition: general.cpp:560
bool show_floating_labels()
Definition: game.cpp:865
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:753
double t
Definition: astarsearch.cpp:64
void set_modifications(const std::vector< std::string > &value, bool mp)
Definition: game.cpp:761
int chat_message_aging()
Definition: game.cpp:941
bool enable_whiteboard_mode_on_start()
Definition: game.cpp:453
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:682
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:728
void set_shuffle_sides(bool value)
Definition: game.cpp:503
void set_fog(bool value)
Definition: game.cpp:568
void set_ask_delete_saves(bool value)
Definition: game.cpp:813
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:68
mock_char c
void set_countdown_reservoir_time(int value)
Definition: game.cpp:666
bool random_start_time()
Definition: game.cpp:553
std::vector< game_config::server_info > user_servers_list()
Definition: game.cpp:389
void set_skip_ai_moves(bool value)
Definition: game.cpp:778
std::string custom_command()
Definition: game.cpp:962
void set_xp_modifier(int value)
Definition: game.cpp:718
bool turn_dialog()
Definition: game.cpp:443
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:698
std::vector< server_info > server_list
Definition: game_config.cpp:94
void set_use_map_settings(bool value)
Definition: game.cpp:521
bool skip_ai_moves()
Definition: game.cpp:773
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:798
int level_type()
Definition: game.cpp:743