Skip to content

Commit c317e0c

Browse files
committed
Fix two problems and optimize for Bombard
- Resolve the issue of the projectile that it will teleport when the height is set too low - Resolve the issue of the turning point exceeding the target position when the projectile speed is too fast - Negative height is not allowed now - Simplify some code
1 parent a1e26ba commit c317e0c

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/Ext/Bullet/Trajectories/BombardTrajectory.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
5858
INI_EX exINI(pINI);
5959

6060
this->Height.Read(exINI, pSection, "Trajectory.Bombard.Height");
61+
this->Height = Math::max(0.0, this->Height);
6162
this->FallPercent.Read(exINI, pSection, "Trajectory.Bombard.FallPercent");
6263
this->FallPercentShift.Read(exINI, pSection, "Trajectory.Bombard.FallPercentShift");
6364
this->FallScatter_Max.Read(exINI, pSection, "Trajectory.Bombard.FallScatter.Max");
@@ -153,14 +154,12 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
153154
if (this->BulletDetonatePreCheck(pBullet))
154155
return true;
155156

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

159-
if (this->IsFalling && !this->Type->FreeFallOnTarget && this->BulletDetonateRemainCheck(pBullet, pOwner))
159+
// Extra check for trajectory falling
160+
if (this->IsFalling && !this->Type->FreeFallOnTarget && this->BulletDetonateRemainCheck(pBullet))
160161
return true;
161162

162-
this->BulletVelocityChange(pBullet);
163-
164163
return false;
165164
}
166165

@@ -208,6 +207,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
208207
pBullet->Velocity *= pType->Trajectory_Speed / pBullet->Velocity.Magnitude();
209208

210209
this->CalculateDisperseBurst(pBullet);
210+
this->RemainingDistance += static_cast<int>(middleLocation.DistanceFrom(pBullet->SourceCoords) + pType->Trajectory_Speed);
211211
}
212212
else
213213
{
@@ -241,8 +241,9 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
241241
this->RefreshBulletLineTrail(pBullet);
242242

243243
pBullet->SetLocation(middleLocation);
244-
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : pExt->FirerHouse;
245-
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pBullet->Owner, pOwner, true);
244+
const auto pTechno = pBullet->Owner;
245+
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
246+
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
246247
}
247248
}
248249

@@ -496,7 +497,7 @@ bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
496497
return false;
497498
}
498499

499-
bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner)
500+
bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet)
500501
{
501502
const auto pType = this->Type;
502503
this->RemainingDistance -= static_cast<int>(pType->FallSpeed);
@@ -519,26 +520,23 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
519520

520521
if (!this->IsFalling)
521522
{
522-
if (pBullet->Location.Z + pBullet->Velocity.Z >= this->Height)
523+
this->RemainingDistance -= static_cast<int>(pType->Trajectory_Speed);
524+
525+
if (this->RemainingDistance < static_cast<int>(pType->Trajectory_Speed))
523526
{
524527
if (this->ToFalling)
525528
{
526529
this->IsFalling = true;
530+
this->RemainingDistance = 1;
527531
const auto pTarget = pBullet->Target;
528532
auto middleLocation = CoordStruct::Empty;
529533

530534
if (!pType->FreeFallOnTarget)
531535
{
532-
middleLocation = CoordStruct
533-
{
534-
static_cast<int>(pBullet->Location.X + pBullet->Velocity.X),
535-
static_cast<int>(pBullet->Location.Y + pBullet->Velocity.Y),
536-
static_cast<int>(pBullet->Location.Z + pBullet->Velocity.Z)
537-
};
538-
539536
if (pType->LeadTimeCalculate && pTarget)
540537
pBullet->TargetCoords += pTarget->GetCoords() - this->InitialTargetCoord + this->CalculateBulletLeadTime(pBullet);
541538

539+
middleLocation = pBullet->Location;
542540
pBullet->Velocity.X = static_cast<double>(pBullet->TargetCoords.X - middleLocation.X);
543541
pBullet->Velocity.Y = static_cast<double>(pBullet->TargetCoords.Y - middleLocation.Y);
544542
pBullet->Velocity.Z = static_cast<double>(pBullet->TargetCoords.Z - middleLocation.Z);
@@ -569,7 +567,8 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
569567

570568
pBullet->SetLocation(middleLocation);
571569
const auto pTechno = pBullet->Owner;
572-
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pTechno ? pTechno->Owner : pExt->FirerHouse, true);
570+
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
571+
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
573572
}
574573
else
575574
{
@@ -579,7 +578,7 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
579578
if (pType->LeadTimeCalculate && pTarget)
580579
this->LastTargetCoord = pTarget->GetCoords();
581580

582-
pBullet->Velocity *= std::abs((this->Height - pBullet->Location.Z) / pBullet->Velocity.Z);
581+
pBullet->Velocity *= this->RemainingDistance / pType->Trajectory_Speed;
583582
}
584583
}
585584
}

src/Ext/Bullet/Trajectories/BombardTrajectory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class BombardTrajectory final : public PhobosTrajectory
119119
void CalculateDisperseBurst(BulletClass* pBullet);
120120
bool BulletPrepareCheck(BulletClass* pBullet);
121121
bool BulletDetonatePreCheck(BulletClass* pBullet);
122-
bool BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner);
122+
bool BulletDetonateRemainCheck(BulletClass* pBullet);
123123
void BulletVelocityChange(BulletClass* pBullet);
124124
void RefreshBulletLineTrail(BulletClass* pBullet);
125125
};

0 commit comments

Comments
 (0)