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