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 1b56f9d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
46 changes: 24 additions & 22 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,35 +176,37 @@ 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 `DisableRadiationDamageOnBuildings` 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
[RadiationTypes]
0=SOMERADTYPE

[Radiation]
UseGlobalRadApplicationDelay=true ; boolean

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

[SOMERADTYPE] ; RadType
RadDurationMultiple=1 ; integer
RadApplicationDelay=16 ; integer
RadApplicationDelay.Building=0 ; integer
RadBuildingDamageMaxCount=-1 ; integer
RadLevelMax=500 ; integer
RadLevelDelay=90 ; integer
RadLightDelay=90 ; integer
RadLevelFactor=0.2 ; floating point value
RadLightFactor=0.1 ; floating point value
RadTintFactor=1.0 ; floating point value
RadColor=0,255,0 ; integer - R,G,B
RadSiteWarhead=RadSite ; WarheadType
RadSiteWarhead.Detonate=false ; boolean
RadSiteWarhead.Detonate.Full=true ; boolean
RadHasOwner=false ; boolean
RadHasInvoker=false ; boolean
UseGlobalRadApplicationDelay=true ; boolean
DisableRadiationDamageOnBuildings=false ; boolean

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

[SOMERADTYPE] ; RadType
RadDurationMultiple=1 ; integer
RadApplicationDelay=16 ; integer
RadApplicationDelay.Building=0 ; integer
RadBuildingDamageMaxCount=-1 ; integer
RadLevelMax=500 ; integer
RadLevelDelay=90 ; integer
RadLightDelay=90 ; integer
RadLevelFactor=0.2 ; floating point value
RadLightFactor=0.1 ; floating point value
RadTintFactor=1.0 ; floating point value
RadColor=0,255,0 ; integer - R,G,B
RadSiteWarhead=RadSite ; WarheadType
RadSiteWarhead.Detonate=false ; boolean
RadSiteWarhead.Detonate.Full=true ; boolean
RadHasOwner=false ; boolean
RadHasInvoker=false ; boolean
```

### Laser Trails
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->DisableRadiationDamageOnBuildings.Read(exINI, GameStrings::Radiation, "DisableRadiationDamageOnBuildings");
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->DisableRadiationDamageOnBuildings)
.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->DisableRadiationDamageOnBuildings)
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> DisableRadiationDamageOnBuildings;
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 }
, DisableRadiationDamageOnBuildings { false }
, RadBuildingDamageMaxCount { -1 }
, RadSiteWarhead_Detonate { false }
, RadSiteWarhead_Detonate_Full { true }
Expand Down

0 comments on commit 1b56f9d

Please sign in to comment.