@@ -119,18 +119,18 @@ bool BombardTrajectory::Save(PhobosStreamWriter& Stm) const
119
119
120
120
void BombardTrajectory::OnUnlimbo (BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity)
121
121
{
122
- const BombardTrajectoryType* const pType = this ->Type ;
122
+ const auto pType = this ->Type ;
123
123
this ->Height += pBullet->TargetCoords .Z ;
124
124
// use scaling since RandomRanged only support int
125
125
this ->FallPercent += ScenarioClass::Instance->Random .RandomRanged (0 , static_cast <int >(200 * pType->FallPercentShift )) / 100.0 ;
126
126
this ->InitialTargetCoord = pBullet->TargetCoords ;
127
127
this ->LastTargetCoord = pBullet->TargetCoords ;
128
128
pBullet->Velocity = BulletVelocity::Empty;
129
129
130
- if (WeaponTypeClass* const pWeapon = pBullet->WeaponType )
130
+ if (const auto pWeapon = pBullet->WeaponType )
131
131
this ->CountOfBurst = pWeapon->Burst ;
132
132
133
- if (TechnoClass* const pOwner = pBullet->Owner )
133
+ if (const auto pOwner = pBullet->Owner )
134
134
{
135
135
this ->CurrentBurst = pOwner->CurrentBurstIndex ;
136
136
@@ -153,7 +153,7 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
153
153
return true ;
154
154
155
155
// 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 ;
157
157
158
158
if (this ->IsFalling && !this ->Type ->FreeFallOnTarget && this ->BulletDetonateRemainCheck (pBullet, pOwner))
159
159
return true ;
@@ -165,13 +165,13 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
165
165
166
166
void BombardTrajectory::OnAIPreDetonate (BulletClass* pBullet)
167
167
{
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 ;
171
171
172
172
if (pCoords.DistanceFrom (pBullet->Location ) <= pType->TargetSnapDistance .Get ())
173
173
{
174
- auto const pExt = BulletExt::ExtMap.Find (pBullet);
174
+ const auto pExt = BulletExt::ExtMap.Find (pBullet);
175
175
pExt->SnappedToTarget = true ;
176
176
pBullet->SetLocation (pCoords);
177
177
}
@@ -194,12 +194,12 @@ TrajectoryCheckReturnType BombardTrajectory::OnAITechnoCheck(BulletClass* pBulle
194
194
195
195
void BombardTrajectory::PrepareForOpenFire (BulletClass* pBullet)
196
196
{
197
- const BombardTrajectoryType* const pType = this ->Type ;
197
+ const auto pType = this ->Type ;
198
198
this ->CalculateTargetCoords (pBullet);
199
199
200
200
if (!pType->NoLaunch )
201
201
{
202
- const CoordStruct middleLocation = this ->CalculateMiddleCoords (pBullet);
202
+ const auto middleLocation = this ->CalculateMiddleCoords (pBullet);
203
203
204
204
pBullet->Velocity .X = static_cast <double >(middleLocation.X - pBullet->SourceCoords .X );
205
205
pBullet->Velocity .Y = static_cast <double >(middleLocation.Y - pBullet->SourceCoords .Y );
@@ -211,7 +211,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
211
211
else
212
212
{
213
213
this ->IsFalling = true ;
214
- CoordStruct middleLocation = CoordStruct::Empty;
214
+ auto middleLocation = CoordStruct::Empty;
215
215
216
216
if (!pType->FreeFallOnTarget )
217
217
{
@@ -230,7 +230,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
230
230
middleLocation = CoordStruct { pBullet->TargetCoords .X , pBullet->TargetCoords .Y , static_cast <int >(this ->Height ) };
231
231
}
232
232
233
- auto const pExt = BulletExt::ExtMap.Find (pBullet);
233
+ const auto pExt = BulletExt::ExtMap.Find (pBullet);
234
234
235
235
if (pExt->LaserTrails .size ())
236
236
{
@@ -240,29 +240,29 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
240
240
this ->RefreshBulletLineTrail (pBullet);
241
241
242
242
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 ;
244
244
AnimExt::CreateRandomAnim (pType->TurningPointAnims , middleLocation, pBullet->Owner , pOwner, true );
245
245
}
246
246
}
247
247
248
248
CoordStruct BombardTrajectory::CalculateMiddleCoords (BulletClass* pBullet)
249
249
{
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 ;
254
254
double scatterX = 0.0 ;
255
255
double scatterY = 0.0 ;
256
256
257
257
if (!pType->FallScatter_Linear )
258
258
{
259
- const double angel = ScenarioClass::Instance->Random .RandomDouble () * Math::TwoPi;
259
+ const auto angel = ScenarioClass::Instance->Random .RandomDouble () * Math::TwoPi;
260
260
scatterX = length * Math::cos (angel);
261
261
scatterY = length * Math::sin (angel);
262
262
}
263
263
else
264
264
{
265
- const double vectorModule = sqrt (vectorX * vectorX + vectorY * vectorY);
265
+ const auto vectorModule = sqrt (vectorX * vectorX + vectorY * vectorY);
266
266
scatterX = vectorY / vectorModule * length;
267
267
scatterY = -(vectorX / vectorModule * length);
268
268
@@ -283,9 +283,9 @@ CoordStruct BombardTrajectory::CalculateMiddleCoords(BulletClass* pBullet)
283
283
284
284
void BombardTrajectory::CalculateTargetCoords (BulletClass* pBullet)
285
285
{
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 ;
289
289
290
290
if (pType->NoLaunch )
291
291
theTargetCoords += this ->CalculateBulletLeadTime (pBullet);
@@ -294,12 +294,12 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
294
294
295
295
if (!pType->LeadTimeCalculate && theTargetCoords == theSourceCoords && pBullet->Owner ) // For disperse.
296
296
{
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 );
299
299
}
300
300
else
301
301
{
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 );
303
303
}
304
304
305
305
if (this ->OffsetCoord != CoordStruct::Empty)
@@ -311,33 +311,33 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
311
311
312
312
if (pBullet->Type ->Inaccurate )
313
313
{
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);
319
319
pBullet->TargetCoords = MapClass::GetRandomCoordsNear (pBullet->TargetCoords , offsetDistance, false );
320
320
}
321
321
}
322
322
323
323
CoordStruct BombardTrajectory::CalculateBulletLeadTime (BulletClass* pBullet)
324
324
{
325
- const BombardTrajectoryType* const pType = this ->Type ;
326
- CoordStruct coords = CoordStruct::Empty;
325
+ const auto pType = this ->Type ;
326
+ auto coords = CoordStruct::Empty;
327
327
328
328
if (pType->LeadTimeCalculate )
329
329
{
330
- if (const AbstractClass* const pTarget = pBullet->Target )
330
+ if (const auto pTarget = pBullet->Target )
331
331
{
332
- const CoordStruct theTargetCoords = pTarget->GetCoords ();
333
- const CoordStruct theSourceCoords = pBullet->Location ;
332
+ const auto theTargetCoords = pTarget->GetCoords ();
333
+ const auto theSourceCoords = pBullet->Location ;
334
334
335
335
if (theTargetCoords != this ->LastTargetCoord )
336
336
{
337
337
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 ;
341
341
342
342
if (pType->FreeFallOnTarget )
343
343
{
@@ -346,34 +346,34 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
346
346
}
347
347
else
348
348
{
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);
352
352
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;
355
355
356
- const double horizonDistanceSquared = theDistanceSquared - verticalDistanceSquared;
357
- const double horizonDistance = sqrt (horizonDistanceSquared);
356
+ const auto horizonDistanceSquared = theDistanceSquared - verticalDistanceSquared;
357
+ const auto horizonDistance = sqrt (horizonDistanceSquared);
358
358
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;
361
361
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;
364
364
365
365
if (squareFactor > 1e-10 )
366
366
{
367
- const double minusFactor = -(horizonDistance * targetSpeed);
367
+ const auto minusFactor = -(horizonDistance * targetSpeed);
368
368
369
369
if (abs (baseFactor) < 1e-10 )
370
370
{
371
371
travelTime = abs (horizonDistance) > 1e-10 ? (static_cast <int >(theDistanceSquared / (2 * horizonDistance * targetSpeed)) + 1 ) : 0 ;
372
372
}
373
373
else
374
374
{
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);
377
377
378
378
if (travelTimeM > 0 && travelTimeP > 0 )
379
379
travelTime = travelTimeM < travelTimeP ? travelTimeM : travelTimeP;
@@ -400,11 +400,11 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
400
400
401
401
void BombardTrajectory::CalculateDisperseBurst (BulletClass* pBullet)
402
402
{
403
- const BombardTrajectoryType* const pType = this ->Type ;
403
+ const auto pType = this ->Type ;
404
404
405
405
if (!this ->UseDisperseBurst && abs (pType->RotateCoord ) > 1e-10 && this ->CountOfBurst > 1 )
406
406
{
407
- const CoordStruct axis = pType->AxisOfRotation ;
407
+ const auto axis = pType->AxisOfRotation . Get () ;
408
408
409
409
BulletVelocity rotationAxis
410
410
{
@@ -413,7 +413,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
413
413
static_cast <double >(axis.Z )
414
414
};
415
415
416
- const double rotationAxisLengthSquared = rotationAxis.MagnitudeSquared ();
416
+ const auto rotationAxisLengthSquared = rotationAxis.MagnitudeSquared ();
417
417
418
418
if (abs (rotationAxisLengthSquared) > 1e-10 )
419
419
{
@@ -432,7 +432,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
432
432
extraRotate = Math::Pi * (pType->RotateCoord * (this ->CurrentBurst / (this ->CountOfBurst - 1.0 ) - 0.5 )) / (this ->IsFalling ? 90 : 180 );
433
433
}
434
434
435
- const double cosRotate = Math::cos (extraRotate);
435
+ const auto cosRotate = Math::cos (extraRotate);
436
436
pBullet->Velocity = (pBullet->Velocity * cosRotate) + (rotationAxis * ((1 - cosRotate) * (pBullet->Velocity * rotationAxis))) + (rotationAxis.CrossProduct (pBullet->Velocity ) * Math::sin (extraRotate));
437
437
}
438
438
}
@@ -446,7 +446,7 @@ bool BombardTrajectory::BulletPrepareCheck(BulletClass* pBullet)
446
446
// necessary to record the position during the first Update(). - CrimRecya
447
447
if (this ->WaitOneFrame == 2 )
448
448
{
449
- if (const AbstractClass* const pTarget = pBullet->Target )
449
+ if (const auto pTarget = pBullet->Target )
450
450
{
451
451
this ->LastTargetCoord = pTarget->GetCoords ();
452
452
this ->WaitOneFrame = 1 ;
@@ -462,7 +462,7 @@ bool BombardTrajectory::BulletPrepareCheck(BulletClass* pBullet)
462
462
463
463
bool BombardTrajectory::BulletDetonatePreCheck (BulletClass* pBullet)
464
464
{
465
- const BombardTrajectoryType* const pType = this ->Type ;
465
+ const auto pType = this ->Type ;
466
466
467
467
// Close enough
468
468
if (pBullet->TargetCoords .DistanceFrom (pBullet->Location ) < pType->DetonationDistance .Get ())
@@ -489,7 +489,7 @@ bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
489
489
490
490
bool BombardTrajectory::BulletDetonateRemainCheck (BulletClass* pBullet, HouseClass* pOwner)
491
491
{
492
- const BombardTrajectoryType* const pType = this ->Type ;
492
+ const auto pType = this ->Type ;
493
493
this ->RemainingDistance -= static_cast <int >(pType->FallSpeed );
494
494
495
495
if (this ->RemainingDistance < 0 )
@@ -506,7 +506,7 @@ bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet, HouseCla
506
506
507
507
void BombardTrajectory::BulletVelocityChange (BulletClass* pBullet)
508
508
{
509
- const BombardTrajectoryType* const pType = this ->Type ;
509
+ const auto pType = this ->Type ;
510
510
511
511
if (!this ->IsFalling )
512
512
{
@@ -515,8 +515,8 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
515
515
if (this ->ToFalling )
516
516
{
517
517
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;
520
520
521
521
if (!pType->FreeFallOnTarget )
522
522
{
@@ -549,23 +549,23 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
549
549
pBullet->Velocity = BulletVelocity::Empty;
550
550
}
551
551
552
- auto const pExt = BulletExt::ExtMap.Find (pBullet);
552
+ const auto pExt = BulletExt::ExtMap.Find (pBullet);
553
553
554
554
if (pExt->LaserTrails .size ())
555
555
{
556
556
for (auto & trail : pExt->LaserTrails )
557
557
trail.LastLocation = middleLocation;
558
558
}
559
-
560
559
this ->RefreshBulletLineTrail (pBullet);
560
+
561
561
pBullet->SetLocation (middleLocation);
562
- TechnoClass* const pTechno = pBullet->Owner ;
562
+ const auto pTechno = pBullet->Owner ;
563
563
AnimExt::CreateRandomAnim (pType->TurningPointAnims , middleLocation, pTechno, pTechno ? pTechno->Owner : pExt->FirerHouse , true );
564
564
}
565
565
else
566
566
{
567
567
this ->ToFalling = true ;
568
- const AbstractClass* const pTarget = pBullet->Target ;
568
+ const auto pTarget = pBullet->Target ;
569
569
570
570
if (pType->LeadTimeCalculate && pTarget)
571
571
this ->LastTargetCoord = pTarget->GetCoords ();
@@ -582,17 +582,17 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
582
582
583
583
void BombardTrajectory::RefreshBulletLineTrail (BulletClass* pBullet)
584
584
{
585
- if (LineTrail* const pLineTrailer = pBullet->LineTrailer )
585
+ if (const auto pLineTrailer = pBullet->LineTrailer )
586
586
{
587
587
pLineTrailer->~LineTrail ();
588
588
pBullet->LineTrailer = nullptr ;
589
589
}
590
590
591
- BulletTypeClass* const pType = pBullet->Type ;
591
+ const auto pType = pBullet->Type ;
592
592
593
593
if (pType->UseLineTrail )
594
594
{
595
- if (LineTrail* const pLineTrailer = GameCreate<LineTrail>())
595
+ if (const auto pLineTrailer = GameCreate<LineTrail>())
596
596
{
597
597
pBullet->LineTrailer = pLineTrailer;
598
598
0 commit comments