The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_state.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[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 #ifndef INCL_GAME_STATE_HPP_
16 #define INCL_GAME_STATE_HPP_
17 
18 class config;
19 
20 #include "filter_context.hpp"
21 #include "game_board.hpp"
22 #include "game_data.hpp"
23 #include "tod_manager.hpp"
24 #include "units/id.hpp"
25 
26 #include <boost/scoped_ptr.hpp>
27 #include <boost/shared_ptr.hpp>
28 
29 class game_display;
30 class play_controller;
31 class game_lua_kernel;
32 class reports;
33 
34 namespace game_events { class manager; class wmi_container; }
35 namespace game_events { struct t_context; }
36 
37 namespace pathfind { class manager; }
38 
39 namespace wb { class manager; }
40 
41 namespace actions { class undo_list; }
42 
43 class game_state : public filter_context
44 {
45 private:
46  friend class replay_controller;
47 public:
51  boost::scoped_ptr<pathfind::manager> pathfind_manager_;
52  boost::scoped_ptr<reports> reports_;
53  boost::scoped_ptr<game_lua_kernel> lua_kernel_;
54  boost::scoped_ptr<game_events::manager> events_manager_;
55  /// undo_stack_ is never nullptr. It is implemented as a pointer so that
56  /// undo_list can be an incomplete type at this point (which reduces the
57  /// number of files that depend on actions/undo.hpp).
58  boost::scoped_ptr<actions::undo_list> undo_stack_;
60 
61  typedef boost::optional<end_level_data> t_possible_end_level_data;
62  t_possible_end_level_data end_level_data_;
65  // used to sync with the mpserver
67  bool& init_side_done() { return init_side_done_; }
68 
69 
72  int first_human_team_; //needed to initialize the viewpoint during setup
73  bool has_human_sides() const { return first_human_team_ != -1; }
74 
75  game_state(const config & level, play_controller &, const tdata_cache & tdata);
76  /// The third parameter is an optimisation.
77  game_state(const config & level, play_controller &, game_board& board);
78 
79  ~game_state();
80 
82 
83  void init(const config& level, play_controller &);
84 
86 
87  void write(config& cfg) const;
88 
89  virtual const display_context & get_disp_context() const { return board_; }
90  virtual const tod_manager & get_tod_man() const { return tod_manager_; }
91  virtual const game_data * get_game_data() const { return &gamedata_; }
92  virtual game_lua_kernel * get_lua_kernel() const { return lua_kernel_.get(); }
93 
94  /// Checks to see if a leader at @a leader_loc could recruit somewhere.
95  bool can_recruit_from(const map_location& leader_loc, int side) const;
96  /// Checks to see if @a leader (assumed a leader) can recruit somewhere.
97  /// This takes into account terrain, shroud, and the presence of visible units.
98  bool can_recruit_from(const unit& leader) const;
99 
100  /// Checks to see if a leader at @a leader_loc could recruit on @a recruit_loc.
101  bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side) const;
102  /// Checks to see if @a leader (assumed a leader) can recruit on @a recruit_loc.
103  /// This takes into account terrain, shroud, and whether or not there is already
104  /// a visible unit at recruit_loc.
105  bool can_recruit_on(const unit& leader, const map_location& recruit_loc) const;
106 
107  /// Checks if any of the sides leaders can recruit at a location
108  bool side_can_recruit_on(int side, map_location loc) const;
109 };
110 
111 #endif
Game board class.
Definition: game_board.hpp:55
Definition: unit.hpp:95
GLint level
Definition: glew.h:1220
virtual const display_context & get_disp_context() const
Definition: game_state.hpp:89
bool has_human_sides() const
Definition: game_state.hpp:73
int first_human_team_
Definition: game_state.hpp:72
int server_request_number_
Definition: game_state.hpp:66
bool can_recruit_on(const map_location &leader_loc, const map_location &recruit_loc, int side) const
Checks to see if a leader at leader_loc could recruit on recruit_loc.
Definition: game_state.cpp:328
virtual const tod_manager & get_tod_man() const
Definition: game_state.hpp:90
boost::scoped_ptr< pathfind::manager > pathfind_manager_
Definition: game_state.hpp:51
game_state(const config &level, play_controller &, const tdata_cache &tdata)
Definition: game_state.cpp:47
bool init_side_done_
Definition: game_state.hpp:63
Unit and team statistics.
virtual const game_data * get_game_data() const
Definition: game_state.hpp:91
boost::scoped_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:53
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
Definition: game_state.cpp:368
boost::scoped_ptr< game_events::manager > events_manager_
Definition: game_state.hpp:54
tod_manager tod_manager_
Definition: game_state.hpp:50
boost::scoped_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
Definition: game_state.hpp:58
Encapsulates the map of the game.
Definition: location.hpp:38
Domain specific events.
Definition: action_wml.cpp:93
void write(config &cfg) const
Definition: game_state.cpp:229
A container of wml_menu_item.
boost::optional< end_level_data > t_possible_end_level_data
Definition: game_state.hpp:61
t_possible_end_level_data end_level_data_
Definition: game_state.hpp:62
bool & init_side_done()
Definition: game_state.hpp:67
bool can_recruit_from(const map_location &leader_loc, int side) const
Checks to see if a leader at leader_loc could recruit somewhere.
Definition: game_state.cpp:296
game_data gamedata_
Definition: game_state.hpp:48
void init(const config &level, play_controller &)
Definition: game_state.cpp:165
void set_game_display(game_display *)
Definition: game_state.cpp:224
game_board board_
Definition: game_state.hpp:49
int player_number_
Definition: game_state.hpp:59
void place_sides_in_preferred_locations(const config &level)
Definition: game_state.cpp:130
virtual game_lua_kernel * get_lua_kernel() const
Definition: game_state.hpp:92
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Definition: display.hpp:47
bool start_event_fired_
Definition: game_state.hpp:64
boost::scoped_ptr< reports > reports_
Definition: game_state.hpp:52
game_events::wmi_container & get_wml_menu_items()
Definition: game_state.cpp:385