Skip to content

Commit 324ccf3

Browse files
committed
use proper bounds check when bashing hull in red-alert
This range check is to ensure that the ship's hull is in a valid range, so it should therefore check that the hull is less than the max strength, not less than the current strength. This was inadvertently changed in 593be42 and a04e83a, but retail behavior is to set the exact hull from the previous mission. Tested for both regular ships and delayed-arrival ships. Fixes #4472.
1 parent 20094df commit 324ccf3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

code/missionui/redalert.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,14 @@ void red_alert_bash_wingman_status()
885885
mprintf(("Invalid ship class specified in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
886886
}
887887

888+
float max_hull;
889+
if (shipp->special_hitpoints)
890+
max_hull = shipp->ship_max_hull_strength;
891+
else
892+
max_hull = Ship_info[shipp->ship_info_index].max_hull_strength;
893+
888894
// restore hull (but not shields)
889-
if (ras->hull >= 0.0f && ras->hull <= ship_objp->hull_strength)
895+
if (ras->hull >= 0.0f && ras->hull <= max_hull)
890896
ship_objp->hull_strength = ras->hull;
891897
else
892898
mprintf(("Invalid health in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
@@ -979,9 +985,15 @@ void red_alert_bash_wingman_status()
979985
}
980986
}
981987

988+
float max_hull;
989+
if (pobjp->special_hitpoints)
990+
max_hull = pobjp->ship_max_hull_strength;
991+
else
992+
max_hull = Ship_info[pobjp->ship_class].max_hull_strength;
993+
982994
// restore hull (but not shields)
983-
if (ras->hull >= 0.0f && ras->hull <= (pobjp->initial_hull * pobjp->ship_max_hull_strength / 100.0f))
984-
pobjp->initial_hull = (int) (ras->hull * 100.0f / pobjp->ship_max_hull_strength);
995+
if (ras->hull >= 0.0f && ras->hull <= max_hull)
996+
pobjp->initial_hull = (int) (ras->hull * 100.0f / max_hull);
985997
else
986998
mprintf(("Invalid health in red alert data for ship %s. Using mission defaults.\n", pobjp->name));
987999

0 commit comments

Comments
 (0)