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

Make Aeon faction's TMD shoot flare to target height #6619

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions changelog/snippets/balance.6619.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6619) Make Aeon TMD (static and naval) launch the flare to the height of the missile being intercepted. This fixes the issue where Aeon TMD cannot intercept UEF TMLs due to them flying too high.
2 changes: 1 addition & 1 deletion engine/Sim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ end
---@param object BoneObject
---@param bone Bone
---@param axis "x" | "y" | "z" | "-x" | "-y" | "-z"
---@param goal? unknown
---@param goal? number
---@param speed? number
---@param accel? number
---@param goalspeed? number
Expand Down
1 change: 1 addition & 0 deletions engine/Sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ end
function Unit:GetUnitId()
end

--- Velocity in ogrids/tick
---@return number x
---@return number y
---@return number z
Expand Down
2 changes: 1 addition & 1 deletion engine/Sim/UnitWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function UnitWeapon:GetBlueprint()
end

---
---@return Blip | Unit | nil
---@return Blip | Unit | Projectile | nil
function UnitWeapon:GetCurrentTarget()
end

Expand Down
2 changes: 1 addition & 1 deletion lua/sim/projectiles/aeon/AIMFlareProjectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ AIMFlareProjectile = ClassProjectile(EmitterProjectile) {

local trash = self.Trash
for k = 1, 3 do
flareSpecs.Radius = 8 + k * 5
flareSpecs.Radius = 2 + k * 7
trash:Add(Flare(flareSpecs))
end
end,
Expand Down
58 changes: 58 additions & 0 deletions lua/sim/weapons/aeon/AAMWillOWisp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,67 @@
--**********************************************************************************

local DefaultProjectileWeapon = import("/lua/sim/defaultweapons.lua").DefaultProjectileWeapon
local DefaultCreateProjectileAtMuzzle = DefaultProjectileWeapon.CreateProjectileAtMuzzle
local EffectTemplate = import("/lua/effecttemplates.lua")
local GetDistanceBetweenTwoPoints2 = import('/lua/utilities.lua').GetDistanceBetweenTwoPoints2

local EntityGetPositionXYZ = moho.entity_methods.GetPositionXYZ
local ProjectileGetVelocity = moho.projectile_methods.GetVelocity
local ProjectileSetVelocity = moho.projectile_methods.SetVelocity
local ProjectileSetBallisticAcceleration = moho.projectile_methods.SetBallisticAcceleration
local WeaponGetCurrentTarget = moho.weapon_methods.GetCurrentTarget

local MathSqrt = math.sqrt
local MathMax = math.max
local ForkThread = ForkThread
local WaitSeconds = WaitSeconds
local IsDestroyed = IsDestroyed

--- Makes the flare fall at a natural speed at the top of its trajectory so that it can catch the missile better
---@param proj Projectile
---@param t number
local function floatProjectile(proj, t)
WaitSeconds(t)
if not IsDestroyed(proj) then
ProjectileSetVelocity(proj, 0, 0, 0)
ProjectileSetBallisticAcceleration(proj, -4.9)
end
end

--- Aeon anti-projectile weapon that launches flares to a bit above the target projectile's height.
---@class AAMWillOWisp : DefaultProjectileWeapon
AAMWillOWisp = ClassWeapon(DefaultProjectileWeapon) {
FxMuzzleFlash = EffectTemplate.AAntiMissileFlareFlash,

--- Launch the flare to the target's height
---@param self AAMWillOWisp
---@param muzzle Bone
---@return Projectile
CreateProjectileAtMuzzle = function(self, muzzle)
local proj = DefaultCreateProjectileAtMuzzle(self, muzzle)

-- Assume we only target and fire at projectiles. The projectile may destroy itself right as we fire though if it hit something.
local target = WeaponGetCurrentTarget(self) --[[@as Projectile?]]
if target then
local targetX, targetY, targetZ = EntityGetPositionXYZ(target)
local targetVX, targetVY, targetVZ = ProjectileGetVelocity(target)

local posX, posY, posZ = EntityGetPositionXYZ(self.unit, muzzle)

-- Make the distance a bit shorter to allow the flare hitbox to catch the projectile and to launch faster to catch projectiles on the edge of the range
local arriveTime = MathMax(GetDistanceBetweenTwoPoints2(targetX, targetZ, posX, posZ) - 10, 10) / (MathSqrt(targetVX * targetVX + targetVZ * targetVZ) * 10)

-- Have a minimum height so that shields don't get hit by diverted projectiles
-- Also launch a bit above the projectile's height to catch it better as the flare falls down
local dy = MathMax(targetY - posY + 9, 17)

local vy0 = dy / arriveTime * 2
ProjectileSetVelocity(proj, 0, vy0, 0)
ProjectileSetBallisticAcceleration(proj, -vy0 / arriveTime)
-- Can't wait in here or else it interrupts the firing cycle
ForkThread(floatProjectile, proj, arriveTime)
end

return proj
end,
}
2 changes: 1 addition & 1 deletion projectiles/AIMAntiMissile01/AIMAntiMissile01_proj.bp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ProjectileBlueprint{
Acceleration = -1.25,
DestroyOnWater = true,
LifeTime = 3,
MaxSpeed = 15,
MaxSpeed = false,
MaxZigZag = 10,
TrackTarget = false,
TurnRate = 0,
Expand Down
62 changes: 32 additions & 30 deletions units/UAB4201/UAB4201_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,43 @@ local AAMWillOWisp = import("/lua/aeonweapons.lua").AAMWillOWisp
local CreateRotator = CreateRotator
local TrashBagAdd = TrashBag.Add


---@class UAB4201 : AStructureUnit
UAB4201 = ClassUnit(AStructureUnit) {
Weapons = {
---@class UAB4201_AntiMissile: AAMWillOWisp
---@field RotatorManipulator moho.RotateManipulator
---@field RotatorManipulatorCounter number
AntiMissile = ClassWeapon(AAMWillOWisp) {
PlayRackRecoil = function(self, rackList)
AAMWillOWisp.PlayRackRecoil(self, rackList)

local unit = self.unit
local rotatorManipulator = self.RotatorManipulator

--CreateRotator(unit, bone, axis, [goal], [speed], [accel], [goalspeed])
if not rotatorManipulator then
rotatorManipulator = CreateRotator(unit, 'Dome', 'z', 20, 40, 40, 40)
rotatorManipulator:SetGoal(45)
self.RotatorManipulatorCounter = 1
else
self.RotatorManipulatorCounter = self.RotatorManipulatorCounter + 1
rotatorManipulator:SetGoal(45 * self.RotatorManipulatorCounter)
end
self.unit.Trash:Add(self.RotatorManipulator)
end,

PlayRackRecoilReturn = function(self, rackList)
AAMWillOWisp.PlayRackRecoilReturn(self, rackList)
if self.RotatorManipulatorCounter == 8 then
self.RotatorManipulator:Destroy()
self.RotatorManipulator = nil
end
end,

},
RotatorManipulatorCounter = 1,

---@param self UAB4201_AntiMissile
OnCreate = function(self)
AAMWillOWisp.OnCreate(self)
-- Speed is set to do a rotation in 1 tick
self.RotatorManipulator = TrashBagAdd(self.Trash, CreateRotator(self.unit, 'Dome', 'z', 0, 225, nil, nil))
end,

--- Rotate the dome when the volcano unpacks
---@param self UAB4201_AntiMissile
PlayFxWeaponUnpackSequence = function(self)
local rotations = self.RotatorManipulatorCounter
self.RotatorManipulator:SetGoal(22.5 * rotations)
self.RotatorManipulatorCounter = rotations + 1

AAMWillOWisp.PlayFxWeaponUnpackSequence(self)
end,

--- Rotate the dome when the volcano packs. Ends on a 45 degree turn so that the mesh doesn't self-intersect.
---@param self UAB4201_AntiMissile
PlayFxWeaponPackSequence = function(self)
local rotations = self.RotatorManipulatorCounter
self.RotatorManipulator:SetGoal(22.5 * rotations)
self.RotatorManipulatorCounter = rotations < 16 and rotations + 1 or 1

AAMWillOWisp.PlayFxWeaponPackSequence(self)
end
},
},

}

TypeClass = UAB4201

6 changes: 3 additions & 3 deletions units/URL0001/URL0001_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) {
DeathWeapon = ClassWeapon(ACUDeathWeapon) {},
RightRipper = ClassWeapon(CCannonMolecularWeapon) {},
Torpedo = ClassWeapon(CANTorpedoLauncherWeapon) {},
---@class MLG : CDFHeavyMicrowaveLaserGeneratorCom
---@class URL0001_MLG : CDFHeavyMicrowaveLaserGeneratorCom
MLG = ClassWeapon(CDFHeavyMicrowaveLaserGeneratorCom) {
DisabledFiringBones = { 'Turret_Muzzle_03' },

---@param self MLG
---@param self URL0001_MLG
---@param transportstate boolean
SetOnTransport = function(self, transportstate)
CDFHeavyMicrowaveLaserGeneratorCom.SetOnTransport(self, transportstate)
self.Trash:Add(ForkThread(self.OnTransportWatch, self))
end,

---@param self MLG
---@param self URL0001_MLG
OnTransportWatch = function(self)
while self:GetOnTransport() do
self:PlayFxBeamEnd()
Expand Down
Loading