Skip to content

Commit

Permalink
Fix two problems and optimize for Bombard
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
CrimRecya committed Feb 12, 2025
1 parent a1e26ba commit c317e0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
35 changes: 17 additions & 18 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
INI_EX exINI(pINI);

this->Height.Read(exINI, pSection, "Trajectory.Bombard.Height");
this->Height = Math::max(0.0, this->Height);
this->FallPercent.Read(exINI, pSection, "Trajectory.Bombard.FallPercent");
this->FallPercentShift.Read(exINI, pSection, "Trajectory.Bombard.FallPercentShift");
this->FallScatter_Max.Read(exINI, pSection, "Trajectory.Bombard.FallScatter.Max");
Expand Down Expand Up @@ -153,14 +154,12 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
if (this->BulletDetonatePreCheck(pBullet))
return true;

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

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

this->BulletVelocityChange(pBullet);

return false;
}

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

this->CalculateDisperseBurst(pBullet);
this->RemainingDistance += static_cast<int>(middleLocation.DistanceFrom(pBullet->SourceCoords) + pType->Trajectory_Speed);
}
else
{
Expand Down Expand Up @@ -241,8 +241,9 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
this->RefreshBulletLineTrail(pBullet);

pBullet->SetLocation(middleLocation);
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pBullet->Owner, pOwner, true);
const auto pTechno = pBullet->Owner;
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
}
}

Expand Down Expand Up @@ -496,7 +497,7 @@ bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
return false;
}

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

if (!this->IsFalling)
{
if (pBullet->Location.Z + pBullet->Velocity.Z >= this->Height)
this->RemainingDistance -= static_cast<int>(pType->Trajectory_Speed);

if (this->RemainingDistance < static_cast<int>(pType->Trajectory_Speed))
{
if (this->ToFalling)
{
this->IsFalling = true;
this->RemainingDistance = 1;
const auto pTarget = pBullet->Target;
auto middleLocation = CoordStruct::Empty;

if (!pType->FreeFallOnTarget)
{
middleLocation = CoordStruct
{
static_cast<int>(pBullet->Location.X + pBullet->Velocity.X),
static_cast<int>(pBullet->Location.Y + pBullet->Velocity.Y),
static_cast<int>(pBullet->Location.Z + pBullet->Velocity.Z)
};

if (pType->LeadTimeCalculate && pTarget)
pBullet->TargetCoords += pTarget->GetCoords() - this->InitialTargetCoord + this->CalculateBulletLeadTime(pBullet);

middleLocation = pBullet->Location;
pBullet->Velocity.X = static_cast<double>(pBullet->TargetCoords.X - middleLocation.X);
pBullet->Velocity.Y = static_cast<double>(pBullet->TargetCoords.Y - middleLocation.Y);
pBullet->Velocity.Z = static_cast<double>(pBullet->TargetCoords.Z - middleLocation.Z);
Expand Down Expand Up @@ -569,7 +567,8 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)

pBullet->SetLocation(middleLocation);
const auto pTechno = pBullet->Owner;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pTechno ? pTechno->Owner : pExt->FirerHouse, true);
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
}
else
{
Expand All @@ -579,7 +578,7 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
if (pType->LeadTimeCalculate && pTarget)
this->LastTargetCoord = pTarget->GetCoords();

pBullet->Velocity *= std::abs((this->Height - pBullet->Location.Z) / pBullet->Velocity.Z);
pBullet->Velocity *= this->RemainingDistance / pType->Trajectory_Speed;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Bullet/Trajectories/BombardTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BombardTrajectory final : public PhobosTrajectory
void CalculateDisperseBurst(BulletClass* pBullet);
bool BulletPrepareCheck(BulletClass* pBullet);
bool BulletDetonatePreCheck(BulletClass* pBullet);
bool BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner);
bool BulletDetonateRemainCheck(BulletClass* pBullet);
void BulletVelocityChange(BulletClass* pBullet);
void RefreshBulletLineTrail(BulletClass* pBullet);
};

0 comments on commit c317e0c

Please sign in to comment.