@@ -64,10 +64,7 @@ void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
64
64
this ->FallScatter_Min .Read (exINI, pSection, " Trajectory.Bombard.FallScatter.Min" );
65
65
this ->FallScatter_Linear .Read (exINI, pSection, " Trajectory.Bombard.FallScatter.Linear" );
66
66
this ->FallSpeed .Read (exINI, pSection, " Trajectory.Bombard.FallSpeed" );
67
-
68
- if (abs (this ->FallSpeed .Get ()) < 1e-10 )
69
- this ->FallSpeed = this ->Trajectory_Speed ;
70
-
67
+ this ->FallSpeed = std::abs (this ->FallSpeed .Get ()) < 1e-10 ? this ->Trajectory_Speed .Get () : this ->FallSpeed .Get ();
71
68
this ->DetonationDistance .Read (exINI, pSection, " Trajectory.Bombard.DetonationDistance" );
72
69
this ->DetonationHeight .Read (exINI, pSection, " Trajectory.Bombard.DetonationHeight" );
73
70
this ->EarlyDetonation .Read (exINI, pSection, " Trajectory.Bombard.EarlyDetonation" );
@@ -123,10 +120,13 @@ void BombardTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bul
123
120
this ->Height += pBullet->TargetCoords .Z ;
124
121
// use scaling since RandomRanged only support int
125
122
this ->FallPercent += ScenarioClass::Instance->Random .RandomRanged (0 , static_cast <int >(200 * pType->FallPercentShift )) / 100.0 ;
123
+
124
+ // Record the initial target coordinates without offset
126
125
this ->InitialTargetCoord = pBullet->TargetCoords ;
127
126
this ->LastTargetCoord = pBullet->TargetCoords ;
128
127
pBullet->Velocity = BulletVelocity::Empty;
129
128
129
+ // Record some information
130
130
if (const auto pWeapon = pBullet->WeaponType )
131
131
this ->CountOfBurst = pWeapon->Burst ;
132
132
@@ -138,6 +138,7 @@ void BombardTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bul
138
138
this ->OffsetCoord .Y = -(this ->OffsetCoord .Y );
139
139
}
140
140
141
+ // Wait, or launch immediately?
141
142
if (!pType->NoLaunch || !pType->LeadTimeCalculate || !abstract_cast<FootClass*>(pBullet->Target ))
142
143
this ->PrepareForOpenFire (pBullet);
143
144
else
@@ -240,7 +241,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
240
241
this ->RefreshBulletLineTrail (pBullet);
241
242
242
243
pBullet->SetLocation (middleLocation);
243
- const auto pOwner = pBullet->Owner ? pBullet->Owner ->Owner : BulletExt::ExtMap. Find (pBullet) ->FirerHouse ;
244
+ const auto pOwner = pBullet->Owner ? pBullet->Owner ->Owner : pExt ->FirerHouse ;
244
245
AnimExt::CreateRandomAnim (pType->TurningPointAnims , middleLocation, pBullet->Owner , pOwner, true );
245
246
}
246
247
}
@@ -292,6 +293,7 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
292
293
293
294
pBullet->TargetCoords = theTargetCoords;
294
295
296
+ // Calculate the orientation of the coordinate system
295
297
if (!pType->LeadTimeCalculate && theTargetCoords == theSourceCoords && pBullet->Owner ) // For disperse.
296
298
{
297
299
const auto theOwnerCoords = pBullet->Owner ->GetCoords ();
@@ -302,13 +304,15 @@ void BombardTrajectory::CalculateTargetCoords(BulletClass* pBullet)
302
304
this ->RotateAngle = Math::atan2 (theTargetCoords.Y - theSourceCoords.Y , theTargetCoords.X - theSourceCoords.X );
303
305
}
304
306
307
+ // Add the fixed offset value
305
308
if (this ->OffsetCoord != CoordStruct::Empty)
306
309
{
307
310
pBullet->TargetCoords .X += static_cast <int >(this ->OffsetCoord .X * Math::cos (this ->RotateAngle ) + this ->OffsetCoord .Y * Math::sin (this ->RotateAngle ));
308
311
pBullet->TargetCoords .Y += static_cast <int >(this ->OffsetCoord .X * Math::sin (this ->RotateAngle ) - this ->OffsetCoord .Y * Math::cos (this ->RotateAngle ));
309
312
pBullet->TargetCoords .Z += this ->OffsetCoord .Z ;
310
313
}
311
314
315
+ // Add random offset value
312
316
if (pBullet->Type ->Inaccurate )
313
317
{
314
318
const auto pTypeExt = BulletTypeExt::ExtMap.Find (pBullet->Type );
@@ -332,6 +336,7 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
332
336
const auto theTargetCoords = pTarget->GetCoords ();
333
337
const auto theSourceCoords = pBullet->Location ;
334
338
339
+ // Solving trigonometric functions
335
340
if (theTargetCoords != this ->LastTargetCoord )
336
341
{
337
342
int travelTime = 0 ;
@@ -344,6 +349,11 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
344
349
travelTime += static_cast <int >(sqrt (2 * (this ->Height - theTargetCoords.Z ) / BulletTypeExt::GetAdjustedGravity (pBullet->Type )));
345
350
coords += extraOffsetCoord * (travelTime + 1 );
346
351
}
352
+ else if (pType->NoLaunch )
353
+ {
354
+ travelTime += static_cast <int >((this ->Height - theTargetCoords.Z ) / pType->FallSpeed );
355
+ coords += extraOffsetCoord * (travelTime + 1 );
356
+ }
347
357
else
348
358
{
349
359
const auto theDistanceSquared = targetSourceCoord.MagnitudeSquared ();
@@ -356,19 +366,18 @@ CoordStruct BombardTrajectory::CalculateBulletLeadTime(BulletClass* pBullet)
356
366
const auto horizonDistanceSquared = theDistanceSquared - verticalDistanceSquared;
357
367
const auto horizonDistance = sqrt (horizonDistanceSquared);
358
368
359
- const auto straightSpeed = pType->FreeFallOnTarget ? pType->Trajectory_Speed : pType->FallSpeed ;
360
- const auto straightSpeedSquared = straightSpeed * straightSpeed;
361
-
369
+ const auto straightSpeedSquared = pType->FallSpeed * pType->FallSpeed ;
362
370
const auto baseFactor = straightSpeedSquared - targetSpeedSquared;
363
371
const auto squareFactor = baseFactor * verticalDistanceSquared + straightSpeedSquared * horizonDistanceSquared;
364
372
373
+ // Is there a solution?
365
374
if (squareFactor > 1e-10 )
366
375
{
367
376
const auto minusFactor = -(horizonDistance * targetSpeed);
368
377
369
- if (abs (baseFactor) < 1e-10 )
378
+ if (std:: abs (baseFactor) < 1e-10 )
370
379
{
371
- travelTime = abs (horizonDistance) > 1e-10 ? (static_cast <int >(theDistanceSquared / (2 * horizonDistance * targetSpeed)) + 1 ) : 0 ;
380
+ travelTime = std:: abs (horizonDistance) > 1e-10 ? (static_cast <int >(theDistanceSquared / (2 * horizonDistance * targetSpeed)) + 1 ) : 0 ;
372
381
}
373
382
else
374
383
{
@@ -402,7 +411,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
402
411
{
403
412
const auto pType = this ->Type ;
404
413
405
- if (!this ->UseDisperseBurst && abs (pType->RotateCoord ) > 1e-10 && this ->CountOfBurst > 1 )
414
+ if (!this ->UseDisperseBurst && std:: abs (pType->RotateCoord ) > 1e-10 && this ->CountOfBurst > 1 )
406
415
{
407
416
const auto axis = pType->AxisOfRotation .Get ();
408
417
@@ -415,7 +424,7 @@ void BombardTrajectory::CalculateDisperseBurst(BulletClass* pBullet)
415
424
416
425
const auto rotationAxisLengthSquared = rotationAxis.MagnitudeSquared ();
417
426
418
- if (abs (rotationAxisLengthSquared) > 1e-10 )
427
+ if (std:: abs (rotationAxisLengthSquared) > 1e-10 )
419
428
{
420
429
double extraRotate = 0.0 ;
421
430
rotationAxis *= 1 / sqrt (rotationAxisLengthSquared);
@@ -570,7 +579,7 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
570
579
if (pType->LeadTimeCalculate && pTarget)
571
580
this ->LastTargetCoord = pTarget->GetCoords ();
572
581
573
- pBullet->Velocity *= abs ((this ->Height - pBullet->Location .Z ) / pBullet->Velocity .Z );
582
+ pBullet->Velocity *= std:: abs ((this ->Height - pBullet->Location .Z ) / pBullet->Velocity .Z );
574
583
}
575
584
}
576
585
}
0 commit comments