Skip to content

Commit

Permalink
dgun stall assist: minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwetuin committed Dec 21, 2024
1 parent 0e4db0d commit 1f8184d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions luaui/Widgets/unit_dgun_stall_assist.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function widget:GetInfo()
return {
name = "DGun Stall Assist",
Expand All @@ -11,9 +10,6 @@ function widget:GetInfo()
}
end

----------------------------------------------------------------
-- Config
----------------------------------------------------------------
local targetEnergy = 600
local watchForTime = 5

Expand All @@ -22,14 +18,13 @@ local watchForTime = 5
----------------------------------------------------------------
local watchTime = 0
local waitedUnits = nil -- nil / waitedUnits[1..n] = uID
local shouldWait = {} -- shouldWait[uDefID] = true / nil
local isFactory = {} -- isFactory[uDefID] = true / nil
local shouldWait = {}
local isFactory = {}

local gameStarted

local stallIds = {UnitDefNames['armcom'].id, UnitDefNames['corcom'].id, UnitDefNames['legcom'] and UnitDefNames['legcom'].id}


----------------------------------------------------------------
-- Speedups
----------------------------------------------------------------
Expand All @@ -41,7 +36,6 @@ local spGetMyTeamID = Spring.GetMyTeamID
local spGetTeamResources = Spring.GetTeamResources
local spGetTeamUnits = Spring.GetTeamUnits
local spGetUnitDefID = Spring.GetUnitDefID
local spGetSpectatingState = Spring.GetSpectatingState
local spGetUnitIsBeingBuilt = Spring.GetUnitIsBeingBuilt

local CMD_DGUN = CMD.DGUN
Expand Down Expand Up @@ -75,7 +69,7 @@ function widget:Initialize()
end

for uDefID, uDef in pairs(UnitDefs) do
if (uDef.buildSpeed > 0) and uDef.canAssist and (not uDef.canManualFire) then
if uDef.buildSpeed > 0 and uDef.canAssist and not uDef.canManualFire then
shouldWait[uDefID] = true
if uDef.isFactory then
isFactory[uDefID] = true
Expand All @@ -97,13 +91,13 @@ function widget:Update(dt)
end
end

if (stallUnitSelected) then
if stallUnitSelected then
watchTime = watchForTime
end
else
watchTime = watchTime - dt

if waitedUnits and (watchTime < 0) then
if waitedUnits and watchTime < 0 then

local toUnwait = {}
for i = 1, #waitedUnits do
Expand All @@ -127,11 +121,11 @@ function widget:Update(dt)
end
end

if (watchTime > 0) and (not waitedUnits) then
if watchTime > 0 and not waitedUnits then

local myTeamID = spGetMyTeamID()
local currentEnergy, energyStorage = spGetTeamResources(myTeamID, "energy")
if (currentEnergy < targetEnergy) and (energyStorage >= targetEnergy) then
if currentEnergy < targetEnergy and energyStorage >= targetEnergy then

waitedUnits = {}
local myUnits = spGetTeamUnits(myTeamID)
Expand Down

0 comments on commit 1f8184d

Please sign in to comment.