Display: rename [viewing|playing]_team to [viewing|playing]_index

This commit is contained in:
Charles Dang 2024-08-31 18:27:28 -04:00
parent 7fa4fe483c
commit 58472054fb
19 changed files with 54 additions and 54 deletions

View file

@ -358,7 +358,7 @@ namespace { // Private helpers for move_unit()
: spectator_(move_spectator)
, skip_sighting_(skip_sightings)
, skip_ally_sighting_(skip_ally_sightings)
, playing_team_is_viewing_(display::get_singleton()->playing_team() == display::get_singleton()->viewing_team() || display::get_singleton()->show_everything())
, playing_team_is_viewing_(display::get_singleton()->playing_team_index() == display::get_singleton()->viewing_team_index() || display::get_singleton()->show_everything())
, route_(route)
, begin_(route.begin())
, full_end_(route.end())

View file

@ -2821,7 +2821,7 @@ void display::draw_overlays_at(const map_location& loc)
if(dont_show_all_ && !ov.team_name.empty()) {
// dont_show_all_ imples that viewing_team() is a valid index to get_teams()
const std::string& current_team_name = get_teams()[viewing_team()].team_name();
const std::string& current_team_name = get_teams()[viewing_team_index()].team_name();
const std::vector<std::string>& current_team_names = utils::split(current_team_name);
const std::vector<std::string>& team_names = utils::split(ov.team_name);

View file

@ -109,7 +109,7 @@ public:
const std::vector<team>& get_teams() const {return dc_->teams();}
/** The playing team is the team whose turn it is. */
std::size_t playing_team() const { return activeTeam_; }
std::size_t playing_team_index() const { return activeTeam_; }
/**
* The viewing team is the team currently viewing the game. It's the team whose gold and income
@ -119,9 +119,10 @@ public:
*
* The value returned is a 0-based index into the vector returned by get_teams().
*/
std::size_t viewing_team() const { return currentTeam_; }
std::size_t viewing_team_index() const { return currentTeam_; }
/**
* The 1-based equivalent of the 0-based viewing_team() function. This is the side-number that
* The 1-based equivalent of the 0-based viewing_team_index() function. This is the side-number that
* WML uses.
*
* TODO: provide a better interface in a better place (consistent base numbers, and not in a GUI

View file

@ -26,7 +26,7 @@ std::unique_ptr<editor_action> mouse_action_village::up_left(editor_display& dis
if (!disp.get_map().on_board(hex)) return nullptr;
if (!disp.get_map().is_village(hex)) return nullptr;
return std::make_unique<editor_action_village>(hex, disp.playing_team());
return std::make_unique<editor_action_village>(hex, disp.playing_team_index());
}
std::unique_ptr<editor_action> mouse_action_village::up_right(editor_display& disp, int x, int y)

View file

@ -632,7 +632,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(const hotkey::ui_comman
case editor::ADDON:
return ACTION_STATELESS;
case editor::SIDE:
return static_cast<std::size_t>(index) == gui_->playing_team()
return static_cast<std::size_t>(index) == gui_->playing_team_index()
? ACTION_SELECTED : ACTION_DESELECTED;
case editor::TIME:
return index == get_current_map_context().get_time_manager()->get_current_time()
@ -1091,7 +1091,7 @@ bool editor_controller::do_execute_command(const hotkey::ui_command& cmd, bool p
get_current_map_context().remove_side();
return true;
case HOTKEY_EDITOR_SIDE_EDIT:
context_manager_->edit_side_dialog(gui_->viewing_team());
context_manager_->edit_side_dialog(gui_->viewing_team_index());
return true;
// Transitions

View file

@ -118,12 +118,12 @@ void game_display::highlight_hex(map_location hex)
{
wb::future_map_if future(!synced_context::is_synced()); /**< Lasts for whole method. */
const unit *u = dc_->get_visible_unit(hex, dc_->teams()[viewing_team()], !dont_show_all_);
const unit *u = dc_->get_visible_unit(hex, dc_->teams()[viewing_team_index()], !dont_show_all_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
} else {
u = dc_->get_visible_unit(mouseoverHex_, dc_->teams()[viewing_team()], !dont_show_all_);
u = dc_->get_visible_unit(mouseoverHex_, dc_->teams()[viewing_team_index()], !dont_show_all_);
if (u) {
// mouse moved from unit hex to non-unit hex
if (dc_->units().count(selectedHex_)) {
@ -145,7 +145,7 @@ void game_display::display_unit_hex(map_location hex)
wb::future_map_if future(!synced_context::is_synced()); /**< Lasts for whole method. */
const unit *u = dc_->get_visible_unit(hex, dc_->teams()[viewing_team()], !dont_show_all_);
const unit *u = dc_->get_visible_unit(hex, dc_->teams()[viewing_team_index()], !dont_show_all_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
@ -240,7 +240,7 @@ void game_display::draw_hex(const map_location& loc)
if(on_map && loc == mouseoverHex_ && !map_screenshot_) {
drawing_layer hex_top_layer = drawing_layer::mouseover_bottom;
const unit* u = dc_->get_visible_unit(loc, dc_->teams()[viewing_team()]);
const unit* u = dc_->get_visible_unit(loc, dc_->teams()[viewing_team_index()]);
if(u != nullptr) {
hex_top_layer = drawing_layer::mouseover_top;
}

View file

@ -404,7 +404,7 @@ void command_executor::surrender_game() {
if(gui2::show_message(_("Surrender"), _("Do you really want to surrender the game?"), gui2::dialogs::message::yes_no_buttons) != gui2::retval::CANCEL) {
playmp_controller* pmc = dynamic_cast<playmp_controller*>(resources::controller);
if(pmc && !pmc->is_linger_mode() && !pmc->is_observer()) {
pmc->surrender(display::get_singleton()->viewing_team());
pmc->surrender(display::get_singleton()->viewing_team_index());
}
}
}

View file

@ -72,15 +72,15 @@ const game_state & play_controller::hotkey_handler::gamestate() const {
bool play_controller::hotkey_handler::browse() const { return play_controller_.is_browsing(); }
bool play_controller::hotkey_handler::linger() const { return play_controller_.is_linger_mode(); }
const team & play_controller::hotkey_handler::viewing_team() const { return play_controller_.get_teams()[gui()->viewing_team()]; }
bool play_controller::hotkey_handler::viewing_team_is_playing() const { return gui()->viewing_team() == gui()->playing_team(); }
const team & play_controller::hotkey_handler::viewing_team() const { return play_controller_.get_teams()[gui()->viewing_team_index()]; }
bool play_controller::hotkey_handler::viewing_team_is_playing() const { return gui()->viewing_team_index() == gui()->playing_team_index(); }
void play_controller::hotkey_handler::objectives(){
menu_handler_.objectives();
}
void play_controller::hotkey_handler::show_statistics(){
menu_handler_.show_statistics(gui()->viewing_team()+1);
menu_handler_.show_statistics(gui()->viewing_team_index()+1);
}
void play_controller::hotkey_handler::unit_list(){

View file

@ -71,11 +71,11 @@ void playsingle_controller::hotkey_handler::recall(){
}
void playsingle_controller::hotkey_handler::toggle_shroud_updates(){
menu_handler_.toggle_shroud_updates(gui()->viewing_team()+1);
menu_handler_.toggle_shroud_updates(gui()->viewing_team_index()+1);
}
void playsingle_controller::hotkey_handler::update_shroud_now(){
menu_handler_.update_shroud_now(gui()->viewing_team()+1);
menu_handler_.update_shroud_now(gui()->viewing_team_index()+1);
}
void playsingle_controller::hotkey_handler::end_turn(){

View file

@ -142,7 +142,7 @@ void menu_handler::status_table()
{
int selected_side;
if(gui2::dialogs::game_stats::execute(board(), gui_->viewing_team(), selected_side)) {
if(gui2::dialogs::game_stats::execute(board(), gui_->viewing_team_index(), selected_side)) {
gui_->scroll_to_leader(selected_side);
}
}
@ -223,7 +223,7 @@ bool menu_handler::has_friends() const
}
for(std::size_t n = 0; n != pc_.get_teams().size(); ++n) {
if(n != gui_->viewing_team() && pc_.get_teams()[gui_->viewing_team()].team_name() == pc_.get_teams()[n].team_name()
if(n != gui_->viewing_team_index() && pc_.get_teams()[gui_->viewing_team_index()].team_name() == pc_.get_teams()[n].team_name()
&& pc_.get_teams()[n].is_network()) {
return true;
}
@ -471,7 +471,7 @@ void menu_handler::show_enemy_moves(bool ignore_units, int side_num)
&& !invisible) {
const unit_movement_resetter move_reset(u);
const pathfind::paths& path
= pathfind::paths(u, false, true, pc_.get_teams()[gui_->viewing_team()], 0, false, ignore_units);
= pathfind::paths(u, false, true, pc_.get_teams()[gui_->viewing_team_index()], 0, false, ignore_units);
gui_->highlight_another_reach(path, hex_under_mouse);
}
@ -669,12 +669,12 @@ unit_map::iterator menu_handler::current_unit()
const mouse_handler& mousehandler = pc_.get_mouse_handler_base();
const bool see_all = gui_->show_everything() || (pc_.is_replay() && pc_.get_replay_controller()->see_all());
unit_map::iterator res = board().find_visible_unit(mousehandler.get_last_hex(), pc_.get_teams()[gui_->viewing_team()], see_all);
unit_map::iterator res = board().find_visible_unit(mousehandler.get_last_hex(), pc_.get_teams()[gui_->viewing_team_index()], see_all);
if(res != pc_.get_units().end()) {
return res;
}
return board().find_visible_unit(mousehandler.get_selected_hex(), pc_.get_teams()[gui_->viewing_team()], see_all);
return board().find_visible_unit(mousehandler.get_selected_hex(), pc_.get_teams()[gui_->viewing_team_index()], see_all);
}
// Helpers for create_unit()
@ -820,7 +820,7 @@ void menu_handler::label_terrain(mouse_handler& mousehandler, bool team_only)
} else {
color = team::get_side_color(gui_->viewing_side());
}
const terrain_label* res = gui_->labels().set_label(loc, label, gui_->viewing_team(), team_name, color);
const terrain_label* res = gui_->labels().set_label(loc, label, gui_->viewing_team_index(), team_name, color);
if(res) {
resources::recorder->add_label(res);
}
@ -1340,7 +1340,7 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
if(board().is_observer()) {
cfg["to_sides"] = game_config::observer_team_name;
} else {
cfg["to_sides"] = pc_.get_teams()[gui_->viewing_team()].allied_human_teams();
cfg["to_sides"] = pc_.get_teams()[gui_->viewing_team_index()].allied_human_teams();
}
}
@ -1403,7 +1403,7 @@ void menu_handler::do_search(const std::string& new_search)
if(std::search(
name.begin(), name.end(), last_search_.begin(), last_search_.end(), utils::chars_equal_insensitive)
!= name.end()) {
if(!pc_.get_teams()[gui_->viewing_team()].is_enemy(ui->side())
if(!pc_.get_teams()[gui_->viewing_team_index()].is_enemy(ui->side())
|| !ui->invisible(ui->get_location())) {
found = true;
}

View file

@ -1518,7 +1518,7 @@ bool mouse_handler::unit_in_cycle(unit_map::const_iterator it)
return false;
}
if(current_team().is_enemy(static_cast<int>(gui().viewing_team() + 1)) && it->invisible(it->get_location())) {
if(current_team().is_enemy(static_cast<int>(gui().viewing_team_index() + 1)) && it->invisible(it->get_location())) {
return false;
}
@ -1582,12 +1582,12 @@ void mouse_handler::set_current_paths(const pathfind::paths& new_paths)
team& mouse_handler::viewing_team()
{
return pc_.get_teams()[gui().viewing_team()];
return pc_.get_teams()[gui().viewing_team_index()];
}
const team& mouse_handler::viewing_team() const
{
return pc_.get_teams()[gui().viewing_team()];
return pc_.get_teams()[gui().viewing_team_index()];
}
team& mouse_handler::current_team()

View file

@ -681,7 +681,7 @@ marked_route mark_route(const plain_route &rt, bool update_move_cost)
assert(last_step || resources::gameboard->map().on_board(*(i+1)));
const int move_cost = last_step ? 0 : u.movement_cost(static_cast<const game_board*>(resources::gameboard)->map()[*(i+1)]);
const team& viewing_team = resources::gameboard->teams()[display::get_singleton()->viewing_team()];
const team& viewing_team = resources::gameboard->teams()[display::get_singleton()->viewing_team_index()];
if (last_step || zoc || move_cost > movement) {
// check if we stop an a village and so maybe capture it

View file

@ -699,7 +699,7 @@ void play_controller::tab()
case gui::TEXTBOX_SEARCH: {
for(const unit& u : get_units()) {
const map_location& loc = u.get_location();
if(!gui_->fogged(loc) && !(get_teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
if(!gui_->fogged(loc) && !(get_teams()[gui_->viewing_team_index()].is_enemy(u.side()) && u.invisible(loc)))
dictionary.insert(u.name());
}
// TODO List map labels
@ -836,7 +836,7 @@ void play_controller::process_keyup_event(const SDL_Event& event)
unit_movement_resetter move_reset(*u, u->side() != current_side());
mouse_handler_.set_current_paths(pathfind::paths(
*u, false, true, get_teams()[gui_->viewing_team()], mouse_handler_.get_path_turns()));
*u, false, true, get_teams()[gui_->viewing_team_index()], mouse_handler_.get_path_turns()));
gui_->highlight_reach(mouse_handler_.current_paths());
} else {
@ -1237,8 +1237,8 @@ void play_controller::check_next_scenario_is_known() {
bool play_controller::can_use_synced_wml_menu() const
{
const team& viewing_team = get_teams()[gui_->viewing_team()];
return gui_->viewing_team() == gui_->playing_team() && !events::commands_disabled && viewing_team.is_local_human()
const team& viewing_team = get_teams()[gui_->viewing_team_index()];
return gui_->viewing_team_index() == gui_->playing_team_index() && !events::commands_disabled && viewing_team.is_local_human()
&& !is_browsing();
}
@ -1300,7 +1300,7 @@ play_controller::scoped_savegame_snapshot::~scoped_savegame_snapshot()
void play_controller::show_objectives() const
{
const team& t = get_teams()[gui_->viewing_team()];
const team& t = get_teams()[gui_->viewing_team_index()];
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);

View file

@ -603,7 +603,7 @@ void playsingle_controller::update_gui_linger()
if(get_end_level_data().transient.reveal_map) {
// Change the view of all players and observers
// to see the whole map regardless of shroud and fog.
update_gui_to_player(gui_->viewing_team(), true);
update_gui_to_player(gui_->viewing_team_index(), true);
}
} else {
gui_->set_game_mode(game_display::RUNNING);
@ -747,7 +747,7 @@ void playsingle_controller::require_end_turn()
void playsingle_controller::check_objectives()
{
if(!get_teams().empty()) {
const team& t = get_teams()[gui_->viewing_team()];
const team& t = get_teams()[gui_->viewing_team_index()];
if(!is_regular_game_end() && !is_browsing() && t.objectives_changed()) {
show_objectives();
@ -879,4 +879,3 @@ void playsingle_controller::on_replay_end(bool is_unit_test)
replay_controller_->stop_replay();
}
}

View file

@ -75,7 +75,7 @@ bool quit_confirmation::default_prompt()
int retval = sq.get_retval();
if(retval == 1)
{
pmc->surrender(display::get_singleton()->viewing_team());
pmc->surrender(display::get_singleton()->viewing_team_index());
return true;
}
else if(retval == 2)

View file

@ -95,7 +95,7 @@ static std::string flush(std::ostringstream &s)
static const time_of_day get_visible_time_of_day_at(const reports::context& rc, const map_location & hex)
{
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
if (viewing_team.shrouded(hex)) {
// Don't show time on shrouded tiles.
return rc.tod().get_time_of_day();
@ -128,21 +128,21 @@ static char const *naps = "</span>";
static const unit *get_visible_unit(const reports::context& rc)
{
return rc.dc().get_visible_unit(rc.screen().displayed_unit_hex(),
rc.teams()[rc.screen().viewing_team()],
rc.teams()[rc.screen().viewing_team_index()],
rc.screen().show_everything());
}
static const unit *get_selected_unit(const reports::context& rc)
{
return rc.dc().get_visible_unit(rc.screen().selected_hex(),
rc.teams()[rc.screen().viewing_team()],
rc.teams()[rc.screen().viewing_team_index()],
rc.screen().show_everything());
}
static unit_const_ptr get_selected_unit_ptr(const reports::context& rc)
{
return rc.dc().get_visible_unit_shared_ptr(rc.screen().selected_hex(),
rc.teams()[rc.screen().viewing_team()],
rc.teams()[rc.screen().viewing_team_index()],
rc.screen().show_everything());
}
@ -448,7 +448,7 @@ static config unit_abilities(const unit* u, const map_location& loc)
REPORT_GENERATOR(unit_abilities, rc)
{
const unit *u = get_visible_unit(rc);
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
const map_location& mouseover_hex = rc.screen().mouseover_hex();
const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
const map_location& hex = (mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex)) ? mouseover_hex : displayed_unit_hex;
@ -461,7 +461,7 @@ REPORT_GENERATOR(selected_unit_abilities, rc)
const map_location& mouseover_hex = rc.screen().mouseover_hex();
const unit *visible_unit = get_visible_unit(rc);
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
if (visible_unit && u && visible_unit->id() != u->id() && mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex))
return unit_abilities(u, mouseover_hex);
@ -615,7 +615,7 @@ static config unit_defense(const reports::context& rc, const unit* u, const map_
REPORT_GENERATOR(unit_defense,rc)
{
const unit *u = get_visible_unit(rc);
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
const map_location& mouseover_hex = rc.screen().mouseover_hex();
const map_location& displayed_unit_hex = rc.screen().displayed_unit_hex();
const map_location& hex = (mouseover_hex.valid() && !viewing_team.shrouded(mouseover_hex)) ? mouseover_hex : displayed_unit_hex;
@ -908,7 +908,7 @@ static int attack_info(const reports::context& rc, const attack_type &at, config
std::map<int, std::set<std::string>, std::greater<int>> resistances;
std::set<std::string> seen_types;
const team &unit_team = rc.dc().get_team(u.side());
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
for (const unit &enemy : rc.units())
{
if (enemy.incapacitated()) //we can't attack statues so don't display them in this tooltip
@ -1696,7 +1696,7 @@ REPORT_GENERATOR(position, rc)
str << mouseover_hex;
const unit *u = get_visible_unit(rc);
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
const team &viewing_team = rc.teams()[rc.screen().viewing_team_index()];
if (!u ||
(displayed_unit_hex != mouseover_hex &&
displayed_unit_hex != rc.screen().selected_hex()) ||
@ -1717,7 +1717,7 @@ REPORT_GENERATOR(position, rc)
REPORT_GENERATOR(side_playing, rc)
{
const team &active_team = rc.teams()[rc.screen().playing_team()];
const team &active_team = rc.teams()[rc.screen().playing_team_index()];
std::string flag_icon = active_team.flag_icon();
std::string old_rgb = game_config::flag_rgb;
std::string new_rgb = team::get_side_color_id(rc.screen().playing_side());

View file

@ -476,7 +476,7 @@ int game_lua_kernel::intf_get_displayed_unit(lua_State *L)
unit_map::const_iterator ui = board().find_visible_unit(
game_display_->displayed_unit_hex(),
teams()[game_display_->viewing_team()],
teams()[game_display_->viewing_team_index()],
game_display_->show_everything());
if (!ui.valid()) return 0;

View file

@ -141,8 +141,8 @@ unit_drawer::unit_drawer(display& thedisp)
, map(dc.map())
, teams(dc.teams())
, halo_man(thedisp.get_halo_manager())
, viewing_team(disp.viewing_team())
, playing_team(disp.playing_team())
, viewing_team(disp.viewing_team_index())
, playing_team(disp.playing_team_index())
, viewing_team_ref(teams[viewing_team])
, playing_team_ref(teams[playing_team])
, is_blindfolded(disp.is_blindfolded())

View file

@ -37,7 +37,7 @@ namespace wb {
std::size_t viewer_team()
{
return display::get_singleton()->viewing_team();
return display::get_singleton()->viewing_team_index();
}
int viewer_side()
@ -48,7 +48,7 @@ int viewer_side()
side_actions_ptr viewer_actions()
{
side_actions_ptr side_actions =
resources::gameboard->teams()[display::get_singleton()->viewing_team()].get_side_actions();
resources::gameboard->teams()[display::get_singleton()->viewing_team_index()].get_side_actions();
return side_actions;
}