28 #define DBG_RG LOG_STREAM(debug, log_engine)
29 #define LOG_RG LOG_STREAM(info, log_engine)
30 #define WRN_RG LOG_STREAM(warn, log_engine)
31 #define ERR_RG LOG_STREAM(err, log_engine)
34 #define DBG_EE LOG_STREAM(debug, log_engine_enemies)
39 , unit_id_manager_(level[
"next_underlying_unit_id"])
45 : teams_(other.teams_)
47 , unit_id_manager_(other.unit_id_manager_)
71 if (
i.side() == player_num) {
79 if (
i.side() == player_num) {
87 i.set_user_end_turn(
true);
94 if (
teams_[un->side() - 1].persistent()) {
101 void game_board::check_victory(
bool & continue_level,
bool & found_player,
bool & found_network_player,
bool & cleared_villages, std::set<unsigned> & not_defeated,
bool remove_from_carryover_on_defeat)
103 continue_level =
true;
104 found_player =
false;
105 found_network_player =
false;
106 cleared_villages =
false;
108 not_defeated = std::set<unsigned>();
112 DBG_EE <<
"Found a unit: " <<
i.id() <<
" on side " <<
i.side() << std::endl;
115 if (
i.can_recruit() && tm.
defeat_condition() == team::DEFEAT_CONDITION::NO_LEADER) {
116 not_defeated.insert(
i.side());
118 not_defeated.insert(
i.side());
124 if(tm.defeat_condition() == team::DEFEAT_CONDITION::NEVER)
126 not_defeated.insert(tm.side());
130 if (not_defeated.find(tm.side()) == not_defeated.end())
135 cleared_villages =
true;
137 if (remove_from_carryover_on_defeat)
142 else if(remove_from_carryover_on_defeat)
149 size_t side = *
n - 1;
151 DBG_EE <<
"Side " << (side+1) <<
" is a not-defeated team" << std::endl;
154 for (++m; m != not_defeated.end(); ++
m) {
155 if (
teams()[side].is_enemy(*m)) {
158 DBG_EE <<
"Side " << (side+1) <<
" and " << *m <<
" are not enemies." << std::endl;
161 if (
teams()[side].is_local_human()) {
165 if (
teams()[side].is_network_human()) {
166 found_network_player =
true;
170 continue_level =
false;
174 const team& current_team,
bool see_all)
178 if (!u.
valid() || !u->is_visible_to_team(current_team, *
map_, see_all))
185 if (!
map_->on_board(loc))
return false;
187 if (!u.
valid() || !u->is_visible_to_team(current_team, *
map_, see_all))
193 const team ¤t_team,
bool see_all)
210 if (leader.
valid()) leader->rename(ctrl.to_string() + std::to_string(side_num));
218 if (pname.empty() || !tm.
is_human()) {
225 if (leader.
valid()) {
226 leader->rename(pname);
234 case team::DEFEAT_CONDITION::ALWAYS:
236 case team::DEFEAT_CONDITION::NO_LEADER:
238 case team::DEFEAT_CONDITION::NO_UNITS:
241 if(u.side() == t.
side())
245 case team::DEFEAT_CONDITION::NEVER:
253 teams_[u->side()-1].recall_list().add(u);
259 boost::optional<std::string> ret = boost::optional<std::string> ();
262 std::map<map_location, int> villages;
263 for(
const auto& village :
map_->villages()) {
266 villages[village] = owner;
273 *ret =
std::string(
"replace_map: Cannot add a unit that would become off-map to the recall list\n");
282 for(
const auto& village : villages) {
284 teams_[village.second].lose_village(village.first);
295 map_->overlay(mask_map, cfg, loc.
x, loc.
y, border);
299 const std::string & mode_str,
bool replace_if_failed)
321 old_t =
map_->get_terrain(loc),
322 new_t =
map_->tdata()->merge_terrains(old_t, terrain, mode, replace_if_failed);
326 if (
map_->tdata()->is_village(old_t) && !
map_->tdata()->is_village(new_t)) {
329 teams_[owner].lose_village(loc);
332 map_->set_terrain(loc, new_t);
343 for(std::vector<team>::const_iterator
t =
teams_.begin();
t !=
teams_.end(); ++
t) {
344 int side_num =
t -
teams_.begin() + 1;
348 side[
"no_leader"] =
true;
349 side[
"side"] = std::to_string(side_num);
354 if (
i.side() == side_num) {
356 i.get_location().write(u);
371 cfg[
"map_data"] =
map_->write();
375 : m_(m),
loc_(loc), temp_(m_.extract(loc))
382 : m_(b.
units_),
loc_(loc), temp_(m_.extract(loc))
399 : m_(m),
loc_(loc), temp_(m_.extract(loc))
404 : m_(b.
units_),
loc_(loc), temp_(m_.extract(loc))
425 : m_(m), src_(src), dst_(dst), old_moves_(-1),
426 temp_(src == dst ?
unit_ptr() : m_.extract(dst))
428 std::pair<unit_map::iterator, bool> move_result =
m_.
move(
src_,
dst_);
431 if ( move_result.second )
433 old_moves_ = move_result.first->movement_left(
true);
434 move_result.first->set_movement(new_moves);
440 : m_(b.
units_), src_(src), dst_(dst), old_moves_(-1),
441 temp_(src == dst ?
unit_ptr() : m_.extract(dst))
443 std::pair<unit_map::iterator, bool> move_result =
m_.
move(
src_,
dst_);
446 if ( move_result.second )
448 old_moves_ = move_result.first->movement_left(
true);
449 move_result.first->set_movement(new_moves);
459 : m_(m), src_(src), dst_(dst), old_moves_(-1),
460 temp_(src == dst ?
unit_ptr() : m_.extract(dst))
467 : m_(b.
units_), src_(src), dst_(dst), old_moves_(-1),
468 temp_(src == dst ?
unit_ptr() : m_.extract(dst))
476 std::pair<unit_map::iterator, bool> move_result =
m_.
move(
dst_,
src_);
void set_all_units_user_end_turn()
virtual const unit_map & units() const
void heal_all_survivors()
n_unit::id_manager unit_id_manager_
void write_config(config &cfg) const
size_t get_save_id() const
Used for saving id to savegame.
unit_iterator find_leader(int side)
const t_terrain NONE_TERRAIN
bool is_village(const map_location &loc) const
boost::scoped_ptr< gamemap > map_
void overlay_map(const gamemap &o, const config &cfg, map_location loc, bool border)
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
virtual const std::vector< team > & teams() const
DEFEAT_CONDITION defeat_condition() const
void change_controller(const std::string &new_controller)
void set_current_player(const std::string &player)
Definitions for the interface to Wesnoth Markup Language (WML).
t_terrain read_terrain_code(const std::string &str, const t_layer filler)
Reads a single terrain from a string.
bool team_is_defeated(const team &t) const
Calculates whether a team is defeated.
GLdouble GLdouble GLdouble b
This class stores all the data for a single 'side' (in game nomenclature).
static lg::log_domain log_engine_enemies("engine/enemies")
virtual ~temporary_unit_remover()
game_board & operator=(game_board other)
std::vector< team > teams_
temporary_unit_remover(unit_map &m, const map_location &loc)
unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
std::pair< unit_iterator, bool > insert(unit_ptr p)
Adds the unit to the map.
void side_drop_to(int side_num, team::CONTROLLER ctrl, team::PROXY_CONTROLLER proxy=team::PROXY_CONTROLLER::PROXY_HUMAN)
friend void swap(game_board &one, game_board &other)
void set_local(bool local)
std::set< t_translation::t_terrain > & encountered_terrains()
Encapsulates the map of the game.
config & add_child(const std::string &key)
void check_victory(bool &, bool &, bool &, bool &, std::set< unsigned > &, bool)
virtual ~temporary_unit_mover()
static const ::config * terrain
The terrain used to create the cache.
std::pair< unit_iterator, bool > add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
temporary_unit_placer(unit_map &m, const map_location &loc, unit &u)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Encapsulates the map of the game.
virtual ~temporary_unit_placer()
bool has_visible_unit(const map_location &loc, const team &team, bool see_all=false) const
unit & clone(bool is_temporary=true)
Mark this unit as clone so it can be inserted to unit_map.
std::map< std::string, tfilter >::iterator itor
void change_proxy(PROXY_CONTROLLER proxy)
bool change_terrain(const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
boost::shared_ptr< std::vector< unit_const_ptr > > units_
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
game_board(const tdata_cache &tdata, const config &level)
size_t erase(const map_location &l)
Erases the unit at location l, if any.
GLint GLint GLsizei GLsizei GLsizei GLint border
bool on_board(const map_location &loc) const
Tell if a location is on the map.
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...
boost::optional< std::string > replace_map(const gamemap &r)
void swap(game_board &one, game_board &other)
Standard logging facilities (interface).
Container associating units to locations.
unit_iterator find(size_t id)
static lg::log_domain log_engine("enginerefac")
bool try_add_unit_to_recall_list(const map_location &loc, const unit_ptr u)
A config object defines a single node in a WML file, with access to child nodes.
GLsizei const GLcharARB ** string
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
void side_change_controller(int side_num, bool is_local, const std::string &pname="")
const std::string valid
Little parts of regex templates used to parse Wml annoations.