Skip to content

Commit

Permalink
Allow disabling radiation damage vs building hook for perf optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku committed Feb 25, 2025
1 parent 962a8a4 commit 2ff45a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ SuppressReflectDamage.Types= ; List of AttachEffectTypes
- `RadHasOwner`, if set to true, makes damage dealt by the radiation count as having been dealt by the house that fired the projectile that created the radiation field. This means that Warhead controls such as `AffectsAllies` will be respected and any units killed will count towards that player's destroyed units count.
- `RadHasInvoker`, if set to true, makes the damage dealt by the radiation count as having been dealt by the TechnoType (the 'invoker') that fired the projectile that created the radiation field. In addition to the effects of `RadHasOwner`, this will also grant experience from units killed by the radiation to the invoker. Note that if the invoker dies at any point during the radiation's lifetime it continues to behave as if not having an invoker.
- By default `UseGlobalRadApplicationDelay` is set to true. This makes game always use `RadApplicationDelay` and `RadApplicationDelay.Building` from `[Radiation]` rather than specific radiation types. This is a performance-optimizing measure that should be disabled if a radiation type declares different application delay.
- Setting `DisableRadDamageOnBuildings` to true under `[Radiation]` fully disables functionality of `RadApplicationDelay.Building`, which otherwise affects game performance even if not used. Note that this option cannot be set or changed in map files.

In `rulesmd.ini`:
```ini
Expand All @@ -184,10 +185,11 @@ In `rulesmd.ini`:

[Radiation]
UseGlobalRadApplicationDelay=true ; boolean
DisableRadDamageOnBuildings=false ; boolean

[SOMEWEAPON] ; WeaponType
RadType=Radiation ; RadType to use instead of default of [Radiation]

[SOMERADTYPE] ; RadType
RadDurationMultiple=1 ; integer
RadApplicationDelay=16 ; integer
Expand Down
15 changes: 15 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <New/Type/LaserTrailTypeClass.h>
#include <New/Type/DigitalDisplayTypeClass.h>
#include <New/Type/AttachEffectTypeClass.h>
#include <Utilities/Patch.h>

std::unique_ptr<RulesExt::ExtData> RulesExt::Data = nullptr;

Expand Down Expand Up @@ -84,6 +85,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->AISuperWeaponDelay.Read(exINI, GameStrings::General, "AISuperWeaponDelay");
this->UseGlobalRadApplicationDelay.Read(exINI, GameStrings::Radiation, "UseGlobalRadApplicationDelay");
this->RadApplicationDelay_Building.Read(exINI, GameStrings::Radiation, "RadApplicationDelay.Building");
this->DisableRadDamageOnBuildings.Read(exINI, GameStrings::Radiation, "DisableRadDamageOnBuildings");
this->RadBuildingDamageMaxCount.Read(exINI, GameStrings::Radiation, "RadBuildingDamageMaxCount");
this->RadSiteWarhead_Detonate.Read(exINI, GameStrings::Radiation, "RadSiteWarhead.Detonate");
this->RadSiteWarhead_Detonate_Full.Read(exINI, GameStrings::Radiation, "RadSiteWarhead.Detonate.Full");
Expand Down Expand Up @@ -317,6 +319,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->AISuperWeaponDelay)
.Process(this->UseGlobalRadApplicationDelay)
.Process(this->RadApplicationDelay_Building)
.Process(this->DisableRadDamageOnBuildings)
.Process(this->RadBuildingDamageMaxCount)
.Process(this->RadSiteWarhead_Detonate)
.Process(this->RadSiteWarhead_Detonate_Full)
Expand Down Expand Up @@ -616,3 +619,15 @@ DEFINE_HOOK(0x6744E4, RulesClass_ReadJumpjetControls_Extra, 0x7)

// skip vanilla JumpjetControls and make it earlier load
// DEFINE_JUMP(LJMP, 0x668EB5, 0x668EBD); // RulesClass_Process_SkipJumpjetControls // Really necessary? won't hurt to read again

// After rulesmd.ini has been parsed, before anything else like maps and only once on game init.
DEFINE_HOOK(0x6876B1, ReadScenarioINI_Optimizations, 0x5)
{
auto const pRulesExt = RulesExt::Global();

// Disable BuildingClass_AI_Radiation
if (pRulesExt->DisableRadDamageOnBuildings)
Patch::Apply_RAW(0x43FB23, { 0x53, 0x55, 0x56, 0x8B, 0xF1 });

return 0;
}
2 changes: 2 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class RulesExt
Nullable<int> AISuperWeaponDelay;
Valueable<bool> UseGlobalRadApplicationDelay;
Valueable<int> RadApplicationDelay_Building;
Valueable<bool> DisableRadDamageOnBuildings;
Valueable<int> RadBuildingDamageMaxCount;
Valueable<bool> RadSiteWarhead_Detonate;
Valueable<bool> RadSiteWarhead_Detonate_Full;
Expand Down Expand Up @@ -207,6 +208,7 @@ class RulesExt
, AISuperWeaponDelay {}
, UseGlobalRadApplicationDelay { true }
, RadApplicationDelay_Building { 0 }
, DisableRadDamageOnBuildings { false }
, RadBuildingDamageMaxCount { -1 }
, RadSiteWarhead_Detonate { false }
, RadSiteWarhead_Detonate_Full { true }
Expand Down

0 comments on commit 2ff45a0

Please sign in to comment.