diff --git a/CREDITS.md b/CREDITS.md index ecf82be902..c8f8d87a77 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -692,6 +692,7 @@ This page lists all the individual contributions to the project by their author. - Fix an issue where units recruited by a team with `AreTeamMembersRecruitable=false` cannot be recruited even if they have been liberated by that team - Global default value for `DefaultToGuardArea` - Weapon range finding in cylinder + - Allow disable an over-optimization in targeting - **solar-III (凤九歌)** - Target scanning delay customization (documentation) - Skip target scanning function calling for unarmed technos (documentation) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 8e683b6ade..227e055760 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -1338,6 +1338,18 @@ AllowAirstrike= ; boolean AirstrikeTargets=buildings ; List of Affected Target Enumeration (none|infantry|units|buildings|all) ``` +### Allow disable an over-optimization in targeting + +- In vanilla, there is an optimization in targeting: if a unit finds a valid target within the 1/4 or 1/2 range, it will stop looking for other targets. Now you can disable it. + - This optimization has a negligible effect on average performance, as most targeting calls fail to find a valid target. + - At the same time, it can affect the gaming experience, as it will make units attack nearby targets while ignoring more threatening targets that are farther away. + +In `rulesmd.ini`: +```ini +[General] +DisableOveroptimizationInTargeting=false ; boolean +``` + ### Alternate FLH customizations - `AlternateFLH.OnTurret` can be used to customize whether or not `AlternateFLH` used for `OpenTopped` transport firing coordinates, multiple mind control link offsets etc. is calculated relative to the unit's turret if available or body. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 975aeed572..f3a162e67a 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -592,6 +592,7 @@ Vanilla fixes: - Fixed the issue where units recruited by a team with `AreTeamMembersRecruitable=false` cannot be recruited even if they have been liberated by that team (by TaranDahl) - Fixed the bug that cause technos teleport to cell 0,0 by ChronoSphere superweapon (by NetsuNegi) - Fixed the bug that techno in attack move will move to target if it cannot attack it (by NetsuNegi) +- [Allow disable an over-optimization in targeting](Fixed-or-Improved-Logics.md#allow-disable-an-over-optimization-in-targeting) (by TaranDahl) Phobos fixes: - Fixed the bug that `AllowAirstrike=no` cannot completely prevent air strikes from being launched against it (by NetsuNegi) diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index ca47eeb3f8..7033daf413 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -1,4 +1,4 @@ -#include "Body.h" +#include "Body.h" #include #include @@ -364,6 +364,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) this->CylinderRangefinding.Read(exINI, GameStrings::General, "CylinderRangefinding"); + this->DisableOveroptimizationInTargeting.Read(exINI, GameStrings::General, "DisableOveroptimizationInTargeting"); + // Section AITargetTypes int itemsCount = pINI->GetKeyCount("AITargetTypes"); for (int i = 0; i < itemsCount; ++i) @@ -663,6 +665,7 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->AIParadropMission) .Process(this->DefaultToGuardArea) .Process(this->CylinderRangefinding) + .Process(this->DisableOveroptimizationInTargeting) ; } diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index 4001f0238b..f11431fbfe 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -311,6 +311,7 @@ class RulesExt Valueable AIParadropMission; Valueable DefaultToGuardArea; + Valueable DisableOveroptimizationInTargeting; Valueable CylinderRangefinding; @@ -570,6 +571,7 @@ class RulesExt , DefaultToGuardArea { false } , CylinderRangefinding { false } + , DisableOveroptimizationInTargeting { false } { } virtual ~ExtData() = default; diff --git a/src/Ext/Techno/Hooks.Targeting.cpp b/src/Ext/Techno/Hooks.Targeting.cpp index ff1da00c3d..3f9162dd64 100644 --- a/src/Ext/Techno/Hooks.Targeting.cpp +++ b/src/Ext/Techno/Hooks.Targeting.cpp @@ -69,3 +69,9 @@ DEFINE_HOOK(0x6F7CE2, TechnoClass_CanAutoTargetObject_IronCurtain, 0x6) return 0; } + +// WW adds an optimization that: If the techno get a target in 1/4 or 1/2 of their targeting range, then it will not checking other targets. +DEFINE_HOOK(0x6F9AF4, TechnoClass_SelectAutoTarget_DisableStupid, 0x6) +{ + return RulesExt::Global()->DisableOveroptimizationInTargeting ? 0x6F9B1B : 0; +}