Skip to content

Commit 0076cdb

Browse files
authored
Fix 'ignore if dead' flag (scp-fs2open#7509)
* Fix 'ignore if dead' flag Fixes scp-fs2open#7508. The subsystem flag "ignore if dead" that many mods use is supposed to "prevent homing weapons from attempting to hit the now destroyed submodel and instead tells them to home on the main hull of the target." Though, in actuality, the code makes the weapon dumb fire instead of home. This bug means if you destroy a subsystem with this flag, then lock onto it with an aspect weapon and fire the weapon, the weapon will just dumb fire. With `wp->homing_subsys` cleared as this PR does, the homing code at `weapons.cpp`:5730 falls into its else branch and picks an attack point on the ship body (`ai_big_pick_attack_point / hobjp->pos`) — which is what the flag promises. Javelins, which can only home on engines, will still correctly try to re-acquire another engine in the block just below and drop lock if there's none. This fix is tested and now the flag works as expected. * fix for javelins
1 parent d4c21ec commit 0076cdb

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

code/ai/ai_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ namespace AI {
190190
Do_not_set_override_when_assigning_form_on_wing,
191191
Purge_player_issued_form_on_wing_after_subsequent_order,
192192
Cancel_future_waves_of_any_wing_launched_from_an_exited_ship,
193+
Fix_ignore_if_dead_flag,
193194

194195
NUM_VALUES
195196
};

code/ai/ai_profiles.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ void parse_ai_profiles_tbl(const char *filename)
747747

748748
set_flag(profile, "$ships intercept mines:", AI::Profile_Flags::Ships_intercept_mines);
749749

750+
set_flag(profile, "$fix 'ignore if dead' flag:", AI::Profile_Flags::Fix_ignore_if_dead_flag);
751+
750752

751753
// end of options ----------------------------------------
752754

@@ -970,4 +972,7 @@ void ai_profile_t::reset()
970972
flags.set(AI::Profile_Flags::Purge_player_issued_form_on_wing_after_subsequent_order);
971973
flags.set(AI::Profile_Flags::Cancel_future_waves_of_any_wing_launched_from_an_exited_ship);
972974
}
975+
if (mod_supports_version(26, 0, 0)) {
976+
flags.set(AI::Profile_Flags::Fix_ignore_if_dead_flag);
977+
}
973978
}

code/weapon/weapons.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5834,8 +5834,21 @@ void weapon_home(object *obj, int num, float frame_time)
58345834
if (wp->homing_subsys != NULL) {
58355835
if (wp->homing_subsys->flags[Ship::Subsystem_Flags::Missiles_ignore_if_dead]) {
58365836
if ((wp->homing_subsys->max_hits > 0) && (wp->homing_subsys->current_hits <= 0)) {
5837-
wp->homing_object = &obj_used_list;
5838-
return;
5837+
if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ignore_if_dead_flag]) {
5838+
// fixed way: clear dead subsys so the missile picks a hull attack point
5839+
// or, for Javelins, re-acquire another engine
5840+
wp->homing_subsys = nullptr;
5841+
if (wip->wi_flags[Weapon::Info_Flags::Homing_javelin] && hobjp->type == OBJ_SHIP) {
5842+
int sindex = ship_get_by_signature(wp->target_sig);
5843+
if (sindex >= 0) {
5844+
wp->homing_subsys = ship_get_closest_subsys_in_sight(&Ships[sindex], SUBSYSTEM_ENGINE, &obj->pos);
5845+
}
5846+
}
5847+
} else {
5848+
// old way: resulted in weapon not homing
5849+
wp->homing_object = &obj_used_list;
5850+
return;
5851+
}
58395852
}
58405853
}
58415854
}

0 commit comments

Comments
 (0)