Skip to content

Commit

Permalink
[Customized] Damage multiplier for different houses (#1307)
Browse files Browse the repository at this point in the history
- Warheads are now able to define the extra damage multiplier for owner
house, ally houses and enemy houses. The values in warheads are default
to respective `[CombatDamage]` -> `DamageXXMultiplier`, which all
default to 1.0 .Note that this will not affect damage with ignore
defenses.

In `rulesmd.ini`:
```ini
[CombatDamage]
DamageOwnerMultiplier=1.0     ; floating point value
DamageAlliesMultiplier=1.0    ; floating point value
DamageEnemiesMultiplier=1.0   ; floating point value

[SOMEWARHEAD]                 ; Warhead
DamageOwnerMultiplier=        ; floating point value
DamageAlliesMultiplier=       ; floating point value
DamageEnemiesMultiplier=      ; floating point value
```
  • Loading branch information
CrimRecya authored Feb 24, 2025
1 parent c93235b commit 00752e4
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 17 deletions.
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ This page lists all the individual contributions to the project by their author.
- New Parabola trajectory
- Enhanced Bombard trajectory
- No turret unit turn to the target
- Damage multiplier for different houses
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
17 changes: 17 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,23 @@ In `rulesmd.ini`:
NotHuman.DeathSequence= ; integer (1 to 5)
```

### Damage multiplier for different houses

- Warheads are now able to define the extra damage multiplier for owner house, ally houses and enemy houses. If the warhead's own `DamageXXMultiplier` are not set, these will default to respective `[CombatDamage]` -> `DamageXXMultiplier` which all default to 1.0 .Note that `DamageAlliesMultiplier` won't affect your own units like `AffectsAllies` did, and this function will not affect damage with ignore defenses like `Suicide`.etc .

In `rulesmd.ini`:
```ini
[CombatDamage]
DamageOwnerMultiplier=1.0 ; floating point value
DamageAlliesMultiplier=1.0 ; floating point value
DamageEnemiesMultiplier=1.0 ; floating point value

[SOMEWARHEAD] ; Warhead
DamageOwnerMultiplier= ; floating point value
DamageAlliesMultiplier= ; floating point value
DamageEnemiesMultiplier= ; floating point value
```

## Weapons

### AreaFire target customization
Expand Down
3 changes: 2 additions & 1 deletion docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ New:
- Enhanced Bombard trajectory (by CrimRecya & Ollerus, based on knowledge of NaotoYuuki)
- Toggle waypoint for building (by TaranDahl)
- Bunkerable checks dehardcode (by TaranDahl)
- No turret unit turn to the target (by CrimRecya & TaranDahl)
- Damage multiplier for different houses (by CrimRecya)
Vanilla fixes:
- Prevent the units with locomotors that cause problems from entering the tank bunker (by TaranDahl)
Expand Down Expand Up @@ -498,7 +500,6 @@ New:
- Allow infantry to use land sequences in water (by Starkku)
- `<Player @ X>` can now be used as owner for pre-placed objects on skirmish and multiplayer maps (by Starkku)
- Allow customizing charge turret delays per burst on a weapon (by Starkku)
- No turret unit turn to the target (by CrimRecya & TaranDahl)
- Unit `Speed` setting now accepts floating point values (by Starkku)
- Extending `Power` to all TechnoTypes (by Morton)

Expand Down
7 changes: 7 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->Vehicles_DefaultDigitalDisplayTypes.Read(exINI, GameStrings::AudioVisual, "Vehicles.DefaultDigitalDisplayTypes");
this->Aircraft_DefaultDigitalDisplayTypes.Read(exINI, GameStrings::AudioVisual, "Aircraft.DefaultDigitalDisplayTypes");

this->DamageOwnerMultiplier.Read(exINI, GameStrings::CombatDamage, "DamageOwnerMultiplier");
this->DamageAlliesMultiplier.Read(exINI, GameStrings::CombatDamage, "DamageAlliesMultiplier");
this->DamageEnemiesMultiplier.Read(exINI, GameStrings::CombatDamage, "DamageEnemiesMultiplier");

this->AircraftLevelLightMultiplier.Read(exINI, GameStrings::AudioVisual, "AircraftLevelLightMultiplier");
this->JumpjetLevelLightMultiplier.Read(exINI, GameStrings::AudioVisual, "JumpjetLevelLightMultiplier");

Expand Down Expand Up @@ -401,6 +405,9 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->ShowDesignatorRange)
.Process(this->DropPodTrailer)
.Process(this->PodImage)
.Process(this->DamageOwnerMultiplier)
.Process(this->DamageAlliesMultiplier)
.Process(this->DamageEnemiesMultiplier)
.Process(this->AircraftLevelLightMultiplier)
.Process(this->JumpjetLevelLightMultiplier)
.Process(this->VoxelLightSource)
Expand Down
8 changes: 7 additions & 1 deletion src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class RulesExt
Valueable<AnimTypeClass*> Promote_VeteranAnimation;
Valueable<AnimTypeClass*> Promote_EliteAnimation;

Valueable<double> DamageOwnerMultiplier;
Valueable<double> DamageAlliesMultiplier;
Valueable<double> DamageEnemiesMultiplier;

Valueable<double> AircraftLevelLightMultiplier;
Valueable<double> JumpjetLevelLightMultiplier;

Expand All @@ -171,7 +175,6 @@ class RulesExt
Nullable<Vector3D<float>> VoxelLightSource;
// Nullable<Vector3D<float>> VoxelShadowLightSource;
Valueable<bool> UseFixedVoxelLighting;

Valueable<bool> NoTurret_TrackTarget;

Valueable<bool> GatherWhenMCVDeploy;
Expand Down Expand Up @@ -298,6 +301,9 @@ class RulesExt
, ShowDesignatorRange { true }
, DropPodTrailer { }
, PodImage { }
, DamageOwnerMultiplier { 1.0 }
, DamageAlliesMultiplier { 1.0 }
, DamageEnemiesMultiplier { 1.0 }
, AircraftLevelLightMultiplier { 1.0 }
, JumpjetLevelLightMultiplier { 0.0 }
, VoxelLightSource { }
Expand Down
45 changes: 30 additions & 15 deletions src/Ext/Techno/Hooks.ReceiveDamage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,47 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)

const auto pRules = RulesExt::Global();
const auto pExt = TechnoExt::ExtMap.Find(pThis);
const auto pTypeExt = pExt->TypeExtData;
const auto pType = pTypeExt->OwnerObject();
const auto pWHExt = WarheadTypeExt::ExtMap.Find(args->WH);

int nDamageLeft = *args->Damage;
const auto pSourceHouse = args->SourceHouse;
const auto pTargetHouse = pThis->Owner;

// Calculate Damage Multiplier
if (!args->IgnoreDefenses && *args->Damage)
{
double multiplier = 1.0;

if (!pSourceHouse || !pTargetHouse || !pSourceHouse->IsAlliedWith(pTargetHouse))
multiplier = pWHExt->DamageEnemiesMultiplier.Get(pRules->DamageEnemiesMultiplier);
else if (pSourceHouse != pTargetHouse)
multiplier = pWHExt->DamageAlliesMultiplier.Get(pRules->DamageAlliesMultiplier);
else
multiplier = pWHExt->DamageOwnerMultiplier.Get(pRules->DamageOwnerMultiplier);

if (multiplier != 1.0)
{
const auto sgnDamage = *args->Damage > 0 ? 1 : -1;
const auto calculateDamage = static_cast<int>(*args->Damage * multiplier);
*args->Damage = calculateDamage ? calculateDamage : sgnDamage;
}
}

// Raise Combat Alert
if (pRules->CombatAlert && nDamageLeft > 1)
{
auto raiseCombatAlert = [&]()
{
const auto pHouse = pThis->Owner;

if (!pHouse->IsControlledByCurrentPlayer() || (pRules->CombatAlert_SuppressIfAllyDamage && pHouse->IsAlliedWith(args->SourceHouse)))
if (!pTargetHouse->IsControlledByCurrentPlayer() || (pRules->CombatAlert_SuppressIfAllyDamage && pTargetHouse->IsAlliedWith(pSourceHouse)))
return;

const auto pHouseExt = HouseExt::ExtMap.Find(pHouse);
const auto pHouseExt = HouseExt::ExtMap.Find(pTargetHouse);

if (pHouseExt->CombatAlertTimer.HasTimeLeft())
if (pHouseExt->CombatAlertTimer.HasTimeLeft() || pWHExt->CombatAlert_Suppress.Get(!pWHExt->Malicious || pWHExt->Nonprovocative))
return;

const auto pTypeExt = pExt->TypeExtData;
const auto pType = pTypeExt->OwnerObject();

if (!pTypeExt->CombatAlert.Get(pRules->CombatAlert_Default.Get(!pType->Insignificant && !pType->Spawned)) || !pThis->IsInPlayfield)
return;

const auto pWHExt = WarheadTypeExt::ExtMap.Find(args->WH);

if (pWHExt->CombatAlert_Suppress.Get(!pWHExt->Malicious || pWHExt->Nonprovocative))
else if (!pTypeExt->CombatAlert.Get(pRules->CombatAlert_Default.Get(!pType->Insignificant && !pType->Spawned)) || !pThis->IsInPlayfield)
return;

const auto pBuilding = abstract_cast<BuildingClass*>(pThis);
Expand Down
8 changes: 8 additions & 0 deletions src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->CLIsBlack.Read(exINI, pSection, "CLIsBlack");
this->Particle_AlphaImageIsLightFlash.Read(exINI, pSection, "Particle.AlphaImageIsLightFlash");

this->DamageOwnerMultiplier.Read(exINI, pSection, "DamageOwnerMultiplier");
this->DamageAlliesMultiplier.Read(exINI, pSection, "DamageAlliesMultiplier");
this->DamageEnemiesMultiplier.Read(exINI, pSection, "DamageEnemiesMultiplier");

this->SuppressRevengeWeapons.Read(exINI, pSection, "SuppressRevengeWeapons");
this->SuppressRevengeWeapons_Types.Read(exINI, pSection, "SuppressRevengeWeapons.Types");
this->SuppressReflectDamage.Read(exINI, pSection, "SuppressReflectDamage");
Expand Down Expand Up @@ -485,6 +489,10 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
.Process(this->InflictLocomotor)
.Process(this->RemoveInflictedLocomotor)

.Process(this->DamageOwnerMultiplier)
.Process(this->DamageAlliesMultiplier)
.Process(this->DamageEnemiesMultiplier)

.Process(this->Nonprovocative)

.Process(this->CombatLightDetailLevel)
Expand Down
8 changes: 8 additions & 0 deletions src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class WarheadTypeExt
Valueable<bool> CLIsBlack;
Nullable<bool> Particle_AlphaImageIsLightFlash;

Nullable<double> DamageOwnerMultiplier;
Nullable<double> DamageAlliesMultiplier;
Nullable<double> DamageEnemiesMultiplier;

Valueable<bool> SuppressRevengeWeapons;
ValueableVector<WeaponTypeClass*> SuppressRevengeWeapons_Types;
Valueable<bool> SuppressReflectDamage;
Expand Down Expand Up @@ -300,6 +304,10 @@ class WarheadTypeExt
, CLIsBlack { false }
, Particle_AlphaImageIsLightFlash {}

, DamageOwnerMultiplier {}
, DamageAlliesMultiplier {}
, DamageEnemiesMultiplier {}

, SuppressRevengeWeapons { false }
, SuppressRevengeWeapons_Types {}
, SuppressReflectDamage { false }
Expand Down

0 comments on commit 00752e4

Please sign in to comment.