Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[General Purpose] New Parabola trajectory #1374

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
613ccb2
Core
CrimRecya Sep 4, 2024
1255ae6
Docs
CrimRecya Sep 4, 2024
2fb125f
Others
CrimRecya Sep 4, 2024
2fd854b
New function
CrimRecya Sep 4, 2024
8480e05
Fix `double`, add notes, change enum and revert `trajectory.speed`
CrimRecya Sep 5, 2024
4742533
Update doc
CrimRecya Sep 5, 2024
22579b7
Small fix
CrimRecya Sep 9, 2024
6b22a62
fix doc
CrimRecya Sep 10, 2024
fc0a41c
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Sep 15, 2024
de32af2
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Sep 18, 2024
ce32f2c
Change read enum
CrimRecya Sep 19, 2024
81751df
New function cooperate with Disperse
CrimRecya Sep 20, 2024
326dcf8
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Sep 23, 2024
228d88b
Update with new template
CrimRecya Sep 23, 2024
73376b6
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Sep 28, 2024
a76a734
Optimize
CrimRecya Sep 28, 2024
4d7e911
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Oct 4, 2024
d00577b
Fix merge
CrimRecya Oct 4, 2024
0961d8d
Fix merge
CrimRecya Oct 4, 2024
c7a5092
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Oct 4, 2024
2cfea20
Fix merge
CrimRecya Oct 4, 2024
a3a79ce
Reduce the error during long-distance attacks in Angle Mode to improv…
CrimRecya Oct 5, 2024
3486a5c
Improve inspection accuracy
CrimRecya Oct 6, 2024
483584e
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Oct 6, 2024
71abf6e
Fix merge
CrimRecya Oct 6, 2024
6defd70
Use get instead of static cast
CrimRecya Oct 11, 2024
a389b40
Small fix cur burst idx
CrimRecya Oct 11, 2024
7fcbd0a
Small fix
CrimRecya Oct 11, 2024
ae25e1c
Small fix
CrimRecya Oct 11, 2024
90d256d
Fix inaccurate lead time calculate
CrimRecya Oct 12, 2024
ae12afa
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Nov 7, 2024
7bcb563
Const auto
CrimRecya Nov 7, 2024
fd85bf2
Clear up
CrimRecya Nov 27, 2024
8e74984
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Nov 27, 2024
b444626
Fix doc
CrimRecya Dec 26, 2024
62a1909
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Dec 26, 2024
8ddf1de
Remove useless sanity check
CrimRecya Dec 27, 2024
47b0a25
Synchronize
CrimRecya Dec 27, 2024
fdfbc4e
Synchronize
CrimRecya Dec 29, 2024
5616cf5
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Dec 29, 2024
0fdfa55
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Jan 15, 2025
32c90bd
")"
DeathFishAtEase Feb 2, 2025
dc9b450
Merge branch 'develop' into develop-trajectory-parabola
CrimRecya Feb 3, 2025
9eeed89
Fix merge
CrimRecya Feb 3, 2025
c25897b
Merge remote-tracking branch 'upstream/develop' into develop-trajecto…
CrimRecya Feb 8, 2025
d17be2a
Review and add some comment
CrimRecya Feb 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ This page lists all the individual contributions to the project by their author.
- Re-enable the Veinhole Monster and Weeds from TS
- Recreate the weed-charging of SWs like the TS Chemical Missile
- Allow to change the speed of gas particles
- **CrimRecya**
- New Parabola trajectory
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
2 changes: 2 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<ClCompile Include="src\Ext\Bullet\Trajectories\BombardTrajectory.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\StraightTrajectory.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\ParabolaTrajectory.cpp" />
<ClCompile Include="src\Ext\CaptureManager\Hooks.cpp" />
<ClCompile Include="src\Ext\CaptureManager\Body.cpp" />
<ClCompile Include="src\Ext\OverlayType\Body.cpp" />
Expand Down Expand Up @@ -198,6 +199,7 @@
<ClInclude Include="src\Ext\Bullet\Trajectories\BombardTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\StraightTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\ParabolaTrajectory.h" />
<ClInclude Include="src\Ext\OverlayType\Body.h" />
<ClInclude Include="src\Ext\ParticleType\Body.h" />
<ClInclude Include="src\Ext\Sidebar\Body.h" />
Expand Down
65 changes: 64 additions & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,10 @@ Currently interceptor weapons with projectiles that do not have `Inviso=true` wi

