The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_preferences.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
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 #include "global.hpp"
16 
17 #define GETTEXT_DOMAIN "wesnoth-lib"
18 
19 #include "game_board.hpp"
20 #include "game_display.hpp"
21 #include "game_preferences.hpp"
22 #include "gettext.hpp"
23 #include "log.hpp"
24 #include "map/map.hpp"
27 #include "settings.hpp"
28 #include "units/unit.hpp"
29 #include "units/map.hpp"
30 #include "wml_exception.hpp"
31 
32 #include <cassert>
33 #ifdef _WIN32
34 #include <boost/range/iterator_range.hpp>
35 #ifdef INADDR_ANY
36  #undef INADDR_ANY
37 #endif
38 #ifdef INADDR_BROADCAST
39  #undef INADDR_BROADCAST
40 #endif
41 #ifdef INADDR_NONE
42  #undef INADDR_NONE
43 #endif
44 #include <windows.h> //GetUserName
45 #endif
46 
47 
48 static lg::log_domain log_config("config");
49 #define ERR_CFG LOG_STREAM(err , log_config)
50 
51 namespace {
52 
53 bool message_private_on = false;
54 
55 bool haloes = true;
56 
57 std::map<std::string, std::set<std::string> > completed_campaigns;
58 std::set<std::string> encountered_units_set;
59 std::set<t_translation::t_terrain> encountered_terrains_set;
60 
61 std::map<std::string, std::vector<std::string> > history_map;
62 
63 std::map<std::string, preferences::acquaintance> acquaintances;
64 
65 std::vector<std::string> mp_modifications;
66 bool mp_modifications_initialized = false;
67 std::vector<std::string> sp_modifications;
68 bool sp_modifications_initialized = false;
69 
70 config option_values;
71 bool options_initialized = false;
72 
73 bool authenticated = false;
74 
75 const char WRAP_CHAR = '@';
76 const std::string EMPTY_WRAPPED_STRING = "@@";
77 
78 std::string wrap_credentials_field_value(const std::string& value)
79 {
80  return WRAP_CHAR + value + WRAP_CHAR;
81 }
82 
83 std::string parse_wrapped_credentials_field(const std::string& raw)
84 {
85  if(raw.empty() || raw == EMPTY_WRAPPED_STRING) {
86  // empty (wrapped or not)
87  return raw;
88  } else if(raw.length() < 2 || raw[0] != WRAP_CHAR || raw[raw.length() - 1] != WRAP_CHAR ) {
89  // malformed/not wrapped (shouldn't happen)
90  ERR_CFG << "malformed user credentials (did you manually edit the preferences file?)" << std::endl;
91  return raw;
92  }
93 
94  return raw.substr(1, raw.length() - 2);
95 }
96 
97 void initialize_modifications(bool mp = true)
98 {
99  if (mp) {
100  mp_modifications = utils::split(preferences::get("mp_modifications"), ',');
101  mp_modifications_initialized = true;
102  } else {
103  sp_modifications = utils::split(preferences::get("sp_modifications"), ',');
104  sp_modifications_initialized = true;
105  }
106 }
107 
108 } // anon namespace
109 
110 namespace preferences {
111 
112 
114  base()
115 {
118 
119  set_show_haloes(preferences::get("show_haloes", true));
120  if (!preferences::get("remember_timer_settings", false)) {
121  preferences::erase("mp_countdown_init_time");
122  preferences::erase("mp_countdown_reservoir_time");
123  preferences::erase("mp_countdown_turn_bonus");
124  preferences::erase("mp_countdown_action_bonus");
125  }
126 
127  /*
128  completed_campaigns = "A,B,C"
129  [completed_campaigns]
130  [campaign]
131  name = "A"
132  difficulty_levels = "EASY,MEDIUM"
133  [/campaign]
134  [/completed_campaigns]
135  */
136  for (const std::string &c : utils::split(preferences::get("completed_campaigns"))) {
137  completed_campaigns[c]; // create the elements
138  }
139  if (const config &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  const std::vector<std::string> v (utils::split(preferences::get("encountered_units")));
148  encountered_units_set.insert(v.begin(), v.end());
149 
150  const t_translation::t_list terrain (t_translation::read_list(preferences::get("encountered_terrain_list")));
151  encountered_terrains_set.insert(terrain.begin(), terrain.end());
152 
153  if (const config &history = preferences::get_child("history"))
154  {
155 /* Structure of the history
156  [history]
157  [history_id]
158  [line]
159  message = foobar
160  [/line]
161 */
162  for (const config::any_child &h : history.all_children_range())
163  {
164  for (const config &l : h.cfg.child_range("line")) {
165  history_map[h.key].push_back(l["message"]);
166  }
167  }
168  }
169 
170  //network::ping_timeout = get_ping_timeout();
171 }
172 
174 {
175  config campaigns;
176  typedef const std::pair<std::string, std::set<std::string> > cc_elem;
177  for (cc_elem &elem : completed_campaigns) {
178  config cmp;
179  cmp["name"] = elem.first;
180  cmp["difficulty_levels"] = utils::join(elem.second);
181  campaigns.add_child("campaign", cmp);
182  }
183  preferences::set_child("completed_campaigns", campaigns);
184  std::vector<std::string> v (encountered_units_set.begin(), encountered_units_set.end());
185  preferences::set("encountered_units", utils::join(v));
186  t_translation::t_list terrain (encountered_terrains_set.begin(), encountered_terrains_set.end());
187  preferences::set("encountered_terrain_list", t_translation::write_list(terrain));
188 
189 /* Structure of the history
190  [history]
191  [history_id]
192  [line]
193  message = foobar
194  [/line]
195 */
196  config history;
197  typedef std::pair<std::string, std::vector<std::string> > hack;
198  for (const hack& history_id : history_map) {
199 
200  config history_id_cfg; // [history_id]
201  for (const std::string& line : history_id.second) {
202  config cfg; // [line]
203 
204  cfg["message"] = line;
205  history_id_cfg.add_child("line", cfg);
206  }
207 
208  history.add_child(history_id.first, history_id_cfg);
209  }
210  preferences::set_child("history", history);
211 
212  history_map.clear();
213  encountered_units_set.clear();
214  encountered_terrains_set.clear();
215 }
216 
218  return authenticated;
219 }
220 
222  if(sender != "server") return;
223  if(message.find("You are now recognized as an administrator.") == 0) {
224  authenticated = true;
225  } else if(message.find("You are no longer recognized as an administrator.") == 0) {
226  authenticated = false;
227  }
228 }
229 
231 {
232 }
233 
235 {
236  authenticated = false;
237 }
238 
239 static void load_acquaintances() {
240  if(acquaintances.empty()) {
241  for (const config &acfg : preferences::get_prefs()->child_range("acquaintance")) {
242  acquaintance ac = acquaintance(acfg);
243  acquaintances[ac.get_nick()] = ac;
244  }
245  }
246 }
247 
248 static void save_acquaintances()
249 {
251  cfg->clear_children("acquaintance");
252 
253  for(std::map<std::string, acquaintance>::iterator i = acquaintances.begin();
254  i != acquaintances.end(); ++i)
255  {
256  config& item = cfg->add_child("acquaintance");
257  i->second.save(item);
258  }
259 }
260 
261 const std::map<std::string, acquaintance> & get_acquaintances() {
263  return acquaintances;
264 }
265 
266 //returns acquaintances in the form nick => notes where the status = filter
267 std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter) {
269  std::map<std::string, std::string> ac_nice;
270 
271  for(std::map<std::string, acquaintance>::iterator i = acquaintances.begin(); i != acquaintances.end(); ++i)
272  {
273  if(i->second.get_status() == filter) {
274  ac_nice[i->second.get_nick()] = i->second.get_notes();
275  }
276  }
277 
278  return ac_nice;
279 }
280 
281 bool add_friend(const std::string& nick, const std::string& notes) {
282  if (!utils::isvalid_wildcard(nick)) return false;
283  acquaintances[nick] = preferences::acquaintance(nick, "friend", notes);
285  return true;
286 }
287 
288 bool add_ignore(const std::string& nick, const std::string& reason) {
289  if (!utils::isvalid_wildcard(nick)) return false;
290  acquaintances[nick] = preferences::acquaintance(nick, "ignore", reason);
292  return true;
293 }
294 
295 bool remove_acquaintance(const std::string& nick) {
296  std::map<std::string, acquaintance>::iterator i = acquaintances.find(nick);
297 
298  //nick might include the notes, depending on how we're removing
299  if(i == acquaintances.end()) {
300  size_t pos = nick.find_first_of(' ');
301 
302  if(pos != std::string::npos) {
303  i = acquaintances.find(nick.substr(0, pos));
304  }
305  }
306 
307  if(i == acquaintances.end()) {
308  return false;
309  }
310 
311  acquaintances.erase(i);
313 
314  return true;
315 }
316 
317 bool is_friend(const std::string& nick)
318 {
320  const std::map<std::string, acquaintance
321  >::const_iterator it = acquaintances.find(nick);
322 
323  if(it == acquaintances.end()) {
324  return false;
325  } else {
326  return it->second.get_status() == "friend";
327  }
328 }
329 
330 bool is_ignored(const std::string& nick)
331 {
333  const std::map<std::string, acquaintance
334  >::const_iterator it = acquaintances.find(nick);
335 
336  if(it == acquaintances.end()) {
337  return false;
338  } else {
339  return it->second.get_status() == "ignore";
340  }
341 }
342 
343 void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level) {
344  completed_campaigns[campaign_id].insert(difficulty_level);
345 }
346 
347 bool is_campaign_completed(const std::string& campaign_id) {
348  return completed_campaigns.count(campaign_id) != 0;
349 }
350 
351 bool is_campaign_completed(const std::string& campaign_id, const std::string &difficulty_level) {
352  std::map<std::string, std::set<std::string> >::iterator it = completed_campaigns.find(campaign_id);
353  return it == completed_campaigns.end() ? false : it->second.count(difficulty_level) != 0;
354 }
355 
357 {
358  // If it's actually not a lobby join or leave message return true (show it).
359  if (sender != "server") return true;
360  std::string::size_type pos = message.find(" has logged into the lobby");
361  if (pos == std::string::npos){
362  pos = message.find(" has disconnected");
363  if (pos == std::string::npos) return true;
364  }
365  int lj = lobby_joins();
366  if (lj == SHOW_NONE) return false;
367  if (lj == SHOW_ALL) return true;
368  return is_friend(message.substr(0, pos));
369 }
370 
372 {
373  std::string pref = preferences::get("lobby_joins");
374  if (pref == "friends") {
375  return SHOW_FRIENDS;
376  } else if (pref == "all") {
377  return SHOW_ALL;
378  } else if (pref == "none") {
379  return SHOW_NONE;
380  } else {
381  return SHOW_FRIENDS;
382  }
383 }
384 
385 
387 {
388  if (show == SHOW_FRIENDS) {
389  preferences::set("lobby_joins", "friends");
390  } else if (show == SHOW_ALL) {
391  preferences::set("lobby_joins", "all");
392  } else if (show == SHOW_NONE) {
393  preferences::set("lobby_joins", "none");
394  }
395 }
396 
397 bool new_lobby()
398 {
399  return get("new_lobby", false);
400 }
401 
402 const std::vector<game_config::server_info>& server_list()
403 {
404  static std::vector<game_config::server_info> pref_servers;
405  if(pref_servers.empty()) {
406  std::vector<game_config::server_info> &game_servers = game_config::server_list;
407  VALIDATE(!game_servers.empty(), _("No server has been defined."));
408  pref_servers.insert(pref_servers.begin(), game_servers.begin(), game_servers.end());
409  for(const config &server : get_prefs()->child_range("server")) {
411  sinf.name = server["name"].str();
412  sinf.address = server["address"].str();
413  pref_servers.push_back(sinf);
414  }
415  }
416  return pref_servers;
417 }
418 
420 {
421  const std::string res = preferences::get("host");
422  if(res.empty()) {
423  return server_list().front().address;
424  } else {
425  return res;
426  }
427 }
428 
429 void set_network_host(const std::string& host)
430 {
431  preferences::set("host", host);
432 }
433 
434 unsigned int get_ping_timeout()
435 {
436  return lexical_cast_default<unsigned>(preferences::get("ping_timeout"), 0);
437 }
438 
440 {
441  if(!preferences::get("campaign_server").empty()) {
442  return preferences::get("campaign_server");
443  } else {
444  return "add-ons.wesnoth.org";
445  }
446 }
447 
449 {
450  preferences::set("campaign_server", host);
451 }
452 
454 {
455  const bool have_old_password_format =
456  (!preferences::have_setting("password_is_wrapped")) && preferences::have_setting("password");
457  return have_old_password_format ? false : preferences::get("password_is_wrapped", true);
458 }
459 
460 void set_wrap_password(bool wrap)
461 {
462  preferences::set("password_is_wrapped", wrap);
463 }
464 
466 {
467  const bool have_old_login_format =
468  (!preferences::have_setting("login_is_wrapped")) && preferences::have_setting("login");
469  return have_old_login_format ? false : preferences::get("login_is_wrapped", true);
470 }
471 
472 void set_wrap_login(bool wrap)
473 {
474  preferences::set("login_is_wrapped", wrap);
475 }
476 
478 {
480 #ifdef _WIN32
481  wchar_t buffer[300];
482  DWORD size = 300;
483  if(GetUserNameW(buffer,&size)) {
484  //size includes a terminating null character.
485  assert(size > 0);
486  res = unicode_cast<utf8::string>(boost::iterator_range<wchar_t*>(buffer, buffer + size - 1));
487  }
488 #else
489  if(char* const login = getenv("USER")) {
490  res = login;
491  }
492 #endif
493  return res;
494 }
495 
497 {
498  const std::string res = preferences::get("login");
499  if(res.empty() || res == EMPTY_WRAPPED_STRING) {
501  if(!login.empty()) {
502  return login;
503  }
504 
505  if(res.empty()) {
506  return _("player");
507  }
508  }
509 
510  if(!wrap_login()) {
511  return res;
512  } else {
513  return parse_wrapped_credentials_field(res);
514  }
515 }
516 
517 void set_login(const std::string& username)
518 {
519  set_wrap_login(true);
520  preferences::set("login", wrap_credentials_field_value(username));
521 }
522 
523 namespace prv {
525 }
526 
528 {
529  if(remember_password()) {
530  const std::string saved_pass = preferences::get("password");
531  if(!wrap_password()) {
532  return saved_pass;
533  } else {
534  return parse_wrapped_credentials_field(saved_pass);
535  }
536  } else {
537  return prv::password;
538  }
539 }
540 
542 {
544  if(remember_password()) {
545  set_wrap_password(true);
546  preferences::set("password", wrap_credentials_field_value(password));
547  }
548 }
549 
551 {
552  return preferences::get("remember_password", false);
553 }
554 
555 void set_remember_password(bool remember)
556 {
557  preferences::set("remember_password", remember);
558  preferences::set("password", remember ? prv::password : "");
559 }
560 
562 {
563  return preferences::get("turn_dialog", false);
564 }
565 
566 void set_turn_dialog(bool ison)
567 {
568  preferences::set("turn_dialog", ison);
569 }
570 
572 {
573  return preferences::get("enable_planning_mode_on_start", false);
574 }
575 
577 {
578  preferences::set("enable_planning_mode_on_start", value);
579 }
580 
582 {
583  return preferences::get("hide_whiteboard", false);
584 }
585 
587 {
588  preferences::set("hide_whiteboard", value);
589 }
590 
592 {
593  return preferences::get("show_combat", true);
594 }
595 
597 {
598  return preferences::get("allow_observers", true);
599 }
600 
602 {
603  preferences::set("allow_observers", value);
604 }
605 
607 {
608  return preferences::get("registered_users_only", false);
609 }
610 
612 {
613  preferences::set("registered_users_only", value);
614 }
615 
617 {
618  return preferences::get("shuffle_sides", false);
619 }
620 
622 {
623  preferences::set("shuffle_sides", value);
624 }
625 
627  return preferences::get("random_faction_mode");
628 }
629 
631  preferences::set("random_faction_mode", value);
632 }
633 
635 {
636  return preferences::get("mp_use_map_settings", true);
637 }
638 
640 {
641  preferences::set("mp_use_map_settings", value);
642 }
643 
645 {
646  return lexical_cast_default<int>(preferences::get("mp_server_warning_disabled"), 0);
647 }
648 
650 {
651  preferences::set("mp_server_warning_disabled", value);
652 }
653 
655 {
656  if (path.empty())
657  {
658  preferences::clear("mp_server_program_name");
659  }
660  else
661  {
662  preferences::set("mp_server_program_name", path);
663  }
664 }
665 
667 {
668  return preferences::get("mp_server_program_name");
669 }
670 
672 {
673  return preferences::get("mp_random_start_time", true);
674 }
675 
677 {
678  preferences::set("mp_random_start_time", value);
679 }
680 
681 bool fog()
682 {
683  return preferences::get("mp_fog", true);
684 }
685 
686 void set_fog(bool value)
687 {
688  preferences::set("mp_fog", value);
689 }
690 
691 bool shroud()
692 {
693  return preferences::get("mp_shroud", false);
694 }
695 
696 void set_shroud(bool value)
697 {
698  preferences::set("mp_shroud", value);
699 }
700 
701 int turns()
702 {
703  return settings::get_turns(preferences::get("mp_turns"));
704 }
705 
706 void set_turns(int value)
707 {
708  preferences::set("mp_turns", value);
709 }
710 
711 const config& options()
712 {
713  if (options_initialized) {
714  return option_values;
715  }
716 
717  if (!preferences::get_child("options")) {
718  // It may be an invalid config, which would cause problems in
719  // multiplayer_create, so let's replace it with an empty but valid
720  // config
721  option_values = config();
722  } else {
723  option_values = preferences::get_child("options");
724  }
725 
726  options_initialized = true;
727 
728  return option_values;
729 }
730 
732 {
733  preferences::set_child("options", values);
734  options_initialized = false;
735 }
736 
738 {
739  return preferences::get("skip_mp_replay", false);
740 }
741 
743 {
744  preferences::set("skip_mp_replay", value);
745 }
746 
748 {
749  return preferences::get("blindfold_replay", false);
750 }
751 
753 {
754  preferences::set("blindfold_replay", value);
755 }
756 
757 bool countdown()
758 {
759  return preferences::get("mp_countdown", false);
760 }
761 
763 {
764  preferences::set("mp_countdown", value);
765 }
766 
768 {
769  return lexical_cast_in_range<int>
770  (preferences::get("mp_countdown_init_time"), 270, 0, 1500);
771 }
772 
774 {
775  preferences::set("mp_countdown_init_time", value);
776 }
777 
779 {
780  return lexical_cast_in_range<int>(
781  preferences::get("mp_countdown_reservoir_time"), 330, 30, 1500);
782 }
783 
785 {
786  preferences::set("mp_countdown_reservoir_time", value);
787 }
788 
790 {
791  return lexical_cast_in_range<int>(
792  preferences::get("mp_countdown_turn_bonus"), 60, 0, 300);
793 }
794 
796 {
797  preferences::set("mp_countdown_turn_bonus", value);
798 }
799 
801 {
802  return lexical_cast_in_range<int>(
803  preferences::get("mp_countdown_action_bonus"), 13, 0, 30);
804 }
805 
807 {
808  preferences::set("mp_countdown_action_bonus", value);
809 }
810 
812 {
813  return settings::get_village_gold(preferences::get("mp_village_gold"));
814 }
815 
817 {
818  preferences::set("mp_village_gold", value);
819 }
820 
822 {
823  return settings::get_village_support(preferences::get("mp_village_support"));
824 }
825 
827 {
828  preferences::set("mp_village_support", std::to_string(value));
829 }
830 
832 {
833  return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
834 }
835 
837 {
838  preferences::set("mp_xp_modifier", value);
839 }
840 
842 {
843  return preferences::get("mp_era");
844 }
845 
847 {
848  preferences::set("mp_era", value);
849 }
850 
852 {
853  return preferences::get("mp_level");
854 }
855 
857 {
858  preferences::set("mp_level", value);
859 }
860 
862 {
863  return lexical_cast_default<int>(preferences::get("mp_level_type"), 0);
864 }
865 
867 {
868  preferences::set("mp_level_type", value);
869 }
870 
871 const std::vector<std::string>& modifications(bool mp)
872 {
873  if ((!mp_modifications_initialized && mp) || (!sp_modifications_initialized && !mp))
874  initialize_modifications(mp);
875 
876  return mp ? mp_modifications : sp_modifications;
877 }
878 
879 void set_modifications(const std::vector<std::string>& value, bool mp)
880 {
881  if (mp) {
882  preferences::set("mp_modifications", utils::join(value, ","));
883  mp_modifications_initialized = false;
884  } else {
885  preferences::set("sp_modifications", utils::join(value, ","));
886  sp_modifications_initialized = false;
887  }
888 
889 }
890 
892 {
893  return preferences::get("show_ai_moves", true);
894 }
895 
897 {
898  preferences::set("show_ai_moves", value);
899 }
900 
902 {
903  preferences::set("show_side_colors", value);
904 }
905 
907 {
908  return preferences::get("show_side_colors", true);
909 }
910 
912 {
913  preferences::set("save_replays", value);
914 }
915 
917 {
918  return preferences::get("save_replays", true);
919 }
920 
922 {
923  preferences::set("delete_saves", value);
924 }
925 
927 {
928  return preferences::get("delete_saves", false);
929 }
930 
932 {
933  preferences::set("ask_delete", value);
934 }
935 
937 {
938  return preferences::get("ask_delete", true);
939 }
940 
942 {
943  preferences::set("ally_sighted_interrupts", value);
944 }
945 
947 {
948  return preferences::get("ally_sighted_interrupts", true);
949 }
950 
952 {
953  return lexical_cast_default<int>(preferences::get("auto_save_max"), 10);
954 }
955 
957 {
958  preferences::set("auto_save_max", value);
959 }
960 
962 {
963  if(CVideo::get_singleton().non_interactive()) {
964  static const std::string null_theme = "null";
965  return null_theme;
966  }
967 
968  std::string res = preferences::get("theme");
969  if(res.empty()) {
970 #ifndef PANDORA
971  return "Default";
972 #else
973  return "Pandora";
974 #endif
975  }
976 
977  return res;
978 }
979 
981 {
982  if(theme != "null") {
983  preferences::set("theme", theme);
984  }
985 }
986 
988 {
989  return preferences::get("floating_labels", true);
990 }
991 
993 {
994  preferences::set("floating_labels", value);
995 }
996 
998 {
999  return message_private_on;
1000 }
1001 
1003 {
1004  message_private_on = value;
1005 }
1006 
1008 {
1009  return haloes;
1010 }
1011 
1013 {
1014  haloes = value;
1015  preferences::set("show_haloes", value);
1016 }
1017 
1019 {
1020  const std::string& choice =
1021  preferences::get("compress_saves");
1022 
1023  // "yes" was used in 1.11.7 and earlier; the compress_saves
1024  // option used to be a toggle for gzip in those versions.
1025  if(choice.empty() || choice == "gzip" || choice == "yes") {
1026  return compression::GZIP;
1027  } else if(choice == "bzip2") {
1028  return compression::BZIP2;
1029  } else if(choice == "none" || choice == "no") { // see above
1030  return compression::NONE;
1031  } /*else*/
1032 
1033  // In case the preferences file was created by a later version
1034  // supporting some algorithm we don't; although why would anyone
1035  // playing a game need more algorithms, really...
1036  return compression::GZIP;
1037 }
1038 
1040  if (chat_timestamping()) {
1042  return lg::get_timestamp(t, _("[%H:%M]")) + " ";
1043  }
1044  else {
1045  return lg::get_timestamp(t, _("[%I:%M %p]")) + " ";
1046  }
1047  }
1048  return "";
1049 }
1050 
1052  return preferences::get("chat_timestamp", false);
1053 }
1054 
1056  preferences::set("chat_timestamp", value);
1057 }
1058 
1060 {
1061  return lexical_cast_default<int>(preferences::get("chat_lines"), 6);
1062 }
1063 
1064 void set_chat_lines(int lines)
1065 {
1066  preferences::set("chat_lines", lines);
1067 }
1068 
1069 void set_chat_message_aging(const int aging)
1070 {
1071  preferences::set("chat_message_aging", aging);
1072 }
1073 
1075 {
1076  return lexical_cast_default<int>(preferences::get("chat_message_aging"), 20);
1077 }
1078 
1080 {
1081  preferences::set("max_wml_menu_items", max);
1082 }
1083 
1085 {
1086  return lexical_cast_default<int>(preferences::get("max_wml_menu_items"), 7);
1087 }
1088 
1090  return preferences::get("show_all_units_in_help", false);
1091 }
1092 
1094  preferences::set("show_all_units_in_help", value);
1095 }
1096 
1097 std::set<std::string> &encountered_units() {
1098  return encountered_units_set;
1099 }
1100 
1101 std::set<t_translation::t_terrain> &encountered_terrains() {
1102  return encountered_terrains_set;
1103 }
1104 
1106  return preferences::get("custom_command");
1107 }
1108 
1109 void set_custom_command(const std::string& command) {
1110  preferences::set("custom_command", command);
1111 }
1112 
1113 /**
1114  * Returns a pointer to the history vector associated with given id
1115  * making a new one if it doesn't exist.
1116  *
1117  * @todo FIXME only used for gui2. Could be used for the above histories.
1118  */
1119 std::vector<std::string>* get_history(const std::string& id) {
1120  return &history_map[id];
1121 }
1122 
1124 {
1125  std::string confirmation = preferences::get("confirm_end_turn");
1126 
1127  if (confirmation == "green" || confirmation == "yes")
1128  return true;
1129  return false;
1130 }
1131 
1133 {
1134  return preferences::get("confirm_end_turn") == "yellow";
1135 }
1136 
1138 {
1139  //This is very non-intrusive so it is on by default
1140  const std::string confirmation = preferences::get("confirm_end_turn");
1141  return confirmation == "no_moves" || confirmation.empty();
1142 }
1143 
1144 
1145 void encounter_recruitable_units(const std::vector<team>& teams){
1146  for (std::vector<team>::const_iterator help_team_it = teams.begin();
1147  help_team_it != teams.end(); ++help_team_it) {
1148  help_team_it->log_recruitable();
1149  encountered_units_set.insert(help_team_it->recruits().begin(), help_team_it->recruits().end());
1150  }
1151 }
1152 
1154  for (unit_map::const_iterator help_unit_it = units.begin();
1155  help_unit_it != units.end(); ++help_unit_it) {
1156  encountered_units_set.insert(help_unit_it->type_id());
1157  }
1158 }
1159 
1160 static void encounter_recallable_units(const std::vector<team>& teams){
1161  for (const team& t : teams) {
1162  for (const unit_const_ptr & u : t.recall_list()) {
1163  encountered_units_set.insert(u->type_id());
1164  }
1165  }
1166 }
1167 
1169  for (int map_x = 0; map_x < map.w(); ++map_x) {
1170  for (int map_y = 0; map_y < map.h(); ++map_y) {
1171  const t_translation::t_terrain t = map.get_terrain(map_location(map_x, map_y));
1173  const t_translation::t_list& underlaying_list = map.underlying_union_terrain(map_location(map_x, map_y));
1174  for (std::vector<t_translation::t_terrain>::const_iterator ut = underlaying_list.begin(); ut != underlaying_list.end(); ++ut) {
1175  preferences::encountered_terrains().insert(*ut);
1176  };
1177  }
1178  }
1179 }
1180 
1181 void encounter_all_content(const game_board & gameboard_) {
1186 }
1187 
1189 {
1190  nick_ = cfg["nick"].str();
1191  status_ = cfg["status"].str();
1192  notes_ = cfg["notes"].str();
1193 }
1194 
1196 {
1197  item["nick"] = nick_;
1198  item["status"] = status_;
1199  item["notes"] = notes_;
1200 }
1201 
1202 } // preferences namespace
void set_password(const std::string &password)
child_itors child_range(const std::string &key)
Definition: config.cpp:613
Game board class.
Definition: game_board.hpp:55
void set_hide_whiteboard(bool value)
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
void set_campaign_server(const std::string &host)
virtual const unit_map & units() const
Definition: game_board.hpp:99
unit_iterator end()
Definition: map.hpp:311
void set_village_support(int value)
bool remember_password()
void set_wrap_password(bool wrap)
void set_show_haloes(bool value)
std::string random_faction_mode()
static void encounter_recallable_units(const std::vector< team > &teams)
unsigned int get_ping_timeout()
void set_countdown_action_bonus(int value)
void set_countdown_turn_bonus(int value)
std::string era()
t_list read_list(const std::string &str, const t_layer filler)
Reads a list of terrains from a string, when reading the.
std::string get_timestamp(const time_t &t, const std::string &format)
Definition: log.cpp:174
void set_shroud(bool value)
static lg::log_domain log_config("config")
void set_countdown_init_time(int value)
std::string campaign_server()
const GLfloat * c
Definition: glew.h:12741
int pos
Definition: formula.cpp:800
void set_mp_server_warning_disabled(int value)
bool wrap_login()
Returns whether the MP username is stored wrapped in markers.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
void set_remember_password(bool remember)
void set_show_floating_labels(bool value)
void set_options(const config &values)
bool wrap_password()
Returns whether the password is stored wrapped in markers.
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
const std::map< std::string, acquaintance > & get_acquaintances()
bool is_campaign_completed(const std::string &campaign_id)
void set_show_side_colors(bool value)
std::string network_host()
void load_from_config(const config &cfg)
void parse_admin_authentication(const std::string &sender, const std::string &message)
void clear(const std::string &key)
void set_login(const std::string &username)
void _set_lobby_joins(int show)
void set_chat_lines(int lines)
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
Definition: settings.cpp:42
unit_iterator begin()
Definition: map.hpp:308
std::string status_
status (e.g., "friend", "ignore")
void set_random_faction_mode(const std::string &value)
static CVideo & get_singleton()
Definition: video.hpp:75
static void load_acquaintances()
void set(const std::string &key, bool value)
virtual const std::vector< team > & teams() const
Definition: game_board.hpp:97
void set_network_host(const std::string &host)
#define d
void set_sound_volume(int vol)
void clear_children(const std::string &key)
Definition: config.cpp:820
void set_countdown(bool value)
const t_translation::t_list & underlying_union_terrain(const map_location &loc) const
Definition: map.cpp:61
GLdouble GLdouble t
Definition: glew.h:1366
bool remove_acquaintance(const std::string &nick)
void set_interrupt_when_ally_sighted(bool value)
std::string address
may include ':' followed by port number
Definition: game_config.hpp:66
void set_registered_users_only(bool value)
void set_max_wml_menu_items(int max)
GLboolean GLenum GLenum GLvoid * values
Definition: glew.h:3799
GLdouble l
Definition: glew.h:6966
int get_village_support(const std::string &value)
Gets the village unit level support.
Definition: settings.cpp:47
void set_mp_server_program_name(const std::string &path)
This module controls the multiplayer lobby.
static std::vector< team > *& teams
Definition: team.cpp:50
void set_chat_message_aging(const int aging)
const config & options()
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void set_turn_dialog(bool ison)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
int countdown_turn_bonus()
void set_level_type(int value)
std::string get(const std::string &key)
void set_custom_command(const std::string &command)
GLsizei const char ** path
Definition: glew.h:4654
std::string level()
static void save_acquaintances()
void set_save_replays(bool value)
bool is_friend(const std::string &nick)
GLuint id
Definition: glew.h:1647
std::string write_list(const t_list &list)
Writes a list of terrains to a string, only writes the new format.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void set_theme(const std::string &theme)
void encounter_map_terrain(const gamemap &map)
General settings and defaults for scenarios.
void encounter_start_units(const unit_map &units)
std::string theme()
static std::string get_system_username()
int countdown_reservoir_time()
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_enable_whiteboard_mode_on_start(bool value)
int w() const
Effective map width.
Definition: map.hpp:105
void set_music_volume(int vol)
std::set< t_translation::t_terrain > & encountered_terrains()
Encapsulates the map of the game.
Definition: map.hpp:37
const std::vector< game_config::server_info > & server_list()
void erase(const std::string &key)
void set_random_start_time(bool value)
config & add_child(const std::string &key)
Definition: config.cpp:743
const std::string & get_status() const
Modify, read and display user preferences.
bool registered_users_only()
bool show_all_units_in_help()
void set_blindfold_replay(bool value)
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:135
void set_message_private(bool value)
bool is_ignored(const std::string &nick)
void set_chat_timestamping(bool value)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
GLuint buffer
Definition: glew.h:1648
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Definition: tip.cpp:133
void set_level(const std::string &value)
Encapsulates the map of the game.
Definition: location.hpp:38
std::string login()
bool add_friend(const std::string &nick, const std::string &notes)
bool add_ignore(const std::string &nick, const std::string &reason)
admin_authentication_reset()
Default constructor, defined out of line to work around a warning in gcc 4.5.2.
void set_child(const std::string &key, const config &val)
void set_allow_observers(bool value)
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...
GLuint res
Definition: glew.h:9258
int mp_server_warning_disabled()
std::string get_mp_server_program_name()
int h() const
Effective map height.
Definition: map.hpp:108
bool interrupt_when_ally_sighted()
void set_delete_saves(bool value)
Definition: theme.hpp:37
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
void set_wrap_login(bool wrap)
void encounter_all_content(const game_board &gameboard_)
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
size_t i
Definition: function.cpp:1057
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
Definition: settings.cpp:52
config * get_prefs()
void set_skip_mp_replay(bool value)
std::set< std::string > & encountered_units()
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
const std::string & get_nick() const
const config & get_child(const std::string &key)
void set_turns(int value)
void set_autosavemax(int value)
virtual const gamemap & map() const
Definition: game_board.hpp:98
compression::format save_compression_format()
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:341
void set_show_all_units_in_help(bool value)
GLsizeiptr size
Definition: glew.h:1649
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:3448
int sound_volume()
bool show_floating_labels()
const std::vector< std::string > & modifications(bool mp)
bool have_setting(const std::string &key)
std::string notes_
notes on the acquaintance
std::string get_chat_timestamp(const time_t &t)
#define ERR_CFG
void set_modifications(const std::vector< std::string > &value, bool mp)
bool enable_whiteboard_mode_on_start()
Standard logging facilities (interface).
int countdown_action_bonus()
Container associating units to locations.
Definition: map.hpp:90
void set_show_ai_moves(bool value)
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
#define c
Definition: glew.h:12743
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
void set_era(const std::string &value)
void set_shuffle_sides(bool value)
void set_fog(bool value)
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
void set_ask_delete_saves(bool value)
void encounter_recruitable_units(const std::vector< team > &teams)
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void set_countdown_reservoir_time(int value)
bool random_start_time()
std::string custom_command()
std::string password()
void set_xp_modifier(int value)
int get_turns(const std::string &value)
Gets the number of turns.
Definition: settings.cpp:29
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool use_twelve_hour_clock_format()
unit_map * units
Definition: resources.cpp:35
void set_village_gold(int value)
std::vector< server_info > server_list
void set_use_map_settings(bool value)
int music_volume()
std::string string
std::vector< t_terrain > t_list
Definition: translation.hpp:75
std::string nick_
acquaintance's MP nick