Skip to content

Commit 72e8bb2

Browse files
authored
[Minor] Customizing bridge fall damageFalling down damage (#1421)
![坠落3](https://github.com/user-attachments/assets/9cfed9d4-d19f-423b-b568-17026bbe4f10) ![坠落4](https://github.com/user-attachments/assets/6a128485-5ab0-42b1-88e0-091b92847f94) Now you can customize the damage a unit receives when it falls from a bridge. - `FallingDownDamage` customizes the damage a unit receives at the end of a fall. It can be a percentage or an integer. - `FallingDownDamage.Water` customizes the damage a unit receives when it falls onto the water. Defaults to `FallingDownDamage`. - If it is a negative percentage, corresponding damage will be dealt based on the current health of the unit. In `rulesmd.ini`: ```ini [SOMETECHNO] ; TechnoType FallingDownDamage= ; integer / percentage FallingDownDamage.Water= ; integer / percentage ``` --------- 现在可以自定义单位从桥上坠落下来时受到的伤害。 - `FallingDownDamage`自定义单位坠落后受到的伤害。它可以是百分比,也可以是正数。 - `FallingDownDamage.Water`自定义自定义单位坠落到水面时受到的伤害。默认为`FallingDownDamage`。 - 如果是负百分比的话,它会根据单位的当前血量赋予对应百分比的伤害。
1 parent 5c71e8a commit 72e8bb2

File tree

6 files changed

+111
-2
lines changed

6 files changed

+111
-2
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ This page lists all the individual contributions to the project by their author.
355355
- `Edit/Clear Hate-Value` Trigger Action
356356
- `Set Force Enemy` Trigger Action
357357
- Fix the issue where computer players did not search for new enemies after defeating them or forming alliances with them
358+
- Customize the damage taken when falling from a bridge
358359
- **NetsuNegi**:
359360
- Forbidding parallel AI queues by type
360361
- Jumpjet crash speed fix when crashing onto building

docs/Fixed-or-Improved-Logics.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,20 @@ Wake.Grapple= ; Anim (played when Techno being parasited on the water), d
933933
Wake.Sinking= ; Anim (played when Techno sinking), defaults to [TechnoType] -> Wake
934934
```
935935

936+
### Customize bridge falling down damage
937+
938+
- Now you can customize the damage a unit receives when it falls from a bridge.
939+
- `FallingDownDamage` customizes the damage a unit receives at the end of a fall. It can be a percentage or an integer.
940+
- `FallingDownDamage.Water` customizes the damage a unit receives when it falls onto the water. Defaults to `FallingDownDamage`.
941+
- If it is a negative percentage, corresponding damage will be dealt based on the current health of the unit.
942+
943+
In `rulesmd.ini`:
944+
```ini
945+
[SOMETECHNO] ; TechnoType
946+
FallingDownDamage= ; integer / percentage
947+
FallingDownDamage.Water= ; integer / percentage
948+
```
949+
936950
### Customize resource storage
937951

938952
- Now Ares `Storage` feature can set which Tiberium type from `[Tiberiums]` list should be used for storing resources in structures with `Refinery.UseStorage=yes` and `Storage` > 0.

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ New:
375375
- [Passenger-based insignias](Fixed-or-Improved-Logics.md#customizable-veterancy-insignias) (by Ollerus)
376376
- [Use `InsigniaType` to set the properties of insignia in a batch](Miscellanous.md#insignia-type) (by Ollerus)
377377
- [Tiberium eater logic](New-or-Enhanced-Logics.md#tiberium-eater) (by NetsuNegi)
378+
- [Customize the damage taken when falling from a bridge](Fixed-or-Improved-Logics.md#customize-bridge-falling-down-damage) (by FlyStar)
378379
379380
Vanilla fixes:
380381
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

src/Ext/Techno/Hooks.cpp

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,4 +782,85 @@ DEFINE_HOOK(0x655DDD, RadarClass_ProcessPoint_RadarInvisible, 0x6)
782782
return GoOtherChecks;
783783
}
784784

785-
#pragma endregion
785+
#pragma endregion
786+
787+
#pragma region Customized FallingDown Damage
788+
789+
DEFINE_HOOK(0x5F416A, ObjectClass_DropAsBomb_ResetFallRateRate, 0x7)
790+
{
791+
GET(ObjectClass*, pThis, ESI);
792+
793+
// Reset value, otherwise it'll keep accelerating.
794+
pThis->FallRate = 0;
795+
return 0;
796+
}
797+
798+
DEFINE_HOOK(0x5F4032, ObjectClass_FallingDown_ToDead, 0x6)
799+
{
800+
GET(ObjectClass*, pThis, ESI);
801+
802+
pThis->FallRate = 0;
803+
804+
if (const auto pTechno = abstract_cast<TechnoClass*, true>(pThis))
805+
{
806+
const auto pType = pTechno->GetTechnoType();
807+
const auto pCell = pTechno->GetCell();
808+
809+
if (!pCell->IsClearToMove(pType->SpeedType, true, true, -1, pType->MovementZone, pCell->GetLevel(), pCell->ContainsBridge()))
810+
return 0;
811+
812+
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
813+
double ratio = 0.0;
814+
815+
if (pCell->LandType == LandType::Water && !pTechno->OnBridge)
816+
ratio = pTypeExt->FallingDownDamage_Water.Get(pTypeExt->FallingDownDamage.Get());
817+
else
818+
ratio = pTypeExt->FallingDownDamage.Get();
819+
820+
int damage = 0;
821+
822+
if (ratio < 0.0)
823+
damage = static_cast<int>(pThis->Health * std::abs(ratio));
824+
else if (ratio >= 0.0 && ratio <= 1.0)
825+
damage = static_cast<int>(pType->Strength * ratio);
826+
else
827+
damage = static_cast<int>(ratio);
828+
829+
pThis->ReceiveDamage(&damage, 0, RulesClass::Instance->C4Warhead, nullptr, true, true, nullptr);
830+
831+
if (pThis->Health > 0 && pThis->IsAlive)
832+
{
833+
pThis->IsABomb = false;
834+
const auto abs = pThis->WhatAmI();
835+
836+
if (abs == AbstractType::Infantry)
837+
{
838+
const auto pInf = static_cast<InfantryClass*>(pTechno);
839+
const auto sequenceAnim = pInf->SequenceAnim;
840+
pInf->ShouldDeploy = false;
841+
842+
if (pCell->LandType == LandType::Water && !pInf->OnBridge)
843+
{
844+
if (sequenceAnim != Sequence::Swim)
845+
pInf->PlayAnim(Sequence::Swim, true, false);
846+
}
847+
else if (sequenceAnim != Sequence::Guard)
848+
{
849+
pInf->PlayAnim(Sequence::Ready, true, false);
850+
}
851+
852+
pInf->Scatter(pInf->GetCoords(), true, false);
853+
}
854+
else if (abs == AbstractType::Unit)
855+
{
856+
static_cast<UnitClass*>(pTechno)->UpdatePosition(PCPType::During);
857+
}
858+
}
859+
860+
return 0x5F405B;
861+
}
862+
863+
return 0;
864+
}
865+
866+
#pragma endregion

src/Ext/TechnoType/Body.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
564564
this->Overload_ParticleSys.Read(exINI, pSection, "Overload.ParticleSys");
565565
this->Overload_ParticleSysCount.Read(exINI, pSection, "Overload.ParticleSysCount");
566566

567+
this->FallingDownDamage.Read(exINI, pSection, "FallingDownDamage");
568+
this->FallingDownDamage_Water.Read(exINI, pSection, "FallingDownDamage.Water");
569+
567570
this->Harvester_CanGuardArea.Read(exINI, pSection, "Harvester.CanGuardArea");
568571
this->HarvesterScanAfterUnload.Read(exINI, pSection, "HarvesterScanAfterUnload");
569572

@@ -1108,6 +1111,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
11081111

11091112
.Process(this->Harvester_CanGuardArea)
11101113
.Process(this->HarvesterScanAfterUnload)
1114+
1115+
.Process(this->FallingDownDamage)
1116+
.Process(this->FallingDownDamage_Water)
11111117
;
11121118
}
11131119
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)

src/Ext/TechnoType/Body.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,13 @@ class TechnoTypeExt
348348
NullableIdx<VocClass> Overload_DeathSound;
349349
Nullable<ParticleSystemTypeClass*> Overload_ParticleSys;
350350
Valueable<int> Overload_ParticleSysCount;
351-
351+
352352
Valueable<bool> Harvester_CanGuardArea;
353353
Nullable<bool> HarvesterScanAfterUnload;
354354

355+
Valueable<double> FallingDownDamage;
356+
Nullable<double> FallingDownDamage_Water;
357+
355358
ExtData(TechnoTypeClass* OwnerObject) : Extension<TechnoTypeClass>(OwnerObject)
356359
, HealthBar_Hide { false }
357360
, UIDescription {}
@@ -656,6 +659,9 @@ class TechnoTypeExt
656659

657660
, Harvester_CanGuardArea { false }
658661
, HarvesterScanAfterUnload {}
662+
663+
, FallingDownDamage { 1.0 }
664+
, FallingDownDamage_Water {}
659665
{ }
660666

661667
virtual ~ExtData() = default;

0 commit comments

Comments
 (0)