Skip to content

Commit

Permalink
Add new features
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimRecya committed May 18, 2024
1 parent 52f73f0 commit d1a88fe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 21 deletions.
2 changes: 2 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ Trajectory.Bombard.Height=0.0 ; double
- `Trajectory.Disperse.UniqueCurve` controls whether to enable simulated Qian Xuesen trajectory. After enabling this, it will NOT respect the following 13 items and `Trajectory.Speed`.
- `Trajectory.Disperse.PreAimCoord` controls the initial flight direction of the projectile, and after reaching this coordinate, it will begin to turn towards the target direction. When it is set to 0,0,0 , it will directly face the target.
- `Trajectory.Disperse.FacingCoord` controls whether the forward direction in `Trajectory.Disperse.PreAimCoord` is depending on the orientation of the firer. By default, it will depend on the vector between the firer and the target.
- `Trajectory.Disperse.ReduceCoord` controls whether `Trajectory.Disperse.PreAimCoord` defines the initial movement coordinates when the attack distance is 10 cells, and the actual initial movement coordinates will change with the length of the attack distance. It can be simply understood as an optimization term aimed at ensuring hits at close range.
- `Trajectory.Disperse.LaunchSpeed` controls the initial flight speed of the projectile, it will be directly reduced to this value if it exceeds `Trajectory.Speed`.
- `Trajectory.Disperse.Acceleration` controls the acceleration of the projectile's flight speed, increasing the speed per frame according to this value, the final speed will not exceed `Trajectory.Speed`.
- `Trajectory.Disperse.ROT` controls the turning speed of the projectile and can determine the turning radius of the projectile. The turning speed will increase with the increase of speed.
Expand Down Expand Up @@ -600,6 +601,7 @@ Trajectory=Disperse ; Trajectory type
Trajectory.Disperse.UniqueCurve=false ; boolean
Trajectory.Disperse.PreAimCoord=0,0,0 ; integer - Forward,Lateral,Height
Trajectory.Disperse.FacingCoord=false ; boolean
Trajectory.Disperse.ReduceCoord=false ; boolean
Trajectory.Disperse.LaunchSpeed=0 ; floating point value
Trajectory.Disperse.Acceleration=10.0 ; floating point value
Trajectory.Disperse.ROT=10.0 ; floating point value
Expand Down
79 changes: 61 additions & 18 deletions src/Ext/Bullet/Trajectories/DisperseTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bool DisperseTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChang
.Process(this->UniqueCurve, false)
.Process(this->PreAimCoord, false)
.Process(this->FacingCoord, false)
.Process(this->ReduceCoord, false)
.Process(this->LaunchSpeed, false)
.Process(this->Acceleration, false)
.Process(this->ROT, false)
Expand Down Expand Up @@ -52,6 +53,7 @@ bool DisperseTrajectoryType::Save(PhobosStreamWriter& Stm) const
.Process(this->UniqueCurve)
.Process(this->PreAimCoord)
.Process(this->FacingCoord)
.Process(this->ReduceCoord)
.Process(this->LaunchSpeed)
.Process(this->Acceleration)
.Process(this->ROT)
Expand Down Expand Up @@ -85,6 +87,7 @@ void DisperseTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
this->UniqueCurve.Read(exINI, pSection, "Trajectory.Disperse.UniqueCurve");
this->PreAimCoord.Read(exINI, pSection, "Trajectory.Disperse.PreAimCoord");
this->FacingCoord.Read(exINI, pSection, "Trajectory.Disperse.FacingCoord");
this->ReduceCoord.Read(exINI, pSection, "Trajectory.Disperse.ReduceCoord");
this->LaunchSpeed.Read(exINI, pSection, "Trajectory.Disperse.LaunchSpeed");
this->Acceleration.Read(exINI, pSection, "Trajectory.Disperse.Acceleration");
this->ROT.Read(exINI, pSection, "Trajectory.Disperse.ROT");
Expand Down Expand Up @@ -117,6 +120,7 @@ bool DisperseTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
.Process(this->UniqueCurve)
.Process(this->PreAimCoord)
.Process(this->FacingCoord)
.Process(this->ReduceCoord)
.Process(this->LaunchSpeed)
.Process(this->Acceleration)
.Process(this->ROT)
Expand All @@ -141,7 +145,7 @@ bool DisperseTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
.Process(this->WeaponToAllies)
.Process(this->InStraight)
.Process(this->TargetInAir)
.Process(this->FinalHeight)
.Process(this->OriginalDistance)
.Process(this->LastTargetCoord)
.Process(this->LastReviseMult)
.Process(this->FirepowerMult)
Expand All @@ -158,6 +162,7 @@ bool DisperseTrajectory::Save(PhobosStreamWriter& Stm) const
.Process(this->UniqueCurve)
.Process(this->PreAimCoord)
.Process(this->FacingCoord)
.Process(this->ReduceCoord)
.Process(this->LaunchSpeed)
.Process(this->Acceleration)
.Process(this->ROT)
Expand All @@ -182,7 +187,7 @@ bool DisperseTrajectory::Save(PhobosStreamWriter& Stm) const
.Process(this->WeaponToAllies)
.Process(this->InStraight)
.Process(this->TargetInAir)
.Process(this->FinalHeight)
.Process(this->OriginalDistance)
.Process(this->LastTargetCoord)
.Process(this->LastReviseMult)
.Process(this->FirepowerMult)
Expand All @@ -198,6 +203,7 @@ void DisperseTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bu
this->UniqueCurve = pType->UniqueCurve;
this->PreAimCoord = pType->PreAimCoord;
this->FacingCoord = pType->FacingCoord;
this->ReduceCoord = pType->ReduceCoord;
this->LaunchSpeed = pType->LaunchSpeed;
this->Acceleration = pType->Acceleration > 0.1 ? pType->Acceleration : 0.1;
this->ROT = pType->ROT > 0.1 ? pType->ROT : 0.1;
Expand Down Expand Up @@ -228,7 +234,7 @@ void DisperseTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bu
if (ObjectClass* pTarget = abstract_cast<ObjectClass*>(pBullet->Target))
this->TargetInAir = (pTarget->GetHeight() > 0);

