Skip to content

Commit

Permalink
Fix: Always check for nullptrs and make red-alert respect cur_waves f…
Browse files Browse the repository at this point in the history
…rom last mission (#6262)

* keep from crashing

* Also, bash the number of waves if necessary

* Add Debug warning to modders

* address feedback

* formatting

---------

Co-authored-by: Goober5000 <[email protected]>
  • Loading branch information
JohnAFernandez and Goober5000 authored Aug 27, 2024
1 parent bec860e commit faaa235
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions code/missionui/redalert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,14 @@ void red_alert_bash_ship_status()

// assign the wave number to the wing
wingp->current_wave = rws->latest_wave;

// make sure that num_waves can accommodate the new value of current_wave.
// this would happen if the mission we are entering has too few waves.
if (wingp->num_waves < wingp->current_wave)
{
mprintf(("Red alert warning: wing %s in the current mission has fewer waves than in the last mission. Bashing the number of waves from %i to %i.\n", wingp->name, wingp->num_waves, wingp->current_wave));
wingp->num_waves = wingp->current_wave;
}

if (rws->latest_wave > 1)
{
Expand Down
5 changes: 3 additions & 2 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11949,8 +11949,9 @@ void change_ship_type(int n, int ship_type, int by_sexp)
}

// zookeeper - If we're switching in the loadout screen, make sure we retain initial velocity set in FRED
if (!(Game_mode & GM_IN_MISSION) && !(Fred_running)) {
Objects[sp->objnum].phys_info.speed = (float) p_objp->initial_velocity * sip->max_speed / 100.0f;
if (!(Game_mode & GM_IN_MISSION) && !(Fred_running) && (p_objp != nullptr)) {
Objects[sp->objnum].phys_info.speed = p_objp->initial_velocity * sip->max_speed / 100.0f;

// prev_ramp_vel needs to be in local coordinates
// set z of prev_ramp_vel to initial velocity
vm_vec_zero(&Objects[sp->objnum].phys_info.prev_ramp_vel);
Expand Down

0 comments on commit faaa235

Please sign in to comment.