39 #define DBG_NG LOG_STREAM(debug, log_engine)
40 #define LOG_NG LOG_STREAM(info, log_engine)
41 #define WRN_NG LOG_STREAM(warn, log_engine)
42 #define ERR_NG LOG_STREAM(warn, log_engine)
45 #define DBG_NGE LOG_STREAM(debug, log_engine_enemies)
46 #define LOG_NGE LOG_STREAM(info, log_engine_enemies)
47 #define WRN_NGE LOG_STREAM(warn, log_engine_enemies)
57 const boost::container::flat_set<std::string>
team::attributes = boost::assign::list_of<std::string>(
"ai_config")
58 (
"carryover_add")(
"carryover_percentage")(
"color")(
"controller")(
"current_player")(
"defeat_condition")(
"flag")
59 (
"flag_icon")(
"fog")(
"fog_data")(
"gold")(
"hidden")(
"income")
60 (
"no_leader")(
"objectives")(
"objectives_changed")(
"persistent")(
"lost")
61 (
"recall_cost")(
"recruit")(
"save_id")(
"scroll_to_leader")
62 (
"share_vision")(
"share_maps")(
"share_view")(
"shroud")(
"shroud_data")(
"start_gold")
63 (
"suppress_end_turn_confirmation")
64 (
"team_name")(
"user_team_name")(
"side_name")(
"village_gold")(
"village_support")(
"is_local")
66 (
"player_id")(
"action_bonus_count")(
"allow_changes")(
"allow_player")(
"color_lock")
67 (
"countdown_time")(
"disallow_observers")(
"faction")
68 (
"faction_from_recruit")(
"faction_name")(
"gold_lock")(
"income_lock")
69 (
"leader")(
"random_leader")(
"team_lock")(
"terrain_liked")
70 (
"user_description")(
"controller_lock")(
"chose_random")
71 (
"disallow_shuffle")(
"description").convert_to_container<boost::container::flat_set<std::string> >();
77 income_per_village(0),
78 support_per_village(1),
79 minimum_recruit_price(0),
90 action_bonus_count(0),
94 scroll_to_leader(true),
96 objectives_changed(false),
99 defeat_condition(
team::DEFEAT_CONDITION::NO_LEADER),
100 proxy_controller(
team::PROXY_CONTROLLER::PROXY_HUMAN),
101 share_vision(
team::SHARE_VISION::ALL),
102 disallow_observers(false),
107 no_turn_confirmation(false),
113 carryover_add(false),
122 income = cfg[
"income"];
126 faction = cfg[
"faction"].str();
128 save_id = cfg[
"save_id"].str();
132 flag = cfg[
"flag"].str();
134 id = cfg[
"id"].str();
135 scroll_to_leader = cfg[
"scroll_to_leader"].to_bool(
true);
138 disallow_observers = cfg[
"disallow_observers"].to_bool();
139 allow_player = cfg[
"allow_player"].to_bool(
true);
140 chose_random = cfg[
"chose_random"].to_bool(
false);
142 defeat_condition = cfg[
"defeat_condition"].to_enum<team::DEFEAT_CONDITION>(team::DEFEAT_CONDITION::NO_LEADER);
143 lost = cfg[
"lost"].to_bool(
false);
144 hidden = cfg[
"hidden"].to_bool();
146 side = cfg[
"side"].to_int(1);
152 is_local = cfg[
"is_local"].to_bool(
true);
155 color = cfg[
"color"].str();
157 color = cfg[
"side"].str();
171 can_recruit.insert(recruits.begin(), recruits.end());
175 if (!cfg[
"start_gold"].empty())
177 else if (!cfg[
"gold"].empty())
194 if(village_support.empty())
200 controller.parse(cfg[
"controller"].str());
203 if (controller == CONTROLLER::EMPTY) {
204 disallow_observers = cfg[
"disallow_observers"].to_bool(
true);
208 persistent = cfg[
"persistent"].to_bool(this->controller == CONTROLLER::HUMAN);
215 share_vision = cfg[
"share_vision"].to_enum<team::SHARE_VISION>(team::SHARE_VISION::ALL);
225 if(cfg[
"share_view"].to_bool()) {
228 else if(cfg[
"share_maps"].to_bool(
true)) {
241 cfg[
"income"] = income;
256 cfg[
"village_gold"] = income_per_village;
257 cfg[
"village_support"] = support_per_village;
259 cfg[
"disallow_observers"] = disallow_observers;
260 cfg[
"allow_player"] = allow_player;
261 cfg[
"chose_random"] = chose_random;
266 cfg[
"scroll_to_leader"] = scroll_to_leader;
271 cfg[
"color"] =
color;
321 const config &fog_override = cfg.
child(
"fog_override");
322 if ( fog_override ) {
323 const std::vector<map_location> fog_vector =
325 fog_clearer_.insert(fog_vector.begin(), fog_vector.end());
344 WRN_NG <<
"[side] " <<
current_player() <<
" [village] points to a non-village location " << loc << std::endl;
380 bool gamestate_changed =
false;
391 if(old_value.
blank())
396 return gamestate_changed;
401 const std::set<map_location>::const_iterator vil =
villages_.find(loc);
443 if(teams ==
nullptr || index >= teams->size()) {
457 if(&(*teams)[index] ==
this) {
465 LOG_NGE <<
"team " <<
info_.
side <<
" calculates if it has enemy in team "<<index+1 <<
"; our team_name ["<<
info_.
team_name<<
"], their team_name is ["<<(*teams)[
index].info_.team_name<<
"]"<< std::endl;
466 for(std::vector<std::string>::const_iterator
t = our_teams.begin();
t != our_teams.end(); ++
t) {
467 if(
std::find(their_teams.begin(), their_teams.end(), *
t) != their_teams.end())
469 LOG_NGE <<
"team " <<
info_.
side <<
" found same team name [" << *
t <<
"] in team "<< index+1 << std::endl;
472 LOG_NGE <<
"team " <<
info_.
side <<
" not found same team name [" << *
t <<
"] in team "<< index+1 << std::endl;
475 LOG_NGE <<
"team " <<
info_.
side <<
" has enemy in team " << index+1 << std::endl;
484 controller_server_choice(team::CONTROLLER new_controller,
const team&
team)
485 : new_controller_(new_controller)
492 return config_of(
"controller", new_controller_)(
"is_local",
true);
498 (
"new_controller", new_controller_)
499 (
"old_controller", team_.controller())
500 (
"side", team_.side());
502 virtual const char*
name()
const
504 return "change_controller_wml";
507 team::CONTROLLER new_controller_;
514 CONTROLLER new_controller;
515 if(!new_controller.parse(new_controller_string)) {
516 ERR_NG <<
"ignored attempt to change controller to " << new_controller_string << std::endl;
520 ERR_NG <<
"ignored attempt to change the currently playing side's controller to 'null'" << std::endl;
524 if(!new_controller.parse(choice[
"controller"])) {
526 ERR_NG <<
"recieved an invalid controller string from the server" << choice[
"controller"] << std::endl;
537 if (!user_name.
empty())
551 if(teams !=
nullptr) {
552 for(std::vector<team>::const_iterator
i = teams->begin();
i != teams->end(); ++
i) {
554 i->ally_shroud_.clear();
555 i->ally_fog_.clear();
589 const std::vector<const team::shroud_map*>&
team::ally_shroud(
const std::vector<team>& teams)
const
592 for(
size_t i = 0;
i < teams.size(); ++
i) {
602 const std::vector<const team::shroud_map*>&
team::ally_fog(
const std::vector<team>& teams)
const
605 for(
size_t i = 0;
i < teams.size(); ++
i) {
620 if(
this == &t)
return true;
650 hexes.begin(), hexes.end(),
result.begin());
659 if(teams ==
nullptr) {
663 if(side < 1 || side >
int(teams->size())) {
664 throw game::game_error(
"invalid side(" + std::to_string(side) +
") found in unit definition");
670 if(
enabled_ ==
false || x < 0 || y < 0)
673 if(x >= static_cast<int>(
data_.size()))
676 if(y >= static_cast<int>(
data_[x].
size()))
679 if(
data_[x][y] ==
false) {
689 if(enabled_ ==
false || x < 0 || y < 0)
692 if (x >= static_cast<int>(data_.size())) {
693 DBG_NG <<
"Couldn't place shroud on invalid x coordinate: ("
694 << x <<
", " << y <<
") - max x: " << data_.size() - 1 <<
"\n";
695 }
else if (y >= static_cast<int>(data_[x].
size())) {
696 DBG_NG <<
"Couldn't place shroud on invalid y coordinate: ("
697 << x <<
", " << y <<
") - max y: " << data_[
x].size() - 1 <<
"\n";
705 if(enabled_ ==
false)
708 for(std::vector<std::vector<bool> >::
iterator i = data_.begin();
i != data_.end(); ++
i) {
709 std::fill(
i->begin(),
i->end(),
false);
735 if ( x < 0 || y < 0 )
739 for (
const shroud_map *
const shared_map : maps) {
740 if ( shared_map->enabled_ && !shared_map->value(x,y) )
748 std::stringstream shroud_str;
749 for(std::vector<std::vector<bool> >::const_iterator sh = data_.begin(); sh != data_.end(); ++sh) {
752 for(std::vector<bool>::const_iterator
i = sh->begin();
i != sh->end(); ++
i) {
753 shroud_str << (*
i ?
'1' :
'0');
759 return shroud_str.str();
765 for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) {
767 data_.resize(data_.size()+1);
769 if(data_.empty() ==
false) {
771 data_.back().push_back(
true);
773 data_.back().push_back(
false);
781 for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) {
782 if(*sh ==
'|' && sh != str.begin()) {
785 }
else if(*sh ==
'1') {
788 }
else if(*sh ==
'0') {
796 if(enabled_ ==
false)
799 bool cleared =
false;
800 for(std::vector<const shroud_map*>::const_iterator
i = maps.begin();
i != maps.end(); ++
i) {
801 if((*i)->enabled_ ==
false)
804 const std::vector<std::vector<bool> >&
v = (*i)->data_;
805 for(
size_t x = 0;
x != v.size(); ++
x) {
806 for(
size_t y = 0;
y != v[
x].size(); ++
y) {
825 return(
color_range(0x00FF0000,0x00FFFFFF,0x00000000,0x00FF0000));
842 size_t index = size_t(side-1);
846 if(!side_map.empty()) {
850 return std::to_string(side);
864 LOG_NG <<
"Adding recruitable units: \n";
867 LOG_NG << *it << std::endl;
869 LOG_NG <<
"Added all recruitable units\n";
882 std::vector<int>
res;
883 for(
const team&
t : *teams)
885 if(!
t.is_enemy(this->side()) &&
t.is_human()) {
886 res.push_back(
t.side());
const t_string & faction_name() const
play_controller * controller
child_itors child_range(const std::string &key)
static const int default_team_gold_
const std::string & flag() const
std::vector< bool > enemies_
bool translatable() const
std::string last_recruit_
const std::string & current_player() const
void write(config &cfg) const
static std::string get_side_highlight(int side)
const std::string & color() const
std::map< std::string, color_range > team_rgb_range
void handle_legacy_share_vision(const config &cfg)
void set_objectives(const t_string &new_objectives, bool silently=false)
bool shrouded(const map_location &loc) const
const std::set< std::string > & recruits() const
SDL_Color int_to_color(const Uint32 rgb)
void handle_legacy_share_vision(const config &cfg)
static const color_range get_side_color_range(int side)
bool is_village(const map_location &loc) const
double carryover_bonus() const
bool is_enemy(int n) const
const t_string & objectives() const
void clear(const std::string &key)
virtual config local_choice() const =0
We are in a game with no mp server and need to do this choice locally.
bool objectives_changed() const
unit_type_data unit_types
void build(const config &cfg, const gamemap &map, int gold=default_team_gold_)
bool fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
int minimum_recruit_price
DEFEAT_CONDITION defeat_condition() const
boost::shared_ptr< wb::side_actions > planned_actions_
Whiteboard planned actions for this team.
GLint GLint GLint GLint GLint GLint y
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
bool objectives_changed
< Team's objectives for the current level.
void add_recruit(const std::string &)
void change_controller(const std::string &new_controller)
int carryover_gold() const
Variant for storing WML attributes.
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
SHARE_VISION share_vision() const
static std::string get_side_highlight_pango(int side)
bool blank() const
Tests for an attribute that was never set.
static const boost::container::flat_set< std::string > attributes
Stores the attributes recognized by [side].
static lg::log_domain log_engine_enemies("engine/enemies")
static bool add_ai_for_side_from_file(side_number side, const std::string &file, bool replace=true)
Adds active AI for specified side from file.
static std::vector< team > *& teams
static void raise_recruit_list_changed()
Notifies all observers of 'ai_recruit_list_changed' event.
This class stores all the data for a single 'side' (in game nomenclature).
bool calculate_enemies(size_t index) const
const std::string & flag_icon() const
std::vector< team > * teams
void read(const config &cfg)
virtual const char * name() const =0
int village_support() const
const t_string & user_team_name() const
int carryover_percentage() const
const int gold_carryover_percentage
Default percentage gold carried over to the next scenario.
void set_local(bool local)
static config to_config(side_number side)
Gets AI config for active AI of the given side.
void write(config &cfg) const
Encapsulates the map of the game.
config & add_child(const std::string &key)
const std::string & team_name() const
void log_recruitable() const
Managing the AIs lifecycle - headers.
void merge(const std::string &shroud_data)
Error used for any general game error, e.g.
bool auto_shroud_updates_
void remove_fog_override(const std::set< map_location > &hexes)
Removes the record of hexes that were cleared of fog via WML.
std::vector< const shroud_map * > ally_fog_
game_events::manager * game_events
const std::string & save_id() const
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
Encapsulates the map of the game.
bool calculate_is_enemy(size_t index) const
std::vector< map_location > parse_location_range(const std::string &xvals, const std::string &yvals, bool with_border=false) const
Parses ranges of locations into a vector of locations, using this map's dimensions as bounds...
static void clear_caches()
clear the shroud, fog, and enemies cache for all teams
const std::vector< const shroud_map * > & ally_shroud(const std::vector< team > &teams) const
void write_location_range(const std::set< map_location > &locs, config &cfg)
Write a set of locations into a config using ranges, adding keys x=x1,..,xn and y=y1a-y1b,..,yna-ynb.
bool value(int x, int y) const
const std::vector< const shroud_map * > & ally_fog(const std::vector< team > &teams) const
const std::string & faction() const
void read(const std::string &shroud_data)
void set_enabled(bool enabled)
Game configuration data as global variables.
std::set< map_location > villages_
static SDL_Color get_minimap_color(int side)
Define the game's event mechanism.
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
static SDL_Color get_side_color(int side)
GLint GLint GLint GLint GLint x
bool fogged(const map_location &loc) const
static t_string from_serialized(const std::string &string)
void validate_side(int side)
bool no_turn_confirmation() const
static bool add_ai_for_side_from_config(side_number side, const config &cfg, bool replace=true)
Adds active AI for specified side from cfg.
std::vector< const shroud_map * > ally_shroud_
recall_list_manager recall_list_
void change_controller_by_wml(const std::string &new_controller)
static lg::log_domain log_engine("engine")
game_events::t_pump & pump()
GLuint const GLchar * name
CONTROLLER controller() const
bool knows_about_team(size_t index) const
int countdown_time() const
bool has_attribute(const std::string &key) const
std::set< map_location > fog_clearer_
Stores hexes that have been cleared of fog via WML.
const std::string & side_name() const
bool find(E event, F functor)
Tests whether an event handler is available.
void lose_village(const map_location &)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
std::vector< std::vector< bool > > data_
static std::string get_side_color_index(int side)
void change_team(const std::string &name, const t_string &user_name)
std::string rgb2highlight(Uint32 rgb)
Converts a color value to WML text markup syntax for highlighting.
std::set< std::string > can_recruit
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
bool carryover_add() const
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::string rgb2highlight_pango(Uint32 rgb)
Converts a color value to WML text markup syntax for highlighting.
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
void set_recruits(const std::set< std::string > &recruits)
std::string allied_human_teams() const
A config object defines a single node in a WML file, with access to child nodes.
int action_bonus_count() const
bool copy_from(const std::vector< const shroud_map * > &maps)
virtual config request() const =0
the request which is sended to the mp server.
GLsizei const GLcharARB ** string
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
std::string write() const
bool shared_value(const std::vector< const shroud_map * > &maps, int x, int y) const
bool get_village(const map_location &, const int owner_side, game_data *fire_event)
Acquires a village from owner_side. Pointer fire_event should be the game_data for the game if it is ...
static config ask_server_choice(const server_choice &)
int minimum_recruit_price() const