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