Skip to content

Commit

Permalink
Merge pull request #5732 from Baezon/fix-damaged-engine-max-vel
Browse files Browse the repository at this point in the history
Fix for ets changes when engines are <15%
  • Loading branch information
JohnAFernandez committed Nov 1, 2023
2 parents 3764146 + 729e448 commit 8693fa3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
21 changes: 14 additions & 7 deletions code/hud/hudets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,32 @@ void update_ets(object* objp, float fl_frametime)
// This will translate to 71% max speed at 50% engines, and 31% max speed at 10% engines
//

float engine_aggregate_strength;
float effective_engine_strength;
float actual_engine_strength;
if (ship_p->flags[Ship::Ship_Flags::Maneuver_despite_engines]) {
// Pretend our strength is 100% when this flag is active
engine_aggregate_strength = 1.0f;
effective_engine_strength = 1.0f;
actual_engine_strength = 1.0f;
} else {
engine_aggregate_strength = ship_get_subsystem_strength(ship_p, SUBSYSTEM_ENGINE);
effective_engine_strength = ship_get_subsystem_strength(ship_p, SUBSYSTEM_ENGINE);

// very annoying, but ship_get_subsystem_strength will typically cap at no lower than 15% strength reported
// causing the condition below to possibly erroneously believe the engine strength isn't changing while being
// repaired below that threshold. use the ACTUAL strength for this check
actual_engine_strength = ship_get_subsystem_strength(ship_p, SUBSYSTEM_ENGINE, false, true);
}

// only update max speed if engine_aggregate_strength has changed
// which helps minimize amount of overrides to max speed
if (engine_aggregate_strength != ship_p->prev_engine_aggregate_strength) {
if (actual_engine_strength != ship_p->prev_engine_strength) {
ets_update_max_speed(objp);
ship_p->prev_engine_aggregate_strength = engine_aggregate_strength;
ship_p->prev_engine_strength = actual_engine_strength;

// check if newly updated max speed should be reduced due to engine damage
// don't let engine strength affect max speed when playing on lowest skill level
if ((objp != Player_obj) || (Game_skill_level > 0)) {
if (engine_aggregate_strength < SHIP_MIN_ENGINES_FOR_FULL_SPEED) {
objp->phys_info.max_vel.xyz.z *= fl_sqrt(engine_aggregate_strength);
if (effective_engine_strength < SHIP_MIN_ENGINES_FOR_FULL_SPEED) {
objp->phys_info.max_vel.xyz.z *= fl_sqrt(effective_engine_strength);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6628,7 +6628,7 @@ void ship::clear()
weapon_recharge_index = INTIAL_WEAPON_RECHARGE_INDEX;
engine_recharge_index = INTIAL_ENGINE_RECHARGE_INDEX;
weapon_energy = 0;
prev_engine_aggregate_strength = 1.0f;
prev_engine_strength = 1.0f;
next_manage_ets = timestamp(0);

flags.reset();
Expand Down Expand Up @@ -14814,7 +14814,7 @@ int ship_find_subsys(ship *sp, const char *ss_name)
// 0.0 and 1.0 which is the relative combined strength of the given subsystem type. The number
// calculated for the engines is slightly different. Once an engine reaches < 15% of its hits, its
// output drops to that %. A dead engine has no output.
float ship_get_subsystem_strength( ship *shipp, int type, bool skip_dying_check )
float ship_get_subsystem_strength( ship *shipp, int type, bool skip_dying_check, bool no_minimum_engine_str )
{
float strength;
ship_subsys *ssp;
Expand Down Expand Up @@ -14847,7 +14847,7 @@ float ship_get_subsystem_strength( ship *shipp, int type, bool skip_dying_check
float ratio;

ratio = ssp->current_hits / ssp->max_hits;
if ( ratio < ENGINE_MIN_STR )
if ( ratio < ENGINE_MIN_STR && !no_minimum_engine_str)
ratio = ENGINE_MIN_STR;

percent += ratio;
Expand Down
4 changes: 2 additions & 2 deletions code/ship/ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class ship
int engine_recharge_index; // index into array holding the engine recharge rate
float weapon_energy; // Number of EUs in energy reserves
int next_manage_ets; // timestamp for when ai can next modify ets ( -1 means never )
float prev_engine_aggregate_strength; // used only in update_ets() to allow for minimizing overrides to max speed --Asteroth and wookieejedi
float prev_engine_strength; // used only in update_ets() to allow for minimizing overrides to max speed --Asteroth and wookieejedi

flagset<Ship::Ship_Flags> flags; // flag variable to contain ship state
int reinforcement_index; // index into reinforcement struct or -1
Expand Down Expand Up @@ -1778,7 +1778,7 @@ extern ship_subsys *ship_get_indexed_subsys(ship *sp, int index); // returns ind
extern int ship_find_subsys(ship *sp, const char *ss_name); // returns numerical index in linked list of subsystems
extern int ship_get_subsys_index(ship_subsys *subsys);

extern float ship_get_subsystem_strength( ship *shipp, int type, bool skip_dying_check = false );
extern float ship_get_subsystem_strength( ship *shipp, int type, bool skip_dying_check = false, bool no_minimum_engine_str = false);
extern ship_subsys *ship_get_subsys(const ship *shipp, const char *subsys_name);
extern int ship_get_num_subsys(ship *shipp);
extern ship_subsys *ship_get_closest_subsys_in_sight(ship *sp, int subsys_type, vec3d *attacker_pos);
Expand Down

0 comments on commit 8693fa3

Please sign in to comment.