Skip to content

Commit 2548b55

Browse files
NetsuNegiDeathFishAtEaseCoronia
authored
[Dehardcode]Customize overpower logic (#1604)
Now you can specific how building can be overpowerd. Ares' Battery super weapon won't be affected by this. In `rulesmd.ini`: ```ini [SOMEWARHEAD] ElectricAssaultLevel=1 ; integer [SOMEBUILDING] Overpower.KeepOnline=2 ; integer, negative values mean that cannot keep online Overpower.ChargeWeapon=1 ; integer, negative values mean that weapons can never be switched ``` --------- Co-authored-by: 九千天华 <[email protected]> Co-authored-by: Coronia <[email protected]>
1 parent 8fbf6c6 commit 2548b55

File tree

8 files changed

+116
-1
lines changed

8 files changed

+116
-1
lines changed

CREDITS.md

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

docs/Fixed-or-Improved-Logics.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,24 @@ In `rulesmd.ini`:
530530
BuildingWaypoints=false ; boolean
531531
```
532532

533+
### Customize overpower logic
534+
535+
- Now you can specific how building can be overpowerd.
536+
537+
In `rulesmd.ini`:
538+
```ini
539+
[SOMEWARHEAD]
540+
ElectricAssaultLevel=1 ; integer
541+
542+
[SOMEBUILDING]
543+
Overpower.KeepOnline=2 ; integer, negative values mean that cannot keep online
544+
Overpower.ChargeWeapon=1 ; integer, negative values mean that weapons can never be switched
545+
```
546+
547+
```{note}
548+
Ares' [Battery Super Weapon](https://ares-developers.github.io/Ares-docs/new/superweapons/types/battery.html) won't be affected by this.
549+
```
550+
533551
## Infantry
534552

535553
### Prone speed customization

docs/Whats-New.md

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

src/Ext/Building/Hooks.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,3 +776,80 @@ DEFINE_HOOK(0x4AE95E, DisplayClass_sub_4AE750_DisallowBuildingNonAttackPlanning,
776776
}
777777

778778
#pragma endregion
779+
780+
DEFINE_HOOK(0x4400F9, BuildingClass_AI_UpdateOverpower, 0x6)
781+
{
782+
enum { SkipGameCode = 0x44019D };
783+
784+
GET(BuildingClass*, pThis, ESI);
785+
786+
if (!pThis->Type->Overpowerable)
787+
return SkipGameCode;
788+
789+
int overPower = 0;
790+
791+
for (int idx = pThis->Overpowerers.Count - 1; idx >= 0; idx--)
792+
{
793+
const auto pCharger = pThis->Overpowerers[idx];
794+
795+
if (pCharger->Target != pThis)
796+
{
797+
pThis->Overpowerers.RemoveItem(idx);
798+
continue;
799+
}
800+
801+
const auto pWeapon = pCharger->GetWeapon(1)->WeaponType;
802+
803+
if (!pWeapon || !pWeapon->Warhead || !pWeapon->Warhead->ElectricAssault)
804+
{
805+
pThis->Overpowerers.RemoveItem(idx);
806+
continue;
807+
}
808+
809+
const auto pWHExt = WarheadTypeExt::ExtMap.Find(pWeapon->Warhead);
810+
overPower += pWHExt->ElectricAssaultLevel;
811+
}
812+
813+
const auto pBuildingTypeExt = BuildingTypeExt::ExtMap.Find(pThis->Type);
814+
const int charge = pBuildingTypeExt->Overpower_ChargeWeapon;
815+
816+
if (charge >= 0)
817+
{
818+
const int keepOnline = pBuildingTypeExt->Overpower_KeepOnline;
819+
pThis->IsOverpowered = overPower >= keepOnline + charge || (pThis->Owner->GetPowerPercentage() == 1.0 && pThis->HasPower && overPower >= charge);
820+
}
821+
else
822+
{
823+
pThis->IsOverpowered = false;
824+
}
825+
826+
return SkipGameCode;
827+
}
828+
829+
DEFINE_HOOK_AGAIN(0x45563B, BuildingClass_IsPowerOnline_Overpower, 0x6)
830+
DEFINE_HOOK(0x4555E4, BuildingClass_IsPowerOnline_Overpower, 0x6)
831+
{
832+
enum { LowPower = 0x4556BE, Continue1 = 0x4555F0, Continue2 = 0x455643 };
833+
834+
GET(BuildingClass*, pThis, ESI);
835+
const auto pBuildingTypeExt = BuildingTypeExt::ExtMap.Find(pThis->Type);
836+
const int keepOnline = pBuildingTypeExt->Overpower_KeepOnline;
837+
838+
if (keepOnline < 0)
839+
return LowPower;
840+
841+
int overPower = 0;
842+
843+
for (const auto pCharger : pThis->Overpowerers)
844+
{
845+
const auto pWeapon = pCharger->GetWeapon(1)->WeaponType;
846+
847+
if (pWeapon && pWeapon->Warhead)
848+
{
849+
const auto pWHExt = WarheadTypeExt::ExtMap.Find(pWeapon->Warhead);
850+
overPower += pWHExt->ElectricAssaultLevel;
851+
}
852+
}
853+
854+
return overPower < keepOnline ? LowPower : (R->Origin() == 0x4555E4 ? Continue1 : Continue2);
855+
}

src/Ext/BuildingType/Body.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
177177

178178
this->BarracksExitCell.Read(exINI, pSection, "BarracksExitCell");
179179

180+
this->Overpower_KeepOnline.Read(exINI, pSection, "Overpower.KeepOnline");
181+
this->Overpower_ChargeWeapon.Read(exINI, pSection, "Overpower.ChargeWeapon");
182+
180183
if (pThis->NumberOfDocks > 0)
181184
{
182185
this->AircraftDockingDirs.clear();
@@ -302,6 +305,8 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
302305
.Process(this->Adjacent_Allowed)
303306
.Process(this->Adjacent_Disallowed)
304307
.Process(this->BarracksExitCell)
308+
.Process(this->Overpower_KeepOnline)
309+
.Process(this->Overpower_ChargeWeapon)
305310
;
306311
}
307312

src/Ext/BuildingType/Body.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class BuildingTypeExt
8282

8383
Nullable<Point2D> BarracksExitCell;
8484

85+
Valueable<int> Overpower_KeepOnline;
86+
Valueable<int> Overpower_ChargeWeapon;
87+
8588
ExtData(BuildingTypeClass* OwnerObject) : Extension<BuildingTypeClass>(OwnerObject)
8689
, PowersUp_Owner { AffectedHouse::Owner }
8790
, PowersUp_Buildings {}
@@ -132,6 +135,8 @@ class BuildingTypeExt
132135
, Adjacent_Allowed {}
133136
, Adjacent_Disallowed {}
134137
, BarracksExitCell {}
138+
, Overpower_KeepOnline { 2 }
139+
, Overpower_ChargeWeapon { 1 }
135140
{ }
136141

137142
// Ares 0.A functions

src/Ext/WarheadType/Body.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
282282
this->KillWeapon.Read(exINI, pSection, "KillWeapon");
283283
this->KillWeapon_AffectsHouses.Read(exINI, pSection, "KillWeapon.AffectsHouses");
284284

285+
this->ElectricAssaultLevel.Read(exINI, pSection, "ElectricAssaultLevel");
286+
285287
// Convert.From & Convert.To
286288
TypeConvertGroup::Parse(this->Convert_Pairs, exINI, pSection, AffectedHouse::All);
287289

@@ -524,6 +526,8 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
524526
.Process(this->KillWeapon)
525527
.Process(this->KillWeapon_AffectsHouses)
526528

529+
.Process(this->ElectricAssaultLevel)
530+
527531
// Ares tags
528532
.Process(this->AffectsEnemies)
529533
.Process(this->AffectsOwner)

src/Ext/WarheadType/Body.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class WarheadTypeExt
166166
Valueable<WeaponTypeClass*> KillWeapon;
167167
Valueable<AffectedHouse> KillWeapon_AffectsHouses;
168168

169+
Valueable<int> ElectricAssaultLevel;
170+
169171
// Ares tags
170172
// http://ares-developers.github.io/Ares-docs/new/warheads/general.html
171173
Valueable<bool> AffectsEnemies;
@@ -313,7 +315,7 @@ class WarheadTypeExt
313315

314316
, CombatLightDetailLevel {}
315317
, CombatLightChance { 1.0 }
316-
, CLIsBlack { false }
318+
, CLIsBlack { false }
317319
, Particle_AlphaImageIsLightFlash {}
318320

319321
, DamageOwnerMultiplier {}
@@ -332,6 +334,8 @@ class WarheadTypeExt
332334

333335
, CombatAlert_Suppress {}
334336

337+
, ElectricAssaultLevel { 1 }
338+
335339
, AffectsEnemies { true }
336340
, AffectsOwner {}
337341
, EffectsRequireVerses { true }

0 commit comments

Comments
 (0)