Skip to content

Commit c8955a5

Browse files
committed
Damage multiplier for health percentage
1 parent 28367af commit c8955a5

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ This page lists all the individual contributions to the project by their author.
517517
- Power plant damage factor
518518
- Allow faking digital display for `InfoType=Health` at disguise
519519
- Display banner improvement and doc
520+
- Damage multiplier for health percentage
520521
- **NaotoYuuki** - Vertical & meteor trajectory projectile prototypes
521522
- **handama** - AI script action to `16005 Jump Back To Previous Script`
522523
- **TaranDahl (航味麻酱)**:

docs/New-or-Enhanced-Logics.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,25 +2122,29 @@ MindControl.Anim= ; Animation, defaults to [CombatDamage] ->
21222122
In `rulesmd.ini`:
21232123
```ini
21242124
[SOMEWARHEAD] ; WarheadType
2125-
SplashList=<none> ; List of AnimationTypes
2125+
SplashList= ; List of AnimationTypes
21262126
SplashList.PickRandom=false ; boolean
21272127
```
21282128

2129-
### Damage multiplier for different houses
2129+
### Damage multipliers
21302130

2131-
- Warheads are now able to define the extra damage multiplier for owner house, ally houses and enemy houses. If the warhead's own `Damage(Owner|Allies|Enemies)Multiplier` are not set, these will default to respective `[CombatDamage] -> Damage(Owner|Allies|Enemies)Multiplier` 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 .
2131+
- Warheads are now able to define the extra damage multiplier for owner house, ally houses and enemy houses. If the warhead's own `Damage(Owner|Allies|Enemies)Multiplier` are not set, these will default to respective `[CombatDamage] -> Damage(Owner|Allies|Enemies)Multiplier` which all default to 1.0 .Note that `DamageAlliesMultiplier` won't affect your own units like `AffectsAllies` did.
2132+
- An extra damage multiplier based on the firer or target's health percentage will be added to the total multiplier. To be elaborate: the damage multiplier will firstly increased by the firer's health percentage multiplies `DamageSourceHealthMultiplier`, then increased by the target's health percentage multiplies `DamageTargetHealthMultiplier`.
2133+
- These multipliers will not affect damage with ignore defenses like `Suicide`.etc .
21322134

21332135
In `rulesmd.ini`:
21342136
```ini
21352137
[CombatDamage]
2136-
DamageOwnerMultiplier=1.0 ; floating point value
2137-
DamageAlliesMultiplier=1.0 ; floating point value
2138-
DamageEnemiesMultiplier=1.0 ; floating point value
2139-
2140-
[SOMEWARHEAD] ; WarheadType
2141-
DamageOwnerMultiplier= ; floating point value
2142-
DamageAlliesMultiplier= ; floating point value
2143-
DamageEnemiesMultiplier= ; floating point value
2138+
DamageOwnerMultiplier=1.0 ; floating point value
2139+
DamageAlliesMultiplier=1.0 ; floating point value
2140+
DamageEnemiesMultiplier=1.0 ; floating point value
2141+
2142+
[SOMEWARHEAD] ; WarheadType
2143+
DamageOwnerMultiplier= ; floating point value
2144+
DamageAlliesMultiplier= ; floating point value
2145+
DamageEnemiesMultiplier= ; floating point value
2146+
DamageSourceHealthMultiplier=0.0 ; floating point value
2147+
DamageTargetHealthMultiplier=0.0 ; floating point value
21442148
```
21452149

21462150
### Detonate Warhead on all objects on map

