The Battle for Wesnoth  1.15.9+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  /**
54  * undo_stack_ is never nullptr. It is implemented as a pointer so that
55  * undo_list can be an incomplete type at this point (which reduces the
56  * number of files that depend on actions/undo.hpp).
57  */
58  const std::unique_ptr<actions::undo_list> undo_stack_;
61  /** True if healing should be done at the beginning of the next side turn */
63 
64  std::optional<end_level_data> end_level_data_;
67  // used to sync with the mpserver
69  bool& init_side_done() { return init_side_done_; }
70 
71 
72  game_events::wmi_manager& get_wml_menu_items();
73  const game_events::wmi_manager& get_wml_menu_items() const;
74  int first_human_team_; //needed to initialize the viewpoint during setup
75  bool has_human_sides() const { return first_human_team_ != -1; }
76 
78  /** The third parameter is an optimisation. */
79  game_state(const config & level, play_controller &, game_board& board);
80 
81  ~game_state();
82 
83  void place_sides_in_preferred_locations(const config& level);
84 
85  void init(const config& level, play_controller &);
86 
87  void set_game_display(game_display *);
88 
89  void write(config& cfg) const;
90 
91  /** Inherited from @ref filter_context. */
92  virtual const display_context& get_disp_context() const override
93  {
94  return board_;
95  }
96 
97  /** Inherited from @ref filter_context. */
98  virtual const tod_manager& get_tod_man() const override
99  {
100  return tod_manager_;
101  }
102 
103  /** Inherited from @ref filter_context. */
104  virtual const game_data* get_game_data() const override
105  {
106  return &gamedata_;
107  }
108 
109  /** Inherited from @ref filter_context. */
110  virtual game_lua_kernel* get_lua_kernel() const override
111  {
112  return lua_kernel_.get();
113  }
114 
115  /** Checks to see if a leader at @a leader_loc could recruit somewhere. */
116  bool can_recruit_from(const map_location& leader_loc, int side) const;
117  /** Checks to see if @a leader (assumed a leader) can recruit somewhere. */
118  /** This takes into account terrain, shroud, and the presence of visible units. */
119  bool can_recruit_from(const unit& leader) const;
120 
121  /** Checks to see if a leader at @a leader_loc could recruit on @a recruit_loc. */
122  bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side) const;
123  /**
124  * Checks to see if @a leader (assumed a leader) can recruit on @a recruit_loc.
125  * This takes into account terrain, shroud, and whether or not there is already
126  * a visible unit at recruit_loc.
127  */
128  bool can_recruit_on(const unit& leader, const map_location& recruit_loc) const;
129 
130  /** Checks if any of the sides leaders can recruit at a location */
131  bool side_can_recruit_on(int side, map_location loc) const;
132 
133  /** creates a new side during a game. @todo: maybe add parameters like id etc? */
134  void add_side_wml(config cfg);
135 };
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:58
Game board class.
Definition: game_board.hpp:48
std::unique_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:50
std::optional< end_level_data > end_level_data_
Definition: game_state.hpp:64
ai::manager ai_manager_
Definition: game_state.hpp:51
This class represents a single unit of a specific type.
Definition: unit.hpp:120
virtual const display_context & get_disp_context() const override
Inherited from filter_context.
Definition: game_state.hpp:92
int next_player_number_
Definition: game_state.hpp:60
int first_human_team_
Definition: game_state.hpp:74
int server_request_number_
Definition: game_state.hpp:68
bool do_healing_
True if healing should be done at the beginning of the next side turn.
Definition: game_state.hpp:62
Class that manages AIs for all sides and manages AI redeployment.
Definition: manager.hpp:111
virtual game_lua_kernel * get_lua_kernel() const override
Inherited from filter_context.
Definition: game_state.hpp:110
bool init_side_done_
Definition: game_state.hpp:65
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:98
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:763
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:75
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:37
Domain specific events.
Definition: action_wml.cpp:86
bool & init_side_done()
Definition: game_state.hpp:69
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:104
game_board board_
Definition: game_state.hpp:46
int player_number_
Definition: game_state.hpp:59
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
Definition: display.hpp:48
bool start_event_fired_
Definition: game_state.hpp:66