this->FinalHeight = static_cast<int>(pBullet->TargetCoords.DistanceFrom(pBullet->SourceCoords));
this->OriginalDistance = static_cast<int>(pBullet->TargetCoords.DistanceFrom(pBullet->SourceCoords));
this->LastTargetCoord = pBullet->TargetCoords;
this->FirepowerMult = 1.0;

Expand All @@ -246,20 +252,20 @@ void DisperseTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bu
pBullet->Velocity.Y = 0;
pBullet->Velocity.Z = 4.0;

if (this->FinalHeight < 1280)
if (this->OriginalDistance < 1280)
{
this->FinalHeight = static_cast<int>(this->FinalHeight * 1.2) + 512;
this->SuicideAboveRange = 4 * this->FinalHeight;
this->OriginalDistance = static_cast<int>(this->OriginalDistance * 1.2) + 512;
this->SuicideAboveRange = 4 * this->OriginalDistance;
}
else if (this->FinalHeight > 3840)
else if (this->OriginalDistance > 3840)
{
this->FinalHeight = static_cast<int>(this->FinalHeight * 0.4) + 512;
this->SuicideAboveRange = 2 * this->FinalHeight;
this->OriginalDistance = static_cast<int>(this->OriginalDistance * 0.4) + 512;
this->SuicideAboveRange = 2 * this->OriginalDistance;
}
else
{
this->FinalHeight = 2048;
this->SuicideAboveRange = 3 * this->FinalHeight;
this->OriginalDistance = 2048;
this->SuicideAboveRange = 3 * this->OriginalDistance;
}
}
else if (this->PreAimCoord.X == 0 && this->PreAimCoord.Y == 0 && this->PreAimCoord.Z == 0)
Expand Down Expand Up @@ -295,9 +301,30 @@ void DisperseTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, Bu
RotateAngle = Math::atan2(pBullet->TargetCoords.Y - TheSource.Y , pBullet->TargetCoords.X - TheSource.X);
}

