29 #define DBG_RG LOG_STREAM(debug, log_engine)
30 #define LOG_RG LOG_STREAM(info, log_engine)
31 #define WRN_RG LOG_STREAM(warn, log_engine)
32 #define ERR_RG LOG_STREAM(err, log_engine)
35 #define DBG_EE LOG_STREAM(debug, log_engine_enemies)
40 , unit_id_manager_(
level[
"next_underlying_unit_id"])
46 : teams_(other.teams_)
47 , labels_(other.labels_)
48 , map_(new
gamemap(*(other.map_)))
49 , unit_id_manager_(other.unit_id_manager_)
50 , units_(other.units_)
72 if(
i.side() == player_num) {
81 if(
i.side() == player_num) {
90 i.set_user_end_turn(
true);
105 for(
auto& up :
t.recall_list()) {
115 bool& found_network_player,
116 bool& cleared_villages,
117 std::set<unsigned>& not_defeated,
118 bool remove_from_carryover_on_defeat)
120 continue_level =
true;
121 found_player =
false;
122 found_network_player =
false;
123 cleared_villages =
false;
125 not_defeated = std::set<unsigned>();
128 DBG_EE <<
"Found a unit: " <<
i.id() <<
" on side " <<
i.side();
131 if(
i.can_recruit() && tm.
defeat_cond() == defeat_condition::type::no_leader_left) {
132 not_defeated.insert(
i.side());
133 }
else if(tm.
defeat_cond() == defeat_condition::type::no_units_left) {
134 not_defeated.insert(
i.side());
139 if(tm.defeat_cond() == defeat_condition::type::never) {
140 not_defeated.insert(tm.side());
145 if(not_defeated.find(tm.side()) == not_defeated.end()) {
149 cleared_villages =
true;
151 if(remove_from_carryover_on_defeat) {
154 }
else if(remove_from_carryover_on_defeat) {
160 std::size_t side = *
n - 1;
161 DBG_EE <<
"Side " << (side + 1) <<
" is a not-defeated team";
164 for(++m; m != not_defeated.end(); ++m) {
165 if(
teams()[side].is_enemy(*m)) {
169 DBG_EE <<
"Side " << (side + 1) <<
" and " << *m <<
" are not enemies.";
172 if(
teams()[side].is_local_human()) {
176 if(
teams()[side].is_network_human()) {
177 found_network_player =
true;
181 continue_level =
false;
186 if(!
map_->on_board(loc)) {
191 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
200 if(!
map_->on_board(loc)) {
205 if(!u.
valid() || !u->is_visible_to_team(current_team, see_all)) {
239 int side_num,
bool is_local,
const std::string& pname,
const std::string& controller_type)
246 if(controller_type == side_controller::ai && !tm.
is_ai()) {
249 }
else if(controller_type == side_controller::human && !tm.
is_human()) {
254 if(pname.empty() || !tm.
is_human()) {
262 leader->rename(pname);
268 switch(
t.defeat_cond()) {
269 case defeat_condition::type::always:
271 case defeat_condition::type::no_leader_left:
273 case defeat_condition::type::no_units_left:
275 if(u.side() ==
t.side())
279 case defeat_condition::type::never:
293 std::optional<std::string> ret;
296 std::map<map_location, int> villages;
297 for(
const auto& village :
map_->villages()) {
300 villages[village] = owner;
305 if(!newmap.
on_board(itor->get_location())) {
307 ret = std::string(
"replace_map: Cannot add a unit that would become off-map to the recall list\n");
316 for(
const auto& village : villages) {
327 const map_location& loc,
const std::string& t_str,
const std::string& mode_str,
bool replace_if_failed)
337 if(mode_str ==
"base") {
339 }
else if(mode_str ==
"overlay") {
365 if(
map_->tdata()->is_village(old_t) && !
map_->tdata()->is_village(new_t)) {
371 map_->set_terrain(loc, new_t);
384 for(std::vector<team>::const_iterator
t =
teams_.begin();
t !=
teams_.end(); ++
t) {
385 int side_num = std::distance(
teams_.begin(),
t) + 1;
389 side[
"no_leader"] =
true;
390 side[
"side"] = std::to_string(side_num);
394 if(
i.side() == side_num) {
396 i.get_location().write(u);
409 cfg[
"map_data"] =
map_->write();
415 , temp_(m_.extract(loc))
424 , temp_(m_.extract(loc))
445 , temp_(m_.extract(loc))
452 , temp_(m_.extract(loc))
478 , temp_(src == dst ?
unit_ptr() : m_.extract(dst))
485 iter->set_movement(new_moves);
495 , temp_(src == dst ?
unit_ptr() : m_.extract(dst))
502 iter->set_movement(new_moves);
515 , temp_(src == dst ?
unit_ptr() : m_.extract(dst))
525 , temp_(src == dst ?
unit_ptr() : m_.extract(dst))
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::optional< std::string > replace_map(const gamemap &r)
std::unique_ptr< gamemap > map_
bool change_terrain(const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
game_board(const config &level)
void heal_all_survivors()
bool try_add_unit_to_recall_list(const map_location &loc, const unit_ptr u)
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)
unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
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 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_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(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.
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).
std::set< t_translation::terrain_code > & encountered_terrains()
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
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...
temporary_unit_mover(unit_map &m, const map_location &src, const map_location &dst, int new_moves)
Constructor This version will change the unit's current movement to new_moves while the unit is moved...
virtual ~temporary_unit_mover()
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