6
6
#include < Ext/WarheadType/Body.h>
7
7
#include < Ext/WeaponType/Body.h>
8
8
#include < Ext/Techno/Body.h>
9
+ #include < Utilities/Helpers.Alex.h>
9
10
10
11
#include < AircraftClass.h>
11
12
#include < TacticalClass.h>
@@ -480,11 +481,11 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
480
481
{
481
482
// Do random cells for amount matching Cluster.
482
483
int count = 0 ;
483
- int targetCount = targets.Count ;
484
+ const int targetCount = targets.Count ;
484
485
485
486
while (count < clusterCount)
486
487
{
487
- int index = ScenarioClass::Instance-> Random .RandomRanged (0 , targetCount);
488
+ const int index = random .RandomRanged (0 , targetCount);
488
489
auto const pTarget = targets.GetItem (index);
489
490
490
491
if (count > targetCount || newTargets.FindItemIndex (pTarget) < 0 )
@@ -497,7 +498,7 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
497
498
else
498
499
{
499
500
// 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 );
501
502
502
503
for (int i = 0 ; i < clusterCount; i++)
503
504
{
@@ -514,27 +515,30 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
514
515
}
515
516
else
516
517
{
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 ))
518
524
{
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))
520
527
{
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))
526
530
{
527
531
targets.AddItem (pTechno);
528
532
}
529
533
}
530
534
}
531
535
532
- int range = pTypeExt->Splits_TargetCellRange ;
536
+ const int range = pTypeExt->Splits_TargetCellRange ;
533
537
534
538
while (targets.Count < clusterCount)
535
539
{
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);
538
542
539
543
CellStruct cell = { static_cast <short >(cellTarget.X + x), static_cast <short >(cellTarget.Y + y) };
540
544
auto const pCell = MapClass::Instance.GetCellAt (cell);
@@ -579,8 +583,8 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
579
583
if (auto const pBullet = pTypeSplits->CreateBullet (pTarget, pSource, damage, pWeapon->Warhead , pWeapon->Speed , pWeapon->Bright ))
580
584
{
581
585
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 ();
584
588
585
589
if (pType->Airburst && pTypeExt->Airburst_TargetAsSource )
586
590
{
@@ -592,7 +596,7 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
592
596
593
597
if (scatterMin > 0 || scatterMax > 0 )
594
598
{
595
- int distance = ScenarioClass::Instance-> Random .RandomRanged (scatterMin, scatterMax);
599
+ const int distance = random .RandomRanged (scatterMin, scatterMax);
596
600
coords = MapClass::GetRandomCoordsNear (coords, distance, false );
597
601
}
598
602
0 commit comments