Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ parse_object_flag_description<Mission::Parse_Object_Flags> Parse_object_flag_des
{ Mission::Parse_Object_Flags::SF_Nav_needslink, "This ship requires \"linking\" for autopilot ."},
{ Mission::Parse_Object_Flags::SF_Hide_ship_name, "If set, the ship name can't be seen when the ship is targeted."},
{ Mission::Parse_Object_Flags::SF_Set_class_dynamically, "This ship should have its class assigned rather than simply read from the mission file."},
{ Mission::Parse_Object_Flags::SF_Lock_all_turrets_initially, "Lock all turrets on this ship at mission start or on arrival."},
{ Mission::Parse_Object_Flags::SF_Lock_all_turrets_initially, "Lock all turrets on this ship at mission start, on arrival, or on a class change."},
{ Mission::Parse_Object_Flags::SF_Afterburner_locked, "Will stop a ship from firing their afterburner."},
{ Mission::Parse_Object_Flags::OF_Force_shields_on, "Shields will be activated regardless of other flags."},
{ Mission::Parse_Object_Flags::OF_Immobile, "Will not let a ship change position or orientation. Upon destruction the ship will still do the death roll and explosion."},
Expand Down Expand Up @@ -2818,15 +2818,6 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
if (!ptr)
continue;

if (shipp->flags[Ship::Ship_Flags::Lock_all_turrets_initially])
{
// mark all turrets as locked
if(ptr->system_info->type == SUBSYSTEM_TURRET)
{
ptr->weapons.flags.set(Ship::Weapon_Flags::Turret_Lock);
}
}

if (Fred_running)
{
ptr->current_hits = sssp->percent;
Expand Down Expand Up @@ -2862,6 +2853,16 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
ptr->turret_animation_done_time = 0;
}

// this covers every turret, including any the mission file has no entry for (e.g. after a ship class change)
if (shipp->flags[Ship::Ship_Flags::Lock_all_turrets_initially])
{
for (auto ss : list_range(&shipp->subsys_list))
{
if (ss->system_info->type == SUBSYSTEM_TURRET)
ss->weapons.flags.set(Ship::Weapon_Flags::Turret_Lock);
}
}

