@@ -4093,9 +4093,8 @@ void find_homing_object(object *weapon_objp, int num)
40934093 continue ;
40944094
40954095 homing_object_team = obj_team (objp);
4096- bool can_lock_on_ship = objp->type != OBJ_SHIP || weapon_can_lock_on_ship (wip, objp->instance );
40974096 bool can_attack = weapon_has_iff_restrictions (wip) || iff_x_attacks_y (wp->team , homing_object_team);
4098- if (can_lock_on_ship && can_attack)
4097+ if (weapon_target_satisfies_lock_restrictions (wip, objp) && can_attack)
40994098 {
41004099 if ( objp->type == OBJ_SHIP )
41014100 {
@@ -5353,13 +5352,9 @@ void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_o
53535352
53545353 if ( parent_objp == NULL || Ships[parent_objp->instance ].ai_index >= 0 ) {
53555354 int target_team = -1 ;
5356- int target_ship_num = -1 ;
53575355 if ( target_objnum >= 0 ) {
53585356 int obj_type = Objects[target_objnum].type ;
53595357
5360- if (obj_type == OBJ_SHIP)
5361- target_ship_num = Objects[target_objnum].instance ;
5362-
53635358 if ( (obj_type == OBJ_SHIP) || (obj_type == OBJ_WEAPON) ) {
53645359 target_team = obj_team (&Objects[target_objnum]);
53655360
@@ -5381,7 +5376,7 @@ void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_o
53815376 targeting_same = 0 ;
53825377 }
53835378
5384- bool can_lock = weapon_has_iff_restrictions (wip) && target_ship_num >= 0 ? weapon_can_lock_on_ship (wip, target_ship_num ) :
5379+ bool can_lock = ( weapon_has_iff_restrictions (wip) && target_objnum >= 0 ) ? weapon_target_satisfies_lock_restrictions (wip, &Objects[target_objnum] ) :
53855380 (!targeting_same || (MULTI_DOGFIGHT && (target_team == Iff_traitor)));
53865381
53875382 // Cyborg17 - exclude all invalid object numbers here since in multi, the lock slots can get out of sync.
@@ -8691,16 +8686,19 @@ int weapon_get_max_missile_seekers(weapon_info *wip)
86918686}
86928687
86938688// returns whether a homing weapon can home on a particular ship
8694- bool weapon_can_lock_on_ship (weapon_info* wip, int ship_num )
8689+ bool weapon_target_satisfies_lock_restrictions (weapon_info* wip, object* target )
86958690{
8691+ if (target->type != OBJ_SHIP)
8692+ return true ;
8693+
86968694 auto & restrictions = wip->ship_restrict ;
86978695 // if you didn't specify any restrictions, you can always lock
86988696 if (restrictions.empty ()) return true ;
86998697
8700- int type_num = Ship_info[Ships[ship_num ].ship_info_index ].class_type ;
8701- int class_num = Ships[ship_num ].ship_info_index ;
8702- int species_num = Ship_info[Ships[ship_num ].ship_info_index ].species ;
8703- int iff_num = Ships[ship_num ].team ;
8698+ int type_num = Ship_info[Ships[target-> instance ].ship_info_index ].class_type ;
8699+ int class_num = Ships[target-> instance ].ship_info_index ;
8700+ int species_num = Ship_info[Ships[target-> instance ].ship_info_index ].species ;
8701+ int iff_num = Ships[target-> instance ].team ;
87048702
87058703 // otherwise, you're good as long as it matches one of the allowances in the restriction list
87068704 return std::any_of (restrictions.begin (), restrictions.end (),
0 commit comments