Skip to content

Commit

Permalink
Allow shrapnel weapon to filter targets by weapon/warhead params
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku committed May 10, 2024
1 parent 87be720 commit 6f96546
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
12 changes: 7 additions & 5 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,20 @@ Trajectory=Bombard ; Trajectory type
Trajectory.Bombard.Height=0.0 ; double
```

### Shrapnel enhancement
### Shrapnel enhancements

![image](_static/images/shrapnel.gif)
*Shrapnel appearing against ground & buildings* ([Project Phantom](https://www.moddb.com/mods/project-phantom))

- Shrapnel behavior can be triggered on the ground and buildings.
- `ShrapnelWeapon` can now be triggered against ground & buildings via `Shrapnel.AffectsGround` and `Shrapnel.AffectsBuildings`.
- Setting `Shrapnel.UseWeaponTargeting` now allows weapon target filtering to be enabled for `ShrapnelWeapon`. Target's `LegalTarget` setting, Warhead `Verses` against `Armor` as well as `ShrapnelWeapon` [weapon targeting filters](#weapon-targeting-filter) will be checked.

In `rulesmd.ini`:
```ini
[SOMEPROJECTILE] ; Projectile
Shrapnel.AffectsGround=false ; boolean
Shrapnel.AffectsBuildings=false ; boolean
[SOMEPROJECTILE] ; Projectile
Shrapnel.AffectsGround=false ; boolean
Shrapnel.AffectsBuildings=false ; boolean
Shrapnel.UseWeaponTargeting=false ; boolean
```

### Projectiles blocked by land or water
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ New:
- Toggle for `Explodes=true` BuildingTypes to not explode during buildup or being sold (by Starkku)
- Toggleable height-based shadow scaling for voxel air units (by Trsdy & Starkku)
- User setting toggles for harvester counter & power delta indicator (by Starkku)
- Shrapnel weapon target filtering toggle (by Starkku)
Vanilla fixes:
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)
Expand Down
54 changes: 49 additions & 5 deletions src/Ext/Bullet/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Body.h"
#include <Ext/Anim/Body.h>
#include <Ext/BulletType/Body.h>
#include <Ext/WeaponType/Body.h>
#include <Utilities/EnumFunctions.h>
#include <Utilities/Macro.h>

#include <ScenarioClass.h>
Expand Down Expand Up @@ -202,21 +204,63 @@ DEFINE_HOOK(0x46A3D6, BulletClass_Shrapnel_Forced, 0xA)
{
enum { Shrapnel = 0x46A40C, Skip = 0x46ADCD };

GET(BulletClass*, pBullet, EDI);
GET(BulletClass*, pThis, EDI);

auto const pData = BulletTypeExt::ExtMap.Find(pBullet->Type);
auto const pTypeExt = BulletTypeExt::ExtMap.Find(pThis->Type);

if (auto const pObject = pBullet->GetCell()->FirstObject)
if (auto const pObject = pThis->GetCell()->FirstObject)
{
if (pObject->WhatAmI() != AbstractType::Building || pData->Shrapnel_AffectsBuildings)
if (pObject->WhatAmI() != AbstractType::Building || pTypeExt->Shrapnel_AffectsBuildings)
return Shrapnel;
}
else if (pData->Shrapnel_AffectsGround)
else if (pTypeExt->Shrapnel_AffectsGround)
{
return Shrapnel;
}

return Skip;
}

DEFINE_HOOK(0x46A4FB, BulletClass_Shrapnel_Targeting, 0x6)
{
enum { SkipObject = 0x46A8EA, Continue = 0x46A50F };

GET(BulletClass*, pThis, EDI);
GET(ObjectClass*, pObject, EBP);
GET(TechnoClass*, pSource, EAX);
GET(WeaponTypeClass*, pShrapnelWeapon, ESI);

auto const pOwner = pSource->Owner;
auto const pTypeExt = BulletTypeExt::ExtMap.Find(pThis->Type);

if (pTypeExt->Shrapnel_UseWeaponTargeting)
{
auto const pWeaponExt = WeaponTypeExt::ExtMap.Find(pShrapnelWeapon);
auto const pType = pObject->GetType();

if (!pType->LegalTarget || GeneralUtils::GetWarheadVersusArmor(pShrapnelWeapon->Warhead, pType->Armor) == 0.0)
return SkipObject;
else if (!EnumFunctions::IsCellEligible(pObject->GetCell(), pWeaponExt->CanTarget, true, true))
return SkipObject;

if (auto const pTechno = abstract_cast<TechnoClass*>(pObject))
{
if (!EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pOwner, pTechno->Owner))
return SkipObject;

if (!EnumFunctions::IsTechnoEligible(pTechno, pWeaponExt->CanTarget))
return SkipObject;
}

}
else if (!pOwner->IsAlliedWith(pObject))
{
return SkipObject;
}

return Continue;
}

DEFINE_HOOK(0x46902C, BulletClass_Explode_Cluster, 0x6)
{
enum { SkipGameCode = 0x469091 };
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/BulletType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void BulletTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)

this->Shrapnel_AffectsGround.Read(exINI, pSection, "Shrapnel.AffectsGround");
this->Shrapnel_AffectsBuildings.Read(exINI, pSection, "Shrapnel.AffectsBuildings");
this->Shrapnel_UseWeaponTargeting.Read(exINI, pSection, "Shrapnel.UseWeaponTargeting");
this->ClusterScatter_Min.Read(exINI, pSection, "ClusterScatter.Min");
this->ClusterScatter_Max.Read(exINI, pSection, "ClusterScatter.Max");
this->SubjectToLand.Read(exINI, pSection, "SubjectToLand");
Expand Down Expand Up @@ -114,6 +115,7 @@ void BulletTypeExt::ExtData::Serialize(T& Stm)
.Process(this->Trajectory_Speed)
.Process(this->Shrapnel_AffectsGround)
.Process(this->Shrapnel_AffectsBuildings)
.Process(this->Shrapnel_UseWeaponTargeting)
.Process(this->ClusterScatter_Min)
.Process(this->ClusterScatter_Max)
.Process(this->BallisticScatter_Min)
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/BulletType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BulletTypeExt

Valueable<bool> Shrapnel_AffectsGround;
Valueable<bool> Shrapnel_AffectsBuildings;
Valueable<bool> Shrapnel_UseWeaponTargeting;
Nullable<bool> SubjectToLand;
Valueable<bool> SubjectToLand_Detonate;
Nullable<bool> SubjectToWater;
Expand Down Expand Up @@ -60,6 +61,7 @@ class BulletTypeExt
, Trajectory_Speed { 100.0 }
, Shrapnel_AffectsGround { false }
, Shrapnel_AffectsBuildings { false }
, Shrapnel_UseWeaponTargeting { false }
, ClusterScatter_Min {}
, ClusterScatter_Max {}
, BallisticScatter_Min {}
Expand Down

0 comments on commit 6f96546

Please sign in to comment.