Skip to content

Commit 150b0c2

Browse files
authored
Fix targest nearest attacking ship in multiplayer (scp-fs2open#7326)
* Fix `targest nearest attacking ship` in multiplayer Pressing 'Target Nearest Attacker` in multiplayer does not work when a ship has spontaneously targeted another ship. This is because within, `multi_oo_pack_data` `goals[0].target_name` only covers explicitly ordered goal targets and is empty for spontaneous IFF-based engagements, which means `target_signature` does not return the proper value. This PR adds an extra check for that to pefer the live target_objnum so clients know who is actually being attacked. Tested and works as expected. * comment cleanup * comment cleanup
1 parent 96af51b commit 150b0c2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

code/network/multi_obj.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,16 +1490,18 @@ int multi_oo_pack_data(net_player *pl, object *objp, ushort oo_flags, ubyte *dat
14901490
auto submode = (short)(aip->submode);
14911491
ushort target_signature = 0;
14921492

1493-
// either send out the waypoint they are trying to get to *or* their current target
1493+
// either send out the waypoint they are trying to get to *or* their current target.
14941494
if (umode == AIM_WAYPOINTS) {
14951495
// if it's already started pointing to a waypoint, grab its net_signature and send that instead
14961496
waypoint* wp;
14971497
if ((wp = find_waypoint_at_indexes(aip->wp_list_index, aip->wp_index)) != nullptr) {
14981498
target_signature = Objects[wp->get_objnum()].net_signature;
14991499
}
1500-
} // send the target signature. 2021 Version!
1501-
else if ((aip->goals[0].target_name != nullptr) && strlen(aip->goals[0].target_name) != 0) {
1502-
1500+
} else if (aip->target_objnum >= 0) {
1501+
// prefer live target_objnum so clients can check both ordered goal targets and spontaneous targets
1502+
target_signature = Objects[aip->target_objnum].net_signature;
1503+
} else if ((aip->goals[0].target_name != nullptr) && strlen(aip->goals[0].target_name) != 0) {
1504+
// send the target signature. 2021 Version!
15031505
int instance = ship_name_lookup(aip->goals[0].target_name);
15041506
if (instance > -1) {
15051507
target_signature = Objects[Ships[instance].objnum].net_signature;

0 commit comments

Comments
 (0)