// initial hull strength, shields, and velocity are all expressed as a percentage of the max value/
// so a initial_hull value of 90% means 90% of max. This way is opposite of how subsystems are dealt
// with
Expand Down Expand Up @@ -8883,6 +8884,10 @@ int insert_subsys_status(p_object *pobjp)
// (each p_object's subsys_index points to subsystem 0 in its list)
for (SCP_vector<p_object>::iterator ii = Parse_objects.begin(); ii != Parse_objects.end(); ++ii)
{
// skip this p_object: if it had no subsystems, its base index equals new_index but must stay put
if (&*ii == pobjp)
continue;

// bump up base index to accommodate inserted subsystem
if (ii->subsys_index >= new_index)
ii->subsys_index++;
Expand Down
24 changes: 11 additions & 13 deletions code/missionui/redalert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ extern int insert_subsys_status(p_object *pobjp);

void red_alert_bash_subsys_status(const red_alert_ship_status *ras, p_object *pobjp)
{
int i, j;
int i;
ship_info *sip;
model_subsystem *psub = NULL;
subsys_status *sssp = NULL;
Expand All @@ -677,31 +677,29 @@ void red_alert_bash_subsys_status(const red_alert_ship_status *ras, p_object *po
// do this differently than the other bash_subsys_status... since the p_object may not contain
// all the subsystems, iterate on the red_alert_ship_status entries rather than the p_object's
// and create missing subsystems where necessary
for (i = 0; i < (int) ras->subsys_current_hits.size(); i++)
for (i = 0; (i < sz2i(ras->subsys_current_hits.size())) && (i < sip->n_subsystems); i++)
{
psub = &sip->subsystems[i];

// in the p_object, subsystem 0 is the pilot, and afterwards the subsystems go in order
j = i + 1;
float max_hits = psub->max_subsys_strength * (pobjp->ship_max_hull_strength / sip->max_hull_strength);

// a subsystem with no hitpoints has no damage to restore
if (max_hits <= 0.0f)
continue;

// the mission file only lists some subsystems, in no fixed position, so look this one up by name
sssp = parse_get_subsys_status(pobjp, psub->subobj_name);

// this subsystem is in the p_object
if (j < pobjp->subsys_count)
{
sssp = &Subsys_status[pobjp->subsys_index + j];
}
// must create subsystem (same technique as in parse_copy_damage)
else
if (sssp == nullptr)
{
// jam in the new subsystem at the end of the existing list for this parse object
int new_idx = insert_subsys_status(pobjp);
Comment thread
Goober5000 marked this conversation as resolved.
Resolved
Assert(new_idx == pobjp->subsys_index + j);
sssp = &Subsys_status[new_idx];

strcpy_s(sssp->name, psub->subobj_name);
}

float max_hits = psub->max_subsys_strength * (pobjp->ship_max_hull_strength / sip->max_hull_strength);

float current_hits = ras->subsys_current_hits[i];

sssp->percent = 100.0f * (max_hits - current_hits) / max_hits;
Expand Down
65 changes: 65 additions & 0 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11817,6 +11817,31 @@ static void ship_model_change(int n, int ship_type)
}
}

// runtime subsystem flags kept across a ship class change (rotation locks and cargo scans are not kept)
static const Ship::Subsystem_Flags Runtime_subsys_flags[] =
{
Ship::Subsystem_Flags::Untargetable,
Ship::Subsystem_Flags::No_SS_targeting,
Ship::Subsystem_Flags::No_replace,
Ship::Subsystem_Flags::No_live_debris,
Ship::Subsystem_Flags::Vanished,
Ship::Subsystem_Flags::Missiles_ignore_if_dead
};

static const Ship::Weapon_Flags Runtime_subsys_weapon_flags[] =
{
Ship::Weapon_Flags::Turret_Lock,
Ship::Weapon_Flags::Beam_Free,
Ship::Weapon_Flags::Tagged_Only
};

// which runtime flags differ from what the subsystem's class and the mission would give it, and their values
struct saved_runtime_subsys_flags
{
flagset<Ship::Subsystem_Flags> changed, values;
flagset<Ship::Weapon_Flags> weapon_changed, weapon_values;
};

/**
* Change the ship class on a ship, and changing all required information
* for consistency (ie textures, subsystems, weapons, physics)
Expand Down Expand Up @@ -11980,6 +12005,7 @@ void change_ship_type(int n, int ship_type, int by_sexp)
char **subsys_names = new char *[sip_orig->n_subsystems];
float *subsys_pcts = new float[sip_orig->n_subsystems];
SCP_vector<bool> subsys_blown_off(sip_orig->n_subsystems, false);
SCP_vector<saved_runtime_subsys_flags> subsys_runtime_flags(sip_orig->n_subsystems);

// prevent crashes in the event of a subsystem mismatch
for (i = 0; i < sip_orig->n_subsystems; ++i)
Expand Down Expand Up @@ -12080,6 +12106,23 @@ void change_ship_type(int n, int ship_type, int by_sexp)

subsys_blown_off[num_saved_subsystems] = subsystem_submodels_blown_off(sp, ss);

// only carry over what changed during the mission, so the old class's table settings don't override the new class's
{
flagset<Ship::Subsystem_Flags> default_flags;
flagset<Ship::Weapon_Flags> default_weapon_flags;
resolve_subsystem_flags(*ss->system_info, default_flags, default_weapon_flags);
if (sp->flags[Ship::Ship_Flags::Lock_all_turrets_initially] && ss->system_info->type == SUBSYSTEM_TURRET)
default_weapon_flags.set(Ship::Weapon_Flags::Turret_Lock);

auto &saved = subsys_runtime_flags[num_saved_subsystems];
saved.values = ss->flags;
saved.weapon_values = ss->weapons.flags;
for (auto flag : Runtime_subsys_flags)
saved.changed.set(flag, ss->flags[flag] != default_flags[flag]);
for (auto flag : Runtime_subsys_weapon_flags)
saved.weapon_changed.set(flag, ss->weapons.flags[flag] != default_weapon_flags[flag]);
Comment thread
Goober5000 marked this conversation as resolved.
Resolved
}

num_saved_subsystems++;
ss = GET_NEXT(ss);
}
Expand Down Expand Up @@ -12183,6 +12226,16 @@ void change_ship_type(int n, int ship_type, int by_sexp)
// fix up the subsystems
subsys_set( sp->objnum );

// lock-all-turrets is part of every turret's default, as at ship creation; a turret freed since then is restored below
if (sp->flags[Ship::Ship_Flags::Lock_all_turrets_initially])
{
for (auto turret : list_range(&sp->subsys_list))
{
if (turret->system_info->type == SUBSYSTEM_TURRET)
turret->weapons.flags.set(Ship::Weapon_Flags::Turret_Lock);
}
}
Comment thread
Goober5000 marked this conversation as resolved.
Resolved

// Goober5000 - restore the subsystem percentages
ss = GET_FIRST(&sp->subsys_list);
int ss_index = 0;
Expand All @@ -12196,6 +12249,18 @@ void change_ship_type(int n, int ship_type, int by_sexp)
if (subsys_blown_off[i])
blow_off_subsystem_submodels(sp, ss);

const auto &saved = subsys_runtime_flags[i];
for (auto flag : Runtime_subsys_flags)
{
if (saved.changed[flag])
ss->flags.set(flag, saved.values[flag]);
}
for (auto flag : Runtime_subsys_weapon_flags)
{
if (saved.weapon_changed[flag])
ss->weapons.flags.set(flag, saved.weapon_values[flag]);
}

// MageKing17 - Every AI doing something with this subsystem must transfer to the new one.
{
auto it = subsystem_matches.begin();
Expand Down
2 changes: 1 addition & 1 deletion code/ship/ship_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace Ship {
Hide_ship_name, // Karajorma - Hides the ships name (like the -wcsaga command line used to but for any selected ship)
Afterburner_locked, // KeldorKatarn - This ship can't use its afterburners
Set_class_dynamically, // Karajorma - This ship should have its class assigned rather than simply read from the mission file
Lock_all_turrets_initially, // Karajorma - Lock all turrets on this ship at mission start or on arrival
Lock_all_turrets_initially, // Karajorma - Lock all turrets on this ship at mission start, on arrival, or on a class change
Force_shields_on,
No_ets, // The E - This ship does not have an ETS
Cloaked, // The E - This ship will not be rendered
Expand Down
Loading