docs/Whats-New.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ New:
337337
- [Toggle waypoint for building](Fixed-or-Improved-Logics.md#waypoints-for-buildings) (by TaranDahl)
338338
- [Bunkerable checks dehardcode](Fixed-or-Improved-Logics.md#bunker-entering-check-dehardcode) (by TaranDahl)
339339
- [No turret unit turn to the target](Fixed-or-Improved-Logics.md#unit-without-turret-always-turn-to-target) (by CrimRecya & TaranDahl)
340-
- [Damage multiplier for different houses](New-or-Enhanced-Logics.md#damage-multiplier-for-different-houses) (by CrimRecya)
340+
- [Damage multipliers](New-or-Enhanced-Logics.md#damage-multipliers) (by CrimRecya & Ollerus)
341341
- Customizable duration for electric bolts (by Starkku)
342342
- Customizable FLH tracking for electric bolts (by Starkku)
343343
- [Extended gattling rate down logic](New-or-Enhanced-Logics.md#extended-gattling-rate-down-logic) (by CrimRecya)

src/Ext/Techno/Hooks.ReceiveDamage.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
2525

2626
const auto pSourceHouse = args->SourceHouse;
2727
const auto pTargetHouse = pThis->Owner;
28+
int& damage = *args->Damage;
2829

2930
// Calculate Damage Multiplier
30-
if (!args->IgnoreDefenses && *args->Damage)
31+
if (!args->IgnoreDefenses && damage)
3132
{
3233
double multiplier = 1.0;
3334

@@ -38,16 +39,22 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
3839
else
3940
multiplier = pWHExt->DamageOwnerMultiplier.Get(pRules->DamageOwnerMultiplier);
4041

42+
if (pWHExt->DamageSourceHealthMultiplier && args->Attacker)
43+
multiplier += pWHExt->DamageSourceHealthMultiplier * args->Attacker->GetHealthPercentage();
44+
45+
if (pWHExt->DamageTargetHealthMultiplier)
46+
multiplier += pWHExt->DamageTargetHealthMultiplier * pThis->GetHealthPercentage();
47+
4148
if (multiplier != 1.0)
4249
{
43-
const auto sgnDamage = *args->Damage > 0 ? 1 : -1;
44-
const auto calculateDamage = static_cast<int>(*args->Damage * multiplier);
45-
*args->Damage = calculateDamage ? calculateDamage : sgnDamage;
50+
const auto sgnDamage = damage > 0 ? 1 : -1;
51+
const auto calculateDamage = static_cast<int>(damage * multiplier);
52+
damage = calculateDamage ? calculateDamage : sgnDamage;
4653
}
4754
}
4855

4956
// Raise Combat Alert
50-
if (pRules->CombatAlert && *args->Damage > 1)
57+
if (pRules->CombatAlert && damage > 1)
5158
{
5259
auto raiseCombatAlert = [&]()
5360
{
@@ -104,7 +111,7 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
104111
// Shield Receive Damage
105112
if (!args->IgnoreDefenses)
106113
{
107-
int nDamageLeft = *args->Damage;
114+
int nDamageLeft = damage;
108115

109116
if (const auto pShieldData = pExt->Shield.get())
110117
{
@@ -114,9 +121,9 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
114121

115122
if (nDamageLeft >= 0)
116123
{
117-
*args->Damage = nDamageLeft;
124+
damage = nDamageLeft;
118125

119-
if (auto pTag = pThis->AttachedTag)
126+
if (const auto pTag = pThis->AttachedTag)
120127
pTag->RaiseEvent((TriggerEvent)PhobosTriggerEvent::ShieldBroken, pThis, CellStruct::Empty);
121128
}
122129

@@ -131,7 +138,7 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
131138
&& MapClass::GetTotalDamage(nDamageLeft, args->WH, pThis->GetTechnoType()->Armor, args->DistanceToEpicenter) >= pThis->Health)
132139
{
133140
// Update remaining damage and check if the target will die and should be avoided
134-
*args->Damage = 0;
141+
damage = 0;
135142
pThis->Health = 1;
136143
pThis->EstimatedHealth = 1;
137144
ReceiveDamageTemp::SkipLowDamageCheck = true;

src/Ext/WarheadType/Body.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
258258
this->DamageOwnerMultiplier.Read(exINI, pSection, "DamageOwnerMultiplier");
259259
this->DamageAlliesMultiplier.Read(exINI, pSection, "DamageAlliesMultiplier");
260260
this->DamageEnemiesMultiplier.Read(exINI, pSection, "DamageEnemiesMultiplier");
261+
this->DamageSourceHealthMultiplier.Read(exINI, pSection, "DamageSourceHealthMultiplier");
262+
this->DamageTargetHealthMultiplier.Read(exINI, pSection, "DamageTargetHealthMultiplier");
261263

262264
this->SuppressRevengeWeapons.Read(exINI, pSection, "SuppressRevengeWeapons");
263265
this->SuppressRevengeWeapons_Types.Read(exINI, pSection, "SuppressRevengeWeapons.Types");
@@ -521,6 +523,8 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
521523
.Process(this->DamageOwnerMultiplier)
522524
.Process(this->DamageAlliesMultiplier)
523525
.Process(this->DamageEnemiesMultiplier)
526+
.Process(this->DamageSourceHealthMultiplier)
527+
.Process(this->DamageTargetHealthMultiplier)
524528

525529
.Process(this->Parasite_CullingTarget)
526530

src/Ext/WarheadType/Body.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class WarheadTypeExt
154154
Nullable<double> DamageOwnerMultiplier;
155155
Nullable<double> DamageAlliesMultiplier;
156156
Nullable<double> DamageEnemiesMultiplier;
157+
Valueable<double> DamageSourceHealthMultiplier;
158+
Valueable<double> DamageTargetHealthMultiplier;
157159

158160
Valueable<bool> SuppressRevengeWeapons;
159161
ValueableVector<WeaponTypeClass*> SuppressRevengeWeapons_Types;
@@ -341,6 +343,8 @@ class WarheadTypeExt
341343
, DamageOwnerMultiplier {}
342344
, DamageAlliesMultiplier {}
343345
, DamageEnemiesMultiplier {}
346+
, DamageSourceHealthMultiplier { 0.0 }
347+
, DamageTargetHealthMultiplier { 0.0 }
344348

345349
, SuppressRevengeWeapons { false }
346350
, SuppressRevengeWeapons_Types {}

0 commit comments

Comments
 (0)