The Battle for Wesnoth  1.19.0+dev
game_state.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 
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 
33 namespace pathfind { class manager; }
34 
35 
36 namespace actions { class undo_list; }
37 
38 class game_state : public filter_context
39 {
40 private:
41  friend class replay_controller;
42 public:
46  std::unique_ptr<pathfind::manager> pathfind_manager_;
47  const std::unique_ptr<reports> reports_;
48  std::unique_ptr<game_lua_kernel> lua_kernel_;
50  const std::unique_ptr<game_events::manager> events_manager_;
51  /**
52  * undo_stack_ is never nullptr. It is implemented as a pointer so that
53  * undo_list can be an incomplete type at this point (which reduces the
54  * number of files that depend on actions/undo.hpp).
55  */
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 */
63 
64  std::optional<end_level_data> end_level_data_;
65  // used to sync with the mpserver
67 
68 
71 
73 
74  ~game_state();
75 
77 
78  void init(const config& level, play_controller &);
79 
81 
82  void write(config& cfg) const;
83 
84  /** Inherited from @ref filter_context. */
85  virtual const display_context& get_disp_context() const override
86  {
87  return board_;
88  }
89 
90  /** Inherited from @ref filter_context. */
91  virtual const tod_manager& get_tod_man() const override
92  {
93  return tod_manager_;
94  }
95 
96  /** Inherited from @ref filter_context. */
97  virtual const game_data* get_game_data() const override
98  {
99  return &gamedata_;
100  }
101 
102  /** Inherited from @ref filter_context. */
103  virtual game_lua_kernel* get_lua_kernel() const override
104  {
105  return lua_kernel_.get();
106  }
107 
108 
109  bool in_phase(game_data::PHASE phase) const
110  {
111  return gamedata_.phase() == phase;
112  }
113 
114  template< typename... Arguments >
115  bool in_phase(game_data::PHASE phase, Arguments ... args) const
116  {
117  return in_phase(phase) || in_phase(args...);
118  }
119 
120  /** Checks to see if a leader at @a leader_loc could recruit somewhere. */
121  bool can_recruit_from(const map_location& leader_loc, int side) const;
122  /** Checks to see if @a leader (assumed a leader) can recruit somewhere. */
123  /** This takes into account terrain, shroud, and the presence of visible units. */
124  bool can_recruit_from(const unit& leader) const;
125 
126  /** Checks to see if a leader at @a leader_loc could recruit on @a recruit_loc. */
127  bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side) const;
128  /**
129  * Checks to see if @a leader (assumed a leader) can recruit on @a recruit_loc.
130  * This takes into account terrain, shroud, and whether or not there is already
131  * a visible unit at recruit_loc.
132  */
133  bool can_recruit_on(const unit& leader, const map_location& recruit_loc) const;
134 
135  /** Checks if any of the sides leaders can recruit at a location */
136  bool side_can_recruit_on(int side, map_location loc) const;
137 
138  /** Checks whether this is not the last scenario (usually of a campaign)*/
139  bool has_next_scenario() const;
140  /** creates a new side during a game. @todo: maybe add parameters like id etc? */
141  void add_side_wml(config cfg);
142 };
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
Class that manages AIs for all sides and manages AI redeployment.
Definition: manager.hpp:111
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
Game board class.
Definition: game_board.hpp:46
PHASE phase() const
Definition: game_data.hpp:105
void write(config &cfg) const
Definition: game_state.cpp:218
bool remove_from_carryover_on_defeat_
Definition: game_state.hpp:62
void add_side_wml(config cfg)
creates a new side during a game.
Definition: game_state.cpp:432
const std::unique_ptr< reports > reports_
Definition: game_state.hpp:47
bool in_phase(game_data::PHASE phase, Arguments ... args) const
Definition: game_state.hpp:115
int player_number_
Definition: game_state.hpp:57
bool has_next_scenario() const
Checks whether this is not the last scenario (usually of a campaign)
Definition: game_state.cpp:395
int next_player_number_
Definition: game_state.hpp:58
int server_request_number_
Definition: game_state.hpp:66
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:290
std::optional< end_level_data > end_level_data_
Definition: game_state.hpp:64
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:322
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
bool in_phase(game_data::PHASE phase) const
Definition: game_state.hpp:109
void set_game_display(game_display *)
Definition: game_state.cpp:213
std::unique_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:48
virtual const game_data * get_game_data() const override
Inherited from filter_context.
Definition: game_state.hpp:97
game_state(const config &level, play_controller &)
Definition: game_state.cpp:47
virtual const tod_manager & get_tod_man() const override
Inherited from filter_context.
Definition: game_state.hpp:91
std::unique_ptr< pathfind::manager > pathfind_manager_
Definition: game_state.hpp:46
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
Definition: game_state.hpp:56
void init(const config &level, play_controller &)
Definition: game_state.cpp:146
bool do_healing_
True if healing should be done at the beginning of the next side turn.
Definition: game_state.hpp:60
virtual game_lua_kernel * get_lua_kernel() const override
Inherited from filter_context.
Definition: game_state.hpp:103
virtual const display_context & get_disp_context() const override
Inherited from filter_context.
Definition: game_state.hpp:85
void place_sides_in_preferred_locations(const config &level)
Definition: game_state.cpp:111
game_board board_
Definition: game_state.hpp:44
const std::unique_ptr< game_events::manager > events_manager_
Definition: game_state.hpp:50
game_events::wmi_manager & get_wml_menu_items()
Definition: game_state.cpp:385
ai::manager ai_manager_
Definition: game_state.hpp:49
bool victory_when_enemies_defeated_
Definition: game_state.hpp:61
tod_manager tod_manager_
Definition: game_state.hpp:45
game_data gamedata_
Definition: game_state.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:133
Domain specific events.
Unit and team statistics.
Encapsulates the map of the game.
Definition: location.hpp:38