Skip to content

Commit

Permalink
Selen bugfixes and improvements (FAForever#2794)
Browse files Browse the repository at this point in the history
* prevent cloaking if an attack order is in place

* fix selen bugs

- Fix inconsistent behavior with cloaking if selen starts shooting then attempts to cloak depending on whether shooting was before or after the toggle was triggered.
- Fix multiple concurrent CloakThreads running due to stopping and toggling, which led to a possibility to cloak, toggle cloak off and cloak again while still having it toggled off.
- Fix selen not cloaking without being moved first in some situations.
  • Loading branch information
Petricpwnz authored and JaggedAppliance committed Jun 18, 2019
1 parent 55be4c1 commit 70c58bd
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions units/XSL0101/XSL0101_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ XSL0101 = Class(SWalkingLandUnit) {
Weapons = {
LaserTurret = Class(SDFPhasicAutoGunWeapon) {
OnWeaponFired = function(self)
self.unit:RevealUnit()

-- Each time we fire, reveal cancels CloakThread so we only cloak after firing is over
-- Messy, but can't use weapon IdleState because it's called during and immediately after
-- construction, and before motion events
self.unit.CloakThread = self.unit:ForkThread(self.unit.HideUnit)
if not self.unit.WaitingForCloak then
self.unit:RevealUnit()
-- Firing uncloaks but doesn't stop cloaking attempt (StealthWaitTime)
-- Attack order firing also cancels cloaking attempts
-- Messy, but can't use weapon IdleState because it's called during and immediately after
-- construction, and before motion events
self.unit.CloakThread = self.unit:ForkThread(self.unit.HideUnit)
end
end,
},
},
Expand All @@ -35,7 +37,8 @@ XSL0101 = Class(SWalkingLandUnit) {
OnScriptBitClear = function(self, bit)
if bit == 8 then
self.Sync.LowPriority = true
self.CloakThread = self:ForkThread(self.HideUnit) -- Only actually hides if stationary
-- Only actually hides if stationary and doesn't have an attack order
self.CloakThread = self:ForkThread(self.HideUnit)
else
SWalkingLandUnit.OnScriptBitClear(self, bit)
end
Expand All @@ -58,9 +61,12 @@ XSL0101 = Class(SWalkingLandUnit) {

HideUnit = function(self)
if not self.Dead and self:GetFractionComplete() == 1 and self.Sync.LowPriority then
self.WaitingForCloak = true
WaitSeconds(self:GetBlueprint().Intel.StealthWaitTime)

if self:IsMoving() then return end
if self:IsMoving() or self:IsUnitState("Attacking") then
self.WaitingForCloak = false
return
end

-- Ensure weapon state
self:SetWeaponEnabledByLabel('LaserTurret', false)
Expand All @@ -69,21 +75,25 @@ XSL0101 = Class(SWalkingLandUnit) {
self:SetMaintenanceConsumptionActive()
self:EnableUnitIntel('ToggleBit5', 'RadarStealth')
self:EnableUnitIntel('ToggleBit8', 'Cloak')

self.CloakThread = nil
self.WaitingForCloak = false
end
self.CloakThread = nil
end,

-- Turn off the cloak to begin with
OnStopBeingBuilt = function(self, builder, layer)
SWalkingLandUnit.OnStopBeingBuilt(self, builder, layer)
self:SetScriptBit('RULEUTC_CloakToggle', true)
self.WaitingForCloak = false
self:ForkThread(self.HideUnit)
end,

OnMotionHorzEventChange = function(self, new, old)
-- If we stopped moving, hide
if new == 'Stopped' then
-- Kill possible existing cloak thread from toggle first
KillThread(self.CloakThread)
self.CloakThread = nil
-- We need to fork in order to use WaitSeconds
self.CloakThread = self:ForkThread(self.HideUnit)
end
Expand Down

0 comments on commit 70c58bd

Please sign in to comment.