- Projectiles can now have customizable trajectories.
- `Trajectory` should not be combined with original game's projectile trajectory logics (`Arcing`, `ROT`, `Vertical` or `Inviso`). Attempt to do so will result in the other logics being disabled and a warning being written to log file.
- Initial speed of the projectile is defined by `Trajectory.Speed`, which unlike `Speed` used by `ROT` > 0 projectiles is defined on projectile not weapon.
- The speed of the projectile is defined by `Trajectory.Speed`, which unlike `Speed` used by `ROT` > 0 projectiles is defined on projectile not weapon.
- In `Trajectory=Straight`, it refers to the whole distance speed of the projectile and it has no restrictions.
- In `Trajectory=Bombard`, it refers to the initial speed of the projectile and it has no restrictions.
- In `Trajectory=Parabola`, it refers to the horizontal velocity of the projectile and is only used for modes 0, 3, or 5 and it has no restrictions.

In `rulesmd.ini`:
```ini
Expand Down Expand Up @@ -702,6 +705,66 @@ Trajectory=Bombard ; Trajectory type
Trajectory.Bombard.Height=0.0 ; double
```

#### Parabola trajectory

- As the name says, this is a completely reset `Arcing` with different enhanced functions. Without doubt, It supported linkage with `Trajectory=Disperse`.
- `Trajectory.Parabola.DetonationDistance` controls the maximum distance in cells from intended target (checked at start of each game frame, before the projectile moves) at which the projectile will be forced to detonate. Set to 0 to disable forced detonation.
- `Trajectory.Parabola.TargetSnapDistance` controls the maximum distance in cells from intended target the projectile can be at moment of detonation to make the projectile 'snap' on the intended target. Set to 0 to disable snapping.
- `Trajectory.Parabola.OpenFireMode` controls how should the projectile be launched. This has the following 6 modes.
CrimRecya marked this conversation as resolved.
Show resolved Hide resolved
- Speed - Automatic calculation mode with fixed horizontal velocity, using `Trajectory.Speed` and target coordinates as calculation conditions, i.e. the flight time of the projectile is permanently fixed.
- Height - Automatic calculation mode with fixed maximum height, useing `Trajectory.Parabola.ThrowHeight` and target coordinates as calculation conditions, i.e. the detonation time of the projectile is relatively fixed.
- Angle - Automatic calculation mode with fixed fire angle, useing `Trajectory.Parabola.LaunchAngle` and target coordinates as calculation conditions. In this mode, the performance consumption is high, and may have no solution. It is not recommended to enable `SubjectToCliffs` or enable `AA` with a smaller `MinimumRange` when using this mode.
- SpeedAndHeight - Fixed horizontal velocity and maximum height mode, using `Trajectory.Speed` and `Trajectory.Parabola.ThrowHeight` as calculation conditions, i.e. the trajectory will only undergo altitude changes with the height of the target.
- HeightAndAngle - Fixed maximum height and fire angle mode, using `Trajectory.Parabola.ThrowHeight` and `Trajectory.Parabola.LaunchAngle` as calculation conditions, i.e. the trajectory will change horizontally with the height of the target.
- SpeedAndAngle - Fixed horizontal velocity and fire angle mode, using `Trajectory.Speed` and `Trajectory.Parabola.LaunchAngle` as calculation conditions, i.e. the trajectory will be permanently fixed.
- `Trajectory.Parabola.ThrowHeight` controls the maximum height of the projectile and is only used for modes 1, 3, or 4. The specific height will be determined by taking the larger of the launch height and the target height then increasing this value. Non positive numbers are not supported.
CrimRecya marked this conversation as resolved.
Show resolved Hide resolved
- `Trajectory.Parabola.LaunchAngle` controls the fire angle of the projectile and is only used for modes 2, 4, or 5. Only supports -90.0 ~ 90.0 (Cannot use boundary values) in Mode 2 or 5, and 0.0 ~ 90.0 (Cannot use boundary values) in Mode 4.
- `Trajectory.Parabola.LeadTimeCalculate` controls whether the projectile need to calculate the lead time of the target when firing. Note that this will not affect the facing of the turret.
- `Trajectory.Parabola.LeadTimeSimplify` controls whether only perform simplified calculations when calculate the lead time. You can simply consider this as another calculation mode.
- `Trajectory.Parabola.LeadTimeMultiplier` is an additional lead time multiplier, it will affect the aiming position. You can use this to reduce the errors caused by target speed and target distance.
- `Trajectory.Parabola.DetonationAngle` controls when the angle between the projectile in the current velocity direction and the horizontal plane is less than this value, it will detonate prematurely. Taking effect when the value is at -90.0 ~ 90.0 (Cannot use boundary values).
- `Trajectory.Parabola.DetonationHeight` controls when the projectile is in a descending state and below the height of the launch position plus this value, it will detonate prematurely. Taking effect when it is set to non negative value.
- `Trajectory.Parabola.BounceTimes` controls how many times can it bounce back when the projectile hits the ground or cliff. Be aware that excessive projectile speed may cause abnormal operation. And `Trajectory.Parabola.DetonationDistance` do not conflict with this and will take effect simultaneously. So if you want to explode the bullet only after the times of bounces is exhausted, you should set `Trajectory.Parabola.DetonationDistance` to a non positive value.
- `Trajectory.Parabola.BounceOnWater` controls whether it can bounce on the water surface.
- `Trajectory.Parabola.BounceDetonate` controls whether it detonates the warhead once extra during each bounce.
- `Trajectory.Parabola.BounceAttenuation` controls the attenuation coefficient of projectile bounce damage, that is, how many times the next damage after each bounce is the damage just caused. This will also affect the damage of the final detonation.
- `Trajectory.Parabola.BounceCoefficient` controls the attenuation coefficient of projectile bounce elasticity, that is, how many times the speed after each bounce is the speed before bouncing.
- `Trajectory.Parabola.OffsetCoord` controls the offsets of the target. Projectile will aim at this position to attack. It also supports `Inaccurate=yes` and `Trajectory.Parabola.LeadTimeCalculate=true` on this basis.
- `Trajectory.Parabola.RotateCoord` controls whether to rotate the projectile's firing direction within the angle bisector of `Trajectory.Parabola.OffsetCoord` according to the weapon's `Burst`. Set to 0 to disable this function.
- `Trajectory.Parabola.MirrorCoord` controls whether `Trajectory.Parabola.OffsetCoord` need to mirror the lateral value to adapt to the current burst index. At the same time, the rotation direction calculated by `Trajectory.Parabola.RotateCoord` will also be reversed, and the rotation angle between each adjacent projectile on each side will not change as a result.
- `Trajectory.Parabola.UseDisperseBurst` controls whether the calculation of `Trajectory.Parabola.RotateCoord` is based on its superior's `Trajectory.Disperse.WeaponBurst` of the dispersed trajectory, rather than `Burst` of the weapon. If this value is not appropriate, it will result in unsatisfactory visual displays.
- `Trajectory.Parabola.AxisOfRotation` controls the rotation axis when calculating `Trajectory.Parabola.RotateCoord`. The axis will rotates with the unit orientation or the vector that from target position to the source position.

