Skip to content

Commit

Permalink
use range-based for
Browse files Browse the repository at this point in the history
  • Loading branch information
Goober5000 committed Dec 4, 2024
1 parent 6b55513 commit 29e9a47
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions code/hud/hudwingmanstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,8 @@ void hud_set_new_squadron_wings(const std::array<int, MAX_SQUADRON_WINGS> &new_s
{
// set up a map to tell where wings are going in the new arrangement
SCP_unordered_map<int, int> new_squad_indexes;
for (int cur_squad_index = 0; cur_squad_index < MAX_SQUADRON_WINGS; cur_squad_index++)
for (int wingnum: Squadron_wings)
{
int wingnum = Squadron_wings[cur_squad_index];
if (wingnum >= 0)
{
auto loc = std::find(new_squad_wingnums.begin(), new_squad_wingnums.end(), wingnum);
Expand All @@ -737,17 +736,15 @@ void hud_set_new_squadron_wings(const std::array<int, MAX_SQUADRON_WINGS> &new_s
}

// clear or reassign the ships that are currently in the squadron wings
for (int cur_squad_index = 0; cur_squad_index < MAX_SQUADRON_WINGS; cur_squad_index++)
for (int wingnum: Squadron_wings)
{
int wingnum = Squadron_wings[cur_squad_index];
if (wingnum < 0)
continue;
auto wingp = &Wings[wingnum];
auto new_squad_index = new_squad_indexes.find(wingnum);

for (int j = 0; j < MAX_SHIPS_PER_WING; j++)
for (int shipnum: wingp->ship_index)
{
int shipnum = wingp->ship_index[j];
if (shipnum < 0)
continue;
auto shipp = &Ships[shipnum];
Expand Down Expand Up @@ -800,14 +797,13 @@ void hud_set_new_squadron_wings(const std::array<int, MAX_SQUADRON_WINGS> &new_s
continue;

// clear the status before we actually add any wingmen
for (int j = 0; j < MAX_SHIPS_PER_WING; j++)
HUD_wingman_status[new_squad_index].status[j] = HUD_WINGMAN_STATUS_NONE;
for (int &status: HUD_wingman_status[new_squad_index].status)
status = HUD_WINGMAN_STATUS_NONE;

// now add the existing wingmen
auto wingp = &Wings[wingnum];
for (int j = 0; j < MAX_SHIPS_PER_WING; j++)
for (int shipnum: wingp->ship_index)
{
int shipnum = wingp->ship_index[j];
if (shipnum >= 0)
hud_wingman_status_set_index(new_squad_index, wingp, &Ships[shipnum], nullptr);
}
Expand Down

0 comments on commit 29e9a47

Please sign in to comment.