Skip to content

Commit 67cdb38

Browse files
committed
cast LeptonsPerCell to double in some division scenarios
1 parent e30aa83 commit 67cdb38

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

src/Ext/Bullet/Hooks.DetonateLogics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
569569
}
570570
else
571571
{
572-
const float cellSpread = static_cast<float>(pTypeExt->Splits_TargetingDistance.Get()) / Unsorted::LeptonsPerCell;
572+
const float cellSpread = static_cast<float>(pTypeExt->Splits_TargetingDistance.Get()) / (double)Unsorted::LeptonsPerCell;
573573
const bool isAA = pType->AA;
574574
const bool retargetSelf = pTypeExt->RetargetSelf;
575575
const bool useWeaponTargeting = pTypeExt->Splits_UseWeaponTargeting;

src/Ext/SWType/SWHelpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ std::pair<double, double> SWTypeExt::ExtData::GetEMPulseCannonRange(BuildingClas
259259
{
260260
double maxRange = this->SW_RangeMaximum;
261261
if (maxRange < 0.0)
262-
maxRange = pWeapon->Range / Unsorted::LeptonsPerCell;
262+
maxRange = pWeapon->Range / (double)Unsorted::LeptonsPerCell;
263263

264264
double minRange = this->SW_RangeMinimum;
265265
if (minRange < 0.0)
266266
{
267-
minRange = pWeapon->MinimumRange / Unsorted::LeptonsPerCell;
267+
minRange = pWeapon->MinimumRange / (double)Unsorted::LeptonsPerCell;
268268
}
269269

270270
return std::make_pair(minRange, maxRange);

src/Ext/Script/Body.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void ScriptExt::Mission_Gather_NearTheLeader(TeamClass* pTeam, int countdown)
432432
}
433433
else
434434
{
435-
closeEnough = RulesClass::Instance->CloseEnough / Unsorted::LeptonsPerCell;
435+
closeEnough = RulesClass::Instance->CloseEnough / (double)Unsorted::LeptonsPerCell;
436436
}
437437

438438
// The leader should stay calm & be the group's center
@@ -470,7 +470,7 @@ void ScriptExt::Mission_Gather_NearTheLeader(TeamClass* pTeam, int countdown)
470470

471471
nUnits++;
472472

473-
if ((pUnit->DistanceFrom(pLeaderUnit->GetCell()) / Unsorted::LeptonsPerCell) > closeEnough)
473+
if ((pUnit->DistanceFrom(pLeaderUnit->GetCell()) / (double)Unsorted::LeptonsPerCell) > closeEnough)
474474
{
475475
// Leader's location is too far from me. Regroup
476476
if (pUnit->Destination != pLeaderUnit)
@@ -677,7 +677,7 @@ void ScriptExt::SetCloseEnoughDistance(TeamClass* pTeam, double distance)
677677
pTeamData->CloseEnough = distance;
678678

679679
if (distance <= 0)
680-
pTeamData->CloseEnough = RulesClass::Instance->CloseEnough / Unsorted::LeptonsPerCell;
680+
pTeamData->CloseEnough = RulesClass::Instance->CloseEnough / (double)Unsorted::LeptonsPerCell;
681681

682682
// This action finished
683683
pTeam->StepCompleted = true;
@@ -713,7 +713,7 @@ bool ScriptExt::MoveMissionEndStatus(TeamClass* pTeam, TechnoClass* pFocus, Foot
713713
if (!pFocus || mode < 0 || (mode != 2 && mode != 1 && !pLeader))
714714
return false;
715715

716-
double closeEnough = RulesClass::Instance->CloseEnough / Unsorted::LeptonsPerCell;
716+
double closeEnough = RulesClass::Instance->CloseEnough / (double)Unsorted::LeptonsPerCell;
717717
auto const pTeamData = TeamExt::ExtMap.Find(pTeam);
718718

719719
if (pTeamData->CloseEnough > 0)
@@ -734,7 +734,7 @@ bool ScriptExt::MoveMissionEndStatus(TeamClass* pTeam, TechnoClass* pFocus, Foot
734734
if (mode == 2)
735735
{
736736
// Default mode: all members in range
737-
if ((pUnit->DistanceFrom(pFocus->GetCell()) / Unsorted::LeptonsPerCell) > closeEnough)
737+
if ((pUnit->DistanceFrom(pFocus->GetCell()) / (double)Unsorted::LeptonsPerCell) > closeEnough)
738738
{
739739
bForceNextAction = false;
740740

@@ -758,7 +758,7 @@ bool ScriptExt::MoveMissionEndStatus(TeamClass* pTeam, TechnoClass* pFocus, Foot
758758
if (mode == 1)
759759
{
760760
// Any member in range
761-
if ((pUnit->DistanceFrom(pFocus->GetCell()) / Unsorted::LeptonsPerCell) > closeEnough)
761+
if ((pUnit->DistanceFrom(pFocus->GetCell()) / (double)Unsorted::LeptonsPerCell) > closeEnough)
762762
{
763763
if (pUnit->WhatAmI() == AbstractType::Aircraft && pUnit->Ammo > 0)
764764
pUnit->QueueMission(Mission::Move, false);
@@ -782,7 +782,7 @@ bool ScriptExt::MoveMissionEndStatus(TeamClass* pTeam, TechnoClass* pFocus, Foot
782782
// All other cases: Team Leader mode in range
783783
if (pLeader)
784784
{
785-
if ((pUnit->DistanceFrom(pFocus->GetCell()) / Unsorted::LeptonsPerCell) > closeEnough)
785+
if ((pUnit->DistanceFrom(pFocus->GetCell()) / (double)Unsorted::LeptonsPerCell) > closeEnough)
786786
{
787787
if (pUnit->WhatAmI() == AbstractType::Aircraft && pUnit->Ammo > 0)
788788
pUnit->QueueMission(Mission::Move, false);

src/Ext/Script/Mission.Attack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ TechnoClass* ScriptExt::GreatestThreat(TechnoClass* pTechno, int method, int cal
564564

565565
// Extra threat based on current health. More damaged == More threat (almost destroyed objects gets more priority)
566566
objectThreatValue += pTarget->Health * (1 - pTarget->GetHealthPercentage());
567-
value = (objectThreatValue * threatMultiplier) / ((pTechno->DistanceFrom(pTarget) / Unsorted::LeptonsPerCell) + 1.0);
567+
value = (objectThreatValue * threatMultiplier) / ((pTechno->DistanceFrom(pTarget) / (double)Unsorted::LeptonsPerCell) + 1.0);
568568

569569
if (pTechnoType->VHPScan == 1)
570570
{

src/Ext/Script/Mission.Move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ TechnoClass* ScriptExt::FindBestObject(TechnoClass* pTechno, int method, int cal
332332

333333
// Extra threat based on current health. More damaged == More threat (almost destroyed objects gets more priority)
334334
objectThreatValue += pTarget->Health * (1 - pTarget->GetHealthPercentage());
335-
value = (objectThreatValue * threatMultiplier) / ((pTechno->DistanceFrom(pTarget) / Unsorted::LeptonsPerCell) + 1.0);
335+
value = (objectThreatValue * threatMultiplier) / ((pTechno->DistanceFrom(pTarget) / (double)Unsorted::LeptonsPerCell) + 1.0);
336336

337337
if (calcThreatMode == 0)
338338
{

src/Ext/Techno/Hooks.WeaponRange.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ DEFINE_HOOK(0x6F7294, TechnoClass_InRange_OccupyRange, 0x5)
8484
GET(TechnoClass*, pThis, ESI);
8585
GET(int, range, EDI);
8686

87-
int occupyRange = WeaponTypeExt::GetRangeWithModifiers(nullptr, pThis);
88-
occupyRange /= Unsorted::LeptonsPerCell;
87+
const int occupyRange = WeaponTypeExt::GetRangeWithModifiers(nullptr, pThis) / Unsorted::LeptonsPerCell;
8988

9089
R->EDI(range + occupyRange);
9190

src/Ext/Techno/Hooks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ DEFINE_HOOK(0x4DF3A6, FootClass_UpdateAttackMove_Follow, 0x6)
11041104
if (pTypeExt->AttackMove_Follow || pTypeExt->AttackMove_Follow_IfMindControlIsFull && pThis->CaptureManager && pThis->CaptureManager->CannotControlAnyMore())
11051105
{
11061106
auto const& pTechnoVectors = Helpers::Alex::getCellSpreadItems(pThis->GetCoords(),
1107-
pThis->GetGuardRange(2) / Unsorted::LeptonsPerCell, pTypeExt->AttackMove_Follow_IncludeAir);
1107+
pThis->GetGuardRange(2) / (double)Unsorted::LeptonsPerCell, pTypeExt->AttackMove_Follow_IncludeAir);
11081108

11091109
TechnoClass* pClosestTarget = nullptr;
11101110
int closestRange = 65536;

src/Ext/WarheadType/Detonate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse,
180180
{
181181
// Jun 2, 2024 - Starkku: We should only detonate on the target if the bullet, at the moment of detonation is within acceptable distance of the target.
182182
// Ares uses 64 leptons / quarter of a cell as a tolerance, so for sake of consistency we're gonna do the same here.
183-
if (pBullet->DistanceFrom(pTarget) < Unsorted::LeptonsPerCell / 4)
183+
if (pBullet->DistanceFrom(pTarget) < Unsorted::LeptonsPerCell / 4.0)
184184
this->DetonateOnOneUnit(pHouse, pTarget, pOwner, bulletWasIntercepted);
185185
}
186186
}
187187
else if (this->DamageAreaTarget)
188188
{
189-
if (coords.DistanceFrom(this->DamageAreaTarget->GetCoords()) < Unsorted::LeptonsPerCell / 4)
189+
if (coords.DistanceFrom(this->DamageAreaTarget->GetCoords()) < Unsorted::LeptonsPerCell / 4.0)
190190
this->DetonateOnOneUnit(pHouse, this->DamageAreaTarget, pOwner, bulletWasIntercepted);
191191
}
192192
}

0 commit comments

Comments
 (0)