Skip to content

Commit ddde907

Browse files
committed
some validity checks to order sending
1 parent d562104 commit ddde907

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

code/hud/hudsquadmsg.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ void hud_add_issued_order(const char *name, int order);
231231
void hud_update_last_order(const char *target, int order_source, int special_index);
232232
bool hud_squadmsg_is_target_order_valid(size_t order, ai_info *aip = nullptr);
233233
bool hud_squadmsg_ship_valid(ship *shipp, object *objp = nullptr);
234-
bool hud_squadmsg_ship_order_valid( int shipnum, int order );
235234

236235
// function to set up variables needed when messaging mode is started
237236
void hud_squadmsg_start()
@@ -1529,11 +1528,11 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message,
15291528
int ship_num;
15301529

15311530
// get a random ship in the wing to send the message to the player
1532-
ship_num = ship_get_random_ship_in_wing( wingnum, SHIP_GET_UNSILENCED );
1531+
ship_num = ship_get_random_ship_in_wing( wingnum, SHIP_GET_UNSILENCED, 0.0, 0, command );
15331532

15341533
// in multiplayer, its possible that all ships in a wing are players. so we'll just send from a random ship
15351534
if(ship_num == -1 && (Game_mode & GM_MULTIPLAYER)){
1536-
ship_num = ship_get_random_ship_in_wing(wingnum);
1535+
ship_num = ship_get_random_ship_in_wing(wingnum, SHIP_GET_ANY_SHIP, 0.0, 0, command);
15371536
}
15381537

15391538
// only send message if ship is found. There appear to be cases where all ships
@@ -2098,6 +2097,18 @@ void hud_squadmsg_wing_command()
20982097
if ( !hud_squadmsg_is_target_order_valid((int)order_id, 0) )
20992098
MsgItems[Num_menu_items].active = 0;
21002099

2100+
// if no ship in the wing can depart then gray out the departure order
2101+
if (order_id == DEPART_ITEM) {
2102+
int active = 0;
2103+
for (int i = 0; i < wingp->current_count; i++) {
2104+
if (hud_squadmsg_ship_order_valid(wingp->ship_index[i], (int)order_id)) {
2105+
active = 1;
2106+
break;
2107+
}
2108+
}
2109+
MsgItems[Num_menu_items].active = active;
2110+
}
2111+
21012112
Num_menu_items++;
21022113

21032114
}

code/hud/hudsquadmsg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ void hud_enemymsg_toggle(); // debug function to allow messaging of enemies
166166
// Added for voicer implementation
167167
void hud_squadmsg_do_mode( int mode );
168168

169+
// Added for checking message validity - Mjn
170+
bool hud_squadmsg_ship_order_valid(int shipnum, int order);
171+
169172
class HudGaugeSquadMessage: public HudGauge
170173
{
171174
protected:

code/ship/ship.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15664,7 +15664,7 @@ int ship_get_random_player_wing_ship( int flags, float max_dist, int persona_ind
1566415664

1566515665
// like above function, but returns a random ship in the given wing -- no restrictions
1566615666
// input: max_dist => OPTIONAL PARAMETER (default value 0.0f) max range ship can be from player
15667-
int ship_get_random_ship_in_wing(int wingnum, int flags, float max_dist, int get_first)
15667+
int ship_get_random_ship_in_wing(int wingnum, int flags, float max_dist, int get_first, int order_id)
1566815668
{
1566915669
int i, ship_index, slist[MAX_SHIPS_PER_WING], count, which_one;
1567015670

@@ -15677,6 +15677,13 @@ int ship_get_random_ship_in_wing(int wingnum, int flags, float max_dist, int get
1567715677
continue;
1567815678
}
1567915679

15680+
// specific to sending messages, make sure the ship selected can actually do the order
15681+
if (order_id >= 0) {
15682+
if (!hud_squadmsg_ship_order_valid(ship_index, order_id)) {
15683+
continue;
15684+
}
15685+
}
15686+
1568015687
// see if ship meets our criterea
1568115688
if ( (flags == SHIP_GET_NO_PLAYERS || flags == SHIP_GET_UNSILENCED) && (Objects[Ships[ship_index].objnum].flags[Object::Object_Flags::Player_ship]) )
1568215689
continue;

code/ship/ship.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ ship_subsys *ship_return_next_subsys(ship *shipp, int type, vec3d *attacker_pos)
18011801

18021802
extern int ship_get_random_team_ship(int team_mask, int flags = SHIP_GET_ANY_SHIP, float max_dist = 0.0f);
18031803
extern int ship_get_random_player_wing_ship(int flags = SHIP_GET_ANY_SHIP, float max_dist = 0.0f, int persona_index = -1, int get_first = 0, int multi_team = -1);
1804-
extern int ship_get_random_ship_in_wing(int wingnum, int flags = SHIP_GET_ANY_SHIP, float max_dist = 0.0f, int get_first = 0);
1804+
extern int ship_get_random_ship_in_wing(int wingnum, int flags = SHIP_GET_ANY_SHIP, float max_dist = 0.0f, int get_first = 0, int order_id = -1);
18051805

18061806
// return ship index
18071807
int ship_get_random_targetable_ship();

0 commit comments

Comments
 (0)