In `rulesmd.ini`:
```ini
Trajectory=Parabola ; Trajectory type
Trajectory.Parabola.DetonationDistance=0.4 ; floating point value
Trajectory.Parabola.TargetSnapDistance=0.5 ; floating point value
Trajectory.Parabola.OpenFireMode=speed ; ParabolaFireMode value enumeration (speed|height|angle|speedandheight|heightandangle|speedandangle)
Trajectory.Parabola.ThrowHeight=600 ; integer
Trajectory.Parabola.LaunchAngle=30 ; floating point value
Trajectory.Parabola.LeadTimeCalculate=no ; boolean
Trajectory.Parabola.LeadTimeSimplify=no ; boolean
Trajectory.Parabola.LeadTimeMultiplier=1.0 ; floating point value
Trajectory.Parabola.DetonationAngle=-90.0 ; floating point value
Trajectory.Parabola.DetonationHeight=-1 ; integer
Trajectory.Parabola.BounceTimes=0 ; integer
Trajectory.Parabola.BounceOnWater=no ; boolean
Trajectory.Parabola.BounceDetonate=no ; boolean
Trajectory.Parabola.BounceAttenuation=0.8 ; floating point value
Trajectory.Parabola.BounceCoefficient=0.8 ; floating point value
Trajectory.Parabola.OffsetCoord=0,0,0 ; integer - Forward,Lateral,Height
Trajectory.Parabola.RotateCoord=0 ; floating point value
Trajectory.Parabola.MirrorCoord=yes ; boolean
Trajectory.Parabola.UseDisperseBurst=no ; boolean
Trajectory.Parabola.AxisOfRotation=0,0,1 ; integer - Forward,Lateral,Height
```

