Skip to content

Commit f7d7591

Browse files
authored
Targeting limitation for berzerk technos (#1720)
### Targeting limitation for berzerk technos - Now you can specify which houses berzerk's technos can target and fire. In `rulesmd.ini`: ```ini [General] BerzerkTargeting=all ; AffectedHouse enumeration ```
1 parent e47ca8e commit f7d7591

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ This page lists all the individual contributions to the project by their author.
534534
- Make harvesters do addtional scan after unload
535535
- Customize the scatter caused by aircraft attack mission
536536
- Customize whether `Crater=yes` animation would destroy tiberium
537+
- Targeting limitation for berzerk technos
537538
- **tyuah8**:
538539
- Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
539540
- Destroyed unit leaves sensors bugfix

docs/New-or-Enhanced-Logics.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,16 @@ IsVoiceCreatedGlobal=false ; boolean
17071707
VoiceCreated= ; Sound entry
17081708
```
17091709

1710+
### Targeting limitation for berzerk technos
1711+
1712+
- Now you can specify which houses berzerk's technos can target and fire.
1713+
1714+
In `rulesmd.ini`:
1715+
```ini
1716+
[General]
1717+
BerzerkTargeting=all ; AffectedHouse enumeration
1718+
```
1719+
17101720
### Tiberium eater
17111721

17121722
- TechnoTypes can convert the ores underneath them into credits in real time, like GDI's MARV in Command & Conquer 3 Kane's Wrath.

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ New:
391391
- [Turretless vehicles with `Voxel=no` support use `FireUp` like infantry](New-or-Enhanced-Logics.md#turretless-shape-vehicle-fireup) (by FlyStar)
392392
- Infantry support `IsGattling=yes` (by FlyStar)
393393
- [Several new Infotypes, no display in specific status and a new single frame display method](User-Interface.md#digital-display) (by CrimRecya)
394+
- Targeting limitation for berzerk technos (by TaranDahl)
394395
395396
Vanilla fixes:
396397
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

src/Ext/Rules/Body.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
273273

274274
this->AnimCraterDestroyTiberium.Read(exINI, GameStrings::General, "AnimCraterDestroyTiberium");
275275

276+
this->BerzerkTargeting.Read(exINI, GameStrings::CombatDamage, "BerzerkTargeting");
277+
276278
// Section AITargetTypes
277279
int itemsCount = pINI->GetKeyCount("AITargetTypes");
278280
for (int i = 0; i < itemsCount; ++i)
@@ -501,6 +503,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
501503
.Process(this->DamagedSpeed)
502504
.Process(this->HarvesterScanAfterUnload)
503505
.Process(this->AnimCraterDestroyTiberium)
506+
.Process(this->BerzerkTargeting)
504507
;
505508
}
506509

src/Ext/Rules/Body.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class RulesExt
228228

229229
Valueable<bool> AnimCraterDestroyTiberium;
230230

231+
Valueable<AffectedHouse> BerzerkTargeting;
232+
231233
ExtData(RulesClass* OwnerObject) : Extension<RulesClass>(OwnerObject)
232234
, Storage_TiberiumIndex { -1 }
233235
, HarvesterDumpAmount { 0.0f }
@@ -401,6 +403,8 @@ class RulesExt
401403
, HarvesterScanAfterUnload { false }
402404

403405
, AnimCraterDestroyTiberium { true }
406+
407+
, BerzerkTargeting { AffectedHouse::All }
404408
{ }
405409

406410
virtual ~ExtData() = default;

src/Ext/Techno/Hooks.Firing.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Body.h"
1+
#include "Body.h"
22

33
#include <OverlayTypeClass.h>
44
#include <ScenarioClass.h>
@@ -248,6 +248,7 @@ DEFINE_HOOK(0x6FC339, TechnoClass_CanFire, 0x6)
248248
GET(TechnoClass*, pThis, ESI);
249249
GET(WeaponTypeClass*, pWeapon, EDI);
250250
GET_STACK(AbstractClass*, pTarget, STACK_OFFSET(0x20, 0x4));
251+
GET(TechnoClass*, pTargetTechno, EBP);
251252

252253
// Checking for nullptr is not required here, since the game has already executed them before calling the hook -- Belonit
253254
const auto pWH = pWeapon->Warhead;
@@ -268,15 +269,14 @@ DEFINE_HOOK(0x6FC339, TechnoClass_CanFire, 0x6)
268269
return CannotFire;
269270
}
270271

271-
const auto pTechno = abstract_cast<TechnoClass*>(pTarget);
272272
CellClass* pTargetCell = nullptr;
273273

274274
if (pTarget)
275275
{
276276
if (const auto pObject = abstract_cast<ObjectClass*, true>(pTarget))
277277
{
278278
// Ignore target cell for technos that are in air.
279-
if ((pTechno && !pTechno->IsInAir()) || pObject != pTechno)
279+
if ((pTargetTechno && !pTargetTechno->IsInAir()) || pObject != pTargetTechno)
280280
pTargetCell = pObject->GetCell();
281281
}
282282
else if (const auto pCell = abstract_cast<CellClass*, true>(pTarget))
@@ -293,25 +293,31 @@ DEFINE_HOOK(0x6FC339, TechnoClass_CanFire, 0x6)
293293
return CannotFire;
294294
}
295295

296-
if (pTechno)
296+
if (pTargetTechno)
297297
{
298+
if (pThis->Berzerk
299+
&& !EnumFunctions::CanTargetHouse(RulesExt::Global()->BerzerkTargeting, pThis->Owner, pTargetTechno->Owner))
300+
{
301+
return CannotFire;
302+
}
303+
298304
if (!pWeaponExt->SkipWeaponPicking)
299305
{
300-
if (!EnumFunctions::IsTechnoEligible(pTechno, pWeaponExt->CanTarget)
301-
|| !EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pThis->Owner, pTechno->Owner)
302-
|| !pWeaponExt->IsHealthRatioEligible(pTechno)
303-
|| !pWeaponExt->HasRequiredAttachedEffects(pTechno, pThis))
306+
if (!EnumFunctions::IsTechnoEligible(pTargetTechno, pWeaponExt->CanTarget)
307+
|| !EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pThis->Owner, pTargetTechno->Owner)
308+
|| !pWeaponExt->IsHealthRatioEligible(pTargetTechno)
309+
|| !pWeaponExt->HasRequiredAttachedEffects(pTargetTechno, pThis))
304310
{
305311
return CannotFire;
306312
}
307313
}
308314

309315
if (pWH->Airstrike)
310316
{
311-
if (!pWHExt || !EnumFunctions::IsTechnoEligible(pTechno, pWHExt->AirstrikeTargets))
317+
if (!pWHExt || !EnumFunctions::IsTechnoEligible(pTargetTechno, pWHExt->AirstrikeTargets))
312318
return CannotFire;
313319

314-
if (!TechnoTypeExt::ExtMap.Find(pTechno->GetTechnoType())->AllowAirstrike.Get(pTechno->AbstractFlags & AbstractFlags::Foot ? true : static_cast<BuildingClass*>(pTechno)->Type->CanC4))
320+
if (!TechnoTypeExt::ExtMap.Find(pTargetTechno->GetTechnoType())->AllowAirstrike.Get(pTargetTechno->AbstractFlags & AbstractFlags::Foot ? true : static_cast<BuildingClass*>(pTargetTechno)->Type->CanC4))
315321
return CannotFire;
316322
}
317323
}

0 commit comments

Comments
 (0)