pBullet->Velocity.X = this->PreAimCoord.X * Math::cos(RotateAngle) + this->PreAimCoord.Y * Math::sin(RotateAngle);
pBullet->Velocity.Y = this->PreAimCoord.X * Math::sin(RotateAngle) - this->PreAimCoord.Y * Math::cos(RotateAngle);
pBullet->Velocity.Z = this->PreAimCoord.Z;
double CoordMult = this->OriginalDistance / (32768 / this->ROT);

if (this->ReduceCoord && CoordMult < 1.0)
{
CoordStruct TheAimCoord
{
static_cast<int>(this->PreAimCoord.X * Math::cos(RotateAngle) + this->PreAimCoord.Y * Math::sin(RotateAngle)),
static_cast<int>(this->PreAimCoord.X * Math::sin(RotateAngle) - this->PreAimCoord.Y * Math::cos(RotateAngle)),
this->PreAimCoord.Z
};

CoordStruct TheDistance = pBullet->TargetCoords - pBullet->SourceCoords;
CoordStruct TheDifferece = TheDistance - TheAimCoord;

pBullet->Velocity.X = TheAimCoord.X + (1 - CoordMult) * TheDifferece.X;
pBullet->Velocity.Y = TheAimCoord.Y + (1 - CoordMult) * TheDifferece.Y;
pBullet->Velocity.Z = TheAimCoord.Z + (1 - CoordMult) * TheDifferece.Z;
}
else
{
pBullet->Velocity.X = this->PreAimCoord.X * Math::cos(RotateAngle) + this->PreAimCoord.Y * Math::sin(RotateAngle);
pBullet->Velocity.Y = this->PreAimCoord.X * Math::sin(RotateAngle) - this->PreAimCoord.Y * Math::cos(RotateAngle);
pBullet->Velocity.Z = this->PreAimCoord.Z;
}

if (CalculateBulletVelocity(pBullet, this->LaunchSpeed))
this->SuicideAboveRange = 0.1;
Expand Down Expand Up @@ -371,7 +398,8 @@ bool DisperseTrajectory::OnAI(BulletClass* pBullet)
if (StandardVelocityChange(pBullet))
return true;
}
else if (pBullet->SourceCoords.DistanceFromSquared(pBullet->Location) >= this->PreAimCoord.MagnitudeSquared())
else if (!this->ReduceCoord ? pBullet->SourceCoords.DistanceFromSquared(pBullet->Location) >= this->PreAimCoord.MagnitudeSquared()
: pBullet->SourceCoords.DistanceFrom(pBullet->Location) * 2560 >= this->PreAimCoord.Magnitude() * this->OriginalDistance)
{
this->InStraight = true;

Expand All @@ -381,6 +409,18 @@ bool DisperseTrajectory::OnAI(BulletClass* pBullet)

VelocityUp = true;
}
else if (!this->InStraight)
{
if (this->RetargetRadius != 0 && BulletRetargetTechno(pBullet, pOwner))
return true;

if (!this->ReduceCoord ? pBullet->SourceCoords.DistanceFromSquared(pBullet->Location) >= this->PreAimCoord.MagnitudeSquared()
: pBullet->SourceCoords.DistanceFrom(pBullet->Location) * 2560 >= this->PreAimCoord.Magnitude() * this->OriginalDistance)
{
if (StandardVelocityChange(pBullet))
return true;
}
}

if (VelocityUp && CalculateBulletVelocity(pBullet, this->LaunchSpeed))
return true;
Expand Down Expand Up @@ -518,10 +558,10 @@ bool DisperseTrajectory::CurveVelocityChange(BulletClass* pBullet)

