The Battle for Wesnoth  1.15.2+dev
game.hpp
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 #pragma once
16 
17 class game_board;
18 class gamemap;
19 class team;
20 class unit_map;
21 
22 #include "preferences/general.hpp"
23 #include "game_config.hpp"
24 
26 
27 #include <set>
28 #include <vector>
29 
30 namespace preferences {
31 
32 class acquaintance;
33 
34  struct manager
35  {
36  manager();
37  ~manager();
38 
40  };
41 
42  bool is_authenticated();
43  void parse_admin_authentication(const std::string& sender, const std::string& message);
44 
45  /**
46  * Used to reset is_authenticated flag after disconnecting.
47  *
48  * @todo FIXME: is_authenticated shouldn't be a preferences function. Also,
49  * the name is misleading.
50  */
52  {
53  /**
54  * Default constructor, defined out of line to work around a warning in
55  * gcc 4.5.2
56  */
59  };
60 
61  bool parse_should_show_lobby_join(const std::string& sender, const std::string& message);
62  int lobby_joins();
63  void _set_lobby_joins(int show);
65 
66  const std::map<std::string, acquaintance> & get_acquaintances();
67  const std::string get_ignored_delim();
68  std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter);
69  std::pair<preferences::acquaintance*, bool> add_acquaintance(const std::string& nick, const std::string& mode, const std::string& notes);
70  void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level);
71  bool remove_acquaintance(const std::string& nick);
72  bool is_friend(const std::string& nick);
73  bool is_ignored(const std::string& nick);
74  bool is_campaign_completed(const std::string& campaign_id);
75  bool is_campaign_completed(const std::string& campaign_id, const std::string &difficulty_level);
76 
77  const std::vector<game_config::server_info>& builtin_servers_list();
78  std::vector<game_config::server_info> user_servers_list();
79  void set_user_servers_list(const std::vector<game_config::server_info>& value);
80 
81  std::string network_host();
82  void set_network_host(const std::string& host);
83 
84  std::string campaign_server();
85  void set_campaign_server(const std::string& host);
86 
87  bool turn_dialog();
88  void set_turn_dialog(bool ison);
89 
91  void set_enable_whiteboard_mode_on_start(bool value);
92 
93  bool hide_whiteboard();
94  void set_hide_whiteboard(bool value);
95 
96  bool show_combat();
97 
98  bool allow_observers();
99  void set_allow_observers(bool value);
100 
101  bool registered_users_only();
102  void set_registered_users_only(bool value);
103 
104  bool shuffle_sides();
105  void set_shuffle_sides(bool value);
106 
107  std::string random_faction_mode();
108  void set_random_faction_mode(const std::string & value);
109 
110  bool use_map_settings();
111  void set_use_map_settings(bool value);
112 
114  void set_mp_server_warning_disabled(int value);
115 
116  void set_mp_server_program_name(const std::string&);
117  std::string get_mp_server_program_name();
118 
119  bool random_start_time();
120  void set_random_start_time(bool value);
121 
122  bool fog();
123  void set_fog(bool value);
124 
125  bool shroud();
126  void set_shroud(bool value);
127 
128  int turns();
129  void set_turns(int value);
130 
131  const config& options();
132  void set_options(const config& values);
133 
134  bool skip_mp_replay();
135  void set_skip_mp_replay(bool value);
136 
137  bool blindfold_replay();
138  void set_blindfold_replay(bool value);
139 
140  bool countdown();
141  void set_countdown(bool value);
142  int countdown_init_time();
143  void set_countdown_init_time(int value);
144  int countdown_turn_bonus();
145  void set_countdown_turn_bonus(int value);
147  void set_countdown_reservoir_time(int value);
149  void set_countdown_action_bonus(int value);
150 
151  int village_gold();
152  void set_village_gold(int value);
153 
154  int village_support();
155  void set_village_support(int value);
156 
157  int xp_modifier();
158  void set_xp_modifier(int value);
159 
160  std::string era();
161  void set_era(const std::string& value);
162 
163  std::string level();
164  void set_level(const std::string& value);
165  int level_type();
166  void set_level_type(int value);
167 
168  const std::vector<std::string>& modifications(bool mp=true);
169  void set_modifications(const std::vector<std::string>& value, bool mp=true);
170 
171  bool skip_ai_moves();
172  void set_skip_ai_moves(bool value);
173 
174  void set_show_side_colors(bool value);
175  bool show_side_colors();
176 
177  bool save_replays();
178  void set_save_replays(bool value);
179 
180  bool delete_saves();
181  void set_delete_saves(bool value);
182 
183  void set_ask_delete_saves(bool value);
184  bool ask_delete_saves();
185 
186  void set_interrupt_when_ally_sighted(bool value);
188 
189  void set_autosavemax(int value);
190  int autosavemax();
191 
192  const int INFINITE_AUTO_SAVES = 61;
193 
194  bool show_floating_labels();
195  void set_show_floating_labels(bool value);
196 
197  bool message_private();
198  void set_message_private(bool value);
199 
200  // Multiplayer functions
201  std::string get_chat_timestamp(const std::time_t& t);
202  bool chat_timestamping();
203  void set_chat_timestamping(bool value);
204 
205  int chat_lines();
206  void set_chat_lines(int lines);
207 
208  int chat_message_aging();
209  void set_chat_message_aging(const int aging);
210 
211  bool show_all_units_in_help();
212  void set_show_all_units_in_help(bool value);
213 
215 
216  std::set<std::string> &encountered_units();
217  std::set<t_translation::terrain_code> &encountered_terrains();
218 
219  std::string custom_command();
220  void set_custom_command(const std::string& command);
221 
222  std::vector<std::string>* get_history(const std::string& id);
223 
224  void set_theme(const std::string& theme);
225  std::string theme();
226 
227  // Ask for end turn confirmation
228  bool yellow_confirm();
229  bool green_confirm();
230  bool confirm_no_moves();
231 
232  // Add all recruitable units as encountered so that information
233  // about them are displayed to the user in the help system.
234  void encounter_recruitable_units(const std::vector<team>& teams);
235  // Add all units that exist at the start to the encountered units so
236  // that information about them are displayed to the user in the help
237  // system.
238  void encounter_start_units(const unit_map& units);
239  // Add all units that are recallable as encountered units.
240  void encounter_recallable_units(std::vector<team>& teams);
241  // Add all terrains on the map as encountered terrains.
242  void encounter_map_terrain(const gamemap& map);
243 
244  // Calls all of the above functions on the current game board
245  void encounter_all_content(const game_board & gb);
246 
248 public:
249 
251  {
252  }
253 
254  explicit acquaintance(const config& cfg)
255  {
256  load_from_config(cfg);
257  }
258 
260  const std::string& nick
261  , const std::string& status
262  , const std::string& notes)
263  : nick_(nick)
264  , status_(status)
265  , notes_(notes)
266  {
267 
268  }
269 
270  void load_from_config(const config& cfg);
271 
272  const std::string& get_nick() const { return nick_; }
273  const std::string& get_status() const { return status_; }
274  const std::string& get_notes() const { return notes_; }
275 
276  void save(config& cfg);
277 
278 private:
279 
280  /** acquaintance's MP nick */
281  std::string nick_;
282 
283  /**status (e.g., "friend", "ignore") */
284  std::string status_;
285 
286  /** notes on the acquaintance */
287  std::string notes_;
288 
289 };
290 
291 }
Game board class.
Definition: game_board.hpp:50
void set_hide_whiteboard(bool value)
Definition: game.cpp:468
int autosavemax()
Definition: game.cpp:833
void set_campaign_server(const std::string &host)
Definition: game.cpp:438
void set_village_support(int value)
Definition: game.cpp:708
acquaintance(const config &cfg)
Definition: game.hpp:254
std::string random_faction_mode()
Definition: game.cpp:508
bool message_private()
Definition: game.cpp:875
static void encounter_recallable_units(const std::vector< team > &teams)
Definition: game.cpp:1017
void set_countdown_action_bonus(int value)
Definition: game.cpp:688
void set_countdown_turn_bonus(int value)
Definition: game.cpp:677
std::string era()
Definition: game.cpp:723
hotkey_ptr load_from_config(const config &cfg)
Create and instantiate a hotkey from a config element.
void set_shroud(bool value)
Definition: game.cpp:578
void set_countdown_init_time(int value)
Definition: game.cpp:655
bool is_authenticated()
Definition: game.cpp:181
int xp_modifier()
Definition: game.cpp:713
std::string campaign_server()
Definition: game.cpp:429
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:531
void set_show_floating_labels(bool value)
Definition: game.cpp:870
void set_options(const config &values)
Definition: game.cpp:613
int lobby_joins()
Definition: game.cpp:357
const std::map< std::string, acquaintance > & get_acquaintances()
Definition: game.cpp:225
bool is_campaign_completed(const std::string &campaign_id)
Definition: game.cpp:333
const int INFINITE_AUTO_SAVES
Definition: game.hpp:192
const std::string get_ignored_delim()
Definition: game.cpp:230
bool shuffle_sides()
Definition: game.cpp:498
void set_show_side_colors(bool value)
Definition: game.cpp:783
std::string network_host()
Definition: game.cpp:414
bool hide_whiteboard()
Definition: game.cpp:463
void parse_admin_authentication(const std::string &sender, const std::string &message)
Definition: game.cpp:185
void _set_lobby_joins(int show)
Definition: game.cpp:372
void set_chat_lines(int lines)
Definition: game.cpp:931
int chat_lines()
Definition: game.cpp:926
std::string status_
status (e.g., "friend", "ignore")
Definition: game.hpp:284
void set_random_faction_mode(const std::string &value)
Definition: game.cpp:512
void set_network_host(const std::string &host)
Definition: game.cpp:424
bool show_side_colors()
Definition: game.cpp:788
void set_countdown(bool value)
Definition: game.cpp:644
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:281
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:823
int countdown_init_time()
Definition: game.cpp:649
bool yellow_confirm()
Definition: game.cpp:989
void set_registered_users_only(bool value)
Definition: game.cpp:493
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:536
bool fog()
Definition: game.cpp:563
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:50
bool confirm_no_moves()
Definition: game.cpp:994
void set_chat_message_aging(const int aging)
Definition: game.cpp:936
const config & options()
Definition: game.cpp:593
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:448
int countdown_turn_bonus()
Definition: game.cpp:671
void set_level_type(int value)
Definition: game.cpp:748
void set_custom_command(const std::string &command)
Definition: game.cpp:966
const std::vector< game_config::server_info > & builtin_servers_list()
Definition: game.cpp:383
int village_support()
Definition: game.cpp:703
std::string level()
Definition: game.cpp:733
void set_save_replays(bool value)
Definition: game.cpp:793
bool is_friend(const std::string &nick)
Definition: game.cpp:303
base_manager base
Definition: game.hpp:39
void set_theme(const std::string &theme)
Definition: game.cpp:858
void encounter_map_terrain(const gamemap &map)
Definition: game.cpp:1025
void encounter_start_units(const unit_map &units)
Definition: game.cpp:1010
const std::string & get_nick() const
Definition: game.hpp:272
std::string theme()
Definition: game.cpp:843
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:259
int countdown_reservoir_time()
Definition: game.cpp:660
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:458
bool blindfold_replay()
Definition: game.cpp:629
Encapsulates the map of the game.
Definition: map.hpp:36
void set_random_start_time(bool value)
Definition: game.cpp:558
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:958
void set_user_servers_list(const std::vector< game_config::server_info > &value)
Definition: game.cpp:402
Modify, read and display user preferences.
bool show_combat()
Definition: game.cpp:473
bool registered_users_only()
Definition: game.cpp:488
int village_gold()
Definition: game.cpp:693
Used to reset is_authenticated flag after disconnecting.
Definition: game.hpp:51
bool show_all_units_in_help()
Definition: game.cpp:946
void set_blindfold_replay(bool value)
Definition: game.cpp:634
bool chat_timestamping()
Definition: game.cpp:918
void set_message_private(bool value)
Definition: game.cpp:880
bool is_ignored(const std::string &nick)
Definition: game.cpp:316
void set_chat_timestamping(bool value)
Definition: game.cpp:922
void set_level(const std::string &value)
Definition: game.cpp:738
void set_allow_observers(bool value)
Definition: game.cpp:483
bool countdown()
Definition: game.cpp:639
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:976
bool shroud()
Definition: game.cpp:573
int mp_server_warning_disabled()
Definition: game.cpp:526
std::string get_mp_server_program_name()
Definition: game.cpp:548
bool interrupt_when_ally_sighted()
Definition: game.cpp:828
void set_delete_saves(bool value)
Definition: game.cpp:803
Definition: theme.hpp:38
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
Definition: game.cpp:329
void encounter_all_content(const game_board &gameboard_)
Definition: game.cpp:1036
bool use_map_settings()
Definition: game.cpp:516
bool delete_saves()
Definition: game.cpp:808
void set_skip_mp_replay(bool value)
Definition: game.cpp:624
std::set< std::string > & encountered_units()
Definition: game.cpp:954
const std::string & get_status() const
Definition: game.hpp:273
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:245
bool ask_delete_saves()
Definition: game.cpp:818
bool skip_mp_replay()
Definition: game.cpp:619
const std::string & get_notes() const
Definition: game.hpp:274
static void save(LexState *ls, int c)
Definition: llex.cpp:57
void set_turns(int value)
Definition: game.cpp:588
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:906
void set_autosavemax(int value)
Definition: game.cpp:838
compression::format save_compression_format()
Definition: game.cpp:885
void set_show_all_units_in_help(bool value)
Definition: game.cpp:950
bool allow_observers()
Definition: game.cpp:478
bool green_confirm()
Definition: game.cpp:980
int turns()
Definition: game.cpp:583
bool show_floating_labels()
Definition: game.cpp:865
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:753
double t
Definition: astarsearch.cpp:64
std::string notes_
notes on the acquaintance
Definition: game.hpp:287
void set_modifications(const std::vector< std::string > &value, bool mp)
Definition: game.cpp:761
int chat_message_aging()
Definition: game.cpp:941
bool enable_whiteboard_mode_on_start()
Definition: game.cpp:453
int countdown_action_bonus()
Definition: game.cpp:682
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:342
void set_era(const std::string &value)
Definition: game.cpp:728
void set_shuffle_sides(bool value)
Definition: game.cpp:503
void set_fog(bool value)
Definition: game.cpp:568
void set_ask_delete_saves(bool value)
Definition: game.cpp:813
void encounter_recruitable_units(const std::vector< team > &teams)
Definition: game.cpp:1002
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void set_countdown_reservoir_time(int value)
Definition: game.cpp:666
bool random_start_time()
Definition: game.cpp:553
std::vector< game_config::server_info > user_servers_list()
Definition: game.cpp:389
void set_skip_ai_moves(bool value)
Definition: game.cpp:778
std::string custom_command()
Definition: game.cpp:962
void set_xp_modifier(int value)
Definition: game.cpp:718
bool turn_dialog()
Definition: game.cpp:443
void set_village_gold(int value)
Definition: game.cpp:698
void set_use_map_settings(bool value)
Definition: game.cpp:521
bool skip_ai_moves()
Definition: game.cpp:773
acquaintance(const std::string &nick, const std::string &status, const std::string &notes)
Definition: game.hpp:259
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:154
std::string nick_
acquaintance&#39;s MP nick
Definition: game.hpp:281
bool save_replays()
Definition: game.cpp:798
int level_type()
Definition: game.cpp:743