Skip to content

Commit

Permalink
Prevent stationary tactical missiles from being able to hit TMD (FAFo…
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 authored Feb 22, 2024
1 parent 7bd066c commit 52ddcb1
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 46 deletions.
4 changes: 3 additions & 1 deletion lua/sim/Projectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ Projectile = ClassProjectile(ProjectileMethods) {
local px, _, pz = self:GetCurrentTargetPositionXYZ()

local physics = self.Blueprint.Physics
local fuzziness = physics.TrackTargetGroundFuzziness or 0.8
local fuzziness = physics.TrackTargetGroundFuzziness or 0
local offset = physics.TrackTargetGroundOffset or 0
local tx = px + (Random() - 0.5) * fuzziness * (1 + offset)
local tz = pz + (Random() - 0.5) * fuzziness * (1 + offset)

DrawCircle({tx, GetSurfaceHeight(tx, tz), tz}, 1, 'ffffff')
self:SetNewTargetGroundXYZ(tx, GetSurfaceHeight(tx, tz), tz)
end
end,
Expand Down
1 change: 0 additions & 1 deletion lua/sim/projectiles/aeon/AMissileSerpentineProjectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ AMissileSerpentineProjectile = ClassProjectile(SingleCompositeEmitterProjectile,
local blueprintPhysics = self.Blueprint.Physics
local radius = 0.105 * (blueprintPhysics.MaxSpeed + blueprintPhysics.MaxSpeedRange)
self:SetCollisionShape('Sphere', 0, 0, 0, radius)

self.MoveThread = self.Trash:Add(ForkThread(self.MovementThread, self))
end,

Expand Down
65 changes: 59 additions & 6 deletions lua/sim/projectiles/components/TacticalMissileComponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@

local SemiBallisticComponent = import("/lua/sim/projectiles/components/semiballisticcomponent.lua").SemiBallisticComponent

local MathAbs = math.abs

---@class TacticalMissileComponent : SemiBallisticComponent
---@field TerminalTimeFactor number # Duration of the terminal phase as a proportion of glide time. Default is 0.25.
---@field TerminalDistance number # Approximate distance from the target where terminal phase starts, overrides TerminalTimeFactor.
---@field TerminalSpeed number # MaxSpeed of the missile in the terminal phase.
---@field TerminalZigZagMultiplier number # MaxZigZag of the missile in the terminal phase. Default is 0.25.
TacticalMissileComponent = ClassSimple(SemiBallisticComponent) {

TerminalTimeFactor = 0.25,
TerminalZigZagMultiplier = 0.25,

---@param self TacticalMissileComponent | Projectile
MovementThread = function(self, skipLaunchSequence)
local blueprintPhysics = self.Blueprint.Physics
local blueprintMaxZigZag = blueprintPhysics.MaxZigZag

-- are we a wiggler?
local zigZagger = false
if blueprintPhysics.MaxZigZag and
blueprintPhysics.MaxZigZag > self.MaxZigZagThreshold then
if blueprintMaxZigZag and
blueprintMaxZigZag > self.MaxZigZagThreshold then
zigZagger = true
end

Expand Down Expand Up @@ -88,12 +98,55 @@ TacticalMissileComponent = ClassSimple(SemiBallisticComponent) {
self:SetTurnRate(glideTurnRate)
end

-- reduce the maximum zig zag frequency halfway so that they're unlikely to miss targets
WaitTicks((0.75 * glideTime + 0.1) * 10)
self:ChangeMaxZigZag(0.5)
local terminalTime = glideTime * self.TerminalTimeFactor
local terminalDistance = self.TerminalDistance
local terminalSpeed = self.TerminalSpeed
local terminalZigZagMultiplier = self.TerminalZigZagMultiplier

local maxSpeed = blueprintPhysics.MaxSpeed
local accel = blueprintPhysics.Acceleration

if terminalDistance then
terminalTime = terminalDistance / (terminalSpeed or maxSpeed)
end

-- Changing the max speed below the current speed decelerates the projectile in 2 ticks.
-- Instead, create a smoother deceleration based on the projectile's actual acceleration.
if terminalSpeed then
local accelTime = MathAbs(maxSpeed - terminalSpeed) / accel

-- The glide time is based on max speed, but the terminal phase is based on terminal speed,
-- so we have to convert to the common variable of distance
-- and then back into time by dividing by max speed.
local accelDist = MathAbs((terminalSpeed * terminalSpeed - maxSpeed * maxSpeed) / 2 / accel)
local timeBeforeTerminal = glideTime - terminalTime * terminalSpeed / maxSpeed - accelDist / maxSpeed
-- Wait until the projectile reaches the point where the terminal phase should start.
if timeBeforeTerminal > 0 then
WaitTicks(timeBeforeTerminal * 10)
end

-- We will be changing our velocity in the next Wait, so update the lifetime.
glideTime = accelTime + terminalTime
self:SetLifetime((glideTime + 3))

for t = 0.2, accelTime, 0.2 do
self:SetMaxSpeed(maxSpeed - (maxSpeed - terminalSpeed) * t/accelTime)
WaitTicks(3) -- This waits 2 ticks instead of 3 according to GetGameTick().
end
self:SetMaxSpeed(terminalSpeed)
else
WaitTicks((glideTime - terminalTime) * 10)
end

glideTime = terminalTime

-- at this point we just want to make sure we hit the target, we increase the glide turn rate based
-- on the zig zag that the missile had during flight to make sure it can align if it needs to
self:ChangeMaxZigZag(terminalZigZagMultiplier * blueprintMaxZigZag)
self:SetTurnRate((1 + 0.6 * blueprintMaxZigZag) * glideTurnRate)

-- wait until we've allegedly hit our target
WaitTicks((0.25 * glideTime + 1) * 10)
WaitTicks((glideTime + 1) * 10)

-- then, if we still exist, we just want to stop existing. Therefore we find our way to the ground
-- target the ground below us slowly turn towards the ground so that we do not fly off indefinitely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ProjectileBlueprint {
Acceleration = 6,
DestroyOnWater = true,
InitialSpeed = 2,
MaxSpeed = 14,
MaxSpeed = 12,

TrackTarget = true,
TrackTargetGround = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local AMissileSerpentineProjectile = import("/lua/aeonprojectiles.lua").AMissileSerpentineProjectile

-- Aeon Serpentine Missile
--- Used by ual0111 (T2 Mobile Missile Launcher)
---@class AIFMissileSerpentine01: AMissileSerpentineProjectile
AIFMissileSerpentine01 = ClassProjectile(AMissileSerpentineProjectile) {
LaunchTicks = 2,
LaunchTurnRate = 6,
HeightDistanceFactor = 8,
MinHeight = 2,
FinalBoostAngle = 20,

TerminalZigZagMultiplier = 0.5,
}
TypeClass = AIFMissileSerpentine01
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
local AMissileSerpentineProjectile = import("/lua/aeonprojectiles.lua").AMissileSerpentineProjectile

--- Aeon Serpentine Missile
--- Used by UAS0304 (T3 Stategic Missile Submarine)
---@class AIFMissileSerpentine02 : AMissileSerpentineProjectile
AIFMissileSerpentine02 = ClassProjectile(AMissileSerpentineProjectile) {
FxWaterHitScale = 1.65,

TerminalZigZagMultiplier = 0.5,
}
TypeClass = AIFMissileSerpentine02
TypeClass = AIFMissileSerpentine02
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ AIFMissileTactical03 = ClassProjectile(AMissileSerpentine02Projectile) {
HeightDistanceFactor = 5,
MinHeight = 10,
FinalBoostAngle = 45,

TerminalZigZagMultiplier = 1.0,
}
TypeClass = AIFMissileTactical03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ProjectileBlueprint {
UseGravity = false,
VelocityAlign = true,

MaxZigZag = 5,
MaxZigZag = 4,
ZigZagFrequency = 1.0,
},
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
local AMissileSerpentineProjectile = import("/lua/aeonprojectiles.lua").AMissileSerpentineProjectile

--- Aeon Land-Based Tactical Missile
--- Used by UAB2108 (T2 Tactical Missile Launcher)
---@class AIFMissileTactical01 : AMissileSerpentineProjectile
AIFMissileTactical01 = ClassProjectile(AMissileSerpentineProjectile) {

TerminalZigZagMultiplier = 0.5,

---@param self AIFMissileTactical01
OnCreate = function(self)
AMissileSerpentineProjectile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ProjectileBlueprint {
UseGravity = false,
VelocityAlign = true,

MaxZigZag = 5,
MaxZigZag = 4,
ZigZagFrequency = 0.2,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local AMissileSerpentineProjectile = import("/lua/aeonprojectiles.lua").AMissile
---@class AIFMissileTactical02 : AMissileSerpentineProjectile
AIFMissileTactical02 = ClassProjectile(AMissileSerpentineProjectile) {

TerminalZigZagMultiplier = 0.5,

---@param self AIFMissileTactical02
OnCreate = function(self)
AMissileSerpentineProjectile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ProjectileBlueprint {
UseGravity = false,
VelocityAlign = true,

MaxZigZag = 5,
MaxZigZag = 4,
ZigZagFrequency = 0.2,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local CLOATacticalMissileProjectile = import("/lua/cybranprojectiles.lua").CLOAT
--- Splits into child projectile if it takes enough damage.
---@class CIFMissileTactical01 : CLOATacticalMissileProjectile
CIFMissileTactical01 = ClassProjectile(CLOATacticalMissileProjectile) {
NumChildMissiles = 3,
ChildCount = 3,

FxUnitHitScale = 0.5,
FxLandHitScale = 0.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ local CLOATacticalMissileProjectile = import("/lua/cybranprojectiles.lua").CLOAT
--- if it takes enough damage.
---@class CIFMissileTactical02 : CLOATacticalMissileProjectile
CIFMissileTactical02 = ClassProjectile(CLOATacticalMissileProjectile) {

NumChildMissiles = 3,
ChildCount = 3,

---@param self CIFMissileTactical02
OnCreate = function(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local CLOATacticalMissileProjectile = import("/lua/cybranprojectiles.lua").CLOAT
--- if it takes enough damage.
---@class CIFMissileTactical03 : CLOATacticalMissileProjectile
CIFMissileTactical03 = ClassProjectile(CLOATacticalMissileProjectile) {
NumChildMissiles = 3,
ChildCount = 3,

---@param self CLOATacticalMissileProjectile
OnCreate = function(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').Tacti
---@class SIFLaanseTacticalMissile01 : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissile01 = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {

LaunchTicks = 6,
LaunchTicks = 4,
LaunchTicksRange = 1,
LaunchTurnRate = 8,
LaunchTurnRateRange = 1,
Expand All @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile01 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 12,
FinalBoostAngleRange = 2,

TerminalSpeed = 20,
TerminalDistance = 10,

---@param self SIFLaanseTacticalMissile01
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ ProjectileBlueprint {
HelpText = 0,
},
Physics = {
Acceleration = 8,
Acceleration = 14,
DestroyOnWater = true,
InitialSpeed = 4,
MaxSpeed = 24,
MaxSpeed = 28,
RotationalVelocity = 0,
RotationalVelocityRange = 0,
TrackTarget = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').Tacti
---@class SIFLaanseTacticalMissile02 : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissile02 = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {

LaunchTicks = 16,
LaunchTicks = 9,
LaunchTicksRange = 1,
LaunchTurnRate = 20,
LaunchTurnRate = 60,
LaunchTurnRateRange = 1,
HeightDistanceFactor = 8,
HeightDistanceFactorRange = 0,
Expand All @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile02 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 20,
TerminalDistance = 15,

---@param self SIFLaanseTacticalMissile02
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ProjectileBlueprint {
DestroyOnWater = true,
InitialSpeed = 3,
LifeTime = 30,
MaxSpeed = 20,
MaxSpeed = 28,
RotationalVelocity = 0,
RotationalVelocityRange = 0,
TrackTarget = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').Tacti
---@class SIFLaanseTacticalMissile03 : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissile03 = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {

LaunchTicks = 16,
LaunchTicks = 10,
LaunchTicksRange = 1,
LaunchTurnRate = 20,
LaunchTurnRate = 60,
LaunchTurnRateRange = 1,
HeightDistanceFactor = 8,
HeightDistanceFactorRange = 0,
Expand All @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile03 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 20,
TerminalDistance = 15,

---@param self SIFLaanseTacticalMissile03
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ProjectileBlueprint {
DestroyOnWater = true,
InitialSpeed = 3,
LifeTime = 30,
MaxSpeed = 20,
MaxSpeed = 28,
RotationalVelocity = 0,
RotationalVelocityRange = 0,
TrackTarget = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
local SLaanseTacticalMissile = import("/lua/seraphimprojectiles.lua").SLaanseTacticalMissile
local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').TacticalMissileComponent

--- used by XSB0208
--- used by XSB2108
---@class SIFLaanseTacticalMissile04 : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissile04 = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {
LaunchTicks = 16,

LaunchTicks = 9,
LaunchTicksRange = 1,
LaunchTurnRate = 20,
LaunchTurnRateRange = 1,
Expand All @@ -38,6 +39,9 @@ SIFLaanseTacticalMissile04 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 13,
TerminalDistance = 30,

---@param self SIFLaanseTacticalMissile04
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ ProjectileBlueprint {
VelocityAlign = true,

ZigZagFrequency = 1,
MaxZigZag = 1
MaxZigZag = 1,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
local SLaanseTacticalMissile = import("/lua/seraphimprojectiles.lua").SLaanseTacticalMissile
local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').TacticalMissileComponent

--- Used by xsl0001
--- Used by XSL0001
---@class SIFLaanseTacticalMissileCDR : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissileCDR = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {

LaunchTicks = 16,
LaunchTicks = 8,
LaunchTicksRange = 1,
LaunchTurnRate = 20,
LaunchTurnRateRange = 1,
Expand All @@ -39,6 +39,9 @@ SIFLaanseTacticalMissileCDR = ClassProjectile(SLaanseTacticalMissile, TacticalMi
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 13,
TerminalDistance = 30,

---@param self SIFLaanseTacticalMissileCDR
---@param inWater boolean
OnCreate = function(self, inWater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ProjectileBlueprint {
Acceleration = 3,
DestroyOnWater = false,
InitialSpeed = 3,
MaxSpeed = 12,
MaxSpeed = 20,
RotationalVelocity = 0,
RotationalVelocityRange = 0,
TrackTarget = true,
Expand Down
Loading

0 comments on commit 52ddcb1

Please sign in to comment.