Skip to content

Commit

Permalink
Deploy units that are built without a factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Jun 11, 2024
1 parent b7af912 commit 015f7b8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions LuaRules/Gadgets/unit_nanoframe_death.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

function gadget:GetInfo()
return {
name = "Nano Frame Death Handeling",
desc = "Makes nanoframes explode if above X% completion and makes dying nanoframes leave wrecks.",
name = "Nano Frame Death and Factoryless Deployment",
desc = "Makes nanoframes explode if above X% completion and makes dying nanoframes leave wrecks. Causes units built without a factory to deploy properly.",
author = "Google Frog",
date = "Mar 29, 2009",
license = "GNU GPL, v2 or later",
Expand Down Expand Up @@ -35,6 +35,7 @@ local spCreateFeature = Spring.CreateFeature

local unitFromFactory = {}
local isAFactory = {}
local needDeployUnit = {}

function gadget:UnitCreated(unitID,unitDefID,_,builderID)
local ud = UnitDefs[unitDefID]
Expand All @@ -43,6 +44,8 @@ function gadget:UnitCreated(unitID,unitDefID,_,builderID)
end
if builderID and isAFactory[builderID] then
unitFromFactory[unitID] = true
elseif (not ud.isImmobile) or ud.customParams.mobilebuilding then
needDeployUnit[unitID] = true
end
end

Expand Down Expand Up @@ -86,6 +89,17 @@ local function ScrapUnit(unitID, unitDefID, team, progress, face)
end
end

function gadget:UnitFinished(unitID, unitDefID, teamID, builderID)
if needDeployUnit[unitID] then
local env = Spring.UnitScript.GetScriptEnv(unitID)
if env and env.script.StopMoving then
Spring.UnitScript.CallAsUnit(unitID,env.script.StopMoving)
elseif env and env.StopMoving then

This comment has been minimized.

Copy link
@sprunk

sprunk Jun 11, 2024

Member

StopMoving directly within env instead of in the script subtable sounds like it would be a bug or at least bad code if any unit had it.

This comment has been minimized.

Copy link
@GoogleFrog

GoogleFrog Jun 11, 2024

Author Contributor

It is for a form of reliable stop moving. Ie the whole thing where a script handles start and stop rather than the engine, because the engine is bad at it. It can probably be replaced with the standard form.

Spring.UnitScript.CallAsUnit(unitID,env.StopMoving)
end
end
end

local spawnProjPos = {1, 2, 3}
local spawnProjTable = {ttl = 1, pos = spawnProjPos}
function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
Expand Down Expand Up @@ -122,6 +136,7 @@ function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)

isAFactory[unitID] = nil
unitFromFactory[unitID] = nil
needDeployUnit[unitID] = nil
end

function gadget:Initialize()
Expand Down

2 comments on commit 015f7b8

@sprunk
Copy link
Member

@sprunk sprunk commented on 015f7b8 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be the least obvious gadget to put this in.

@GoogleFrog
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it was the smallest change.

Please sign in to comment.