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)
40 , map_(std::make_unique<
gamemap>(
level[
"map_data"].str()))
41 , unit_id_manager_(
level[
"next_underlying_unit_id"].to_size_t())
60 if(
i.side() == player_num) {
69 if(
i.side() == player_num) {
78 i.set_user_end_turn(
true);
93 for(
auto& up :
t.recall_list()) {
103 bool& found_network_player,
104 bool& cleared_villages,
105 std::set<unsigned>& not_defeated,
106 bool remove_from_carryover_on_defeat)
108 continue_level =
true;
109 found_player =
false;
110 found_network_player =
false;
111 cleared_villages =
false;
113 not_defeated = std::set<unsigned>();
116 DBG_EE <<
"Found a unit: " <<
i.id() <<
" on side " <<
i.side();
119 if(
i.can_recruit() && tm.
defeat_cond() == defeat_condition::type::no_leader_left) {
120 not_defeated.insert(
i.side());
121 }
else if(tm.
defeat_cond() == defeat_condition::type::no_units_left) {
122 not_defeated.insert(
i.side());
127 if(tm.defeat_cond() == defeat_condition::type::never) {
128 not_defeated.insert(tm.side());
133 if(not_defeated.find(tm.side()) == not_defeated.end()) {
137 cleared_villages =
true;
139 if(remove_from_carryover_on_defeat) {
142 }
else if(remove_from_carryover_on_defeat) {
148 std::size_t side = *
n - 1;
149 DBG_EE <<
"Side " << (side + 1) <<
" is a not-defeated team";
152 for(++m; m != not_defeated.end(); ++m) {
157 DBG_EE <<
"Side " << (side + 1) <<
" and " << *m <<
" are not enemies.";
160 if(
teams()[side].is_local_human()) {
164 if(
teams()[side].is_network_human()) {
165 found_network_player =
true;
169 continue_level =
false;
179 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
193 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
217 int side_num,
bool is_local,
const std::string& pname,
const std::string& controller_type)
224 if(controller_type == side_controller::ai && !tm.
is_ai()) {
227 }
else if(controller_type == side_controller::human && !tm.
is_human()) {
232 if(pname.empty() || !tm.
is_human()) {
240 leader->rename(pname);
246 switch(
t.defeat_cond()) {
247 case defeat_condition::type::always:
249 case defeat_condition::type::no_leader_left:
251 case defeat_condition::type::no_units_left:
253 if(u.side() ==
t.side())
257 case defeat_condition::type::never:
271 utils::optional<std::string> ret;
274 std::map<map_location, int> villages;
275 for(
const auto& village :
map_->villages()) {
278 villages[village] = owner;
283 if(!newmap.
on_board(itor->get_location())) {
285 ret = std::string(
"replace_map: Cannot add a unit that would become off-map to the recall list\n");
294 for(
const auto& village : villages) {
305 const map_location&
loc,
const std::string& t_str,
const std::string& mode_str,
bool replace_if_failed)
315 if(mode_str ==
"base") {
317 }
else if(mode_str ==
"overlay") {
327 bool replace_if_failed)
329 const auto [new_terrain, village_status] =
map_->set_terrain(
loc, terrain, mode, replace_if_failed);
365 side[
"no_leader"] =
true;
370 if(
i.side() ==
t.side()) {
372 i.get_location().write(u);
385 cfg[
"map_data"] =
map_->write();
391 , temp_(m_.extract(
loc))
400 , temp_(m_.extract(
loc))
421 , temp_(m_.extract(
loc))
428 , temp_(m_.extract(
loc))
462 iter->set_movement(new_moves);
static bool is_enemy(std::size_t side, std::size_t other_side)
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view 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.
void encounter_map_terrain(const gamemap &map)
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 &)
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.
constexpr terrain_code NONE_TERRAIN
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::string to_string(const Range &range, const Func &op)
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