The Battle for Wesnoth  1.15.2+dev
game_state.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
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 config;
18 
19 #include "ai/manager.hpp"
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 class game_display;
27 class play_controller;
28 class game_lua_kernel;
29 class reports;
30 
31 namespace game_events { class manager; class wmi_manager; }
32 namespace game_events { struct event_context; }
33 
34 namespace pathfind { class manager; }
35 
36 namespace wb { class manager; }
37 
38 namespace actions { class undo_list; }
39 
40 class game_state : public filter_context
41 {
42 private:
43  friend class replay_controller;
44 public:
48  std::unique_ptr<pathfind::manager> pathfind_manager_;
49  const std::unique_ptr<reports> reports_;
50  std::unique_ptr<game_lua_kernel> lua_kernel_;
52  const std::unique_ptr<game_events::manager> events_manager_;
53  /// undo_stack_ is never nullptr. It is implemented as a pointer so that
54  /// undo_list can be an incomplete type at this point (which reduces the
55  /// number of files that depend on actions/undo.hpp).
56  const std::unique_ptr<actions::undo_list> undo_stack_;
59  /// True if healing should be done at the beginning of the next side turn
61 
62  boost::optional<end_level_data> end_level_data_;
65  // used to sync with the mpserver
67  bool& init_side_done() { return init_side_done_; }
68 
69 
70  game_events::wmi_manager& get_wml_menu_items();
71  const game_events::wmi_manager& get_wml_menu_items() const;
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 ter_data_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 
81  void place_sides_in_preferred_locations(const config& level);
82 
83  void init(const config& level, play_controller &);
84 
85  void set_game_display(game_display *);
86 
87  void write(config& cfg) const;
88 
89  /** Inherited from @ref filter_context. */
90  virtual const display_context& get_disp_context() const override
91  {
92  return board_;
93  }
94 
95  /** Inherited from @ref filter_context. */
96  virtual const tod_manager& get_tod_man() const override
97  {
98  return tod_manager_;
99  }
100 
101  /** Inherited from @ref filter_context. */
102  virtual const game_data* get_game_data() const override
103  {
104  return &gamedata_;
105  }
106 
107  /** Inherited from @ref filter_context. */
108  virtual game_lua_kernel* get_lua_kernel() const override
109  {
110  return lua_kernel_.get();
111  }
112 
113  /// Checks to see if a leader at @a leader_loc could recruit somewhere.
114  bool can_recruit_from(const map_location& leader_loc, int side) const;
115  /// Checks to see if @a leader (assumed a leader) can recruit somewhere.
116  /// This takes into account terrain, shroud, and the presence of visible units.
117  bool can_recruit_from(const unit& leader) const;
118 
119  /// Checks to see if a leader at @a leader_loc could recruit on @a recruit_loc.
120  bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side) const;
121  /// Checks to see if @a leader (assumed a leader) can recruit on @a recruit_loc.
122  /// This takes into account terrain, shroud, and whether or not there is already
123  /// a visible unit at recruit_loc.
124  bool can_recruit_on(const unit& leader, const map_location& recruit_loc) const;
125 
126  /// Checks if any of the sides leaders can recruit at a location
127  bool side_can_recruit_on(int side, map_location loc) const;
128 
129  ///creates a new side during a game. todo: maybe add parameters like id etc?
130  void add_side_wml(config cfg);
131 };
const std::unique_ptr< reports > reports_
Definition: game_state.hpp:49
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
Definition: game_state.hpp:56
Game board class.
Definition: game_board.hpp:50
std::unique_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:50
ai::manager ai_manager_
Definition: game_state.hpp:51
This class represents a single unit of a specific type.
Definition: unit.hpp:99
virtual const display_context & get_disp_context() const override
Inherited from filter_context.
Definition: game_state.hpp:90
int next_player_number_
Definition: game_state.hpp:58
int first_human_team_
Definition: game_state.hpp:72
int server_request_number_
Definition: game_state.hpp:66
bool do_healing_
True if healing should be done at the beginning of the next side turn.
Definition: game_state.hpp:60
Class that manages AIs for all sides and manages AI redeployment.
Definition: manager.hpp:118
virtual game_lua_kernel * get_lua_kernel() const override
Inherited from filter_context.
Definition: game_state.hpp:108
bool init_side_done_
Definition: game_state.hpp:63
const std::unique_ptr< game_events::manager > events_manager_
Definition: game_state.hpp:52
Unit and team statistics.
virtual const tod_manager & get_tod_man() const override
Inherited from filter_context.
Definition: game_state.hpp:96
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:762
struct utils::detail::formula_initer init
static events::event_context * event_context
Definition: handler.cpp:63
bool has_human_sides() const
Definition: game_state.hpp:73
tod_manager tod_manager_
Definition: game_state.hpp:47
std::unique_ptr< pathfind::manager > pathfind_manager_
Definition: game_state.hpp:48
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
Encapsulates the map of the game.
Definition: location.hpp:42
Domain specific events.
Definition: action_wml.cpp:88
bool & init_side_done()
Definition: game_state.hpp:67
boost::optional< end_level_data > end_level_data_
Definition: game_state.hpp:62
game_data gamedata_
Definition: game_state.hpp:45
virtual const game_data * get_game_data() const override
Inherited from filter_context.
Definition: game_state.hpp:102
game_board board_
Definition: game_state.hpp:46
int player_number_
Definition: game_state.hpp:57
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
Definition: display.hpp:48
bool start_event_fired_
Definition: game_state.hpp:64
std::shared_ptr< terrain_type_data > ter_data_cache