From c017ef9b8ab69f7d1021012fa990b000195a4c3c Mon Sep 17 00:00:00 2001 From: Asteroth Date: Sun, 29 Oct 2023 23:54:36 -0400 Subject: [PATCH 1/4] fix for ets changes when engines are <15% --- code/hud/hudets.cpp | 9 +++++++-- code/ship/ship.cpp | 4 ++-- code/ship/ship.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/code/hud/hudets.cpp b/code/hud/hudets.cpp index 45fd0204162..6e55dc7c8ee 100644 --- a/code/hud/hudets.cpp +++ b/code/hud/hudets.cpp @@ -133,11 +133,16 @@ void update_ets(object* objp, float fl_frametime) engine_aggregate_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 + float 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_aggregate_strength) { ets_update_max_speed(objp); - ship_p->prev_engine_aggregate_strength = engine_aggregate_strength; + ship_p->prev_engine_aggregate_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 diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 02fe4ce35e3..50dac474939 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -14808,7 +14808,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; @@ -14841,7 +14841,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; diff --git a/code/ship/ship.h b/code/ship/ship.h index 90d00a43b5a..a4a0fd64654 100644 --- a/code/ship/ship.h +++ b/code/ship/ship.h @@ -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); From 55ed0a08f68fed4558d7b1583f5e4963a7b268a1 Mon Sep 17 00:00:00 2001 From: Asteroth Date: Mon, 30 Oct 2023 00:44:22 -0400 Subject: [PATCH 2/4] fix subsys pos finding for improved subsys attack pathing --- code/ai/aibig.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/ai/aibig.cpp b/code/ai/aibig.cpp index 5900bef27da..4a2e4211f09 100644 --- a/code/ai/aibig.cpp +++ b/code/ai/aibig.cpp @@ -538,8 +538,7 @@ bool ai_new_maybe_reposition_attack_subsys() { model_local_to_global_point(&geye, &ep->pnt, pm, 0, &Pl_objp->orient, &Pl_objp->pos); // get world pos of subsystem - polymodel* tgt_pm = model_get(Ship_info[Ships[target_objp->instance].ship_info_index].model_num); - model_local_to_global_point(&gsubpos, &vmd_zero_vector, tgt_pm, aip->targeted_subsys->system_info->subobj_num, &En_objp->orient, &En_objp->pos); + get_subsystem_pos(&gsubpos, target_objp, aip->targeted_subsys); // you're in sight! shoot it! if (ship_subsystem_in_sight(En_objp, aip->targeted_subsys, &geye, &gsubpos, 0)) From 96ae3d06086c48f29fc2f17175be68fc23534abd Mon Sep 17 00:00:00 2001 From: Asteroth Date: Mon, 30 Oct 2023 00:44:37 -0400 Subject: [PATCH 3/4] Revert "fix subsys pos finding for improved subsys attack pathing" This reverts commit 55ed0a08f68fed4558d7b1583f5e4963a7b268a1. --- code/ai/aibig.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/ai/aibig.cpp b/code/ai/aibig.cpp index 4a2e4211f09..5900bef27da 100644 --- a/code/ai/aibig.cpp +++ b/code/ai/aibig.cpp @@ -538,7 +538,8 @@ bool ai_new_maybe_reposition_attack_subsys() { model_local_to_global_point(&geye, &ep->pnt, pm, 0, &Pl_objp->orient, &Pl_objp->pos); // get world pos of subsystem - get_subsystem_pos(&gsubpos, target_objp, aip->targeted_subsys); + polymodel* tgt_pm = model_get(Ship_info[Ships[target_objp->instance].ship_info_index].model_num); + model_local_to_global_point(&gsubpos, &vmd_zero_vector, tgt_pm, aip->targeted_subsys->system_info->subobj_num, &En_objp->orient, &En_objp->pos); // you're in sight! shoot it! if (ship_subsystem_in_sight(En_objp, aip->targeted_subsys, &geye, &gsubpos, 0)) From 729e448fe55a2bfa57e6d2759d79e13c33212825 Mon Sep 17 00:00:00 2001 From: Asteroth Date: Mon, 30 Oct 2023 02:10:18 -0400 Subject: [PATCH 4/4] review fixes --- code/hud/hudets.cpp | 26 ++++++++++++++------------ code/ship/ship.cpp | 2 +- code/ship/ship.h | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/code/hud/hudets.cpp b/code/hud/hudets.cpp index 6e55dc7c8ee..5172a9a679d 100644 --- a/code/hud/hudets.cpp +++ b/code/hud/hudets.cpp @@ -125,30 +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 - float actual_engine_strength = ship_get_subsystem_strength(ship_p, SUBSYSTEM_ENGINE, false, true); + // 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 (actual_engine_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 = actual_engine_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); } } } diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 50dac474939..31340333712 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -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(); diff --git a/code/ship/ship.h b/code/ship/ship.h index a4a0fd64654..4b05dd64170 100644 --- a/code/ship/ship.h +++ b/code/ship/ship.h @@ -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 flags; // flag variable to contain ship state int reinforcement_index; // index into reinforcement struct or -1