From c5aed3eac5676b48efcca815e0b289233609c42d Mon Sep 17 00:00:00 2001 From: wookieejedi Date: Thu, 6 Aug 2026 14:42:05 -0400 Subject: [PATCH 1/2] Fix two small issues Fix copy-paste bug where setting `$Ask Help Hull Percent:` never properly got set. Fortunately this does not affect the AI, only when the AI sends a message to the player asking for help. Fix edge-case issue: in `find_turret_enemy`, the `turret-tgt-ship-tgt` shortcut takes the parent ship's target and indexes Ships[] with it unconditionally, but `aip->target_objnum` could be a weapon or asteroid, which could be at an index higher than the ships index, and then trying to look up team could lead to bad data. --- code/ai/aiturret.cpp | 3 ++- code/ship/ship.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/ai/aiturret.cpp b/code/ai/aiturret.cpp index 974e37557f4..738b8d9cb63 100644 --- a/code/ai/aiturret.cpp +++ b/code/ai/aiturret.cpp @@ -1095,7 +1095,8 @@ int find_turret_enemy(const ship_subsys *turret_subsys, int objnum, const vec3d int target_objnum = aip->target_objnum; if (Objects[target_objnum].signature == aip->target_signature) { - ship* target_shipp = &Ships[Objects[target_objnum].instance]; + // the parent's target can be a weapon or an asteroid, so make sure it's a ship before indexing Ships[] + ship* target_shipp = (Objects[target_objnum].type == OBJ_SHIP) ? &Ships[Objects[target_objnum].instance] : nullptr; if (target_shipp && iff_matches_mask(target_shipp->team, enemy_team_mask)) { if (!(Objects[target_objnum].flags[Object::Object_Flags::Protected])) { // check this flag as well // nprintf(("AI", "Frame %i: Object %i resuming goal of object %i\n", AI_FrameCount, objnum, diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 799c8c09d45..a7433f8b076 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -4336,7 +4336,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool float help_hull_val; stuff_float(&help_hull_val); if (help_hull_val > 0.0f && help_hull_val <= 1.0f) { - sip->ask_help_shield_percent = help_hull_val; + sip->ask_help_hull_percent = help_hull_val; } else { error_display(0,"Ask Help Hull Percent for ship class %s is %f. This value is not within range of 0-1.0." "Assuming default value of %f.", sip->name, help_hull_val, DEFAULT_ASK_HELP_HULL_PERCENT); From 94e52a3bc2d0b373c6f13b40f6dbd7e5c8802812 Mon Sep 17 00:00:00 2001 From: wookieejedi Date: Thu, 6 Aug 2026 22:00:38 -0400 Subject: [PATCH 2/2] comment formatting --- code/ai/aiturret.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ai/aiturret.cpp b/code/ai/aiturret.cpp index 738b8d9cb63..b71a3736ff0 100644 --- a/code/ai/aiturret.cpp +++ b/code/ai/aiturret.cpp @@ -1095,7 +1095,7 @@ int find_turret_enemy(const ship_subsys *turret_subsys, int objnum, const vec3d int target_objnum = aip->target_objnum; if (Objects[target_objnum].signature == aip->target_signature) { - // the parent's target can be a weapon or an asteroid, so make sure it's a ship before indexing Ships[] + // The parent's target can be a weapon or an asteroid, so make sure it's a ship before indexing Ships[] ship* target_shipp = (Objects[target_objnum].type == OBJ_SHIP) ? &Ships[Objects[target_objnum].instance] : nullptr; if (target_shipp && iff_matches_mask(target_shipp->team, enemy_team_mask)) { if (!(Objects[target_objnum].flags[Object::Object_Flags::Protected])) { // check this flag as well