The Battle for Wesnoth  1.17.0-dev
game_state.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 class config;
19 
20 #include "ai/manager.hpp"
21 #include "filter_context.hpp"
22 #include "game_board.hpp"
23 #include "game_data.hpp"
24 #include "tod_manager.hpp"
25 #include "units/id.hpp"
26 
27 class game_display;
28 class play_controller;
29 class game_lua_kernel;
30 class reports;
31 
32 namespace game_events { class manager; class wmi_manager; }
33 namespace game_events { struct event_context; }
34 
35 namespace pathfind { class manager; }
36 
37 namespace wb { class manager; }
38 
39 namespace actions { class undo_list; }
40 
41 class game_state : public filter_context
42 {
43 private:
44  friend class replay_controller;
45 public:
49  std::unique_ptr<pathfind::manager> pathfind_manager_;
50  const std::unique_ptr<reports> reports_;
51  std::unique_ptr<game_lua_kernel> lua_kernel_;
53  const std::unique_ptr<game_events::manager> events_manager_;
54  /**
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  */
59  const std::unique_ptr<actions::undo_list> undo_stack_;
62  /** True if healing should be done at the beginning of the next side turn */
64 
65  std::optional<end_level_data> end_level_data_;
68  // used to sync with the mpserver
70  bool& init_side_done() { return init_side_done_; }
71 
72 
73  game_events::wmi_manager& get_wml_menu_items();
74  const game_events::wmi_manager& get_wml_menu_items() const;
75  int first_human_team_; //needed to initialize the viewpoint during setup
76  bool has_human_sides() const { return first_human_team_ != -1; }
77 
79  /** The third parameter is an optimisation. */
80  game_state(const config & level, play_controller &, game_board& board);
81 
82  ~game_state();
83 
84  void place_sides_in_preferred_locations(const config& level);
85 
86  void init(const config& level, play_controller &);
87 
88  void set_game_display(game_display *);
89 
90  void write(config& cfg) const;
91 
92  /** Inherited from @ref filter_context. */
93  virtual const display_context& get_disp_context() const override
94  {
95  return board_;
96  }
97 
98  /** Inherited from @ref filter_context. */
99  virtual const tod_manager& get_tod_man() const override
100  {
101  return tod_manager_;
102  }
103 
104  /** Inherited from @ref filter_context. */
105  virtual const game_data* get_game_data() const override
106  {
107  return &gamedata_;
108  }
109 
110  /** Inherited from @ref filter_context. */
111  virtual game_lua_kernel* get_lua_kernel() const override
112  {
113  return lua_kernel_.get();
114  }
115 
116  /** Checks to see if a leader at @a leader_loc could recruit somewhere. */
117  bool can_recruit_from(const map_location& leader_loc, int side) const;
118  /** Checks to see if @a leader (assumed a leader) can recruit somewhere. */
119  /** This takes into account terrain, shroud, and the presence of visible units. */
120  bool can_recruit_from(const unit& leader) const;
121 
122  /** Checks to see if a leader at @a leader_loc could recruit on @a recruit_loc. */
123  bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side) const;
124  /**
125  * Checks to see if @a leader (assumed a leader) can recruit on @a recruit_loc.
126  * This takes into account terrain, shroud, and whether or not there is already
127  * a visible unit at recruit_loc.
128  */
129  bool can_recruit_on(const unit& leader, const map_location& recruit_loc) const;
130 
131  /** Checks if any of the sides leaders can recruit at a location */
132  bool side_can_recruit_on(int side, map_location loc) const;
133 
134  /** creates a new side during a game. @todo: maybe add parameters like id etc? */
135  void add_side_wml(config cfg);
136 };
const std::unique_ptr< reports > reports_
Definition: game_state.hpp:50
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
Definition: game_state.hpp:59
Game board class.
Definition: game_board.hpp:51
std::unique_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:51
std::optional< end_level_data > end_level_data_
Definition: game_state.hpp:65
ai::manager ai_manager_
Definition: game_state.hpp:52
This class represents a single unit of a specific type.
Definition: unit.hpp:121
virtual const display_context & get_disp_context() const override
Inherited from filter_context.
Definition: game_state.hpp:93
int next_player_number_
Definition: game_state.hpp:61
int first_human_team_
Definition: game_state.hpp:75
int server_request_number_
Definition: game_state.hpp:69
bool do_healing_
True if healing should be done at the beginning of the next side turn.
Definition: game_state.hpp:63
Class that manages AIs for all sides and manages AI redeployment.
Definition: manager.hpp:113
virtual game_lua_kernel * get_lua_kernel() const override
Inherited from filter_context.
Definition: game_state.hpp:111
bool init_side_done_
Definition: game_state.hpp:66
const std::unique_ptr< game_events::manager > events_manager_
Definition: game_state.hpp:53
Unit and team statistics.
virtual const tod_manager & get_tod_man() const override
Inherited from filter_context.
Definition: game_state.hpp:99
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:764
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:76
tod_manager tod_manager_
Definition: game_state.hpp:48
std::unique_ptr< pathfind::manager > pathfind_manager_
Definition: game_state.hpp:49
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
Encapsulates the map of the game.
Definition: location.hpp:38
Domain specific events.
Definition: action_wml.cpp:87
bool & init_side_done()
Definition: game_state.hpp:70
game_data gamedata_
Definition: game_state.hpp:46
virtual const game_data * get_game_data() const override
Inherited from filter_context.
Definition: game_state.hpp:105
game_board board_
Definition: game_state.hpp:47
int player_number_
Definition: game_state.hpp:60
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
Definition: display.hpp:49
bool start_event_fired_
Definition: game_state.hpp:67