From afdb95d50e0208ceb312b6c3fe72141dd2308547 Mon Sep 17 00:00:00 2001 From: Shaman <48730089+Arch-Shaman@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:44:07 -0500 Subject: [PATCH 1/3] Fix strider hub not inflicting initial states onto units --- LuaUI/Widgets/unit_start_state.lua | 73 +++++++++++++----------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/LuaUI/Widgets/unit_start_state.lua b/LuaUI/Widgets/unit_start_state.lua index 88542b4d82..c5b18d66c8 100644 --- a/LuaUI/Widgets/unit_start_state.lua +++ b/LuaUI/Widgets/unit_start_state.lua @@ -2,16 +2,16 @@ -------------------------------------------------------------------------------- function widget:GetInfo() - return { - name = "Unit Start State", - desc = "Configurable starting unit states for units", - author = "GoogleFrog", - date = "13 April 2011", --last update: 29 January 2014 - license = "GNU GPL, v2 or later", - handler = false, - layer = 1, - enabled = true, -- loaded by default? - } + return { + name = "Unit Start State", + desc = "Configurable starting unit states for units", + author = "GoogleFrog", + date = "13 April 2011", --last update: 29 January 2014 + license = "GNU GPL, v2 or later", + handler = false, + layer = 1, + enabled = true, -- loaded by default? + } end -------------------------------------------------------------------------------- @@ -146,6 +146,10 @@ for i = 1, #UnitDefs do end end +local notAFactory = { + [UnitDefNames["athena"]] = true, -- use stupid hax to avoid not treating striderhubs like a factory. +} + options_path = 'Settings/Unit Behaviour/Default States' options_order = { 'inheritcontrol', 'presetlabel', @@ -1265,21 +1269,20 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID) local name = ud.name if unitAlreadyAdded[name] then + local builderDefID = builderID and Spring.GetUnitDefID(builderID) -- DO. NOT. CALL. THIS. FOR. EVERY. STATE! CPU cycles do not grow on trees! + local isAFactory = false + if builderDefID then + isAFactory = not notAFactory[builderDefID] -- this simplifies the check a bit, probably. note this hits athena only! + end local value = GetStateValue(name, "firestate0") if value ~= nil then if value == -1 then - local trueBuilder = false - if builderID then - local bdid = Spring.GetUnitDefID(builderID) - if UnitDefs[bdid] and UnitDefs[bdid].isFactory then - local firestate = Spring.Utilities.GetUnitFireState(builderID) - if firestate then - orderArray[#orderArray + 1] = {CMD.FIRE_STATE, {firestate}, CMD.OPT_SHIFT} - trueBuilder = true - end + if isAFactory then + local firestate = Spring.Utilities.GetUnitFireState(builderID) + if firestate then + orderArray[#orderArray + 1] = {CMD.FIRE_STATE, {firestate}, CMD.OPT_SHIFT} end - end - if not trueBuilder then -- inherit from factory def's start state, not the current state of any specific factory unit + else -- inherit from factory def's start state, not the current state of any specific factory unit local firestate = GetFactoryDefState(name, "firestate0") if firestate ~= nil then orderArray[#orderArray + 1] = {CMD.FIRE_STATE, {firestate}, CMD.OPT_SHIFT} @@ -1293,18 +1296,12 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID) value = GetStateValue(name, "movestate1") if value ~= nil then if value == -1 then - local trueBuilder = false - if builderID then - local bdid = Spring.GetUnitDefID(builderID) - if UnitDefs[bdid] and UnitDefs[bdid].isFactory then - local movestate = Spring.Utilities.GetUnitMoveState(builderID) - if movestate then - orderArray[#orderArray + 1] = {CMD.MOVE_STATE, {movestate}, CMD.OPT_SHIFT} - trueBuilder = true - end + if isAFactory then + local movestate = Spring.Utilities.GetUnitMoveState(builderID) + if movestate then + orderArray[#orderArray + 1] = {CMD.MOVE_STATE, {movestate}, CMD.OPT_SHIFT} end - end - if not trueBuilder then -- inherit from factory def's start state, not the current state of any specific factory unit + else local movestate = GetFactoryDefState(name, "movestate1") if movestate ~= nil then orderArray[#orderArray + 1] = {CMD.MOVE_STATE, {movestate}, CMD.OPT_SHIFT} @@ -1316,16 +1313,8 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID) end value = GetStateValue(name, "flylandstate_1") - if value == -1 then - local trueBuilder = false - if builderID then - local bdid = Spring.GetUnitDefID(builderID) - if UnitDefs[bdid] and UnitDefs[bdid].isFactory then - trueBuilder = true - -- inheritance handled in unit_air_plants gadget - end - end - if not trueBuilder then -- inherit from factory def's start state, not the current state of any specific factory unit + if value == -1 then -- inheritance handled in unit_air_plants gadget + if not isAFactory then -- inherit from factory def's start state, not the current state of any specific factory unit value = GetFactoryDefState(name, "flylandstate_1_factory") if value ~= nil then orderArray[#orderArray + 1] = {CMD.IDLEMODE, {value}, CMD.OPT_SHIFT} From 279d7fc07825cc82e8ee96729120b65e18a948d4 Mon Sep 17 00:00:00 2001 From: Shaman <48730089+Arch-Shaman@users.noreply.github.com> Date: Sat, 13 Jan 2024 17:29:01 -0500 Subject: [PATCH 2/3] Fix mobile cons inflicting initial states --- LuaUI/Widgets/unit_start_state.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LuaUI/Widgets/unit_start_state.lua b/LuaUI/Widgets/unit_start_state.lua index c5b18d66c8..a8e01327be 100644 --- a/LuaUI/Widgets/unit_start_state.lua +++ b/LuaUI/Widgets/unit_start_state.lua @@ -1272,7 +1272,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID) local builderDefID = builderID and Spring.GetUnitDefID(builderID) -- DO. NOT. CALL. THIS. FOR. EVERY. STATE! CPU cycles do not grow on trees! local isAFactory = false if builderDefID then - isAFactory = not notAFactory[builderDefID] -- this simplifies the check a bit, probably. note this hits athena only! + isAFactory = not notAFactory[builderDefID] and not UnitDefs[builderDefID].isMobileBuilder -- this simplifies the check a bit, probably. note this hits athena only! end local value = GetStateValue(name, "firestate0") if value ~= nil then From c17613289d697cae6d7afdfb44e515d0cb85bdf0 Mon Sep 17 00:00:00 2001 From: Shaman <48730089+Arch-Shaman@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:27:30 -0400 Subject: [PATCH 3/3] Use notreallyafactory instead --- LuaUI/Widgets/unit_start_state.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/LuaUI/Widgets/unit_start_state.lua b/LuaUI/Widgets/unit_start_state.lua index a8e01327be..a89c2bffbe 100644 --- a/LuaUI/Widgets/unit_start_state.lua +++ b/LuaUI/Widgets/unit_start_state.lua @@ -146,9 +146,13 @@ for i = 1, #UnitDefs do end end -local notAFactory = { - [UnitDefNames["athena"]] = true, -- use stupid hax to avoid not treating striderhubs like a factory. -} +local notAFactory = {} +for i = 1, #UnitDefs do + local ud = UnitDefs[i] + if ud.customParams.notreallyafactory then + notAFactory[ud.name] = true + end +end options_path = 'Settings/Unit Behaviour/Default States' options_order = {