Skip to content

Commit

Permalink
Made more use of play_controller::get_teams
Browse files Browse the repository at this point in the history
Looks like some of these (esp in mouse_handler) would not have worked before without the non-const overload of get_teams.
  • Loading branch information
Vultraz committed Jan 3, 2021
1 parent 3006359 commit 627bde7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/mouse_events.cpp
Expand Up @@ -1380,7 +1380,7 @@ std::set<map_location> mouse_handler::get_adj_enemies(const map_location& loc, i
{
std::set<map_location> res;

const team& uteam = pc_.gamestate().board_.teams_[side - 1];
const team& uteam = pc_.get_teams()[side - 1];

adjacent_loc_array_t adj;
get_adjacent_tiles(loc, adj.data());
Expand Down Expand Up @@ -1411,7 +1411,7 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator& u)

// Get the teams involved.
const team& cur_team = current_team();
const team& u_team = pc_.gamestate().board_.teams_[u->side() - 1];
const team& u_team = pc_.get_teams()[u->side() - 1];

// Check each adjacent hex.
adjacent_loc_array_t adj;
Expand Down Expand Up @@ -1514,17 +1514,17 @@ void mouse_handler::set_current_paths(const pathfind::paths& new_paths)

team& mouse_handler::viewing_team()
{
return pc_.gamestate().board_.teams_[gui().viewing_team()];
return pc_.get_teams()[gui().viewing_team()];
}

const team& mouse_handler::viewing_team() const
{
return pc_.gamestate().board_.teams()[gui().viewing_team()];
return pc_.get_teams()[gui().viewing_team()];
}

team& mouse_handler::current_team()
{
return pc_.gamestate().board_.teams_[side_num_ - 1];
return pc_.get_teams()[side_num_ - 1];
}

mouse_handler* mouse_handler::singleton_ = nullptr;
Expand Down
26 changes: 13 additions & 13 deletions src/play_controller.cpp
Expand Up @@ -274,7 +274,7 @@ void play_controller::init(const config& level)
// Find first team that is allowed to be observed.
// If not set here observer would be without fog until
// the first turn of observable side
for (const team& t : gamestate().board_.teams())
for (const team& t : get_teams())
{
if (!t.get_disallow_observers())
{
Expand Down Expand Up @@ -675,7 +675,7 @@ void play_controller::tab()
for (const unit& u : gamestate().board_.units()){
const map_location& loc = u.get_location();
if(!gui_->fogged(loc) &&
!(gamestate().board_.teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
!(get_teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
dictionary.insert(u.name());
}
//TODO List map labels
Expand All @@ -689,7 +689,7 @@ void play_controller::tab()
}
case gui::TEXTBOX_MESSAGE:
{
for (const team& t : gamestate().board_.teams()) {
for (const team& t : get_teams()) {
if(!t.is_empty())
dictionary.insert(t.current_player());
}
Expand Down Expand Up @@ -726,7 +726,7 @@ void play_controller::tab()

team& play_controller::current_team()
{
if(gamestate().board_.teams().size() == 0) {
if(get_teams().size() == 0) {
throw game::game_error("The scenario has no sides defined");
}
assert(gamestate().board_.has_team(current_side()));
Expand All @@ -735,7 +735,7 @@ team& play_controller::current_team()

const team& play_controller::current_team() const
{
if(gamestate().board_.teams().size() == 0) {
if(get_teams().size() == 0) {
throw game::game_error("The scenario has no sides defined");
}
assert(gamestate().board_.has_team(current_side()));
Expand All @@ -755,8 +755,8 @@ bool play_controller::is_team_visible(int team_num, bool observer) const

int play_controller::find_last_visible_team() const
{
assert(current_side() <= static_cast<int>(gamestate().board_.teams().size()));
const int num_teams = gamestate().board_.teams().size();
assert(current_side() <= static_cast<int>(get_teams().size()));
const int num_teams = get_teams().size();
const bool is_observer = this->is_observer();

for(int i = 0; i < num_teams; i++) {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ void play_controller::start_game()
return;
}

for (const team& t : gamestate().board_.teams()) {
for (const team& t : get_teams()) {
actions::clear_shroud(t.side(), false, false);
}

Expand All @@ -1138,7 +1138,7 @@ void play_controller::start_game()
sync.do_final_checkup();
gui_->recalculate_minimap();
// Initialize countdown clock.
for (const team& t : gamestate().board_.teams())
for (const team& t : get_teams())
{
if (saved_game_.mp_settings().mp_countdown) {
t.set_countdown_time(1000 * saved_game_.mp_settings().mp_countdown_init_time);
Expand Down Expand Up @@ -1216,7 +1216,7 @@ void play_controller::play_turn()
int last_player_number = gamestate_->player_number_;
int next_player_number = gamestate_->next_player_number_;

while(gamestate_->player_number_ <= static_cast<int>(gamestate().board_.teams().size())) {
while(gamestate_->player_number_ <= static_cast<int>(get_teams().size())) {
gamestate_->next_player_number_ = gamestate_->player_number_ + 1;
next_player_number = gamestate_->next_player_number_;
last_player_number = gamestate_->player_number_;
Expand All @@ -1233,7 +1233,7 @@ void play_controller::play_turn()
play_side();
//ignore any changes to next_player_number_ that happen after the [end_turn] is sended to the server, otherwise we will get OOS.
next_player_number = gamestate_->next_player_number_;
assert(next_player_number <= 2 * static_cast<int>(gamestate().board_.teams().size()));
assert(next_player_number <= 2 * static_cast<int>(get_teams().size()));
if(is_regular_game_end()) {
return;
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void play_controller::play_turn()
check_time_over();

if (!is_regular_game_end()) {
gamestate_->player_number_ = modulo(next_player_number, gamestate().board_.teams().size(), 1);
gamestate_->player_number_ = modulo(next_player_number, get_teams().size(), 1);
}
}

Expand Down Expand Up @@ -1310,7 +1310,7 @@ play_controller::scoped_savegame_snapshot::~scoped_savegame_snapshot()

void play_controller::show_objectives() const
{
const team& t = gamestate().board_.teams()[gui_->viewing_team()];
const team& t = get_teams()[gui_->viewing_team()];
static const std::string no_objectives(_("No objectives available"));
std::string objectives = utils::interpolate_variables_into_string(t.objectives(), *gamestate_->get_game_data());
gui2::show_transient_message(get_scenario_name(), (objectives.empty() ? no_objectives : objectives), "", true);
Expand Down
2 changes: 1 addition & 1 deletion src/playmp_controller.cpp
Expand Up @@ -413,7 +413,7 @@ void playmp_controller::maybe_linger()
{
// mouse_handler expects at least one team for linger mode to work.
assert(is_regular_game_end());
if (!get_end_level_data_const().transient.linger_mode || gamestate().board_.teams().empty() || gui_->video().faked()) {
if (!get_end_level_data_const().transient.linger_mode || get_teams().empty() || gui_->video().faked()) {
const bool has_next_scenario = !gamestate().gamedata_.next_scenario().empty() && gamestate().gamedata_.next_scenario() != "null";
if(!is_host() && has_next_scenario) {
// If we continue without lingering we need to
Expand Down
14 changes: 7 additions & 7 deletions src/playsingle_controller.cpp
Expand Up @@ -160,7 +160,7 @@ void playsingle_controller::play_scenario_main_loop()
LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks()) << "\n";

ai_testing::log_game_start();
if(gamestate().board_.teams().empty())
if(get_teams().empty())
{
ERR_NG << "Playing game with 0 teams." << std::endl;
}
Expand Down Expand Up @@ -193,10 +193,10 @@ void playsingle_controller::play_scenario_main_loop()
// game (luckily this is never the case for autosaves).
//
boost::dynamic_bitset<> local_players;
local_players.resize(gamestate().board_.teams().size(), true);
local_players.resize(get_teams().size(), true);
//Preserve side controllers, because we won't get the side controoller updates again when replaying.
for(std::size_t i = 0; i < local_players.size(); ++i) {
local_players[i] = gamestate().board_.teams()[i].is_local();
local_players[i] = get_teams()[i].is_local();
}
if(ex.start_replay) {
// MP "Back to turn"
Expand Down Expand Up @@ -278,7 +278,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)

const end_level_data& end_level = get_end_level_data_const();

if (gamestate().board_.teams().empty())
if (get_teams().empty())
{
//store persistent teams
saved_game_.set_snapshot(config());
Expand Down Expand Up @@ -622,8 +622,8 @@ void playsingle_controller::force_end_turn(){

void playsingle_controller::check_objectives()
{
if (!gamestate().board_.teams().empty()) {
const team &t = gamestate().board_.teams()[gui_->viewing_team()];
if (!get_teams().empty()) {
const team &t = get_teams()[gui_->viewing_team()];

if (!is_regular_game_end() && !is_browsing() && t.objectives_changed()) {
show_objectives();
Expand All @@ -636,7 +636,7 @@ void playsingle_controller::maybe_linger()
{
// mouse_handler expects at least one team for linger mode to work.
assert(is_regular_game_end());
if (get_end_level_data_const().transient.linger_mode && !gamestate().board_.teams().empty()) {
if (get_end_level_data_const().transient.linger_mode && !get_teams().empty()) {
linger();
}
}
Expand Down

0 comments on commit 627bde7

Please sign in to comment.