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