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