Skip to content

Commit 53fff4f

Browse files
committed
make split weapon check cells instead of techno array
1 parent 19c15f6 commit 53fff4f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Ext/Bullet/Hooks.DetonateLogics.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Ext/WarheadType/Body.h>
77
#include <Ext/WeaponType/Body.h>
88
#include <Ext/Techno/Body.h>
9+
#include <Utilities/Helpers.Alex.h>
910

1011
#include <AircraftClass.h>
1112
#include <TacticalClass.h>
@@ -480,11 +481,11 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
480481
{
481482
// Do random cells for amount matching Cluster.
482483
int count = 0;
483-
int targetCount = targets.Count;
484+
const int targetCount = targets.Count;
484485

485486
while (count < clusterCount)
486487
{
487-
int index = ScenarioClass::Instance->Random.RandomRanged(0, targetCount);
488+
const int index = random.RandomRanged(0, targetCount);
488489
auto const pTarget = targets.GetItem(index);
489490

490491
if (count > targetCount || newTargets.FindItemIndex(pTarget) < 0)
@@ -497,7 +498,7 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
497498
else
498499
{
499500
// Do evenly selected cells for amount matching Cluster.
500-
double stepSize = (targets.Count - 1.0) / (clusterCount - 1.0);
501+
const double stepSize = (targets.Count - 1.0) / (clusterCount - 1.0);
501502

502503
for (int i = 0; i < clusterCount; i++)
503504
{
@@ -514,27 +515,30 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
514515
}
515516
else
516517
{
517-
for (auto const pTechno : TechnoClass::Array)
518+
const float cellSpread = static_cast<float>(pTypeExt->Splits_TargetingDistance.Get()) / Unsorted::LeptonsPerCell;
519+
const bool isAA = pType->AA;
520+
const bool retargetSelf = pTypeExt->RetargetSelf;
521+
const bool useWeaponTargeting = pTypeExt->Splits_UseWeaponTargeting;
522+
523+
for (auto const pTechno : Helpers::Alex::getCellSpreadItems(coordsTarget, cellSpread, true))
518524
{
519-
if (pTechno->IsInPlayfield && pTechno->IsOnMap && pTechno->Health > 0 && (pTypeExt->RetargetSelf || pTechno != pThis->Owner))
525+
if (pTechno->IsInPlayfield && pTechno->IsOnMap && pTechno->IsAlive && pTechno->Health > 0 && !pTechno->InLimbo
526+
&& (retargetSelf || pTechno != pSource))
520527
{
521-
auto const coords = pTechno->GetCoords();
522-
523-
if (coordsTarget.DistanceFrom(coords) < pTypeExt->Splits_TargetingDistance.Get()
524-
&& (pType->AA || !pTechno->IsInAir())
525-
&& IsAllowedSplitsTarget(pSource, pOwner, pWeapon, pTechno, pTypeExt->Splits_UseWeaponTargeting))
528+
if ((isAA || !pTechno->IsInAir()) &&
529+
IsAllowedSplitsTarget(pSource, pOwner, pWeapon, pTechno, useWeaponTargeting))
526530
{
527531
targets.AddItem(pTechno);
528532
}
529533
}
530534
}
531535

532-
int range = pTypeExt->Splits_TargetCellRange;
536+
const int range = pTypeExt->Splits_TargetCellRange;
533537

534538
while (targets.Count < clusterCount)
535539
{
536-
int x = random.RandomRanged(-range, range);
537-
int y = random.RandomRanged(-range, range);
540+
const int x = random.RandomRanged(-range, range);
541+
const int y = random.RandomRanged(-range, range);
538542

539543
CellStruct cell = { static_cast<short>(cellTarget.X + x), static_cast<short>(cellTarget.Y + y) };
540544
auto const pCell = MapClass::Instance.GetCellAt(cell);
@@ -579,8 +583,8 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
579583
if (auto const pBullet = pTypeSplits->CreateBullet(pTarget, pSource, damage, pWeapon->Warhead, pWeapon->Speed, pWeapon->Bright))
580584
{
581585
auto coords = pThis->Location;
582-
int scatterMin = pTypeExt->AirburstWeapon_SourceScatterMin.Get();
583-
int scatterMax = pTypeExt->AirburstWeapon_SourceScatterMax.Get();
586+
const int scatterMin = pTypeExt->AirburstWeapon_SourceScatterMin.Get();
587+
const int scatterMax = pTypeExt->AirburstWeapon_SourceScatterMax.Get();
584588

585589
if (pType->Airburst && pTypeExt->Airburst_TargetAsSource)
586590
{
@@ -592,7 +596,7 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
592596

593597
if (scatterMin > 0 || scatterMax > 0)
594598
{
595-
int distance = ScenarioClass::Instance->Random.RandomRanged(scatterMin, scatterMax);
599+
const int distance = random.RandomRanged(scatterMin, scatterMax);
596600
coords = MapClass::GetRandomCoordsNear(coords, distance, false);
597601
}
598602

0 commit comments

Comments
 (0)