@@ -1723,26 +1723,26 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message,
17231723// return number of available reinforcements, 0 if none available
17241724int hud_squadmsg_reinforcements_available (int team)
17251725{
1726- int i, count = 0 ;
1726+ int count = 0 ;
17271727
1728- for (i = 0 ; i < Num_reinforcements; i++ ) {
1728+ for (const auto &reinforcement: Reinforcements ) {
17291729 int wingnum;
17301730
17311731 // no more left
1732- if ( Reinforcements[i] .num_uses >= Reinforcements[i] .uses ){
1732+ if (reinforcement .num_uses >= reinforcement .uses ){
17331733 continue ;
17341734 }
17351735
17361736 // incorrect team
1737- if ( team != ship_get_reinforcement_team (i ) ){
1737+ if ( team != ship_get_reinforcement_team (reinforcement ) ){
17381738 continue ;
17391739 }
17401740
17411741 // check the arrival cue sexpression of the ship/wing of this reinforcement.
17421742 // Goober5000 - if it can't arrive, it doesn't count. This should check
17431743 // for SEXP_FALSE as well as SEXP_KNOWN_FALSE, otherwise you end up with
17441744 // a reinforcement menu containing no valid selections.
1745- if ( (wingnum = wing_name_lookup (Reinforcements[i] .name , 1 )) != -1 ) {
1745+ if ( (wingnum = wing_name_lookup (reinforcement .name , 1 )) != -1 ) {
17461746 Assert ( Wings[wingnum].arrival_cue >= 0 );
17471747 if ( Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_FALSE
17481748 || Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -1751,7 +1751,7 @@ int hud_squadmsg_reinforcements_available(int team)
17511751 } else {
17521752 p_object *p_objp;
17531753
1754- p_objp = mission_parse_get_arrival_ship ( Reinforcements[i] .name );
1754+ p_objp = mission_parse_get_arrival_ship ( reinforcement .name );
17551755 if ( p_objp != NULL ) {
17561756 if ( Sexp_nodes[p_objp->arrival_cue ].value == SEXP_FALSE
17571757 || Sexp_nodes[p_objp->arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -1973,23 +1973,20 @@ void hud_squadmsg_msg_all_fighters()
19731973
19741974// called to actually bring in a reinforcement. For single player games, always gets called.
19751975// for multiplayer games, always called on the server side. Clients should never get here
1976- void hud_squadmsg_call_reinforcement (int reinforcement_num , int /* player_num*/ )
1976+ void hud_squadmsg_call_reinforcement (reinforcements &reinforcement , int /* player_num*/ )
19771977{
19781978 int i, delay;
1979- reinforcements *rp;
19801979 p_object *p_objp;
19811980
1982- rp = &Reinforcements[reinforcement_num];
1983-
19841981 // safety net mainly for multiplayer servers in case some odd data desync occurs between
19851982 // server and clients
1986- if ( MULTIPLAYER_MASTER && (rp-> num_uses >= rp-> uses ) ) {
1983+ if ( MULTIPLAYER_MASTER && (reinforcement. num_uses >= reinforcement. uses ) ) {
19871984 return ;
19881985 }
19891986
19901987 // check to see if the reinforcement called was a wing.
19911988 for (i = 0 ; i < Num_wings; i++ ) {
1992- if ( !stricmp (rp-> name , Wings[i].name ) ) {
1989+ if ( !stricmp (reinforcement. name , Wings[i].name ) ) {
19931990 // if the wing is currently present, skip this request so we don't waste a "use"
19941991 if (Wings[i].current_count > 0 ) {
19951992 return ;
@@ -2001,7 +1998,7 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20011998 Wings[i].flags .set (Ship::Wing_Flags::Reset_reinforcement);
20021999
20032000 // set up the arrival delay. If it is 0, then make is some random number of seconds
2004- delay = rp-> arrival_delay ;
2001+ delay = reinforcement. arrival_delay ;
20052002 if ( delay == 0 )
20062003 delay = (int )(frand () * 3.0 ) + 3 ;
20072004 Wings[i].arrival_delay = timestamp (delay * 1000 );
@@ -2012,14 +2009,14 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20122009 // if we found no wing name that matched the reinforcement name, then look for a ship
20132010 // of the same name
20142011 if ( i == Num_wings ) {
2015- p_objp = mission_parse_get_arrival_ship ( rp-> name );
2012+ p_objp = mission_parse_get_arrival_ship ( reinforcement. name );
20162013 if ( p_objp ) {
20172014 // by resetting the reinforcement flag, we will allow code which normally handles arrivals
20182015 // to make this reinforcement arrive. Doing so keeps the data structures clean.
20192016 p_objp->flags .remove (Mission::Parse_Object_Flags::SF_Reinforcement);
20202017
20212018 // set up the arrival delay
2022- delay = rp-> arrival_delay ;
2019+ delay = reinforcement. arrival_delay ;
20232020 if ( delay == 0 )
20242021 delay = (int )(frand () * 3.0 ) + 3 ; // between 3 and 6 seconds to arrive
20252022 p_objp->arrival_delay = timestamp (delay * 1000 );
@@ -2031,7 +2028,7 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20312028
20322029 // increment the number of times this is used. Incremented here on single player and multiplayer
20332030 // server side only. Clients keep track of own count when they actually call something in.
2034- rp-> num_uses ++;
2031+ reinforcement. num_uses ++;
20352032
20362033 // commented out on 9/9/98 because these messages simply are not used
20372034 /*
@@ -2043,50 +2040,49 @@ void hud_squadmsg_call_reinforcement(int reinforcement_num, int /*player_num*/)
20432040 break;
20442041
20452042 //if ( i > 0 )
2046- // message_send_to_player( rp->yes_messages[Random::next(i)], rp-> name, MESSAGE_PRIORITY_NORMAL, HUD_SOURCE_FRIENDLY );
2043+ // message_send_to_player( rp->yes_messages[Random::next(i)], reinforcement. name, MESSAGE_PRIORITY_NORMAL, HUD_SOURCE_FRIENDLY );
20472044 */
20482045
2049- mission_log_add_entry (LOG_PLAYER_CALLED_FOR_REINFORCEMENT , rp-> name , NULL );
2046+ mission_log_add_entry (LOG_PLAYER_CALLED_FOR_REINFORCEMENT , reinforcement. name , nullptr );
20502047}
20512048
20522049// function to display a list of reinforcements available to the player
20532050void hud_squadmsg_reinforcement_select ()
20542051{
2055- int i, k, wingnum;
2056- reinforcements *rp;
2052+ int i = -1 , wingnum;
20572053
20582054 if ( Num_menu_items == -1 ) {
20592055 Num_menu_items = 0 ;
2060- for (i = 0 ; i < Num_reinforcements; i++ ) {
2061- rp = &Reinforcements[i];
2062- SCP_string rp_name = rp-> name ;
2056+ for (const auto &reinforcement: Reinforcements ) {
2057+ ++i; // start at 0; increment at top of loop due to continues
2058+ SCP_string r_name = reinforcement. name ; // copy it
20632059
20642060 // don't put reinforcements onto the list that have already been used up.
2065- if ( rp-> num_uses >= rp-> uses ){
2061+ if (reinforcement. num_uses >= reinforcement. uses ){
20662062 continue ;
20672063 }
20682064
20692065 // don't put items which are not on my team
2070- if ((Player_ship != NULL ) && (ship_get_reinforcement_team (i ) != Player_ship->team )){
2066+ if ((Player_ship != NULL ) && (ship_get_reinforcement_team (reinforcement ) != Player_ship->team )){
20712067 continue ;
20722068 }
20732069
20742070 // check the arrival cue sexpression of the ship/wing of this reinforcement.
20752071 // Goober5000 - if it can't arrive, it doesn't count. This should check
20762072 // for SEXP_FALSE as well as SEXP_KNOWN_FALSE, otherwise you end up with
20772073 // a reinforcement menu containing no valid selections.
2078- if ( (wingnum = wing_name_lookup (rp-> name , 1 )) != -1 ) {
2074+ if ( (wingnum = wing_name_lookup (reinforcement. name , 1 )) != -1 ) {
20792075 Assert ( Wings[wingnum].arrival_cue >= 0 );
20802076 if ( Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_FALSE
20812077 || Sexp_nodes[Wings[wingnum].arrival_cue ].value == SEXP_KNOWN_FALSE ){
20822078 continue ;
20832079 }
20842080
2085- end_string_at_first_hash_symbol (rp_name );
2081+ end_string_at_first_hash_symbol (r_name );
20862082 } else {
20872083 p_object *p_objp;
20882084
2089- p_objp = mission_parse_get_arrival_ship ( rp-> name );
2085+ p_objp = mission_parse_get_arrival_ship (reinforcement. name );
20902086 if ( p_objp != NULL ) {
20912087 if ( Sexp_nodes[p_objp->arrival_cue ].value == SEXP_FALSE
20922088 || Sexp_nodes[p_objp->arrival_cue ].value == SEXP_KNOWN_FALSE ){
@@ -2097,15 +2093,15 @@ void hud_squadmsg_reinforcement_select()
20972093 continue ;
20982094 }
20992095
2100- rp_name = p_objp->get_display_name (); // this will handle getting rid of the hash if necessary
2096+ r_name = p_objp->get_display_name (); // this will handle getting rid of the hash if necessary
21012097 }
21022098
21032099 Assert ( Num_menu_items < MAX_MENU_ITEMS );
2104- MsgItems[Num_menu_items].text = std::move (rp_name );
2100+ MsgItems[Num_menu_items].text = std::move (r_name );
21052101 MsgItems[Num_menu_items].instance = i;
21062102 MsgItems[Num_menu_items].active = 0 ;
21072103
2108- if ( rp-> flags & RF_IS_AVAILABLE ) {
2104+ if ( reinforcement. flags & RF_IS_AVAILABLE ) {
21092105 MsgItems[Num_menu_items].active = 1 ;
21102106 }
21112107
@@ -2115,7 +2111,7 @@ void hud_squadmsg_reinforcement_select()
21152111
21162112// hud_squadmsg_display_menu( "Select Reinforcement" );
21172113 strcpy_s (Squad_msg_title, XSTR ( " Select Ship/Wing" , 319 )); // AL 11-14-97: Reinforcement didn't fit, so using this for now
2118- k = hud_squadmsg_get_key ();
2114+ int k = hud_squadmsg_get_key ();
21192115 if (k != -1 ) {
21202116 int rnum;
21212117
@@ -2135,7 +2131,7 @@ void hud_squadmsg_reinforcement_select()
21352131 Reinforcements[rnum].num_uses ++; // increment this variable here since clients need to maintain a valid count
21362132 send_player_order_packet (SQUAD_MSG_REINFORCEMENT , rnum, 0 );
21372133 } else {
2138- hud_squadmsg_call_reinforcement (rnum);
2134+ hud_squadmsg_call_reinforcement (Reinforcements[ rnum] );
21392135 }
21402136 }
21412137}
0 commit comments