diff --git a/CREDITS.md b/CREDITS.md index b04dd710cc..8d1e0ec5e4 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -398,6 +398,7 @@ This page lists all the individual contributions to the project by their author. - Fast access structure - Iron Curtain/Custom Tint Support for SHP Turreted Vehicles - Reactivate unused trigger events 2, 53, and 54 + - 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 4fab9a74c3..1090a52f41 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -1312,6 +1312,18 @@ 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 +``` + ### Aircraft spawner customizations ![image](_static/images/spawnrange-01.gif) @@ -2575,6 +2587,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 bb745beab6..5553c7a841 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -458,6 +458,7 @@ New: - Fast access structure (by FlyStar) - Toggle off laser trail and shake effects (by Ollerus) - [Dehardcode the `ZAdjust` of warhead anim](Fixed-or-Improved-Logics.md#dehardcode-the-zadjust-of-warhead-anim) (by TaranDahl) +- 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 e1673b2efe..9b0faef60c 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -329,6 +329,9 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) this->IvanBombAttachToCenter.Read(exINI, GameStrings::CombatDamage, "IvanBombAttachToCenter"); + 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) @@ -600,6 +603,8 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->AdjacentWallDamage) .Process(this->WarheadAnimZAdjust) .Process(this->IvanBombAttachToCenter) + .Process(this->AutoTarget_NoThreatBuildings) + .Process(this->AutoTargetAI_NoThreatBuildings) ; } diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index 07fe5f2036..0f06fe820c 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -278,6 +278,9 @@ class RulesExt Valueable IvanBombAttachToCenter; + Valueable AutoTarget_NoThreatBuildings; + Valueable AutoTargetAI_NoThreatBuildings; + ExtData(RulesClass* OwnerObject) : Extension(OwnerObject) , Storage_TiberiumIndex { -1 } , HarvesterDumpAmount { 0.0f } @@ -494,6 +497,9 @@ class RulesExt , WarheadAnimZAdjust { -15 } , IvanBombAttachToCenter { false } + + , 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..98a36f150f 100644 --- a/src/Ext/Techno/Hooks.TargetEvaluation.cpp +++ b/src/Ext/Techno/Hooks.TargetEvaluation.cpp @@ -203,8 +203,10 @@ DEFINE_HOOK(0x6F85AB, TechnoClass_CanAutoTargetObject_AggressiveAttackMove, 0x6) GET(TechnoClass* const, pThis, EDI); - if (!pThis->Owner->IsControlledByHuman()) - return CanTarget; + // Now, it is possible to customize which types of national active attacks on non-threatening buildings, so this part has been commented out. + // The new judgment code is in TechnoClass_CanAutoTarget_AttackNoThreatBuildings of Hook.cpp. + // if (!pThis->Owner->IsControlledByHuman()) + // return CanTarget; if (!pThis->MegaMissionIsAttackMove()) return ContinueCheck; diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 7d3733ea8d..b987ea751a 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -1520,3 +1520,44 @@ DEFINE_HOOK(0x6F9398, TechnoClass_SelectAutoTarget_Scan_FallingDown, 0x9) } #pragma endregion + +#pragma region AutoTargetExtension + +namespace CanAutoTargetTemp +{ + TechnoTypeExt::ExtData* TypeExtData = nullptr; + WeaponTypeExt::ExtData* WeaponExt = nullptr; +} + +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.TryFind(pWeapon); + + return 0; +} + +DEFINE_HOOK(0x6F85CF, TechnoClass_CanAutoTarget_AttackNoThreatBuildings, 0xA) +{ + enum { CanAttack = 0x6F8604, Continue = 0x6F85D9 }; + + GET(TechnoClass*, pThis, EDI); + GET(BuildingClass*, pTarget, ESI); + + bool canAttack = pThis->Owner->IsControlledByHuman() ? RulesExt::Global()->AutoTarget_NoThreatBuildings : RulesExt::Global()->AutoTargetAI_NoThreatBuildings; + + if (const auto pWeaponExt = CanAutoTargetTemp::WeaponExt) + canAttack = pWeaponExt->AttackNoThreatBuildings.Get(canAttack); + + if (canAttack) + return CanAttack; + + R->EAX(pTarget->GetTurretWeapon()); + return Continue; +} + +#pragma endregion + diff --git a/src/Ext/WeaponType/Body.cpp b/src/Ext/WeaponType/Body.cpp index 7f2037c577..3968ece227 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;