@@ -1721,26 +1721,24 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message,
17211721// return number of available reinforcements, 0 if none available
17221722int hud_squadmsg_reinforcements_available (int team)
17231723{
1724- int i, count = 0 ;
1725-
1726- for (i = 0 ; i < Num_reinforcements; i++) {
1727- int wingnum;
1724+ int count = 0 ;
17281725
1726+ for (const auto &reinforcement: Reinforcements) {
17291727 // no more left
1730- if ( Reinforcements[i] .num_uses >= Reinforcements[i] .uses ){
1728+ if (reinforcement .num_uses >= reinforcement .uses ){
17311729 continue ;
17321730 }
17331731
17341732 // incorrect team
1735- if ( team != ship_get_reinforcement_team (i ) ){
1733+ if ( team != ship_get_reinforcement_team (reinforcement ) ){
17361734 continue ;
17371735 }
17381736
17391737 // check the arrival cue sexpression of the ship/wing of this reinforcement.
17401738 // Goober5000 - if it can't arrive, it doesn't count. This should check
17411739 // for SEXP_FALSE as well as SEXP_KNOWN_FALSE, otherwise you end up with
17421740 // a reinforcement menu containing no valid selections.
1743- if ( ( wingnum = wing_name_lookup (Reinforcements[i] .name , 1 )) != -1 ) {
1741+ if (int wingnum = wing_name_lookup (reinforcement .name , 1 ); wingnum != -1 ) {
17441742 Assert ( Wings[wingnum].arrival_cue >= 0 );
17451743 if ( Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_FALSE
17461744 || Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -1749,7 +1747,7 @@ int hud_squadmsg_reinforcements_available(int team)
17491747 } else {
17501748 p_object *p_objp;
17511749
1752- p_objp = mission_parse_get_arrival_ship ( Reinforcements[i] .name );
1750+ p_objp = mission_parse_get_arrival_ship ( reinforcement .name );
17531751 if ( p_objp != NULL ) {
17541752 if ( Sexp_nodes[p_objp->arrival_cue ].value == SEXP_FALSE
17551753 || Sexp_nodes[p_objp->arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -1971,23 +1969,20 @@ void hud_squadmsg_msg_all_fighters()
19711969
19721970// called to actually bring in a reinforcement. For single player games, always gets called.
19731971// for multiplayer games, always called on the server side. Clients should never get here
1974- void hud_squadmsg_call_reinforcement (int reinforcement_num , int /* player_num*/ )
1972+ void hud_squadmsg_call_reinforcement (reinforcements &reinforcement , int /* player_num*/ )
19751973{
19761974 int i, delay;
1977- reinforcements *rp;
19781975 p_object *p_objp;
19791976
1980- rp = &Reinforcements[reinforcement_num];
1981-
19821977 // safety net mainly for multiplayer servers in case some odd data desync occurs between
19831978 // server and clients
1984- if ( MULTIPLAYER_MASTER && (rp-> num_uses >= rp-> uses ) ) {
1979+ if ( MULTIPLAYER_MASTER && (reinforcement. num_uses >= reinforcement. uses ) ) {
19851980 return ;
19861981 }
19871982
19881983 // check to see if the reinforcement called was a wing.
19891984 for (i = 0 ; i < Num_wings; i++ ) {
1990- if ( !stricmp (rp-> name , Wings[i].name ) ) {
1985+ if ( !stricmp (reinforcement. name , Wings[i].name ) ) {
19911986 // if the wing is currently present, skip this request so we don't waste a "use"
19921987 if (Wings[i].current_count > 0 ) {
19931988 return ;
@@ -1999,7 +1994,7 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
19991994 Wings[i].flags .set (Ship::Wing_Flags::Reset_reinforcement);
20001995
20011996 // set up the arrival delay. If it is 0, then make is some random number of seconds
2002- delay = rp-> arrival_delay ;
1997+ delay = reinforcement. arrival_delay ;
20031998 if ( delay == 0 )
20041999 delay = (int )(frand () * 3.0 ) + 3 ;
20052000 Wings[i].arrival_delay = timestamp (delay * 1000 );
@@ -2010,14 +2005,14 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20102005 // if we found no wing name that matched the reinforcement name, then look for a ship
20112006 // of the same name
20122007 if ( i == Num_wings ) {
2013- p_objp = mission_parse_get_arrival_ship ( rp-> name );
2008+ p_objp = mission_parse_get_arrival_ship ( reinforcement. name );
20142009 if ( p_objp ) {
20152010 // by resetting the reinforcement flag, we will allow code which normally handles arrivals
20162011 // to make this reinforcement arrive. Doing so keeps the data structures clean.
20172012 p_objp->flags .remove (Mission::Parse_Object_Flags::SF_Reinforcement);
20182013
20192014 // set up the arrival delay
2020- delay = rp-> arrival_delay ;
2015+ delay = reinforcement. arrival_delay ;
20212016 if ( delay == 0 )
20222017 delay = (int )(frand () * 3.0 ) + 3 ; // between 3 and 6 seconds to arrive
20232018 p_objp->arrival_delay = timestamp (delay * 1000 );
@@ -2029,7 +2024,7 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20292024
20302025 // increment the number of times this is used. Incremented here on single player and multiplayer
20312026 // server side only. Clients keep track of own count when they actually call something in.
2032- rp-> num_uses ++;
2027+ reinforcement. num_uses ++;
20332028
20342029 // commented out on 9/9/98 because these messages simply are not used
20352030 /*
@@ -2041,50 +2036,49 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20412036 break;
20422037
20432038 //if ( i > 0 )
2044- // message_send_to_player( rp->yes_messages[Random::next(i)], rp-> name, MESSAGE_PRIORITY_NORMAL, HUD_SOURCE_FRIENDLY );
2039+ // message_send_to_player( rp->yes_messages[Random::next(i)], reinforcement. name, MESSAGE_PRIORITY_NORMAL, HUD_SOURCE_FRIENDLY );
20452040 */
20462041
2047- mission_log_add_entry (LOG_PLAYER_CALLED_FOR_REINFORCEMENT , rp-> name , NULL );
2042+ mission_log_add_entry (LOG_PLAYER_CALLED_FOR_REINFORCEMENT , reinforcement. name , nullptr );
20482043}
20492044
20502045// function to display a list of reinforcements available to the player
20512046void hud_squadmsg_reinforcement_select ()
20522047{
2053- int i, k, wingnum;
2054- reinforcements *rp;
2055-
20562048 if ( Num_menu_items == -1 ) {
20572049 Num_menu_items = 0 ;
2058- for (i = 0 ; i < Num_reinforcements; i++) {
2059- rp = &Reinforcements[i];
2050+
2051+ int i = -1 ;
2052+ for (const auto &reinforcement: Reinforcements) {
2053+ ++i; // start at 0; increment at top of loop due to continues
20602054
20612055 // don't put reinforcements onto the list that have already been used up.
2062- if ( rp-> num_uses >= rp-> uses ) {
2056+ if (reinforcement. num_uses >= reinforcement. uses ) {
20632057 continue ;
20642058 }
20652059
20662060 // don't put items which are not on my team
2067- if ((Player_ship != NULL ) && (ship_get_reinforcement_team (i ) != Player_ship->team )){
2061+ if ((Player_ship != nullptr ) && (ship_get_reinforcement_team (reinforcement ) != Player_ship->team )) {
20682062 continue ;
20692063 }
20702064
20712065 // check the arrival cue sexpression of the ship/wing of this reinforcement.
20722066 // Goober5000 - if it can't arrive, it doesn't count. This should check
20732067 // for SEXP_FALSE as well as SEXP_KNOWN_FALSE, otherwise you end up with
20742068 // a reinforcement menu containing no valid selections.
2075- SCP_string rp_name ;
2076- if ( ( wingnum = wing_name_lookup (rp-> name , 1 )) != -1 ) {
2069+ const char *r_name ;
2070+ if (int wingnum = wing_name_lookup (reinforcement. name , 1 ); wingnum != -1 ) {
20772071 Assert ( Wings[wingnum].arrival_cue >= 0 );
20782072 if ( Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_FALSE
20792073 || Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_KNOWN_FALSE ){
20802074 continue ;
20812075 }
20822076
2083- rp_name = Wings[wingnum].get_display_name (); // this will handle getting rid of the hash if necessary
2077+ r_name = Wings[wingnum].get_display_name (); // this will handle getting rid of the hash if necessary
20842078 } else {
20852079 p_object *p_objp;
20862080
2087- p_objp = mission_parse_get_arrival_ship ( rp-> name );
2081+ p_objp = mission_parse_get_arrival_ship (reinforcement. name );
20882082 if ( p_objp != NULL ) {
20892083 if ( Sexp_nodes[p_objp->arrival_cue ].value == SEXP_FALSE
20902084 || Sexp_nodes[p_objp->arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -2095,15 +2089,15 @@ void hud_squadmsg_reinforcement_select()
20952089 continue ;
20962090 }
20972091
2098- rp_name = p_objp->get_display_name (); // this will handle getting rid of the hash if necessary
2092+ r_name = p_objp->get_display_name (); // this will handle getting rid of the hash if necessary
20992093 }
21002094
21012095 Assert ( Num_menu_items < MAX_MENU_ITEMS );
2102- MsgItems[Num_menu_items].text = std::move (rp_name) ;
2096+ MsgItems[Num_menu_items].text = r_name ;
21032097 MsgItems[Num_menu_items].instance = i;
21042098 MsgItems[Num_menu_items].active = 0 ;
21052099
2106- if ( rp-> flags & RF_IS_AVAILABLE ) {
2100+ if ( reinforcement. flags & RF_IS_AVAILABLE ) {
21072101 MsgItems[Num_menu_items].active = 1 ;
21082102 }
21092103
@@ -2113,7 +2107,7 @@ void hud_squadmsg_reinforcement_select()
21132107
21142108// hud_squadmsg_display_menu( "Select Reinforcement" );
21152109 strcpy_s (Squad_msg_title, XSTR ( " Select Ship/Wing" , 319 )); // AL 11-14-97: Reinforcement didn't fit, so using this for now
2116- k = hud_squadmsg_get_key ();
2110+ int k = hud_squadmsg_get_key ();
21172111 if (k != -1 ) {
21182112 int rnum;
21192113
@@ -2133,7 +2127,7 @@ void hud_squadmsg_reinforcement_select()
21332127 Reinforcements[rnum].num_uses ++; // increment this variable here since clients need to maintain a valid count
21342128 send_player_order_packet (SQUAD_MSG_REINFORCEMENT , rnum, 0 );
21352129 } else {
2136- hud_squadmsg_call_reinforcement (rnum);
2130+ hud_squadmsg_call_reinforcement (Reinforcements[ rnum] );
21372131 }
21382132 }
21392133}
0 commit comments