if (!this->InStraight)
{
int OffHeight = this->FinalHeight - 1600;
int OffHeight = this->OriginalDistance - 1600;

if (this->FinalHeight < 3200)
OffHeight = this->FinalHeight / 2;
if (this->OriginalDistance < 3200)
OffHeight = this->OriginalDistance / 2;

CoordStruct HorizonVelocity { TargetLocation.X - pBullet->Location.X, TargetLocation.Y - pBullet->Location.Y, 0 };
double HorizonDistance = HorizonVelocity.Magnitude();
Expand Down Expand Up @@ -686,6 +726,9 @@ bool DisperseTrajectory::ChangeBulletVelocity(BulletClass* pBullet, CoordStruct
pBullet->Velocity.X = TargetVelocity.X;
pBullet->Velocity.Y = TargetVelocity.Y;
pBullet->Velocity.Z = TargetVelocity.Z;

if (!Curve && this->LockDirection)
this->InStraight = true;
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/Ext/Bullet/Trajectories/DisperseTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DisperseTrajectoryType final : public PhobosTrajectoryType
, UniqueCurve { false }
, PreAimCoord { { 0, 0, 0 } }
, FacingCoord { false }
, ReduceCoord { false }
, LaunchSpeed { 0 }
, Acceleration { 10.0 }
, ROT { 10.0 }
Expand Down Expand Up @@ -41,6 +42,7 @@ class DisperseTrajectoryType final : public PhobosTrajectoryType
Valueable<bool> UniqueCurve;
Valueable<CoordStruct> PreAimCoord;
Valueable<bool> FacingCoord;
Valueable<bool> ReduceCoord;
Valueable<double> LaunchSpeed;
Valueable<double> Acceleration;
Valueable<double> ROT;
Expand Down Expand Up @@ -72,6 +74,7 @@ class DisperseTrajectory final : public PhobosTrajectory
, UniqueCurve { false }
, PreAimCoord {}
, FacingCoord { false }
, ReduceCoord { false }
, LaunchSpeed { 0 }
, Acceleration { 10.0 }
, ROT { 10.0 }
Expand All @@ -97,7 +100,7 @@ class DisperseTrajectory final : public PhobosTrajectory
, InStraight { false }
, Accelerate { true }
, TargetInAir { false }
, FinalHeight { 0 }
, OriginalDistance { 0 }
, LastTargetCoord {}
, LastReviseMult { 0 }
, FirepowerMult { 1.0 }
Expand All @@ -107,6 +110,7 @@ class DisperseTrajectory final : public PhobosTrajectory
, UniqueCurve { false }
, PreAimCoord {}
, FacingCoord { false }
, ReduceCoord { false }
, LaunchSpeed { 0 }
, Acceleration { 10.0 }
, ROT { 10.0 }
Expand All @@ -132,7 +136,7 @@ class DisperseTrajectory final : public PhobosTrajectory
, InStraight { false }
, Accelerate { true }
, TargetInAir { false }
, FinalHeight { 0 }
, OriginalDistance { 0 }
, LastTargetCoord {}
, LastReviseMult { 0 }
, FirepowerMult { 1.0 }
Expand All @@ -151,6 +155,7 @@ class DisperseTrajectory final : public PhobosTrajectory
bool UniqueCurve;
CoordStruct PreAimCoord;
bool FacingCoord;
bool ReduceCoord;
double LaunchSpeed;
double Acceleration;
double ROT;
Expand All @@ -176,7 +181,7 @@ class DisperseTrajectory final : public PhobosTrajectory
bool InStraight;
bool Accelerate;
bool TargetInAir;
int FinalHeight;
int OriginalDistance;
CoordStruct LastTargetCoord;
double LastReviseMult;
double FirepowerMult;
Expand Down

0 comments on commit d1a88fe

Please sign in to comment.