From 64e1f66b341420cd6dc5b986562291240c9e5756 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 06:55:02 -0800 Subject: [PATCH] Use `Vector` types instead of tables for Scathis script (#6528) --- changelog/snippets/other.6438.md | 2 +- lua/EffectTemplates.lua | 2 +- units/URL0401/URL0401_Script.lua | 63 ++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/changelog/snippets/other.6438.md b/changelog/snippets/other.6438.md index d9e6646414..15ac7e4dc4 100644 --- a/changelog/snippets/other.6438.md +++ b/changelog/snippets/other.6438.md @@ -1,4 +1,4 @@ -- (#5061, #6438, #6527, #6525) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. +- (#5061, #6438, #6527, #6525, #6528) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. - This **removes** the file `/lua/shared/quaternions.lua`, which was added in #4768 (Mar 4, 2023), so mods that use that file will have to be updated. - The metamethods (defined globally in `/lua/system/utils.lua`) include: - Vector/Vector2 addition/subtraction/negation diff --git a/lua/EffectTemplates.lua b/lua/EffectTemplates.lua index ee90fb2593..436ae9c714 100644 --- a/lua/EffectTemplates.lua +++ b/lua/EffectTemplates.lua @@ -1456,7 +1456,7 @@ CArtilleryFlash01 = { EmtBpPath .. 'proton_artillery_muzzle_08_emit.bp', } CArtilleryFlash02 = { - EmtBpPath .. 'proton_artillery_muzzle_07_emit.bp', + EmtBpPath .. 'proton_artillery_muzzle_07_emit.bp', -- Large, faint rings of air expanding outwards } CArtilleryHit01 = DefaultHitExplosion01 diff --git a/units/URL0401/URL0401_Script.lua b/units/URL0401/URL0401_Script.lua index 2b089a40fd..ce3f60abfd 100644 --- a/units/URL0401/URL0401_Script.lua +++ b/units/URL0401/URL0401_Script.lua @@ -18,22 +18,39 @@ local muzzleBones = { 'Turret_Barrel_F_B03', 'Turret_Barrel_E_B03', 'Turret_Barr URL0401 = ClassUnit(CLandUnit) { Weapons = { + ---@class URL0401_Gun01 : CIFArtilleryWeapon + ---@field losttarget boolean + ---@field initialaim boolean + ---@field PitchRotators moho.RotateManipulator[] # Pitch rotators for the fake turret barrels + ---@field currentbarrel number # Which barrel is currently aligned with the aim's yaw + ---@field Goal number # Yaw goal of fake barrels + ---@field restdirvector Vector + ---@field dirvector Vector + ---@field basedirvector Vector + ---@field basediftorest number # "BaseDifToRest" angle in between Yaw aim bone and the resting fake barrel + ---@field pitchdif number # "PitchDif" angle in between fake barrel pitch and aim barrel pitch + ---@field Rotator moho.RotateManipulator # Yaw rotator for the `"Turret_Fake"` bone created every time the weapon fires after being packed + ---@field unit URL0401 Gun01 = ClassWeapon(CIFArtilleryWeapon) { - + ---@param self URL0401_Gun01 OnCreate = function(self) CIFArtilleryWeapon.OnCreate(self) self.losttarget = false self.initialaim = true self.PitchRotators = {} - self.restdirvector = {} + self.restdirvector = Vector(0, 0, 0) + self.dirvector = Vector(0, 0, 0) + self.basedirvector = Vector(0, 0, 0) self.currentbarrel = 1 end, + ---@param self URL0401_Gun01 OnLostTarget = function(self) CIFArtilleryWeapon.OnLostTarget(self) self.losttarget = true end, + ---@param self URL0401_Gun01 PlayFxWeaponPackSequence = function(self) if self.PitchRotators then for k, v in barrelBones do @@ -48,6 +65,7 @@ URL0401 = ClassUnit(CLandUnit) { CIFArtilleryWeapon.PlayFxWeaponPackSequence(self) end, + ---@param self URL0401_Gun01 LaunchEffects = function(self) local FxLaunch = EffectTemplate.CArtilleryFlash02 for k, v in FxLaunch do @@ -55,7 +73,17 @@ URL0401 = ClassUnit(CLandUnit) { end end, + --- Empty function because `CreateProjectileAtMuzzle` will wait when aiming the fake barrels, so the FX needs to be created in there for correct timing + ---@param self URL0401_Gun01 + ---@param muzzle Bone + PlayFxMuzzleSequence = function(self, muzzle) + end, + + ---@param self URL0401_Gun01 + ---@param muzzle Bone CreateProjectileAtMuzzle = function(self, muzzle) + -- set up the yaw and pitch rotators for the fake barrels since we just unpacked + -- Creates the animation where the barrels are at their lowest pitch and look spread out if self.initialaim then self.Rotator = CreateRotator(self.unit, 'Turret_Fake', 'y') self.unit.Trash:Add(self.Rotator) @@ -68,21 +96,23 @@ URL0401 = ClassUnit(CLandUnit) { self.unit.Trash:Add(self.PitchRotators[k]) end + -- fake barrel with the same yaw as the aim yaw local barrel = self.currentbarrel - local basedirvector = {} + local basedirvector = self.basedirvector self.Goal = 0 - self.restdirvector.x, self.restdirvector.y, self.restdirvector.z = self.unit:GetBoneDirection(barrelBones + self.restdirvector[1], self.restdirvector[2], self.restdirvector[3] = self.unit:GetBoneDirection(barrelBones [barrel]) - basedirvector.x, basedirvector.y, basedirvector.z = self.unit:GetBoneDirection('Turret_Aim') + basedirvector[1], basedirvector[2], basedirvector[3] = self.unit:GetBoneDirection('Turret_Aim') self.basediftorest = Util.GetAngleInBetween(self.restdirvector, basedirvector) end + -- since we got a new target, adjust the pitch of the fake barrels to match the aim barrel if self.losttarget or self.initialaim then - local dirvector = {} - dirvector.x, dirvector.y, dirvector.z = self.unit:GetBoneDirection('Turret_Aim_Barrel') - local basedirvector = {} - basedirvector.x, basedirvector.y, basedirvector.z = self.unit:GetBoneDirection('Turret_Aim') + local dirvector = self.dirvector + dirvector[1], dirvector[2], dirvector[3] = self.unit:GetBoneDirection('Turret_Aim_Barrel') + local basedirvector = self.basedirvector + basedirvector[1], basedirvector[2], basedirvector[3] = self.unit:GetBoneDirection('Turret_Aim') local basediftoaim = Util.GetAngleInBetween(dirvector, basedirvector) @@ -94,7 +124,7 @@ URL0401 = ClassUnit(CLandUnit) { end WaitFor(self.PitchRotators[1]) - + -- Wait for aesthetics, to let the barrel rest at the final position a bit before firing WaitTicks(3) if self.losttarget then @@ -106,19 +136,13 @@ URL0401 = ClassUnit(CLandUnit) { end end - local muzzleIdx = 0 - for i = 1, self.unit:GetBoneCount() do - if self.unit:GetBoneName(i) == 'Turret_Aim_Barrel_Muzzle' then - muzzleIdx = i - break - end - end - - CIFArtilleryWeapon.CreateProjectileAtMuzzle(self, muzzleIdx) + CIFArtilleryWeapon.PlayFxMuzzleSequence(self, muzzle) + CIFArtilleryWeapon.CreateProjectileAtMuzzle(self, muzzle) self.Trash:Add(ForkThread(self.LaunchEffects, self)) self.Trash:Add(ForkThread(self.RotateBarrels, self)) end, + ---@param self URL0401_Gun01 RotateBarrels = function(self) if not self.losttarget then self.Rotator:SetSpeed(320) @@ -132,7 +156,6 @@ URL0401 = ClassUnit(CLandUnit) { if self.currentbarrel > 6 then self.currentbarrel = 1 end - self.rotatedbarrel = true end end, },