From 86c04f4b6566f5b13053ff76b3fbff5fecdb9b39 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 10 May 2024 02:41:47 -0700 Subject: [PATCH 01/16] Don't check for target in firing state Fixes lightning storm ground attacking Removing Haltfire usage prevents Scathis state locking up when losing target when in firing state that required this target check --- lua/sim/weapons/DefaultProjectileWeapon.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 18cb6361bc..80bfda981e 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1110,8 +1110,6 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { unit.Trash:Add(ForkThread(self.DisabledWhileReloadingThread, self, 1 / rof)) end - local hasTarget = self:WeaponHasTarget() - -- Deal with the rack firing sequence if self.CurrentRackSalvoNumber > rackBoneCount then self.CurrentRackSalvoNumber = 1 @@ -1119,7 +1117,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { ChangeState(self, self.RackSalvoReloadState) elseif bp.RackSalvoChargeTime > 0 then ChangeState(self, self.IdleState) - elseif countedProjectile or not hasTarget then + elseif countedProjectile then if bp.WeaponUnpacks then ChangeState(self, self.WeaponPackingState) else @@ -1128,7 +1126,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { else ChangeState(self, self.RackSalvoFireReadyState) end - elseif countedProjectile or not hasTarget then + elseif countedProjectile then if bp.WeaponUnpacks then ChangeState(self, self.WeaponPackingState) else From 513d4f3a498fca13ede4e1a5b40874594bdb5106 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 10 May 2024 02:15:55 -0700 Subject: [PATCH 02/16] Revert FiringState OnLostTarget working through HaltFire Essentially reverts it to Steam behavior, except we have the fix for the state to call the base class --- lua/sim/weapons/DefaultProjectileWeapon.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 80bfda981e..f74dd7767a 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1138,7 +1138,17 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { end, OnLostTarget = function(self) - self.HaltFireOrdered = true + -- Override the default OnLostTarget but not inherited ones + local baseOnLostTarget = self.__base.OnLostTarget + if baseOnLostTarget ~= DefaultProjectileWeapon.OnLostTarget then + baseOnLostTarget(self) + else + Weapon.OnLostTarget(self) + + if self.Blueprint.WeaponUnpacks then + ChangeState(self, self.WeaponPackingState) + end + end end, -- Set a bool so we won't fire if the target reticle is moved From 6eed2bd3d6c5ae2f9286e6efd5fe45f566124625 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 21 Jun 2024 20:05:20 -0700 Subject: [PATCH 03/16] Add a comment --- lua/sim/weapons/DefaultProjectileWeapon.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index f74dd7767a..f4203e8175 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1203,6 +1203,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { end, OnLostTarget = function(self) + -- Override default OnLostTarget to prevent bypassing reload time by switching to idle state immediately end, }, From 9bb0917d2f355ee191b139df26b1e7b6b3a3017d Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:16:22 -0700 Subject: [PATCH 04/16] Do full rack reload when losing target while firing Prevents bypassing reloads --- lua/sim/weapons/DefaultProjectileWeapon.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index f4203e8175..19e72fc824 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1145,8 +1145,23 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { else Weapon.OnLostTarget(self) - if self.Blueprint.WeaponUnpacks then - ChangeState(self, self.WeaponPackingState) + -- Deal with the rack firing sequence + if self.CurrentRackSalvoNumber > self.NumRackBones then + self.CurrentRackSalvoNumber = 1 + + if bp.RackSalvoReloadTime > 0 then + ChangeState(self, self.RackSalvoReloadState) + elseif bp.WeaponUnpacks then + ChangeState(self, self.WeaponPackingState) + else + ChangeState(self, self.IdleState) + end + else + if bp.WeaponUnpacks then + ChangeState(self, self.WeaponPackingState) + else + ChangeState(self, self.IdleState) + end end end end, From b84ff69a008b2894b2b6a2659ed84ade1a0fc217 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 9 May 2024 22:09:08 -0700 Subject: [PATCH 05/16] Add state change and lost target debug log --- lua/sim/weapon.lua | 1 + lua/sim/weapons/DefaultProjectileWeapon.lua | 1 + lua/system/class.lua | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/lua/sim/weapon.lua b/lua/sim/weapon.lua index 890d7ae8c9..6d495192a0 100644 --- a/lua/sim/weapon.lua +++ b/lua/sim/weapon.lua @@ -334,6 +334,7 @@ Weapon = ClassWeapon(WeaponMethods) { ---@param self Weapon OnLostTarget = function(self) + LOG("weapon.lua:losttarget") local animator = self.unit.Animator if self.DisabledFiringBones and animator then for _, value in self.DisabledFiringBones do diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 19e72fc824..183a8d284f 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -655,6 +655,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { -- Includes the manual selection of a new target, and the issuing of a move order ---@param self DefaultProjectileWeapon OnLostTarget = function(self) + LOG("Default OnLostTarget") -- Issue 43 -- Tell the owner this weapon has lost the target local unit = self.unit diff --git a/lua/system/class.lua b/lua/system/class.lua index 993cedad0f..29ab7f5294 100644 --- a/lua/system/class.lua +++ b/lua/system/class.lua @@ -785,6 +785,14 @@ EffectFactory = { ---@param instance table The current instance we want to switch states for ---@param newState State the state we want to insert between the instance and its base class function ChangeState(instance, newState) + LOG(string.format("T:%d %s changing state: %s (%s) -> %s (%s)\n" + , GetGameTick() + , tostring(instance) + , instance.StateName or 'unnamed', tostring(instance.__StateIdentifier) + , newState.StateName or 'unnamed', tostring(newState.__StateIdentifier) + )) + local dbg = debug.getinfo(2, 'Sl') + LOG(string.format('%10s:%s', dbg.short_src, dbg.currentline)) -- call on-exit function if instance.OnExitState then From 84139d0749087f18a0de3c11347c1fe537fb8b49 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:38:01 -0700 Subject: [PATCH 06/16] Revert "Do full rack reload when losing target while firing" Changing states kills the thread and cancels any firing, which prevents the last shot on AttackGroundTries from firing. This reverts commit 9bb0917d2f355ee191b139df26b1e7b6b3a3017d. --- lua/sim/weapons/DefaultProjectileWeapon.lua | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 183a8d284f..0222ca1f9f 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1146,23 +1146,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { else Weapon.OnLostTarget(self) - -- Deal with the rack firing sequence - if self.CurrentRackSalvoNumber > self.NumRackBones then - self.CurrentRackSalvoNumber = 1 - - if bp.RackSalvoReloadTime > 0 then - ChangeState(self, self.RackSalvoReloadState) - elseif bp.WeaponUnpacks then - ChangeState(self, self.WeaponPackingState) - else - ChangeState(self, self.IdleState) - end - else - if bp.WeaponUnpacks then - ChangeState(self, self.WeaponPackingState) - else - ChangeState(self, self.IdleState) - end + if self.Blueprint.WeaponUnpacks then + ChangeState(self, self.WeaponPackingState) end end end, From f9e22b55f9c980f4f15e37074dc58907b1de751a Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 01:23:25 -0700 Subject: [PATCH 07/16] Add unit callback to the OnLostTarget overrides --- lua/sim/weapons/DefaultProjectileWeapon.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 0222ca1f9f..7e6e95492c 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1144,6 +1144,11 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { if baseOnLostTarget ~= DefaultProjectileWeapon.OnLostTarget then baseOnLostTarget(self) else + local unit = self.unit + if unit then + unit:OnLostTarget(self) + end + Weapon.OnLostTarget(self) if self.Blueprint.WeaponUnpacks then @@ -1205,6 +1210,12 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { OnLostTarget = function(self) -- Override default OnLostTarget to prevent bypassing reload time by switching to idle state immediately + local unit = self.unit + if unit then + unit:OnLostTarget(self) + end + + Weapon.OnLostTarget(self) end, }, From bd60d268b1520375bf529950d741c6d1d6b8553c Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 03:08:34 -0700 Subject: [PATCH 08/16] Never cancel salvo --- lua/sim/weapons/DefaultProjectileWeapon.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 7e6e95492c..8bc4981d5a 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1151,9 +1151,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { Weapon.OnLostTarget(self) - if self.Blueprint.WeaponUnpacks then - ChangeState(self, self.WeaponPackingState) - end + -- don't change states as that will cancel the salvo, which we want to keep around for AttackGroundTries to function end end, From be0ba23d6fe6a84916b0343c8372859d5f8b92d3 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 01:24:26 -0700 Subject: [PATCH 09/16] Revert "Add state change and lost target debug log" This reverts commit b84ff69a008b2894b2b6a2659ed84ade1a0fc217. --- lua/sim/weapon.lua | 1 - lua/sim/weapons/DefaultProjectileWeapon.lua | 1 - lua/system/class.lua | 8 -------- 3 files changed, 10 deletions(-) diff --git a/lua/sim/weapon.lua b/lua/sim/weapon.lua index 6d495192a0..890d7ae8c9 100644 --- a/lua/sim/weapon.lua +++ b/lua/sim/weapon.lua @@ -334,7 +334,6 @@ Weapon = ClassWeapon(WeaponMethods) { ---@param self Weapon OnLostTarget = function(self) - LOG("weapon.lua:losttarget") local animator = self.unit.Animator if self.DisabledFiringBones and animator then for _, value in self.DisabledFiringBones do diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 8bc4981d5a..1860cad81e 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -655,7 +655,6 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { -- Includes the manual selection of a new target, and the issuing of a move order ---@param self DefaultProjectileWeapon OnLostTarget = function(self) - LOG("Default OnLostTarget") -- Issue 43 -- Tell the owner this weapon has lost the target local unit = self.unit diff --git a/lua/system/class.lua b/lua/system/class.lua index 29ab7f5294..993cedad0f 100644 --- a/lua/system/class.lua +++ b/lua/system/class.lua @@ -785,14 +785,6 @@ EffectFactory = { ---@param instance table The current instance we want to switch states for ---@param newState State the state we want to insert between the instance and its base class function ChangeState(instance, newState) - LOG(string.format("T:%d %s changing state: %s (%s) -> %s (%s)\n" - , GetGameTick() - , tostring(instance) - , instance.StateName or 'unnamed', tostring(instance.__StateIdentifier) - , newState.StateName or 'unnamed', tostring(newState.__StateIdentifier) - )) - local dbg = debug.getinfo(2, 'Sl') - LOG(string.format('%10s:%s', dbg.short_src, dbg.currentline)) -- call on-exit function if instance.OnExitState then From 3b3de9ef9c79a95141b01ee5a25b186e2d3571d2 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 03:49:05 -0700 Subject: [PATCH 10/16] Add more details to comment --- lua/sim/weapons/DefaultProjectileWeapon.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 1860cad81e..684c684ace 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1139,6 +1139,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { OnLostTarget = function(self) -- Override the default OnLostTarget but not inherited ones + -- the inherited ones are needed for beam weapons to stop firing: https://github.com/FAForever/fa/pull/4863 + -- and for ythotha storm to not instantly stop firing: https://github.com/FAForever/fa/pull/5291 local baseOnLostTarget = self.__base.OnLostTarget if baseOnLostTarget ~= DefaultProjectileWeapon.OnLostTarget then baseOnLostTarget(self) From eb18a62941f90865b34f76109957f83a2c86ced6 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 03:49:35 -0700 Subject: [PATCH 11/16] Revert "Never cancel salvo" Needed for weapons like Ythotha's to not look ridiculous firing into empty space. This reverts commit bd60d268b1520375bf529950d741c6d1d6b8553c. --- lua/sim/weapons/DefaultProjectileWeapon.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 684c684ace..30b0f0284e 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1152,7 +1152,9 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { Weapon.OnLostTarget(self) - -- don't change states as that will cancel the salvo, which we want to keep around for AttackGroundTries to function + if self.Blueprint.WeaponUnpacks then + ChangeState(self, self.WeaponPackingState) + end end end, From ce9eeafe2a6faef00bb731d01d2fa8add83c69ef Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 03:56:48 -0700 Subject: [PATCH 12/16] Add comments --- lua/sim/weapons/DefaultProjectileWeapon.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 30b0f0284e..f4bb06d7de 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1152,6 +1152,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { Weapon.OnLostTarget(self) + -- Some weapons look too ridiculous shooting into the air, so stop them from firing + -- stopping firing will cause the last shot of AttackGroundTries to not fire if self.Blueprint.WeaponUnpacks then ChangeState(self, self.WeaponPackingState) end From 8989d1016194c58b20ef3ef9f22ee94804944700 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 04:34:16 -0700 Subject: [PATCH 13/16] Prevent skipping reload for packing weapons Non-packing weapons can't cancel their salvos and will shoot into the air --- lua/sim/weapons/DefaultProjectileWeapon.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index f4bb06d7de..df10a3f08a 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1154,8 +1154,15 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { -- Some weapons look too ridiculous shooting into the air, so stop them from firing -- stopping firing will cause the last shot of AttackGroundTries to not fire - if self.Blueprint.WeaponUnpacks then - ChangeState(self, self.WeaponPackingState) + local bp = self.Blueprint + if bp.WeaponUnpacks then + -- since we're stopping firing anyway, also prevent skipping the reload state here + if bp.RackSalvoReloadTime > 0 then + self.CurrentRackSalvoNumber = 1 + ChangeState(self, self.RackSalvoReloadState) + else + ChangeState(self, self.WeaponPackingState) + end end end end, From 3ac9e8530ebef879e7ac10117db120641da3d88d Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 04:34:25 -0700 Subject: [PATCH 14/16] Remove old unused code --- lua/sim/weapons/DefaultProjectileWeapon.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index df10a3f08a..fbfd144179 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1192,9 +1192,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { if notExclusive then unit:SetBusy(false) end - self.ReloadEndTime = GetGameTick() + MATH_IRound(bp.RackSalvoReloadTime * 10) + WaitSeconds(bp.RackSalvoReloadTime) - self.ReloadEndTime = nil self:WaitForAndDestroyManips() From ad6ea0392f855d2e8bba1948d3129ad898658bc6 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 05:04:27 -0700 Subject: [PATCH 15/16] Add an exception for long muzzle charges too --- lua/sim/weapons/DefaultProjectileWeapon.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 1d7e1d3a67..834661a3b9 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -1150,7 +1150,6 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { if unit then unit:OnLostTarget(self) end - Weapon.OnLostTarget(self) -- Some weapons look too ridiculous shooting into the air, so stop them from firing @@ -1164,6 +1163,13 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) { else ChangeState(self, self.WeaponPackingState) end + elseif bp.MuzzleChargeDelay > 0.5 then + if bp.RackSalvoReloadTime > 0 then + self.CurrentRackSalvoNumber = 1 + ChangeState(self, self.RackSalvoReloadState) + else + ChangeState(self, self.IdleState) + end end end end, From 091551d461b56bfed3a40b1b932720d4c1aad419 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sat, 22 Jun 2024 05:14:53 -0700 Subject: [PATCH 16/16] Create fix.6289.md --- changelog/snippets/fix.6289.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/snippets/fix.6289.md diff --git a/changelog/snippets/fix.6289.md b/changelog/snippets/fix.6289.md new file mode 100644 index 0000000000..a3aad53694 --- /dev/null +++ b/changelog/snippets/fix.6289.md @@ -0,0 +1,3 @@ +- (#6289) Fix Ythotha lightning storm not attacking the ground or allies. + +- (#6289) Fix `AttackGroundTries` not firing on the last shot for most weapons.