Deploy display_context::get_team when possible
This replaces uses of teams()[side - 1] when appropriate. Doesn't touch usecases in other classes.
This commit is contained in:
parent
d4529dfc1e
commit
f9a021eaab
18 changed files with 36 additions and 36 deletions
|
@ -170,7 +170,7 @@ namespace
|
|||
{
|
||||
//the 'side' parameter might differ from side_num_-
|
||||
int res = 0;
|
||||
team t = resources::gameboard->teams()[side_num_ - 1];
|
||||
team t = resources::gameboard->get_team(side_num_);
|
||||
//i wonder how this got included here ?
|
||||
bool is_mp = resources::controller->is_networked_mp();
|
||||
bool is_current_side = resources::controller->current_side() == side_num_;
|
||||
|
|
|
@ -854,7 +854,7 @@ namespace {
|
|||
// The event could have killed either the attacker or
|
||||
// defender, so we have to make sure they still exist
|
||||
refresh_bc();
|
||||
if(!a_.valid() || !d_.valid() || !resources::gameboard->teams()[a_.get_unit().side() - 1].is_enemy(d_.get_unit().side())) {
|
||||
if(!a_.valid() || !d_.valid() || !resources::gameboard->get_team(a_.get_unit().side()).is_enemy(d_.get_unit().side())) {
|
||||
actions::recalculate_fog(defender_side);
|
||||
if (update_display_){
|
||||
resources::screen->redraw_minimap();
|
||||
|
|
|
@ -440,7 +440,7 @@ void undo_list::redo()
|
|||
bool undo_list::apply_shroud_changes() const
|
||||
{
|
||||
game_display &disp = *resources::screen;
|
||||
team &tm = resources::gameboard->teams()[side_ - 1];
|
||||
team &tm = resources::gameboard->get_team(side_);
|
||||
// No need to do clearing if fog/shroud has been kept up-to-date.
|
||||
if ( tm.auto_shroud_updates() || !tm.fog_or_shroud() ) {
|
||||
return false;
|
||||
|
|
|
@ -706,7 +706,7 @@ bool actor_sighted(const unit & target, const std::vector<int> * cache)
|
|||
*/
|
||||
void recalculate_fog(int side)
|
||||
{
|
||||
team &tm = resources::gameboard->teams()[side - 1];
|
||||
team &tm = resources::gameboard->get_team(side);
|
||||
|
||||
if (!tm.uses_fog())
|
||||
return;
|
||||
|
@ -755,7 +755,7 @@ void recalculate_fog(int side)
|
|||
*/
|
||||
bool clear_shroud(int side, bool reset_fog, bool fire_events)
|
||||
{
|
||||
team &tm = resources::gameboard->teams()[side - 1];
|
||||
team &tm = resources::gameboard->get_team(side);
|
||||
if (!tm.uses_shroud() && !tm.uses_fog())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -1631,7 +1631,7 @@ void leader_shares_keep_phase::execute()
|
|||
//for each leader, check if he's allied and can reach our keep
|
||||
for(path_map::const_iterator i = possible_moves.begin(); i != possible_moves.end(); ++i){
|
||||
const unit_map::const_iterator itor = resources::gameboard->units().find(i->first);
|
||||
team &leader_team = resources::gameboard->teams()[itor->side() - 1];
|
||||
team &leader_team = resources::gameboard->get_team(itor->side());
|
||||
if(itor != resources::gameboard->units().end() && itor->can_recruit() && itor->side() != get_side() && (leader_team.total_income() + leader_team.gold() > leader_team.minimum_recruit_price())){
|
||||
pathfind::paths::dest_vect::const_iterator tokeep = i->second.destinations.find(keep);
|
||||
if(tokeep != i->second.destinations.end()){
|
||||
|
|
|
@ -82,7 +82,7 @@ int default_ai_context_impl::count_free_hexes_in_castle(const map_location &loc,
|
|||
if (u == units_.end()
|
||||
|| (current_team().is_enemy(u->side())
|
||||
&& u->invisible(adj[n], *resources::gameboard))
|
||||
|| ((&resources::gameboard->teams()[u->side() - 1]) == ¤t_team()
|
||||
|| ((&resources::gameboard->get_team(u->side()) == ¤t_team())
|
||||
&& u->movement_left() > 0)) {
|
||||
ret += 1;
|
||||
}
|
||||
|
|
|
@ -677,7 +677,7 @@ double recruitment::get_average_defense(const std::string& u_type) const {
|
|||
*/
|
||||
const pathfind::full_cost_map recruitment::get_cost_map_of_side(int side) const {
|
||||
const unit_map& units = resources::gameboard->units();
|
||||
const team& team = resources::gameboard->teams()[side - 1];
|
||||
const team& team = resources::gameboard->get_team(side);
|
||||
|
||||
pathfind::full_cost_map cost_map(true, true, team, true, true);
|
||||
|
||||
|
@ -748,7 +748,7 @@ void recruitment::update_average_lawful_bonus() {
|
|||
void recruitment::update_average_local_cost() {
|
||||
average_local_cost_.clear();
|
||||
const gamemap& map = resources::gameboard->map();
|
||||
const team& team = resources::gameboard->teams()[get_side() - 1];
|
||||
const team& team = resources::gameboard->get_team(get_side());
|
||||
|
||||
for(int x = 0; x < map.w(); ++x) {
|
||||
for (int y = 0; y < map.h(); ++y) {
|
||||
|
@ -1411,7 +1411,7 @@ bool recruitment::remove_job_if_no_blocker(config* job) {
|
|||
* positive or negative.
|
||||
*/
|
||||
double recruitment::get_estimated_income(int turns) const {
|
||||
const team& team = resources::gameboard->teams()[get_side() - 1];
|
||||
const team& team = resources::gameboard->get_team(get_side());
|
||||
const size_t own_villages = team.villages().size();
|
||||
const double village_gain = get_estimated_village_gain();
|
||||
const double unit_gain = get_estimated_unit_gain();
|
||||
|
|
|
@ -80,7 +80,7 @@ bool display_context::unit_can_move(const unit &u) const
|
|||
return false;
|
||||
}
|
||||
|
||||
const team ¤t_team = teams()[u.side() - 1];
|
||||
const team ¤t_team = get_team(u.side());
|
||||
|
||||
map_location locs[6];
|
||||
get_adjacent_tiles(u.get_location(), locs);
|
||||
|
|
|
@ -177,12 +177,12 @@ void verify_and_set_global_variable(const vconfig &pcfg)
|
|||
if (unsigned(side-1) > resources::gameboard->teams().size()) {
|
||||
ERR_PERSIST << "[set_global_variable] attribute \"side\" specifies invalid side number.";
|
||||
valid = false;
|
||||
} else if (resources::gameboard->teams()[side - 1].is_empty()) {
|
||||
} else if (resources::gameboard->get_team(side).is_empty()) {
|
||||
LOG_PERSIST << "[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
|
||||
valid = false;
|
||||
} else {
|
||||
//Set the variable only if it is meant for a side we control
|
||||
valid = resources::gameboard->teams()[side - 1].is_local();
|
||||
valid = resources::gameboard->get_team(side).is_local();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,12 +216,12 @@ void verify_and_clear_global_variable(const vconfig &pcfg)
|
|||
if (unsigned(side-1) > resources::gameboard->teams().size()) {
|
||||
ERR_PERSIST << "[clear_global_variable] attribute \"side\" specifies invalid side number.";
|
||||
valid = false;
|
||||
} else if (resources::gameboard->teams()[side - 1].is_empty()) {
|
||||
} else if (resources::gameboard->get_team(side).is_empty()) {
|
||||
LOG_PERSIST << "[clear_global_variable] attribute \"side\" specifies a null-controlled side number.";
|
||||
valid = false;
|
||||
} else {
|
||||
//Clear the variable only if it is meant for a side we control
|
||||
valid = resources::gameboard->teams()[side - 1].is_local();
|
||||
valid = resources::gameboard->get_team(side).is_local();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -666,13 +666,13 @@ void play_controller::tab()
|
|||
team& play_controller::current_team()
|
||||
{
|
||||
assert(current_side() > 0 && current_side() <= int(gamestate().board_.teams().size()));
|
||||
return gamestate().board_.teams_[current_side() - 1];
|
||||
return gamestate().board_.get_team(current_side());
|
||||
}
|
||||
|
||||
const team& play_controller::current_team() const
|
||||
{
|
||||
assert(current_side() > 0 && current_side() <= int(gamestate().board_.teams().size()));
|
||||
return gamestate().board_.teams()[current_side() - 1];
|
||||
return gamestate().board_.get_team(current_side());
|
||||
}
|
||||
|
||||
/// @returns: the number n in [min, min+mod ) so that (n - num) is a multiple of mod.
|
||||
|
@ -692,7 +692,7 @@ static int modulo(int num, int mod, int min)
|
|||
|
||||
bool play_controller::is_team_visible(int team_num, bool observer) const
|
||||
{
|
||||
const team& t = gamestate().board_.teams()[team_num - 1];
|
||||
const team& t = gamestate().board_.get_team(team_num);
|
||||
if(observer) {
|
||||
return !t.get_disallow_observers() && !t.is_empty();
|
||||
}
|
||||
|
@ -1132,7 +1132,7 @@ void play_controller::play_side()
|
|||
// This flag can be set by derived classes (in overridden functions).
|
||||
player_type_changed_ = false;
|
||||
|
||||
statistics::reset_turn_stats(gamestate().board_.teams()[current_side() - 1].save_id());
|
||||
statistics::reset_turn_stats(gamestate().board_.get_team(current_side()).save_id());
|
||||
|
||||
play_side_impl();
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ void playsingle_controller::show_turn_dialog(){
|
|||
gui_->recalculate_minimap();
|
||||
std::string message = _("It is now $name|’s turn");
|
||||
utils::string_map symbols;
|
||||
symbols["name"] = gamestate().board_.teams()[current_side() - 1].side_name();
|
||||
symbols["name"] = gamestate().board_.get_team(current_side()).side_name();
|
||||
message = utils::interpolate_variables_into_string(message, &symbols);
|
||||
gui2::show_transient_message(gui_->video(), "", message);
|
||||
}
|
||||
|
|
|
@ -682,7 +682,7 @@ REPLAY_RETURN do_replay(bool one_move)
|
|||
REPLAY_RETURN do_replay_handle(bool one_move)
|
||||
{
|
||||
|
||||
//team ¤t_team = resources::gameboard->teams()[side_num - 1];
|
||||
//team ¤t_team = resources::gameboard->get_team(side_num);
|
||||
|
||||
const int side_num = resources::controller->current_side();
|
||||
while(true)
|
||||
|
@ -812,7 +812,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
|
||||
replay::process_error(errbuf.str());
|
||||
} else {
|
||||
resources::gameboard->teams()[tval - 1].set_countdown_time(val);
|
||||
resources::gameboard->get_team(tval).set_countdown_time(val);
|
||||
}
|
||||
}
|
||||
else if ((*cfg)["dependent"].to_bool(false))
|
||||
|
|
|
@ -45,7 +45,7 @@ unit* lua_unit::get()
|
|||
if (ptr) return ptr.get();
|
||||
if (c_ptr) return c_ptr;
|
||||
if (side) {
|
||||
return resources::gameboard->teams()[side - 1].recall_list().find_if_matches_underlying_id(uid).get();
|
||||
return resources::gameboard->get_team(side).recall_list().find_if_matches_underlying_id(uid).get();
|
||||
}
|
||||
unit_map::unit_iterator ui = resources::gameboard->units().find(uid);
|
||||
if (!ui.valid()) return nullptr;
|
||||
|
@ -55,7 +55,7 @@ unit_ptr lua_unit::get_shared()
|
|||
{
|
||||
if (ptr) return ptr;
|
||||
if (side) {
|
||||
return resources::gameboard->teams()[side - 1].recall_list().find_if_matches_underlying_id(uid);
|
||||
return resources::gameboard->get_team(side).recall_list().find_if_matches_underlying_id(uid);
|
||||
}
|
||||
unit_map::unit_iterator ui = resources::gameboard->units().find(uid);
|
||||
if (!ui.valid()) return unit_ptr();
|
||||
|
@ -80,7 +80,7 @@ bool lua_unit::put_map(const map_location &loc)
|
|||
return false;
|
||||
}
|
||||
} else if (side) { // recall list
|
||||
unit_ptr it = resources::gameboard->teams()[side - 1].recall_list().extract_if_matches_underlying_id(uid);
|
||||
unit_ptr it = resources::gameboard->get_team(side).recall_list().extract_if_matches_underlying_id(uid);
|
||||
if (it) {
|
||||
side = 0;
|
||||
// uid may be changed by unit_map on insertion
|
||||
|
|
|
@ -67,7 +67,7 @@ synced_command::map& synced_command::registry()
|
|||
SYNCED_COMMAND_HANDLER_FUNCTION(recruit, child, use_undo, show, error_handler)
|
||||
{
|
||||
int current_team_num = resources::controller->current_side();
|
||||
team ¤t_team = resources::gameboard->teams()[current_team_num - 1];
|
||||
team ¤t_team = resources::gameboard->get_team(current_team_num);
|
||||
|
||||
map_location loc(child, resources::gamedata);
|
||||
map_location from(child.child_or_empty("from"), resources::gamedata);
|
||||
|
@ -132,7 +132,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(recall, child, use_undo, show, error_handler)
|
|||
{
|
||||
|
||||
int current_team_num = resources::controller->current_side();
|
||||
team ¤t_team = resources::gameboard->teams()[current_team_num - 1];
|
||||
team ¤t_team = resources::gameboard->get_team(current_team_num);
|
||||
|
||||
const std::string& unit_id = child["value"];
|
||||
map_location loc(child, resources::gamedata);
|
||||
|
@ -231,7 +231,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(disband, child, /*use_undo*/, /*show*/, error_ha
|
|||
{
|
||||
|
||||
int current_team_num = resources::controller->current_side();
|
||||
team ¤t_team = resources::gameboard->teams()[current_team_num - 1];
|
||||
team ¤t_team = resources::gameboard->get_team(current_team_num);
|
||||
|
||||
const std::string& unit_id = child["value"];
|
||||
size_t old_size = current_team.recall_list().size();
|
||||
|
@ -254,7 +254,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(disband, child, /*use_undo*/, /*show*/, error_ha
|
|||
SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler)
|
||||
{
|
||||
int current_team_num = resources::controller->current_side();
|
||||
team ¤t_team = resources::gameboard->teams()[current_team_num - 1];
|
||||
team ¤t_team = resources::gameboard->get_team(current_team_num);
|
||||
|
||||
std::vector<map_location> steps;
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
return false;
|
||||
if (i.has_attribute("is_enemy")) {
|
||||
const display_context& dc = resources::filter_con->get_disp_context();
|
||||
if (i["is_enemy"].to_bool() != dc.teams()[unit->side() - 1].is_enemy(side_)) {
|
||||
if (i["is_enemy"].to_bool() != dc.get_team(unit->side()).is_enemy(side_)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ bool attack_type::special_active(const config& special, AFFECTS whom,
|
|||
return false;
|
||||
if (i.has_attribute("is_enemy")) {
|
||||
const display_context& dc = resources::filter_con->get_disp_context();
|
||||
if (i["is_enemy"].to_bool() != dc.teams()[unit->side() - 1].is_enemy(self->side())) {
|
||||
if (i["is_enemy"].to_bool() != dc.get_team(unit->side()).is_enemy(self->side())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,9 +512,9 @@ bool basic_unit_filter_impl::internal_matches_filter(const unit & u, const map_l
|
|||
|
||||
bool found = false;
|
||||
for (const int viewer : viewers) {
|
||||
bool fogged = fc_.get_disp_context().teams()[viewer - 1].fogged(loc);
|
||||
bool fogged = fc_.get_disp_context().get_team(viewer).fogged(loc);
|
||||
bool hiding = u.invisible(loc, fc_.get_disp_context())
|
||||
&& fc_.get_disp_context().teams()[viewer - 1].is_enemy(u.side());
|
||||
&& fc_.get_disp_context().get_team(viewer).is_enemy(u.side());
|
||||
bool unit_hidden = fogged || hiding;
|
||||
if (vision["visible"].to_bool(true) != unit_hidden) {
|
||||
found = true;
|
||||
|
@ -552,7 +552,7 @@ bool basic_unit_filter_impl::internal_matches_filter(const unit & u, const map_l
|
|||
is_enemy = adj_cfg["is_enemy"].to_bool();
|
||||
}
|
||||
if (!is_enemy || *is_enemy ==
|
||||
fc_.get_disp_context().teams()[u.side() - 1].is_enemy(unit_itor->side())) {
|
||||
fc_.get_disp_context().get_team(u.side()).is_enemy(unit_itor->side())) {
|
||||
++match_count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ action::error attack::check_validity() const
|
|||
return NO_ATTACK_LEFT;
|
||||
}
|
||||
// Verify that the attacker and target are enemies
|
||||
if(!resources::gameboard->teams()[get_unit()->side() - 1].is_enemy(resources::gameboard->units().find(target_hex_)->side())){
|
||||
if(!resources::gameboard->get_team(get_unit()->side()).is_enemy(resources::gameboard->units().find(target_hex_)->side())){
|
||||
return NOT_AN_ENEMY;
|
||||
}
|
||||
//@todo: (maybe) verify that the target hex contains the same unit that before,
|
||||
|
|
|
@ -57,7 +57,7 @@ side_actions_ptr viewer_actions()
|
|||
side_actions_ptr current_side_actions()
|
||||
{
|
||||
side_actions_ptr side_actions =
|
||||
resources::gameboard->teams()[resources::controller->current_side() - 1].get_side_actions();
|
||||
resources::gameboard->get_team(resources::controller->current_side()).get_side_actions();
|
||||
return side_actions;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue