Skip to content

Commit 8fa259a

Browse files
committed
Allow weapon range modifiers to apply on ProjectileRange
1 parent 26d660d commit 8fa259a

9 files changed

Lines changed: 45 additions & 1 deletion

File tree

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ This page lists all the individual contributions to the project by their author.
293293
- GapGen + SpySat desync fix
294294
- Frame CRC generation rewrite
295295
- Laser drawing Z-adjust customization
296+
- `ProjectileRange` weapon range modifiers interaction fix
296297
- **Morton (MortonPL)**:
297298
- `XDrawOffset` for animations
298299
- Shield passthrough & absorption

docs/Fixed-or-Improved-Logics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
377377
- `EVA.Tag` already supports being set for specific countries, and `EVAIndex` is no longer reset after load game.
378378
- `DisableWeapons.Duration` now makes `Gattling=yes` rate tick down and stops the sounds from playing, no longer interferes with target acquisition and works together with Phobos' `OpenTopped.CheckTransportDisableWeapons`.
379379
- Allowed Ares' `SW.AuxBuildings` and `SW.NegBuildings` to count building upgrades.
380+
- `ProjectileRange` now has weapon range modifiers applied to it unless `ProjectileRange.ApplyModifiers` is set to false on the WeaponType
380381

381382
## Newly added global settings
382383

docs/Whats-New.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This serves as a changelog for when you just need to drop the new version in wit
2929

3030
### Version TBD (develop branch nightly builds)
3131

