Skip to content

Commit

Permalink
Revert FiringState OnLostTarget working through HaltFire (FAForever#6289
Browse files Browse the repository at this point in the history
)

<!-- General useful tooling:
- [ScreenToGif](https://www.screentogif.com/): Free, open source screen
recorder that can export to MP4. If the changes are visual, these can
help you tell us exactly what the changes imply!
-->
<!-- Feel free to remove unused parts of this template. -->

## Description of the proposed changes
<!-- A clear and concise description (or visuals) of what the changes
imply. -->
<!-- If it closes an issue, make sure to link the issue by using
"(Closes/Fixes/Resolves) #(Issue Number)" in your pull request. -->
Essentially reverts it to Steam behavior, except we have the fix for the
state to call the base class.
- ✔️ Fixes ythotha storm not attacking the ground or allies by removing
the `hasTarget` check and re-adding the base class call.
- ✔️ Fixes projectile weapons (but not beams) not firing their last shot
in `AttackGroundTries`.
- ❌ Non-packing weapons will fire their salvo off into the air.
Thankfully there are few of them. The actual solution to this is to add
a proper salvo retargeting system, which is beyond the scope of the PR,
so there are just some hack fix exceptions.

## Testing done on the proposed changes
<!-- List all relevant testing that you've done to confirm the changes
work. -->
Tested units with various firing cycles, particularly relevant are
Ravager, Ythotha and its storm, GC Beam after tractoring something, and
Scathis.
<details> <summary> Spawn units command: </summary>

```
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xsl0301_missile', 0,    3.82,    0.50,  0.00000)
   CreateUnitAtMouse('dslk004', 0,   11.82,   -4.50,  0.00000)
   CreateUnitAtMouse('delk002', 0,    8.82,   -4.50,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xsb2301', 0,   -4.24,    1.83,  2.64765)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xsb2401', 0,   -8.24,   -8.17,  0.00000)
   CreateUnitAtMouse('drl0204', 0,   10.15,   -0.33,  0.02394)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('urb2108', 0,    9.76,    5.83,  0.00000)
   CreateUnitAtMouse('uel0001', 0,    2.17,    5.30,  0.51364)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('url0401', 0,  -11.74,    7.08, -0.00668)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xsb2108', 0,   12.76,    6.83,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xel0306', 0,   -2.10,    5.51, -0.57607)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xeb2306', 0,   -8.24,    7.83,  2.60117)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xsl0401', 0,   14.76,    0.83, -0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xab1401', 0,   -1.24,   -8.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('url0304', 0,   -5.25,    5.22,  0.23978)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('del0204', 0,    6.23,    5.95,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('drlk001', 0,    5.82,   -4.50,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('xrb0304', 0,   -0.24,   -0.17,  0.00000)
   CreateUnitAtMouse('ual0401', 0,  -18.30,   -3.43,  0.21756)
   ```
   </details>

## Checklist
- [x] Changes are annotated, including comments where useful
- [x] Changes are documented in the changelog for the next game version
  • Loading branch information
lL1l1 authored Jun 25, 2024
1 parent e493ae8 commit 4a6fc47
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog/snippets/fix.6289.md
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 43 additions & 7 deletions lua/sim/weapons/DefaultProjectileWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1111,16 +1111,14 @@ 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
if bp.RackSalvoReloadTime > 0 then
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
Expand All @@ -1129,7 +1127,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
Expand All @@ -1141,7 +1139,39 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
end,

OnLostTarget = function(self)
self.HaltFireOrdered = true
-- 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)
else
local unit = self.unit
if unit then
unit:OnLostTarget(self)
end
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
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
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,

-- Set a bool so we won't fire if the target reticle is moved
Expand Down Expand Up @@ -1169,9 +1199,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()

Expand All @@ -1196,6 +1225,13 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
end,

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,
},

Expand Down

0 comments on commit 4a6fc47

Please sign in to comment.