From d00577b6d3cb6aac7b677a9ea48371dd35084996 Mon Sep 17 00:00:00 2001 From: CrimRecya <335958461@qq.com> Date: Fri, 4 Oct 2024 18:37:42 +0800 Subject: [PATCH] Fix merge --- .../Trajectories/ParabolaTrajectory.cpp | 130 +++++++----------- .../Bullet/Trajectories/ParabolaTrajectory.h | 16 +-- .../Bullet/Trajectories/PhobosTrajectory.cpp | 24 ---- 3 files changed, 61 insertions(+), 109 deletions(-) diff --git a/src/Ext/Bullet/Trajectories/ParabolaTrajectory.cpp b/src/Ext/Bullet/Trajectories/ParabolaTrajectory.cpp index 1bbc22f43..135f76503 100644 --- a/src/Ext/Bullet/Trajectories/ParabolaTrajectory.cpp +++ b/src/Ext/Bullet/Trajectories/ParabolaTrajectory.cpp @@ -5,9 +5,9 @@ #include #include -PhobosTrajectory* ParabolaTrajectoryType::CreateInstance() const +std::unique_ptr ParabolaTrajectoryType::CreateInstance() const { - return new ParabolaTrajectory(this); + return std::make_unique(this); } template @@ -128,10 +128,7 @@ bool ParabolaTrajectory::Save(PhobosStreamWriter& Stm) const void ParabolaTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity) { - if (!this->Type) // After load - this->Type = this->GetTrajectoryType(pBullet); - - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; this->LastTargetCoord = pBullet->TargetCoords; pBullet->Velocity = BulletVelocity::Empty; FootClass* const pTarget = abstract_cast(pBullet->Target); @@ -166,9 +163,6 @@ void ParabolaTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bu bool ParabolaTrajectory::OnAI(BulletClass* pBullet) { - if (!this->Type) // After load - this->Type = this->GetTrajectoryType(pBullet); - if (this->WaitOneFrame.IsTicking() && this->BulletPrepareCheck(pBullet)) return false; @@ -230,7 +224,7 @@ TrajectoryCheckReturnType ParabolaTrajectory::OnAITechnoCheck(BulletClass* pBull void ParabolaTrajectory::PrepareForOpenFire(BulletClass* pBullet) { - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; const AbstractClass* const pTarget = pBullet->Target; bool leadTimeCalculate = pType->LeadTimeCalculate && pTarget; CoordStruct theTargetCoords = leadTimeCalculate ? pTarget->GetCoords() : pBullet->TargetCoords; @@ -329,7 +323,7 @@ bool ParabolaTrajectory::BulletPrepareCheck(BulletClass* pBullet) void ParabolaTrajectory::CalculateBulletVelocityLeadTime(BulletClass* pBullet, CoordStruct* pSourceCoords, double gravity) { - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; if (pType->LeadTimeSimplify) // Only simple guess, not exact solution { @@ -371,7 +365,7 @@ void ParabolaTrajectory::CalculateBulletVelocityLeadTime(BulletClass* pBullet, C default: { // Assuming equal height - leadTime = static_cast((Unsorted::LeptonsPerCell << 2) / this->GetTrajectorySpeed(pBullet)); + leadTime = static_cast((Unsorted::LeptonsPerCell << 2) / this->Speed); break; } } @@ -454,36 +448,33 @@ void ParabolaTrajectory::CalculateBulletVelocityLeadTime(BulletClass* pBullet, C } case ParabolaFireMode::SpeedAndHeight: // Fixed horizontal speed and fixed max height { - // Step 1: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); - - // Step 2: Calculate the time when the projectile meets the target directly using horizontal velocity - const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, horizontalSpeed); + // Step 1: Calculate the time when the projectile meets the target directly using horizontal velocity + const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, this->Speed); - // Step 3: Substitute the time into the calculation of the attack coordinates + // Step 2: Substitute the time into the calculation of the attack coordinates pBullet->TargetCoords += (targetCoords - this->LastTargetCoord) * (speedFixMult * meetTime); const CoordStruct destinationCoords = pBullet->TargetCoords - *pSourceCoords; - // Step 4: Check if it is an unsolvable solution + // Step 3: Check if it is an unsolvable solution if (meetTime <= 1e-10 || destinationCoords.Magnitude() <= 1e-10) break; - // Step 5: Calculate the ratio of horizontal velocity to horizontal distance + // Step 4: Calculate the ratio of horizontal velocity to horizontal distance const double horizontalDistance = Point2D{ destinationCoords.X, destinationCoords.Y }.Magnitude(); - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 6: Calculate the horizontal component of the projectile velocity + // Step 5: Calculate the horizontal component of the projectile velocity pBullet->Velocity.X = destinationCoords.X * mult; pBullet->Velocity.Y = destinationCoords.Y * mult; - // Step 7: Determine the maximum height that the projectile should reach + // Step 6: Determine the maximum height that the projectile should reach const int sourceHeight = pSourceCoords->Z, targetHeight = sourceHeight + destinationCoords.Z; const int maxHeight = destinationCoords.Z > 0 ? this->ThrowHeight + targetHeight : this->ThrowHeight + sourceHeight; - // Step 8: Calculate the vertical component of the projectile velocity + // Step 7: Calculate the vertical component of the projectile velocity pBullet->Velocity.Z = sqrt(2 * gravity * (maxHeight - sourceHeight)) + gravity / 2; - // Step 9: Record whether it requires additional checks during the flight + // Step 8: Record whether it requires additional checks during the flight this->CheckIfNeedExtraCheck(pBullet); return; } @@ -525,68 +516,62 @@ void ParabolaTrajectory::CalculateBulletVelocityLeadTime(BulletClass* pBullet, C } case ParabolaFireMode::SpeedAndAngle: // Fixed horizontal speed and fixed fire angle { - // Step 1: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); + // Step 1: Calculate the time when the projectile meets the target directly using horizontal velocity + const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, this->Speed); - // Step 2: Calculate the time when the projectile meets the target directly using horizontal velocity - const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, horizontalSpeed); - - // Step 3: Substitute the time into the calculation of the attack coordinates + // Step 2: Substitute the time into the calculation of the attack coordinates pBullet->TargetCoords += (targetCoords - this->LastTargetCoord) * (speedFixMult * meetTime); const CoordStruct destinationCoords = pBullet->TargetCoords - *pSourceCoords; - // Step 4: Check if it is an unsolvable solution + // Step 3: Check if it is an unsolvable solution if (meetTime <= 1e-10 || destinationCoords.Magnitude() <= 1e-10) break; - // Step 5: Calculate the ratio of horizontal velocity to horizontal distance + // Step 4: Calculate the ratio of horizontal velocity to horizontal distance const double horizontalDistance = Point2D{ destinationCoords.X, destinationCoords.Y }.Magnitude(); - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 6: Calculate each horizontal component of the projectile velocity + // Step 5: Calculate each horizontal component of the projectile velocity pBullet->Velocity.X = destinationCoords.X * mult; pBullet->Velocity.Y = destinationCoords.Y * mult; - // Step 7: Calculate whole horizontal component of the projectile velocity + // Step 6: Calculate whole horizontal component of the projectile velocity const double horizontalVelocity = horizontalDistance * mult; - // Step 8: Read the appropriate fire angle + // Step 7: Read the appropriate fire angle double radian = pType->LaunchAngle * Math::Pi / 180.0; radian = (radian >= Math::HalfPi || radian <= -Math::HalfPi) ? (Math::HalfPi / 3) : radian; - // Step 9: Calculate the vertical component of the projectile velocity + // Step 8: Calculate the vertical component of the projectile velocity pBullet->Velocity.Z = horizontalVelocity * Math::tan(radian) + gravity / 2; - // Step 10: Record whether it requires additional checks during the flight + // Step 9: Record whether it requires additional checks during the flight this->CheckIfNeedExtraCheck(pBullet); return; } default: // Fixed horizontal speed and aim at the target { - // Step 1: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); - - // Step 2: Calculate the time when the projectile meets the target directly using horizontal velocity - const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, horizontalSpeed); + // Step 1: Calculate the time when the projectile meets the target directly using horizontal velocity + const double meetTime = this->SolveFixedSpeedMeetTime(pSourceCoords, &targetCoords, &offsetCoords, this->Speed); - // Step 3: Substitute the time into the calculation of the attack coordinates + // Step 2: Substitute the time into the calculation of the attack coordinates pBullet->TargetCoords += (targetCoords - this->LastTargetCoord) * (speedFixMult * meetTime); const CoordStruct destinationCoords = pBullet->TargetCoords - *pSourceCoords; - // Step 4: Check if it is an unsolvable solution + // Step 3: Check if it is an unsolvable solution if (meetTime <= 1e-10 || destinationCoords.Magnitude() <= 1e-10) break; - // Step 5: Calculate the ratio of horizontal velocity to horizontal distance + // Step 4: Calculate the ratio of horizontal velocity to horizontal distance const double horizontalDistance = Point2D{ destinationCoords.X, destinationCoords.Y }.Magnitude(); - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 6: Calculate the projectile velocity + // Step 5: Calculate the projectile velocity pBullet->Velocity.X = destinationCoords.X * mult; pBullet->Velocity.Y = destinationCoords.Y * mult; - pBullet->Velocity.Z = destinationCoords.Z * mult + (gravity * horizontalDistance) / (2 * horizontalSpeed) + gravity / 2; + pBullet->Velocity.Z = destinationCoords.Z * mult + (gravity * horizontalDistance) / (2 * this->Speed) + gravity / 2; - // Step 7: Record whether it requires additional checks during the flight + // Step 6: Record whether it requires additional checks during the flight this->CheckIfNeedExtraCheck(pBullet); return; } @@ -601,7 +586,7 @@ void ParabolaTrajectory::CalculateBulletVelocityLeadTime(BulletClass* pBullet, C void ParabolaTrajectory::CalculateBulletVelocityRightNow(BulletClass* pBullet, CoordStruct* pSourceCoords, double gravity) { - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; // Calculate horizontal distance const CoordStruct distanceCoords = pBullet->TargetCoords - *pSourceCoords; const double distance = distanceCoords.Magnitude(); @@ -661,13 +646,10 @@ void ParabolaTrajectory::CalculateBulletVelocityRightNow(BulletClass* pBullet, C // Step 2: Calculate the vertical component of the projectile velocity pBullet->Velocity.Z = sqrt(2 * gravity * (maxHeight - sourceHeight)); - // Step 3: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); - - // Step 4: Calculate the ratio of horizontal velocity to horizontal distance - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; + // Step 3: Calculate the ratio of horizontal velocity to horizontal distance + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 5: Calculate the horizontal component of the projectile velocity + // Step 4: Calculate the horizontal component of the projectile velocity pBullet->Velocity.X = distanceCoords.X * mult; pBullet->Velocity.Y = distanceCoords.Y * mult; break; @@ -695,36 +677,30 @@ void ParabolaTrajectory::CalculateBulletVelocityRightNow(BulletClass* pBullet, C } case ParabolaFireMode::SpeedAndAngle: // Fixed horizontal speed and fixed fire angle { - // Step 1: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); + // Step 1: Calculate the ratio of horizontal velocity to horizontal distance + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 2: Calculate the ratio of horizontal velocity to horizontal distance - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; - - // Step 3: Calculate the horizontal component of the projectile velocity + // Step 2: Calculate the horizontal component of the projectile velocity pBullet->Velocity.X = distanceCoords.X * mult; pBullet->Velocity.Y = distanceCoords.Y * mult; - // Step 4: Read the appropriate fire angle + // Step 3: Read the appropriate fire angle double radian = pType->LaunchAngle * Math::Pi / 180.0; radian = (radian >= Math::HalfPi || radian <= -Math::HalfPi) ? (Math::HalfPi / 3) : radian; - // Step 5: Calculate the vertical component of the projectile velocity - pBullet->Velocity.Z = horizontalSpeed * Math::tan(radian); + // Step 4: Calculate the vertical component of the projectile velocity + pBullet->Velocity.Z = this->Speed * Math::tan(radian); break; } default: // Fixed horizontal speed and aim at the target { - // Step 1: Read the appropriate horizontal speed - const double horizontalSpeed = this->GetTrajectorySpeed(pBullet); - - // Step 2: Calculate the ratio of horizontal velocity to horizontal distance - const double mult = horizontalDistance > 1e-10 ? horizontalSpeed / horizontalDistance : 1.0; + // Step 1: Calculate the ratio of horizontal velocity to horizontal distance + const double mult = horizontalDistance > 1e-10 ? this->Speed / horizontalDistance : 1.0; - // Step 3: Calculate the projectile velocity + // Step 2: Calculate the projectile velocity pBullet->Velocity.X = distanceCoords.X * mult; pBullet->Velocity.Y = distanceCoords.Y * mult; - pBullet->Velocity.Z = distanceCoords.Z * mult + (gravity * horizontalDistance) / (2 * horizontalSpeed); + pBullet->Velocity.Z = distanceCoords.Z * mult + (gravity * horizontalDistance) / (2 * this->Speed); break; } } @@ -749,7 +725,7 @@ void ParabolaTrajectory::CheckIfNeedExtraCheck(BulletClass* pBullet) } default: // Fixed horizontal speed and blabla { - this->NeedExtraCheck = this->GetTrajectorySpeed(pBullet) > 256.0; + this->NeedExtraCheck = this->Speed > 256.0; break; } } @@ -939,7 +915,7 @@ bool ParabolaTrajectory::CalculateBulletVelocityAfterBounce(BulletClass* pBullet --this->BounceTimes; this->ShouldBounce = false; - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; const BulletVelocity groundNormalVector = this->GetGroundNormalVector(pBullet, pCell); pBullet->Velocity = (this->LastVelocity - groundNormalVector * (this->LastVelocity * groundNormalVector) * 2) * pType->BounceCoefficient; pBullet->Velocity.Z -= gravity; @@ -1088,7 +1064,7 @@ bool ParabolaTrajectory::BulletDetonatePreCheck(BulletClass* pBullet) if (this->ShouldDetonate) return true; - ParabolaTrajectoryType* const pType = this->Type; + const ParabolaTrajectoryType* const pType = this->Type; if (pType->DetonationHeight >= 0 && pBullet->Velocity.Z < 1e-10 && (pBullet->Location.Z - pBullet->SourceCoords.Z) < pType->DetonationHeight) return true; diff --git a/src/Ext/Bullet/Trajectories/ParabolaTrajectory.h b/src/Ext/Bullet/Trajectories/ParabolaTrajectory.h index 2a6040340..0deacb8e8 100644 --- a/src/Ext/Bullet/Trajectories/ParabolaTrajectory.h +++ b/src/Ext/Bullet/Trajectories/ParabolaTrajectory.h @@ -40,7 +40,7 @@ class ParabolaTrajectoryType final : public PhobosTrajectoryType virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override; virtual bool Save(PhobosStreamWriter& Stm) const override; - virtual PhobosTrajectory* CreateInstance() const override; + virtual std::unique_ptr CreateInstance() const override; virtual void Read(CCINIClass* const pINI, const char* pSection) override; Valueable DetonationDistance; @@ -74,12 +74,12 @@ class ParabolaTrajectory final : public PhobosTrajectory public: ParabolaTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { } - ParabolaTrajectory(PhobosTrajectoryType const* pType) : PhobosTrajectory(TrajectoryFlag::Parabola) - , Type { static_cast(const_cast(pType)) } - , ThrowHeight { Type->ThrowHeight > 0 ? Type->ThrowHeight : 600 } - , BounceTimes { Type->BounceTimes } - , OffsetCoord { static_cast(Type->OffsetCoord) } - , UseDisperseBurst { Type->UseDisperseBurst } + ParabolaTrajectory(ParabolaTrajectoryType const* trajType) : PhobosTrajectory(TrajectoryFlag::Parabola, trajType->Trajectory_Speed) + , Type { trajType } + , ThrowHeight { trajType->ThrowHeight > 0 ? trajType->ThrowHeight : 600 } + , BounceTimes { trajType->BounceTimes } + , OffsetCoord { trajType->OffsetCoord.Get() } + , UseDisperseBurst { trajType->UseDisperseBurst } , ShouldDetonate { false } , ShouldBounce { false } , NeedExtraCheck { false } @@ -100,7 +100,7 @@ class ParabolaTrajectory final : public PhobosTrajectory virtual TrajectoryCheckReturnType OnAITargetCoordCheck(BulletClass* pBullet) override; virtual TrajectoryCheckReturnType OnAITechnoCheck(BulletClass* pBullet, TechnoClass* pTechno) override; - ParabolaTrajectoryType* Type; + const ParabolaTrajectoryType* Type; int ThrowHeight; int BounceTimes; CoordStruct OffsetCoord; diff --git a/src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp b/src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp index 0051aa9bd..3f237fca5 100644 --- a/src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp +++ b/src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp @@ -7,10 +7,7 @@ #include "StraightTrajectory.h" #include "BombardTrajectory.h" -#include "DisperseTrajectory.h" -#include "EngraveTrajectory.h" #include "ParabolaTrajectory.h" -#include "TracingTrajectory.h" TrajectoryTypePointer::TrajectoryTypePointer(TrajectoryFlag flag) { @@ -22,18 +19,9 @@ TrajectoryTypePointer::TrajectoryTypePointer(TrajectoryFlag flag) case TrajectoryFlag::Bombard: _ptr = std::make_unique(); return; - case TrajectoryFlag::Disperse: - _ptr = std::make_unique(); - return; - case TrajectoryFlag::Engrave: - _ptr = std::make_unique(); - return; case TrajectoryFlag::Parabola: _ptr = std::make_unique(); return; - case TrajectoryFlag::Tracing: - _ptr = std::make_unique(); - return; } _ptr.reset(); } @@ -49,10 +37,7 @@ namespace detail { {"Straight", TrajectoryFlag::Straight}, {"Bombard" ,TrajectoryFlag::Bombard}, - {"Disperse", TrajectoryFlag::Disperse}, - {"Engrave" ,TrajectoryFlag::Engrave}, {"Parabola", TrajectoryFlag::Parabola}, - {"Tracing" ,TrajectoryFlag::Tracing}, }; for (auto [name, flag] : FlagNames) { @@ -133,18 +118,9 @@ bool TrajectoryPointer::Load(PhobosStreamReader& Stm, bool registerForChange) case TrajectoryFlag::Bombard: _ptr = std::make_unique(noinit_t {}); break; - case TrajectoryFlag::Disperse: - _ptr = std::make_unique(noinit_t {}); - break; - case TrajectoryFlag::Engrave: - _ptr = std::make_unique(noinit_t {}); - break; case TrajectoryFlag::Parabola: _ptr = std::make_unique(noinit_t {}); break; - case TrajectoryFlag::Tracing: - _ptr = std::make_unique(noinit_t {}); - break; default: _ptr.reset(); break;