Skip to content

Commit cd0746a

Browse files
authored
[Dehardcode]Customize damaged speed (#1606)
- In vanilla, units using drive/ship loco will has hardcoded speed multiplier when damaged. Now you can customize it. - The max valuebale value is 1.0, you cannot make unit get faster on yellow condition by it. In `rulesmd.ini` ```ini [General] DamagedSpeed=0.75 ; double [SOMEUNIT] DamagedSpeed= ; double ```
1 parent 5a37e23 commit cd0746a

File tree

8 files changed

+46
-2
lines changed

8 files changed

+46
-2
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ This page lists all the individual contributions to the project by their author.
364364
- Fix `DefaultDisguise` showing wrong house colors for different players
365365
- Taking over Ares' AlphaImage respawn logic to reduce lags from it
366366
- Allow voxel projectiles to use AnimPalette and FirersPalette
367+
- Customize damaged speed ratio of drive/ship loco
367368
- **Apollo** - Translucent SHP drawing patches
368369
- **ststl**:
369370
- Customizable `ShowTimer` priority of superweapons

docs/Fixed-or-Improved-Logics.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,21 @@ ProneSpeed.NoCrawls=1.5 ; floating point value, multiplier
546546
ProneSpeed= ; floating point value, multiplier, by default, use the corresponding global value according to Crawls
547547
```
548548

549+
## Unit
550+
551+
### Damaged speed customization
552+
553+
- In vanilla, units using drive/ship loco will has hardcoded speed multiplier when damaged. Now you can customize it.
554+
- The max valuebale value is 1.0, you cannot make unit get faster on yellow condition by it.
555+
556+
In `rulesmd.ini`
557+
```ini
558+
[General]
559+
DamagedSpeed=0.75 ; double
560+
561+
[SOMEUNIT]
562+
DamagedSpeed= ; double
563+
549564
## Particle systems
550565

551566
### Fire particle target coordinate adjustment when firer rotates

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ New:
352352
- [Airburst weapon firing/source coordinate customizations](Fixed-or-Improved-Logics.md#airburst--splits) (by Starkku)
353353
- [AlternateFLH on-turret toggle](Fixed-or-Improved-Logics.md#alternate-flh-customizations) (by Starkku)
354354
- Prone speed customization (by TaranDahl)
355+
- Customize damaged speed ratio of drive/ship loco (by NetsuNegi)
355356
356357
Vanilla fixes:
357358
- Prevent the units with locomotors that cause problems from entering the tank bunker (by TaranDahl)

src/Ext/Rules/Body.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
249249
this->ProneSpeed_Crawls.Read(exINI, GameStrings::General, "ProneSpeed.Crawls");
250250
this->ProneSpeed_NoCrawls.Read(exINI, GameStrings::General, "ProneSpeed.NoCrawls");
251251

252+
this->DamagedSpeed.Read(exINI, GameStrings::General, "DamagedSpeed");
253+
252254
// Section AITargetTypes
253255
int itemsCount = pINI->GetKeyCount("AITargetTypes");
254256
for (int i = 0; i < itemsCount; ++i)
@@ -461,6 +463,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
461463
.Process(this->BuildingTypeSelectable)
462464
.Process(this->ProneSpeed_Crawls)
463465
.Process(this->ProneSpeed_NoCrawls)
466+
.Process(this->DamagedSpeed)
464467
;
465468
}
466469

src/Ext/Rules/Body.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class RulesExt
205205
Valueable<double> ProneSpeed_Crawls;
206206
Valueable<double> ProneSpeed_NoCrawls;
207207

208+
Valueable<double> DamagedSpeed;
209+
208210
ExtData(RulesClass* OwnerObject) : Extension<RulesClass>(OwnerObject)
209211
, Storage_TiberiumIndex { -1 }
210212
, InfantryGainSelfHealCap {}
@@ -358,6 +360,8 @@ class RulesExt
358360
, BuildingTypeSelectable { false }
359361
, ProneSpeed_Crawls { 0.67 }
360362
, ProneSpeed_NoCrawls { 1.5 }
363+
364+
, DamagedSpeed { 0.75 }
361365
{ }
362366

363367
virtual ~ExtData() = default;

src/Ext/Techno/Hooks.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,15 @@ DEFINE_HOOK(0x521D94, InfantryClass_CurrentSpeed_ProneSpeed, 0x6)
727727
R->ECX(currentSpeed);
728728
return 0x521DC5;
729729
}
730+
731+
DEFINE_HOOK_AGAIN(0x6A343F, LocomotionClass_Process_DamagedSpeedMultiplier, 0x6)// Ship
732+
DEFINE_HOOK(0x4B3DF0, LocomotionClass_Process_DamagedSpeedMultiplier, 0x6)// Drive
733+
{
734+
GET(FootClass*, pLinkedTo, ECX);
735+
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pLinkedTo->GetTechnoType());
736+
737+
const double multiplier = pTypeExt->DamagedSpeed.Get(RulesExt::Global()->DamagedSpeed);
738+
__asm fmul multiplier;
739+
740+
return R->Origin() + 0x6;
741+
}

src/Ext/TechnoType/Body.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,11 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
503503
this->Sinkable.Read(exINI, pSection, "Sinkable");
504504
this->Sinkable_SquidGrab.Read(exINI, pSection, "Sinkable.SquidGrab");
505505
this->SinkSpeed.Read(exINI, pSection, "SinkSpeed");
506-
506+
507507
this->ProneSpeed.Read(exINI, pSection, "ProneSpeed");
508508

509+
this->DamagedSpeed.Read(exINI, pSection, "DamagedSpeed");
510+
509511
this->SuppressKillWeapons.Read(exINI, pSection, "SuppressKillWeapons");
510512
this->SuppressKillWeapons_Types.Read(exINI, pSection, "SuppressKillWeapons.Types");
511513

@@ -932,6 +934,8 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
932934
.Process(this->Sinkable_SquidGrab)
933935
.Process(this->SinkSpeed)
934936

937+
.Process(this->DamagedSpeed)
938+
935939
.Process(this->SuppressKillWeapons)
936940
.Process(this->SuppressKillWeapons_Types)
937941

src/Ext/TechnoType/Body.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ class TechnoTypeExt
280280
Valueable<int> SinkSpeed;
281281

282282
Nullable<double> ProneSpeed;
283-
283+
284+
Nullable<double> DamagedSpeed;
285+
284286
struct LaserTrailDataEntry
285287
{
286288
ValueableIdx<LaserTrailTypeClass> idxType;
@@ -557,6 +559,8 @@ class TechnoTypeExt
557559
, Sinkable_SquidGrab { true }
558560
, SinkSpeed { 5 }
559561

562+
, DamagedSpeed { }
563+
560564
, SuppressKillWeapons { false }
561565
, SuppressKillWeapons_Types {}
562566

0 commit comments

Comments
 (0)