```{note}
- Compared to vanilla `Arcing`, this can also be used for aircrafts and airburst weapon.
- Certainly, `Gravity` can also affect the trajectory.
```

### Shrapnel enhancements

![image](_static/images/shrapnel.gif)
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ New:
- Custom object palettes for TerrainTypes (by Starkku)
- Forbidding parallel AI queues for specific TechnoTypes (by Starkku)
- Nonprovocative Warheads (by Starkku)
- New Parabola trajectory (by CrimRecya)
- Option to restore `PowerSurplus` setting for AI (by Starkku)
- `FireOnce` infantry sequence reset toggle (by Starkku)

Expand Down
61 changes: 52 additions & 9 deletions src/Ext/Bullet/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ DEFINE_HOOK(0x467CCA, BulletClass_AI_TargetSnapChecks, 0x6)
}
else if (auto const pExt = BulletAITemp::ExtData)
{
if (pExt->Trajectory)
if (auto const pTrajectory = pExt->Trajectory)
{
if (pExt->Trajectory->Flag == TrajectoryFlag::Straight)
const TrajectoryFlag flag = pTrajectory->Flag;

if (flag == TrajectoryFlag::Straight || flag == TrajectoryFlag::Parabola)
{
R->EAX(pThis->Type);
return SkipChecks;
Expand Down Expand Up @@ -336,10 +338,18 @@ DEFINE_HOOK(0x468E61, BulletClass_Explode_TargetSnapChecks1, 0x6)
}
else if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
if (!pExt->SnappedToTarget)
{
R->EAX(pThis->Type);
return SkipChecks;
if (auto const pTrajectory = pExt->Trajectory)
{
const TrajectoryFlag flag = pTrajectory->Flag;

if (flag == TrajectoryFlag::Straight || flag == TrajectoryFlag::Parabola)
{
R->EAX(pThis->Type);
return SkipChecks;
}
}
}
}

Expand Down Expand Up @@ -367,8 +377,18 @@ DEFINE_HOOK(0x468E9F, BulletClass_Explode_TargetSnapChecks2, 0x6)
// Fixes issues with walls etc.
if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
return SkipSetCoordinate;
if (!pExt->SnappedToTarget)
{
if (auto const pTrajectory = pExt->Trajectory)
{
const TrajectoryFlag flag = pTrajectory->Flag;

if (flag == TrajectoryFlag::Straight || flag == TrajectoryFlag::Parabola)
{
return SkipSetCoordinate;
}
}
}
}

return 0;
Expand All @@ -382,8 +402,15 @@ DEFINE_HOOK(0x468D3F, BulletClass_ShouldExplode_AirTarget, 0x6)

if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight)
return SkipCheck;
if (auto const pTrajectory = pExt->Trajectory)
{
const TrajectoryFlag flag = pTrajectory->Flag;

if (flag == TrajectoryFlag::Straight || flag == TrajectoryFlag::Parabola)
{
return SkipCheck;
}
}
}

return 0;
Expand Down Expand Up @@ -448,3 +475,19 @@ DEFINE_HOOK(0x44D23C, BuildingClass_Mission_Missile_ArcingFix, 0x7)

return 0;
}

// Vanilla inertia effect only for bullets with ROT=0
DEFINE_HOOK(0x415F25, AircraftClass_Fire_TrajectorySkipInertiaEffect, 0x6)
{
enum { SkipCheck = 0x4160BC };

GET(BulletClass*, pThis, ESI);

if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory)
return SkipCheck;
}

return 0;
}
Loading
Loading