30 #define DBG_RG LOG_STREAM(debug, log_engine)
31 #define LOG_RG LOG_STREAM(info, log_engine)
32 #define WRN_RG LOG_STREAM(warn, log_engine)
33 #define ERR_RG LOG_STREAM(err, log_engine)
36 #define DBG_EE LOG_STREAM(debug, log_engine_enemies)
41 , unit_id_manager_(
level[
"next_underlying_unit_id"].to_size_t())
47 : teams_(other.teams_)
48 , labels_(other.labels_)
49 , map_(new
gamemap(*(other.map_)))
50 , unit_id_manager_(other.unit_id_manager_)
51 , units_(other.units_)
73 if(
i.side() == player_num) {
82 if(
i.side() == player_num) {
91 i.set_user_end_turn(
true);
106 for(
auto& up :
t.recall_list()) {
116 bool& found_network_player,
117 bool& cleared_villages,
118 std::set<unsigned>& not_defeated,
119 bool remove_from_carryover_on_defeat)
121 continue_level =
true;
122 found_player =
false;
123 found_network_player =
false;
124 cleared_villages =
false;
126 not_defeated = std::set<unsigned>();
129 DBG_EE <<
"Found a unit: " <<
i.id() <<
" on side " <<
i.side();
132 if(
i.can_recruit() && tm.
defeat_cond() == defeat_condition::type::no_leader_left) {
133 not_defeated.insert(
i.side());
134 }
else if(tm.
defeat_cond() == defeat_condition::type::no_units_left) {
135 not_defeated.insert(
i.side());
140 if(tm.
defeat_cond() == defeat_condition::type::never) {
141 not_defeated.insert(tm.
side());
146 if(not_defeated.find(tm.
side()) == not_defeated.end()) {
150 cleared_villages =
true;
152 if(remove_from_carryover_on_defeat) {
155 }
else if(remove_from_carryover_on_defeat) {
161 std::size_t side = *
n - 1;
162 DBG_EE <<
"Side " << (side + 1) <<
" is a not-defeated team";
165 for(++m; m != not_defeated.end(); ++m) {
166 if(
teams()[side].is_enemy(*m)) {
170 DBG_EE <<
"Side " << (side + 1) <<
" and " << *m <<
" are not enemies.";
173 if(
teams()[side].is_local_human()) {
177 if(
teams()[side].is_network_human()) {
178 found_network_player =
true;
182 continue_level =
false;
192 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
206 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
230 int side_num,
bool is_local,
const std::string& pname,
const std::string& controller_type)
237 if(controller_type == side_controller::ai && !tm.
is_ai()) {
240 }
else if(controller_type == side_controller::human && !tm.
is_human()) {
245 if(pname.empty() || !tm.
is_human()) {
253 leader->rename(pname);
259 switch(
t.defeat_cond()) {
260 case defeat_condition::type::always:
262 case defeat_condition::type::no_leader_left:
264 case defeat_condition::type::no_units_left:
266 if(u.side() ==
t.side())
270 case defeat_condition::type::never:
284 utils::optional<std::string> ret;
287 std::map<map_location, int> villages;
288 for(
const auto& village :
map_->villages()) {
291 villages[village] = owner;
296 if(!newmap.
on_board(itor->get_location())) {
298 ret = std::string(
"replace_map: Cannot add a unit that would become off-map to the recall list\n");
307 for(
const auto& village : villages) {
318 const map_location&
loc,
const std::string& t_str,
const std::string& mode_str,
bool replace_if_failed)
328 if(mode_str ==
"base") {
330 }
else if(mode_str ==
"overlay") {
356 if(
map_->tdata()->is_village(old_t) && !
map_->tdata()->is_village(new_t)) {
378 side[
"no_leader"] =
true;
379 side[
"side"] = std::to_string(
t.side());
383 if(
i.side() ==
t.side()) {
385 i.get_location().write(u);
398 cfg[
"map_data"] =
map_->write();
404 , temp_(m_.extract(
loc))
413 , temp_(m_.extract(
loc))
434 , temp_(m_.extract(
loc))
441 , temp_(m_.extract(
loc))
475 iter->set_movement(new_moves);
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(config_key_type key)
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it,...
void check_victory(bool &, bool &, bool &, bool &, std::set< unsigned > &, bool)
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
bool has_visible_unit(const map_location &loc, const team &team, bool see_all=false) const
virtual const std::vector< team > & teams() const override
std::vector< team > teams_
void side_drop_to(int side_num, side_controller::type ctrl, side_proxy_controller::type proxy=side_proxy_controller::type::human)
std::unique_ptr< gamemap > map_
bool change_terrain(const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
utils::optional< std::string > replace_map(const gamemap &r)
game_board(const config &level)
void heal_all_survivors()
n_unit::id_manager unit_id_manager_
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
bool team_is_defeated(const team &t) const
Calculates whether a team is defeated.
void side_change_controller(int side_num, bool is_local, const std::string &pname, const std::string &controller_type)
bool try_add_unit_to_recall_list(const map_location &loc, const unit_ptr &u)
void set_all_units_user_end_turn()
void write_config(config &cfg) const
virtual const unit_map & units() const override
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Encapsulates the map of the game.
bool is_village(const map_location &loc) const
std::size_t get_save_id() const
Used for saving id to savegame.
std::set< t_translation::terrain_code > & encountered_terrains()
void add(const unit_ptr &ptr, int pos=-1)
Add a unit to the list.
This class stores all the data for a single 'side' (in game nomenclature).
void change_proxy(side_proxy_controller::type proxy)
void set_local(bool local)
void set_current_player(const std::string &player)
defeat_condition::type defeat_cond() const
void change_controller(const std::string &new_controller)
recall_list_manager & recall_list()
void lose_village(const map_location &)
void set_lost(bool value=true)
Container associating units to locations.
unit_ptr find_unit_ptr(const T &val)
unit_iterator find(std::size_t id)
std::size_t erase(const map_location &l)
Erases the unit at location l, if any.
umap_retval_pair_t add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
unit_iterator find_leader(int side)
umap_retval_pair_t insert(const unit_ptr &p)
Inserts the unit pointed to by p into the map.
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
This class represents a single unit of a specific type.
Definitions for the interface to Wesnoth Markup Language (WML).
void swap(game_board &one, game_board &other)
static lg::log_domain log_engine("enginerefac")
static lg::log_domain log_engine_enemies("engine/enemies")
unit & mark_clone(bool is_temporary)
Mark this unit as clone so it can be inserted to unit_map.
Standard logging facilities (interface).
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
const terrain_code NONE_TERRAIN
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::string::const_iterator iterator
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< unit > unit_ptr
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
Encapsulates the map of the game.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
virtual ~temporary_unit_mover()
temporary_unit_mover(unit_map &m, const map_location &src, const map_location &dst, int new_moves, bool stand)
Constructor This version will change the unit's current movement to new_moves while the unit is moved...
virtual ~temporary_unit_placer()
temporary_unit_placer(unit_map &m, const map_location &loc, unit &u)
temporary_unit_remover(unit_map &m, const map_location &loc)
virtual ~temporary_unit_remover()
static map_location::direction n