Skip to content

Commit f0fb4de

Browse files
committed
Use auto instead
1 parent ee7462d commit f0fb4de

File tree

3 files changed

+72
-76
lines changed

3 files changed

+72
-76
lines changed

src/Ext/Bullet/Hooks.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ DEFINE_HOOK(0x46902C, BulletClass_Explode_Cluster, 0x6)
292292

293293
constexpr bool CheckTrajectoryCanNotAlwaysSnap(const TrajectoryFlag flag)
294294
{
295-
return flag == TrajectoryFlag::Straight
296-
|| flag == TrajectoryFlag::Bombard
297-
|| flag == TrajectoryFlag::Parabola;
295+
return flag != TrajectoryFlag::Invalid;
298296
}
299297

300298
DEFINE_HOOK(0x467CCA, BulletClass_AI_TargetSnapChecks, 0x6)

src/Ext/Bullet/Trajectories/BombardTrajectory.cpp

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,18 @@ bool BombardTrajectory::Save(PhobosStreamWriter& Stm) const
119119

120120
void BombardTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity)
121121
{
122-
const BombardTrajectoryType* const pType = this->Type;
122+
const auto pType = this->Type;
123123
this->Height += pBullet->TargetCoords.Z;
124124
// use scaling since RandomRanged only support int
125125
this->FallPercent += ScenarioClass::Instance->Random.RandomRanged(0, static_cast<int>(200 * pType->FallPercentShift)) / 100.0;
126126
this->InitialTargetCoord = pBullet->TargetCoords;
127127
this->LastTargetCoord = pBullet->TargetCoords;
128128
pBullet->Velocity = BulletVelocity::Empty;
129129

130-
if (WeaponTypeClass* const pWeapon = pBullet->WeaponType)
130+
if (const auto pWeapon = pBullet->WeaponType)
131131
this->CountOfBurst = pWeapon->Burst;
132132

133-
if (TechnoClass* const pOwner = pBullet->Owner)
133+
if (const auto pOwner = pBullet->Owner)
134134
{
135135
this->CurrentBurst = pOwner->CurrentBurstIndex;
136136

@@ -153,7 +153,7 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
153153
return true;
154154

155155
// Extra check for trajectory falling
156-
auto const pOwner = pBullet->Owner ? pBullet->Owner->Owner : BulletExt::ExtMap.Find(pBullet)->FirerHouse;
156+
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : BulletExt::ExtMap.Find(pBullet)->FirerHouse;
157157

158158
if (this->IsFalling && !this->Type->FreeFallOnTarget && this->BulletDetonateRemainCheck(pBullet, pOwner))
159159
return true;
@@ -165,13 +165,13 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
165165

166166
void BombardTrajectory::OnAIPreDetonate(BulletClass* pBullet)
167167
{
168-
const BombardTrajectoryType* const pType = this->Type;
169-
auto pTarget = abstract_cast<ObjectClass*>(pBullet->Target);
170-
auto pCoords = pTarget ? pTarget->GetCoords() : pBullet->Data.Location;
168+
const auto pType = this->Type;
169+
const auto pTarget = abstract_cast<ObjectClass*>(pBullet->Target);
170+
const auto pCoords = pTarget ? pTarget->GetCoords() : pBullet->Data.Location;
171171

172172
if (pCoords.DistanceFrom(pBullet->Location) <= pType->TargetSnapDistance.Get())
173173
{
174-
auto const pExt = BulletExt::ExtMap.Find(pBullet);
174+
const auto pExt = BulletExt::ExtMap.Find(pBullet);
175175
pExt->SnappedToTarget = true;
176176
pBullet->SetLocation(pCoords);
177177
}
@@ -194,12 +194,12 @@ TrajectoryCheckReturnType BombardTrajectory::OnAITechnoCheck(BulletClass* pBulle
194194

195195
void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
196196
{
197-
const BombardTrajectoryType* const pType = this->Type;
197+
const auto pType = this->Type;
198198
this->CalculateTargetCoords(pBullet);
199199

200200
if (!pType->NoLaunch)
201201
{
202-
const CoordStruct middleLocation = this->CalculateMiddleCoords(pBullet);
202+
const auto middleLocation = this->CalculateMiddleCoords(pBullet);
203203

204204
pBullet->Velocity.X = static_cast<double>(middleLocation.X - pBullet->SourceCoords.X);
205205
pBullet->Velocity.Y = static_cast<double>(middleLocation.Y - pBullet->SourceCoords.Y);
@@ -211,7 +211,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
211211
else
212212
{
213213
this->IsFalling = true;
214-
CoordStruct middleLocation = CoordStruct::Empty;
214+
auto middleLocation = CoordStruct::Empty;
215215

216216
if (!pType->FreeFallOnTarget)
217217
{
@@ -230,7 +230,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
230230
middleLocation = CoordStruct { pBullet->TargetCoords.X, pBullet->TargetCoords.Y, static_cast<int>(this->Height) };
231231
}
232232

233-
auto const pExt = BulletExt::ExtMap.Find(pBullet);
233+
const auto pExt = BulletExt::ExtMap.Find(pBullet);
234234

235235
if (pExt->LaserTrails.size())
236236
{
@@ -240,29 +240,29 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
240240
this->RefreshBulletLineTrail(pBullet);
241241

242242
pBullet->SetLocation(middleLocation);
243-
HouseClass* const pOwner = pBullet->Owner ? pBullet->Owner->Owner : BulletExt::ExtMap.Find(pBullet)->FirerHouse;
243+
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : BulletExt::ExtMap.Find(pBullet)->FirerHouse;
244244
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pBullet->Owner, pOwner, true);
245245
}
246246
}
247247

248248
CoordStruct BombardTrajectory::CalculateMiddleCoords(BulletClass* pBullet)
249249
{
250-
const BombardTrajectoryType* const pType = this->Type;
251-
const double length = ScenarioClass::Instance->Random.RandomRanged(pType->FallScatter_Min.Get(), pType->FallScatter_Max.Get());
252-
const double vectorX = (pBullet->TargetCoords.X - pBullet->SourceCoords.X) * this->FallPercent;
253-
const double vectorY = (pBullet->TargetCoords.Y - pBullet->SourceCoords.Y) * this->FallPercent;
250+
const auto pType = this->Type;
251+
const auto length = ScenarioClass::Instance->Random.RandomRanged(pType->FallScatter_Min.Get(), pType->FallScatter_Max.Get());
252+
const auto vectorX = (pBullet->TargetCoords.X - pBullet->SourceCoords.X) * this->FallPercent;
253+
const auto vectorY = (pBullet->TargetCoords.Y - pBullet->SourceCoords.Y) * this->FallPercent;
254254
double scatterX = 0.0;
255255
double scatterY = 0.0;
256256

257257
if (!pType->FallScatter_Linear)
258258
{
259-
const double angel = ScenarioClass::Instance->Random.RandomDouble() * Math::TwoPi;
259+
const auto angel = ScenarioClass::Instance->Random.RandomDouble() * Math::TwoPi;
260260
scatterX = length * Math::cos(angel);
261261
scatterY = length * Math::sin(angel);
262262
}
263263
else
264264
{
265-
const double vectorModule = sqrt(vectorX * vectorX + vectorY * vectorY);
265+
const auto vectorModule = sqrt(vectorX * vectorX + vectorY * vectorY);
266266
scatterX = vectorY / vectorModule * length;
267267
scatterY = -(vectorX / vectorModule * length);
268268

@@ -283,9 +283,9 @@ CoordStruct BombardTrajectory::CalculateMiddleCoords(BulletClass* pBullet)
283283

284284
void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
285285
{
286-
const BombardTrajectoryType* const pType = this->Type;
287-
CoordStruct theTargetCoords = pBullet->TargetCoords;
288-
CoordStruct theSourceCoords = pBullet->SourceCoords;
286+
const auto pType = this->Type;
287+
auto theTargetCoords = pBullet->TargetCoords;
288+
const auto theSourceCoords = pBullet->SourceCoords;
289289

290290
if (pType->NoLaunch)
291291
theTargetCoords += this->CalculateBulletLeadTime(pBullet);
@@ -294,12 +294,12 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
294294

295295
if (!pType->LeadTimeCalculate && theTargetCoords == theSourceCoords && pBullet->Owner) //For disperse.
296296
{
297-
const CoordStruct theOwnerCoords = pBullet->Owner->GetCoords();
298-
this->RotateAngle = Math::atan2(theTargetCoords.Y - theOwnerCoords.Y, theTargetCoords.X - theOwnerCoords.X);
297+
const auto theOwnerCoords = pBullet->Owner->GetCoords();
298+
this->RotateAngle = Math::atan2(theTargetCoords.Y - theOwnerCoords.Y , theTargetCoords.X - theOwnerCoords.X);
299299
}
300300
else
301301
{
302-
this->RotateAngle = Math::atan2(theTargetCoords.Y - theSourceCoords.Y, theTargetCoords.X - theSourceCoords.X);
302+
this->RotateAngle = Math::atan2(theTargetCoords.Y - theSourceCoords.Y , theTargetCoords.X - theSourceCoords.X);
303303
}
304304

305305
if (this->OffsetCoord != CoordStruct::Empty)
@@ -311,33 +311,33 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
311311

312312
if (pBullet->Type->Inaccurate)
313313
{
314-
auto const pTypeExt = BulletTypeExt::ExtMap.Find(pBullet->Type);
315-
const double offsetMult = 0.0004 * pBullet->SourceCoords.DistanceFrom(pBullet->TargetCoords);
316-
const int offsetMin = static_cast<int>(offsetMult * pTypeExt->BallisticScatter_Min.Get(Leptons(0)));
317-
const int offsetMax = static_cast<int>(offsetMult * pTypeExt->BallisticScatter_Max.Get(Leptons(RulesClass::Instance->BallisticScatter)));
318-
const int offsetDistance = ScenarioClass::Instance->Random.RandomRanged(offsetMin, offsetMax);
314+
const auto pTypeExt = BulletTypeExt::ExtMap.Find(pBullet->Type);
315+
const auto offsetMult = 0.0004 * pBullet->SourceCoords.DistanceFrom(pBullet->TargetCoords);
316+
const auto offsetMin = static_cast<int>(offsetMult * pTypeExt->BallisticScatter_Min.Get(Leptons(0)));
317+
const auto offsetMax = static_cast<int>(offsetMult * pTypeExt->BallisticScatter_Max.Get(Leptons(RulesClass::Instance->BallisticScatter)));
318+
const auto offsetDistance = ScenarioClass::Instance->Random.RandomRanged(offsetMin, offsetMax);
319319
pBullet->TargetCoords = MapClass::GetRandomCoordsNear(pBullet->TargetCoords, offsetDistance, false);
320320
}
321321
}
322322

323323
CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
324324
{
325-
const BombardTrajectoryType* const pType = this->Type;
326-
CoordStruct coords = CoordStruct::Empty;
325+
const auto pType = this->Type;
326+
auto coords = CoordStruct::Empty;
327327

328328
if (pType->LeadTimeCalculate)
329329
{
330-
if (const AbstractClass* const pTarget = pBullet->Target)
330+
if (const auto pTarget = pBullet->Target)
331331
{
332-
const CoordStruct theTargetCoords = pTarget->GetCoords();
333-
const CoordStruct theSourceCoords = pBullet->Location;
332+
const auto theTargetCoords = pTarget->GetCoords();
333+
const auto theSourceCoords = pBullet->Location;
334334

335335
if (theTargetCoords != this->LastTargetCoord)
336336
{
337337
int travelTime = 0;
338-
const CoordStruct extraOffsetCoord = theTargetCoords - this->LastTargetCoord;
339-
const CoordStruct targetSourceCoord = theSourceCoords - theTargetCoords;
340-
const CoordStruct lastSourceCoord = theSourceCoords - this->LastTargetCoord;
338+
const auto extraOffsetCoord = theTargetCoords - this->LastTargetCoord;
339+
const auto targetSourceCoord = theSourceCoords - theTargetCoords;
340+
const auto lastSourceCoord = theSourceCoords - this->LastTargetCoord;
341341

342342
if (pType->FreeFallOnTarget)
343343
{
@@ -346,34 +346,34 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
346346
}
347347
else
348348
{
349-
const double theDistanceSquared = targetSourceCoord.MagnitudeSquared();
350-
const double targetSpeedSquared = extraOffsetCoord.MagnitudeSquared();
351-
const double targetSpeed = sqrt(targetSpeedSquared);
349+
const auto theDistanceSquared = targetSourceCoord.MagnitudeSquared();
350+
const auto targetSpeedSquared = extraOffsetCoord.MagnitudeSquared();
351+
const auto targetSpeed = sqrt(targetSpeedSquared);
352352

353-
const double crossFactor = lastSourceCoord.CrossProduct(targetSourceCoord).MagnitudeSquared();
354-
const double verticalDistanceSquared = crossFactor / targetSpeedSquared;
353+
const auto crossFactor = lastSourceCoord.CrossProduct(targetSourceCoord).MagnitudeSquared();
354+
const auto verticalDistanceSquared = crossFactor / targetSpeedSquared;
355355

356-
const double horizonDistanceSquared = theDistanceSquared - verticalDistanceSquared;
357-
const double horizonDistance = sqrt(horizonDistanceSquared);
356+
const auto horizonDistanceSquared = theDistanceSquared - verticalDistanceSquared;
357+
const auto horizonDistance = sqrt(horizonDistanceSquared);
358358

359-
const double straightSpeed = pType->FreeFallOnTarget ? pType->Trajectory_Speed : pType->FallSpeed;
360-
const double straightSpeedSquared = straightSpeed * straightSpeed;
359+
const auto straightSpeed = pType->FreeFallOnTarget ? pType->Trajectory_Speed : pType->FallSpeed;
360+
const auto straightSpeedSquared = straightSpeed * straightSpeed;
361361

362-
const double baseFactor = straightSpeedSquared - targetSpeedSquared;
363-
const double squareFactor = baseFactor * verticalDistanceSquared + straightSpeedSquared * horizonDistanceSquared;
362+
const auto baseFactor = straightSpeedSquared - targetSpeedSquared;
363+
const auto squareFactor = baseFactor * verticalDistanceSquared + straightSpeedSquared * horizonDistanceSquared;
364364

365365
if (squareFactor > 1e-10)
366366
{
367-
const double minusFactor = -(horizonDistance * targetSpeed);
367+
const auto minusFactor = -(horizonDistance * targetSpeed);
368368

369369
if (abs(baseFactor) < 1e-10)
370370
{
371371
travelTime = abs(horizonDistance) > 1e-10 ? (static_cast<int>(theDistanceSquared / (2 * horizonDistance * targetSpeed)) + 1) : 0;
372372
}
373373
else
374374
{
375-
const int travelTimeM = static_cast<int>((minusFactor - sqrt(squareFactor)) / baseFactor);
376-
const int travelTimeP = static_cast<int>((minusFactor + sqrt(squareFactor)) / baseFactor);
375+
const auto travelTimeM = static_cast<int>((minusFactor - sqrt(squareFactor)) / baseFactor);
376+
const auto travelTimeP = static_cast<int>((minusFactor + sqrt(squareFactor)) / baseFactor);
377377

378378
if (travelTimeM > 0 && travelTimeP > 0)
379379
travelTime = travelTimeM < travelTimeP ? travelTimeM : travelTimeP;
@@ -400,11 +400,11 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
400400

401401
void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
402402
{
403-
const BombardTrajectoryType* const pType = this->Type;
403+
const auto pType = this->Type;
404404

405405
if (!this->UseDisperseBurst && abs(pType->RotateCoord) > 1e-10 && this->CountOfBurst > 1)
406406
{
407-
const CoordStruct axis = pType->AxisOfRotation;
407+
const auto axis = pType->AxisOfRotation.Get();
408408

409409
BulletVelocity rotationAxis
410410
{
@@ -413,7 +413,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
413413
static_cast<double>(axis.Z)
414414
};
415415

416-
const double rotationAxisLengthSquared = rotationAxis.MagnitudeSquared();
416+
const auto rotationAxisLengthSquared = rotationAxis.MagnitudeSquared();
417417

418418
if (abs(rotationAxisLengthSquared) > 1e-10)
419419
{
@@ -432,7 +432,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
432432
extraRotate = Math::Pi * (pType->RotateCoord * (this->CurrentBurst / (this->CountOfBurst - 1.0) - 0.5)) / (this->IsFalling ? 90 : 180);
433433
}
434434

435-
const double cosRotate = Math::cos(extraRotate);
435+
const auto cosRotate = Math::cos(extraRotate);
436436
pBullet->Velocity = (pBullet->Velocity * cosRotate) + (rotationAxis * ((1 - cosRotate) * (pBullet->Velocity * rotationAxis))) + (rotationAxis.CrossProduct(pBullet->Velocity) * Math::sin(extraRotate));
437437
}
438438
}
@@ -446,7 +446,7 @@ bool BombardTrajectory::BulletPrepareCheck(BulletClass* pBullet)
446446
// necessary to record the position during the first Update(). - CrimRecya
447447
if (this->WaitOneFrame == 2)
448448
{
449-
if (const AbstractClass* const pTarget = pBullet->Target)
449+
if (const auto pTarget = pBullet->Target)
450450
{
451451
this->LastTargetCoord = pTarget->GetCoords();
452452
this->WaitOneFrame = 1;
@@ -462,7 +462,7 @@ bool BombardTrajectory::BulletPrepareCheck(BulletClass* pBullet)
462462

463463
bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
464464
{
465-
const BombardTrajectoryType* const pType = this->Type;
465+
const auto pType = this->Type;
466466

467467
// Close enough
468468
if (pBullet->TargetCoords.DistanceFrom(pBullet->Location) < pType->DetonationDistance.Get())
@@ -489,7 +489,7 @@ bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
489489

490490
bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner)
491491
{
492-
const BombardTrajectoryType* const pType = this->Type;
492+
const auto pType = this->Type;
493493
this->RemainingDistance -= static_cast<int>(pType->FallSpeed);
494494

495495
if (this->RemainingDistance < 0)
@@ -506,7 +506,7 @@ bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet, HouseCla
506506

507507
void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
508508
{
509-
const BombardTrajectoryType* const pType = this->Type;
509+
const auto pType = this->Type;
510510

511511
if (!this->IsFalling)
512512
{
@@ -515,8 +515,8 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
515515
if (this->ToFalling)
516516
{
517517
this->IsFalling = true;
518-
const AbstractClass* const pTarget = pBullet->Target;
519-
CoordStruct middleLocation = CoordStruct::Empty;
518+
const auto pTarget = pBullet->Target;
519+
auto middleLocation = CoordStruct::Empty;
520520

521521
if (!pType->FreeFallOnTarget)
522522
{
@@ -549,23 +549,23 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
549549
pBullet->Velocity = BulletVelocity::Empty;
550550
}
551551

552-
auto const pExt = BulletExt::ExtMap.Find(pBullet);
552+
const auto pExt = BulletExt::ExtMap.Find(pBullet);
553553

554554
if (pExt->LaserTrails.size())
555555
{
556556
for (auto& trail : pExt->LaserTrails)
557557
trail.LastLocation = middleLocation;
558558
}
559-
560559
this->RefreshBulletLineTrail(pBullet);
560+
561561
pBullet->SetLocation(middleLocation);
562-
TechnoClass* const pTechno = pBullet->Owner;
562+
const auto pTechno = pBullet->Owner;
563563
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pTechno ? pTechno->Owner : pExt->FirerHouse, true);
564564
}
565565
else
566566
{
567567
this->ToFalling = true;
568-
const AbstractClass* const pTarget = pBullet->Target;
568+
const auto pTarget = pBullet->Target;
569569

570570
if (pType->LeadTimeCalculate && pTarget)
571571
this->LastTargetCoord = pTarget->GetCoords();
@@ -582,17 +582,17 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
582582

583583
void BombardTrajectory::RefreshBulletLineTrail(BulletClass* pBullet)
584584
{
585-
if (LineTrail* const pLineTrailer = pBullet->LineTrailer)
585+
if (const auto pLineTrailer = pBullet->LineTrailer)
586586
{
587587
pLineTrailer->~LineTrail();
588588
pBullet->LineTrailer = nullptr;
589589
}
590590

591-
BulletTypeClass* const pType = pBullet->Type;
591+
const auto pType = pBullet->Type;
592592

593593
if (pType->UseLineTrail)
594594
{
595-
if (LineTrail* const pLineTrailer = GameCreate<LineTrail>())
595+
if (const auto pLineTrailer = GameCreate<LineTrail>())
596596
{
597597
pBullet->LineTrailer = pLineTrailer;
598598

0 commit comments

Comments
 (0)