32+
- `ProjectileRange` (Ares feature) now has weapon range modifiers applied to it unless `ProjectileRange.ApplyModifiers` is set to false on the WeaponType.
3233
- `Splits.TargetCellRange` < 0 now applies special behaviour where the projectile does not consider nearby cells as additional targets if there are not enough techno targets to match `Cluster` count at all.
3334
- Combat light customizations introduced a bug that removed vanilla behaviour of ignoring detail level / framerate checks for colored combat light. This bug has been fixed but the previous behaviour can be restored by setting `CombatLightDetailLevel.CheckColored` on Warhead or globally under `[AudioVisual]`.
3435
- `[TechnoType] -> WarpAway=` has now been changed to set the animation when units are erased to maintain semantic consistency with `[General] -> WarpAway=`. The animation that was originally controlled by `[TechnoType] -> WarpAway=`, which played instead of `[General] -> WarpOut=` when a Techno is chronowarped by chronosphere, now needs to be specified using `[TechnoType] -> Chronoshift.WarpOut=`, which defaults to the value of `[TechnoType] -> WarpOut=`.
@@ -732,6 +733,7 @@ HideShakeEffects=false ; boolean
732733
- `DisableWeapons.Duration` now makes `Gattling=yes` rate tick down and stops the sounds from playing, no longer interferes with target acquisition and works together with Phobos' `OpenTopped.CheckTransportDisableWeapons` (by Starkku)
733734
- Allowed `AuxBuilding` and Ares' `SW.Aux/NegBuildings` to count building upgrades (by Ollerus & NetsuNegi)
734735
- [Aux technos and TechLevel requirement of superweapon](New-or-Enhanced-Logics.md#aux-technos-and-techlevel-requirement-of-superweapon) (by NetsuNegi & Ollerus)
736+
- `ProjectileRange` now has weapon range modifiers applied to it unless `ProjectileRange.ApplyModifiers` is set to false on the WeaponType (by Starkku)
735737
```
736738

737739
### 0.4.0.3

src/Ext/Bullet/Body.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ void BulletExt::ExtData::Serialize(T& Stm)
446446
.Process(this->DamageNumberOffset)
447447
.Process(this->ParabombFallRate)
448448
.Process(this->IsInstantDetonation)
449+
.Process(this->DistanceTraveled)
449450

450451
.Process(this->Trajectory) // Keep this shit at last
451452
;

src/Ext/Bullet/Body.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BulletExt
2727
int DamageNumberOffset;
2828
int ParabombFallRate;
2929
bool IsInstantDetonation;
30+
int DistanceTraveled;
3031

3132
TrajectoryPointer Trajectory;
3233

@@ -43,6 +44,7 @@ class BulletExt
4344
, DamageNumberOffset { INT32_MIN }
4445
, ParabombFallRate { 0 }
4546
, IsInstantDetonation { false }
47+
, DistanceTraveled { 0 }
4648
{ }
4749

4850
virtual ~ExtData() = default;

src/Ext/Bullet/Hooks.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,30 @@ DEFINE_HOOK(0x467AB2, BulletClass_AI_Parabomb, 0x7)
600600
}
601601

602602
#pragma endregion
603+
604+
// Replaces Ares' handling of Ranged=true projectiles.
605+
DEFINE_HOOK(0x467BA4, BulletClass_AI_Ranged, 0x6)
606+
{
607+
GET(BulletClass*, pThis, EBP);
608+
REF_STACK(CoordStruct, coordNew, STACK_OFFSET(0x1A8, -0x184));
609+
REF_STACK(bool, shouldExplode, STACK_OFFSET(0x1A8, -0x190));
610+
611+
if (pThis->Type->Ranged)
612+
{
613+
auto const pExt = BulletExt::ExtMap.Find(pThis);
614+
pExt->DistanceTraveled += Game::F2I(coordNew.DistanceFrom(pThis->GetCoords()));
615+
int maxRange = pThis->Range;
616+
617+
if (maxRange > 0 && pThis->WeaponType && pThis->Owner
618+
&& WeaponTypeExt::ExtMap.Find(pThis->WeaponType)->ProjectileRange_ApplyModifiers)
619+
{
620+
maxRange = WeaponTypeExt::GetRangeWithModifiers(pThis->WeaponType, pThis->Owner, maxRange);
621+
}
622+
623+
shouldExplode |= pExt->DistanceTraveled >= maxRange;
624+
}
625+
626+
pThis->SetLocation(coordNew);
627+
628+
return 0;
629+
}

src/Ext/WeaponType/Body.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
8181

8282
this->DiskLaser_Radius.Read(exINI, pSection, "DiskLaser.Radius");
8383
this->ProjectileRange.Read(exINI, pSection, "ProjectileRange");
84+
this->ProjectileRange_ApplyModifiers.Read(exINI, pSection, "ProjectileRange.ApplyModifiers");
8485

8586
for (int idx = 0; idx < 3; ++idx)
8687
{
@@ -190,6 +191,7 @@ void WeaponTypeExt::ExtData::Serialize(T& Stm)
190191
Stm
191192
.Process(this->DiskLaser_Radius)
192193
.Process(this->ProjectileRange)
194+
.Process(this->ProjectileRange_ApplyModifiers)
193195
.Process(this->Bolt_Color)
194196
.Process(this->Bolt_Disable)
195197
.Process(this->Bolt_ParticleSystem)
@@ -376,7 +378,7 @@ int WeaponTypeExt::GetRangeWithModifiers(WeaponTypeClass* pThis, TechnoClass* pF
376378
if (type->WeaponRange_DisallowWeapons.size() > 0 && type->WeaponRange_DisallowWeapons.Contains(pThis))
377379
continue;
378380

379-
range = static_cast<int>(range * Math::max(type->WeaponRange_Multiplier, 0.0));
381+
range = GeneralUtils::SafeMultiply(range, Math::max(type->WeaponRange_Multiplier, 0.0));
380382
extraRange += type->WeaponRange_ExtraRange;
381383
}
382384

src/Ext/WeaponType/Body.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class WeaponTypeExt
1919

2020
Valueable<double> DiskLaser_Radius;
2121
Valueable<Leptons> ProjectileRange;
22+
Valueable<bool> ProjectileRange_ApplyModifiers;
2223
Valueable<RadTypeClass*> RadType;
2324
Nullable<ColorStruct> Bolt_Color[3];
2425
Valueable<bool> Bolt_Disable[3];
@@ -108,6 +109,7 @@ class WeaponTypeExt
108109
ExtData(WeaponTypeClass* OwnerObject) : Extension<WeaponTypeClass>(OwnerObject)
109110
, DiskLaser_Radius { DiskLaserClass::Radius }
110111
, ProjectileRange { Leptons(100000) }
112+
, ProjectileRange_ApplyModifiers { true }
111113
, RadType {}
112114
, Bolt_Color {}
113115
, Bolt_Disable { Valueable<bool>(false) }

src/Misc/Hooks.Ares.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ void Apply_Ares3_0_Patches()
203203

204204
// Fix building direction of Ares's UnitDelivery
205205
Patch::Apply_VTABLE(AresHelper::AresBaseAddress + 0xA8D94, &UnitDeliveryStateMachine_Update_Wrapper);
206+
207+
// Skip Ares' ProjectileRange handling - our replacement hooked at 0x467BA4 (BulletClass_AI_Ranged).
208+
Patch::Apply_LJMP(AresHelper::AresBaseAddress + 0x1ACA3, AresHelper::AresBaseAddress + 0x1AD20);
206209
}
207210

208211
void Apply_Ares3_0p1_Patches()
@@ -289,4 +292,7 @@ void Apply_Ares3_0p1_Patches()
289292

290293
// Fix building direction of Ares's UnitDelivery
291294
Patch::Apply_VTABLE(AresHelper::AresBaseAddress + 0xA9F28, &UnitDeliveryStateMachine_Update_Wrapper);
295+
296+
// Skip Ares' ProjectileRange handling - our replacement hooked at 0x467BA4 (BulletClass_AI_Ranged).
297+
Patch::Apply_LJMP(AresHelper::AresBaseAddress + 0x1B393, AresHelper::AresBaseAddress + 0x1B410);
292298
}

0 commit comments

Comments
 (0)