The Battle for Wesnoth  1.15.0+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>& server_list();
78 
79  std::string network_host();
80  void set_network_host(const std::string& host);
81 
82  std::string campaign_server();
83  void set_campaign_server(const std::string& host);
84 
85  bool turn_dialog();
86  void set_turn_dialog(bool ison);
87 
89  void set_enable_whiteboard_mode_on_start(bool value);
90 
91  bool hide_whiteboard();
92  void set_hide_whiteboard(bool value);
93 
94  bool show_combat();
95 
96  bool allow_observers();
97  void set_allow_observers(bool value);
98 
99  bool registered_users_only();
100  void set_registered_users_only(bool value);
101 
102  bool shuffle_sides();
103  void set_shuffle_sides(bool value);
104 
105  std::string random_faction_mode();
106  void set_random_faction_mode(const std::string & value);
107 
108  bool use_map_settings();
109  void set_use_map_settings(bool value);
110 
112  void set_mp_server_warning_disabled(int value);
113 
114  void set_mp_server_program_name(const std::string&);
115  std::string get_mp_server_program_name();
116 
117  bool random_start_time();
118  void set_random_start_time(bool value);
119 
120  bool fog();
121  void set_fog(bool value);
122 
123  bool shroud();
124  void set_shroud(bool value);
125 
126  int turns();
127  void set_turns(int value);
128 
129  const config& options();
130  void set_options(const config& values);
131 
132  bool skip_mp_replay();
133  void set_skip_mp_replay(bool value);
134 
135  bool blindfold_replay();
136  void set_blindfold_replay(bool value);
137 
138  bool countdown();
139  void set_countdown(bool value);
140  int countdown_init_time();
141  void set_countdown_init_time(int value);
142  int countdown_turn_bonus();
143  void set_countdown_turn_bonus(int value);
145  void set_countdown_reservoir_time(int value);
147  void set_countdown_action_bonus(int value);
148 
149  int village_gold();
150  void set_village_gold(int value);
151 
152  int village_support();
153  void set_village_support(int value);
154 
155  int xp_modifier();
156  void set_xp_modifier(int value);
157 
158  std::string era();
159  void set_era(const std::string& value);
160 
161  std::string level();
162  void set_level(const std::string& value);
163  int level_type();
164  void set_level_type(int value);
165 
166  const std::vector<std::string>& modifications(bool mp=true);
167  void set_modifications(const std::vector<std::string>& value, bool mp=true);
168 
169  bool skip_ai_moves();
170  void set_skip_ai_moves(bool value);
171 
172  void set_show_side_colors(bool value);
173  bool show_side_colors();
174 
175  bool save_replays();
176  void set_save_replays(bool value);
177 
178  bool delete_saves();
179  void set_delete_saves(bool value);
180 
181  void set_ask_delete_saves(bool value);
182  bool ask_delete_saves();
183 
184  void set_interrupt_when_ally_sighted(bool value);
186 
187  void set_autosavemax(int value);
188  int autosavemax();
189 
190  const int INFINITE_AUTO_SAVES = 61;
191 
192  bool show_floating_labels();
193  void set_show_floating_labels(bool value);
194 
195  bool message_private();
196  void set_message_private(bool value);
197 
198  bool show_haloes();
199  void set_show_haloes(bool value);
200 
201 
202  // Multiplayer functions
203  std::string get_chat_timestamp(const std::time_t& t);
204  bool chat_timestamping();
205  void set_chat_timestamping(bool value);
206 
207  int chat_lines();
208  void set_chat_lines(int lines);
209 
210  int chat_message_aging();
211  void set_chat_message_aging(const int aging);
212 
213  bool show_all_units_in_help();
214  void set_show_all_units_in_help(bool value);
215 
217 
218  std::set<std::string> &encountered_units();
219  std::set<t_translation::terrain_code> &encountered_terrains();
220 
221  std::string custom_command();
222  void set_custom_command(const std::string& command);
223 
224  std::vector<std::string>* get_history(const std::string& id);
225 
226  void set_theme(const std::string& theme);
227  std::string theme();
228 
229  // Ask for end turn confirmation
230  bool yellow_confirm();
231  bool green_confirm();
232  bool confirm_no_moves();
233 
234  // Add all recruitable units as encountered so that information
235  // about them are displayed to the user in the help system.
236  void encounter_recruitable_units(const std::vector<team>& teams);
237  // Add all units that exist at the start to the encountered units so
238  // that information about them are displayed to the user in the help
239  // system.
240  void encounter_start_units(const unit_map& units);
241  // Add all units that are recallable as encountered units.
242  void encounter_recallable_units(std::vector<team>& teams);
243  // Add all terrains on the map as encountered terrains.
244  void encounter_map_terrain(const gamemap& map);
245 
246  // Calls all of the above functions on the current game board
247  void encounter_all_content(const game_board & gb);
248 
250 public:
251 
253  {
254  }
255 
256  explicit acquaintance(const config& cfg)
257  {
258  load_from_config(cfg);
259  }
260 
262  const std::string& nick
263  , const std::string& status
264  , const std::string& notes)
265  : nick_(nick)
266  , status_(status)
267  , notes_(notes)
268  {
269 
270  }
271 
272  void load_from_config(const config& cfg);
273 
274  const std::string& get_nick() const { return nick_; }
275  const std::string& get_status() const { return status_; }
276  const std::string& get_notes() const { return notes_; }
277 
278  void save(config& cfg);
279 
280 private:
281 
282  /** acquaintance's MP nick */
283  std::string nick_;
284 
285  /**status (e.g., "friend", "ignore") */
286  std::string status_;
287 
288  /** notes on the acquaintance */
289  std::string notes_;
290 
291 };
292 
293 }
Game board class.
Definition: game_board.hpp:50
void set_hide_whiteboard(bool value)
Definition: game.cpp:457
int autosavemax()
Definition: game.cpp:822
void set_campaign_server(const std::string &host)
Definition: game.cpp:427
void set_village_support(int value)
Definition: game.cpp:697
void set_show_haloes(bool value)
Definition: game.cpp:879
acquaintance(const config &cfg)
Definition: game.hpp:256
std::string random_faction_mode()
Definition: game.cpp:497
bool message_private()
Definition: game.cpp:864
static void encounter_recallable_units(const std::vector< team > &teams)
Definition: game.cpp:1017
void set_countdown_action_bonus(int value)
Definition: game.cpp:677
void set_countdown_turn_bonus(int value)
Definition: game.cpp:666
std::string era()
Definition: game.cpp:712
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:567
void set_countdown_init_time(int value)
Definition: game.cpp:644
bool is_authenticated()
Definition: game.cpp:184
int xp_modifier()
Definition: game.cpp:702
std::string campaign_server()
Definition: game.cpp:418
void set_mp_server_warning_disabled(int value)
Definition: game.cpp:520
void set_show_floating_labels(bool value)
Definition: game.cpp:859
void set_options(const config &values)
Definition: game.cpp:602
int lobby_joins()
Definition: game.cpp:360
const std::map< std::string, acquaintance > & get_acquaintances()
Definition: game.cpp:228
bool is_campaign_completed(const std::string &campaign_id)
Definition: game.cpp:336
const int INFINITE_AUTO_SAVES
Definition: game.hpp:190
const std::string get_ignored_delim()
Definition: game.cpp:233
bool shuffle_sides()
Definition: game.cpp:487
void set_show_side_colors(bool value)
Definition: game.cpp:772
std::string network_host()
Definition: game.cpp:403
bool hide_whiteboard()
Definition: game.cpp:452
void parse_admin_authentication(const std::string &sender, const std::string &message)
Definition: game.cpp:188
void _set_lobby_joins(int show)
Definition: game.cpp:375
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:286
void set_random_faction_mode(const std::string &value)
Definition: game.cpp:501
void set_network_host(const std::string &host)
Definition: game.cpp:413
bool show_side_colors()
Definition: game.cpp:777
void set_countdown(bool value)
Definition: game.cpp:633
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:284
void set_interrupt_when_ally_sighted(bool value)
Definition: game.cpp:812
int countdown_init_time()
Definition: game.cpp:638
bool yellow_confirm()
Definition: game.cpp:989
void set_registered_users_only(bool value)
Definition: game.cpp:482
bool show_haloes()
Definition: game.cpp:874
void set_mp_server_program_name(const std::string &path)
Definition: game.cpp:525
bool fog()
Definition: game.cpp:552
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:49
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:582
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:437
int countdown_turn_bonus()
Definition: game.cpp:660
void set_level_type(int value)
Definition: game.cpp:737
void set_custom_command(const std::string &command)
Definition: game.cpp:966
int village_support()
Definition: game.cpp:692
std::string level()
Definition: game.cpp:722
void set_save_replays(bool value)
Definition: game.cpp:782
bool is_friend(const std::string &nick)
Definition: game.cpp:306
base_manager base
Definition: game.hpp:39
void set_theme(const std::string &theme)
Definition: game.cpp:847
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:274
std::string theme()
Definition: game.cpp:832
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:262
int countdown_reservoir_time()
Definition: game.cpp:649
void set_enable_whiteboard_mode_on_start(bool value)
Definition: game.cpp:447
bool blindfold_replay()
Definition: game.cpp:618
Encapsulates the map of the game.
Definition: map.hpp:36
const std::vector< game_config::server_info > & server_list()
Definition: game.cpp:386
void set_random_start_time(bool value)
Definition: game.cpp:547
std::set< t_translation::terrain_code > & encountered_terrains()
Definition: game.cpp:958
Modify, read and display user preferences.
bool show_combat()
Definition: game.cpp:462
bool registered_users_only()
Definition: game.cpp:477
int village_gold()
Definition: game.cpp:682
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:623
bool chat_timestamping()
Definition: game.cpp:918
void set_message_private(bool value)
Definition: game.cpp:869
bool is_ignored(const std::string &nick)
Definition: game.cpp:319
void set_chat_timestamping(bool value)
Definition: game.cpp:922
void set_level(const std::string &value)
Definition: game.cpp:727
void set_allow_observers(bool value)
Definition: game.cpp:472
bool countdown()
Definition: game.cpp:628
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:562
int mp_server_warning_disabled()
Definition: game.cpp:515
std::string get_mp_server_program_name()
Definition: game.cpp:537
bool interrupt_when_ally_sighted()
Definition: game.cpp:817
void set_delete_saves(bool value)
Definition: game.cpp:792
Definition: theme.hpp:38
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
Definition: game.cpp:332
void encounter_all_content(const game_board &gameboard_)
Definition: game.cpp:1036
bool use_map_settings()
Definition: game.cpp:505
bool delete_saves()
Definition: game.cpp:797
void set_skip_mp_replay(bool value)
Definition: game.cpp:613
std::set< std::string > & encountered_units()
Definition: game.cpp:954
const std::string & get_status() const
Definition: game.hpp:275
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Definition: game.cpp:248
bool ask_delete_saves()
Definition: game.cpp:807
bool skip_mp_replay()
Definition: game.cpp:608
const std::string & get_notes() const
Definition: game.hpp:276
static void save(LexState *ls, int c)
Definition: llex.cpp:57
void set_turns(int value)
Definition: game.cpp:577
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:906
void set_autosavemax(int value)
Definition: game.cpp:827
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:467
bool green_confirm()
Definition: game.cpp:980
int turns()
Definition: game.cpp:572
bool show_floating_labels()
Definition: game.cpp:854
const std::vector< std::string > & modifications(bool mp)
Definition: game.cpp:742
double t
Definition: astarsearch.cpp:64
std::string notes_
notes on the acquaintance
Definition: game.hpp:289
void set_modifications(const std::vector< std::string > &value, bool mp)
Definition: game.cpp:750
int chat_message_aging()
Definition: game.cpp:941
bool enable_whiteboard_mode_on_start()
Definition: game.cpp:442
int countdown_action_bonus()
Definition: game.cpp:671
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:345
void set_era(const std::string &value)
Definition: game.cpp:717
void set_shuffle_sides(bool value)
Definition: game.cpp:492
void set_fog(bool value)
Definition: game.cpp:557
void set_ask_delete_saves(bool value)
Definition: game.cpp:802
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:92
void set_countdown_reservoir_time(int value)
Definition: game.cpp:655
bool random_start_time()
Definition: game.cpp:542
void set_skip_ai_moves(bool value)
Definition: game.cpp:767
std::string custom_command()
Definition: game.cpp:962
void set_xp_modifier(int value)
Definition: game.cpp:707
bool turn_dialog()
Definition: game.cpp:432
void set_village_gold(int value)
Definition: game.cpp:687
void set_use_map_settings(bool value)
Definition: game.cpp:510
bool skip_ai_moves()
Definition: game.cpp:762
acquaintance(const std::string &nick, const std::string &status, const std::string &notes)
Definition: game.hpp:261
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:283
bool save_replays()
Definition: game.cpp:787
int level_type()
Definition: game.cpp:732