diff --git a/CREDITS.md b/CREDITS.md index d2a1d351cc..60fbb67f93 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -394,6 +394,7 @@ This page lists all the individual contributions to the project by their author. - Health bar permanently displayed - Unlimbo Detonate warhead - Fast access structure + - Attack non-threatening structures extensions - **NetsuNegi**: - Forbidding parallel AI queues by type - Jumpjet crash speed fix when crashing onto building diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 04d3f11a14..f6d7de4383 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -1312,6 +1312,21 @@ In `rulesmd.ini`: AttackMove.IgnoreWeaponCheck=false ; boolean ``` +### Attack non-threatening structures + +- You can now freely configure whether units can automatically target non-threatening structures. + - `AutoTarget.NoThreatBuildings` affects player-controlled units, `AutoTargetAI.NoThreatBuildings` affects other units. + +In `rulesmd.ini`: +```ini +[General] +AutoTarget.NoThreatBuildings=false ; boolean +AutoTargetAI.NoThreatBuildings=true ; boolean + +[SOMETECHNO] ; TechnoType +AttackNoThreatBuildings= ; boolean, default to [General] -> AutoTarget.NoThreatBuildings/AutoTargetAI.NoThreatBuildings. +``` + ### Aircraft spawner customizations ![image](_static/images/spawnrange-01.gif) @@ -2568,6 +2583,16 @@ In `rulesmd.ini`: AreaFire.Target=base ; AreaFire Target Enumeration (base|self|random) ``` +### Attack non-threatening structures + +- `AttackNoThreatBuildings` permits shooters to attack non-threatening structures. This setting overrides other configurations. + +In `rulesmd.ini`: +```ini +[SOMEWEAPON] ; WeaponType +AttackNoThreatBuildings= ; boolean +``` + ### Burst delay customizations - `Burst.Delays` allows specifying weapon-specific burst shot delays. Takes precedence over the old `BurstDelayX` logic available on VehicleTypes, functions with Infantry & BuildingType weapons (AircraftTypes are not supported due to their weapon firing system being completely different) and allows every shot of `Burst` to have a separate delay instead of only first four shots. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index f2ec7d530c..11b58b97c7 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -452,6 +452,7 @@ New: - [Unlimbo Detonate warhead](New-or-Enhanced-Logics.md#unlimbo-detonate-warhead) (by FlyStar) - Attack and damage technos underground (by TaranDahl) - Fast access structure (by FlyStar) +- Attack non-threatening structures extensions (by FlyStar) Vanilla fixes: - Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya) diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 5fcd2d9c0f..02c65bd704 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -323,6 +323,9 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) this->AdjacentWallDamage.Read(exINI, GameStrings::CombatDamage, "AdjacentWallDamage"); + this->AutoTarget_NoThreatBuildings.Read(exINI, GameStrings::General, "AutoTarget.NoThreatBuildings"); + this->AutoTargetAI_NoThreatBuildings.Read(exINI, GameStrings::General, "AutoTargetAI.NoThreatBuildings"); + // Section AITargetTypes int itemsCount = pINI->GetKeyCount("AITargetTypes"); for (int i = 0; i < itemsCount; ++i) @@ -595,6 +598,8 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->Parasite_GrappleAnim) .Process(this->InfantryAutoDeploy) .Process(this->AdjacentWallDamage) + .Process(this->AutoTarget_NoThreatBuildings) + .Process(this->AutoTargetAI_NoThreatBuildings) ; } diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index 7f8c9c53aa..36241bf973 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -273,7 +273,10 @@ class RulesExt Valueable InfantryAutoDeploy; Valueable AdjacentWallDamage; - + + Valueable AutoTarget_NoThreatBuildings; + Valueable AutoTargetAI_NoThreatBuildings; + ExtData(RulesClass* OwnerObject) : Extension(OwnerObject) , Storage_TiberiumIndex { -1 } , HarvesterDumpAmount { 0.0f } @@ -486,6 +489,9 @@ class RulesExt , Parasite_GrappleAnim {} , InfantryAutoDeploy { false } , AdjacentWallDamage { 200 } + + , AutoTarget_NoThreatBuildings { false } + , AutoTargetAI_NoThreatBuildings { true } { } virtual ~ExtData() = default; diff --git a/src/Ext/Techno/Hooks.TargetEvaluation.cpp b/src/Ext/Techno/Hooks.TargetEvaluation.cpp index 10daf28aac..91379ab69e 100644 --- a/src/Ext/Techno/Hooks.TargetEvaluation.cpp +++ b/src/Ext/Techno/Hooks.TargetEvaluation.cpp @@ -197,23 +197,6 @@ DEFINE_HOOK(0x4DF3A0, FootClass_UpdateAttackMove_SelectNewTarget, 0x6) return 0; } -DEFINE_HOOK(0x6F85AB, TechnoClass_CanAutoTargetObject_AggressiveAttackMove, 0x6) -{ - enum { ContinueCheck = 0x6F85BA, CanTarget = 0x6F8604 }; - - GET(TechnoClass* const, pThis, EDI); - - if (!pThis->Owner->IsControlledByHuman()) - return CanTarget; - - if (!pThis->MegaMissionIsAttackMove()) - return ContinueCheck; - - const auto pExt = TechnoExt::ExtMap.Find(pThis); - - return pExt->TypeExtData->AttackMove_Aggressive.Get(RulesExt::Global()->AttackMove_Aggressive) ? CanTarget : ContinueCheck; -} - #pragma endregion #pragma region HealingWeapons diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index fb5669c234..21049f6d2c 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -1459,3 +1459,45 @@ DEFINE_HOOK(0x6F7E1E, TechnoClass_CanAutoTargetObject_AU, 0x6) } #pragma endregion + +#pragma region AutoTargetExtension + +namespace CanAutoTargetTemp +{ + TechnoTypeExt::ExtData* TypeExtData; + WeaponTypeExt::ExtData* WeaponExt; +} + +DEFINE_HOOK(0x6F7E30, TechnoClass_CanAutoTarget_SetContent, 0x6) +{ + GET(TechnoClass*, pThis, EDI); + GET(WeaponTypeClass*, pWeapon, EBP); + + CanAutoTargetTemp::TypeExtData = TechnoExt::ExtMap.Find(pThis)->TypeExtData; + CanAutoTargetTemp::WeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon); + + return 0; +} + +DEFINE_HOOK(0x6F85AB, TechnoClass_CanAutoTargetObject_AggressiveAttackMove, 0x6) +{ + enum { ContinueCheck = 0x6F85BA, CanTarget = 0x6F8604 }; + + GET(TechnoClass* const, pThis, EDI); + + if (!pThis->MegaMissionIsAttackMove()) + return ContinueCheck; + + const bool canAttack = CanAutoTargetTemp::WeaponExt->AttackNoThreatBuildings.Get( + CanAutoTargetTemp::TypeExtData->AutoTarget_NoThreatBuildings.Get(pThis->Owner->IsControlledByHuman() + ? RulesExt::Global()->AutoTarget_NoThreatBuildings : RulesExt::Global()->AutoTargetAI_NoThreatBuildings)); + + if (!canAttack) + return ContinueCheck; + + const auto pExt = TechnoExt::ExtMap.Find(pThis); + + return pExt->TypeExtData->AttackMove_Aggressive.Get(RulesExt::Global()->AttackMove_Aggressive) ? CanTarget : ContinueCheck; +} + +#pragma endregion diff --git a/src/Ext/TechnoType/Body.cpp b/src/Ext/TechnoType/Body.cpp index d8bf5ebdb1..d85cad9fbc 100644 --- a/src/Ext/TechnoType/Body.cpp +++ b/src/Ext/TechnoType/Body.cpp @@ -1198,6 +1198,8 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) // VoiceIFVRepair from Ares 0.2 this->VoiceIFVRepair.Read(exINI, pSection, "VoiceIFVRepair"); this->ParseVoiceWeaponAttacks(exINI, pSection, this->VoiceWeaponAttacks, this->VoiceEliteWeaponAttacks); + + this->AutoTarget_NoThreatBuildings.Read(exINI, pSection, "AutoTarget.NoThreatBuildings"); } void TechnoTypeExt::ExtData::LoadFromINIByWhatAmI(INI_EX& exINI, const char* pSection, INI_EX& exArtINI, const char* pArtSection) @@ -1609,6 +1611,8 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm) .Process(this->InfantryAutoDeploy) .Process(this->TurretResponse) + + .Process(this->AutoTarget_NoThreatBuildings) ; } void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) diff --git a/src/Ext/TechnoType/Body.h b/src/Ext/TechnoType/Body.h index 277021f05d..445f3a7726 100644 --- a/src/Ext/TechnoType/Body.h +++ b/src/Ext/TechnoType/Body.h @@ -431,6 +431,8 @@ class TechnoTypeExt Nullable TurretResponse; + Nullable AutoTarget_NoThreatBuildings; + ExtData(TechnoTypeClass* OwnerObject) : Extension(OwnerObject) , HealthBar_Hide { false } , HealthBar_HidePips { false } @@ -812,6 +814,8 @@ class TechnoTypeExt , InfantryAutoDeploy {} , TurretResponse {} + + , AutoTarget_NoThreatBuildings {} { } virtual ~ExtData() = default; diff --git a/src/Ext/WeaponType/Body.cpp b/src/Ext/WeaponType/Body.cpp index be24ebc24f..c88b337102 100644 --- a/src/Ext/WeaponType/Body.cpp +++ b/src/Ext/WeaponType/Body.cpp @@ -153,6 +153,7 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->DelayedFire_OnlyOnInitialBurst.Read(exINI, pSection, "DelayedFire.OnlyOnInitialBurst"); this->DelayedFire_AnimOffset.Read(exINI, pSection, "DelayedFire.AnimOffset"); this->DelayedFire_AnimOnTurret.Read(exINI, pSection, "DelayedFire.AnimOnTurret"); + this->AttackNoThreatBuildings.Read(exINI, pSection, "AttackNoThreatBuildings"); // handle SkipWeaponPicking if (this->CanTarget != AffectedTarget::All || this->CanTargetHouses != AffectedHouse::All @@ -237,6 +238,7 @@ void WeaponTypeExt::ExtData::Serialize(T& Stm) .Process(this->DelayedFire_OnlyOnInitialBurst) .Process(this->DelayedFire_AnimOffset) .Process(this->DelayedFire_AnimOnTurret) + .Process(this->AttackNoThreatBuildings) ; }; diff --git a/src/Ext/WeaponType/Body.h b/src/Ext/WeaponType/Body.h index 03d6fe37e0..438f085f29 100644 --- a/src/Ext/WeaponType/Body.h +++ b/src/Ext/WeaponType/Body.h @@ -91,6 +91,7 @@ class WeaponTypeExt Valueable DelayedFire_OnlyOnInitialBurst; Nullable DelayedFire_AnimOffset; Valueable DelayedFire_AnimOnTurret; + Nullable AttackNoThreatBuildings; bool SkipWeaponPicking; @@ -164,6 +165,7 @@ class WeaponTypeExt , DelayedFire_OnlyOnInitialBurst { false } , DelayedFire_AnimOffset {} , DelayedFire_AnimOnTurret { true } + , AttackNoThreatBuildings {} { } int GetBurstDelay(int burstIndex) const;