The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
game_state.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2014 - 2025
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
18class 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
26class game_display;
27class play_controller;
28class game_lua_kernel;
29class reports;
30
31namespace game_events { class manager; class wmi_manager; }
32
33namespace pathfind { class manager; }
34
35
36namespace actions { class undo_list; }
37
39{
40private:
41 friend class replay_controller;
42public:
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 utils::optional<end_level_data> end_level_data_;
65 // used to sync with the mpserver
67
68
71
72 game_state(const config & level, play_controller &);
73
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};
map_location loc
Definition move.cpp:172
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:157
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
Game board class.
PHASE phase() const
void write(config &cfg) const
utils::optional< end_level_data > end_level_data_
bool remove_from_carryover_on_defeat_
void add_side_wml(config cfg)
creates a new side during a game.
const std::unique_ptr< reports > reports_
bool in_phase(game_data::PHASE phase, Arguments ... args) const
int player_number_
bool has_next_scenario() const
Checks whether this is not the last scenario (usually of a campaign)
int next_player_number_
virtual game_lua_kernel * get_lua_kernel() const override
Inherited from filter_context.
virtual const display_context & get_disp_context() const override
Inherited from filter_context.
int server_request_number_
bool can_recruit_from(const map_location &leader_loc, int side) const
Checks to see if a leader at leader_loc could recruit somewhere.
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.
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
bool in_phase(game_data::PHASE phase) const
virtual const game_data * get_game_data() const override
Inherited from filter_context.
void set_game_display(game_display *)
std::unique_ptr< game_lua_kernel > lua_kernel_
std::unique_ptr< pathfind::manager > pathfind_manager_
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
void init(const config &level, play_controller &)
bool do_healing_
True if healing should be done at the beginning of the next side turn.
void place_sides_in_preferred_locations(const config &level)
game_board board_
virtual const tod_manager & get_tod_man() const override
Inherited from filter_context.
const std::unique_ptr< game_events::manager > events_manager_
game_events::wmi_manager & get_wml_menu_items()
ai::manager ai_manager_
bool victory_when_enemies_defeated_
tod_manager tod_manager_
game_data gamedata_
This class represents a single unit of a specific type.
Definition unit.hpp:39
const config * cfg
Domain specific events.
Unit and team statistics.
Encapsulates the map of the game.
Definition location.hpp:46