-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- -- file: unit_factory_kickstart.lua -- brief: assigns new builder units to guard their source factory -- author: OWen Martindell -- -- Copyright (C) 2007. -- Licensed under the terms of the GNU GPL, v2 or later. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function widget:GetInfo() return { name = "Factory KickStart", desc = "Replaces default factory Move order with Move,Fight v1.1", author = "TheFatController", date = "Jun 29, 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = false -- loaded by default? } end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- local OrderUnit = Spring.GiveOrderToUnit local GetMyTeamID = Spring.GetMyTeamID local GetCommandQueue = Spring.GetCommandQueue local GetUnitBuildFacing = Spring.GetUnitBuildFacing local GetUnitPosition = Spring.GetUnitPosition function widget:UnitFromFactory(unitID, unitDefID, unitTeam, factID, factDefID, userOrders) if (unitTeam ~= GetMyTeamID()) then return elseif (userOrders) then return end local cQueue = GetCommandQueue(factID) for _, elem in ipairs(cQueue) do if ((elem.id == CMD.MOVE) or (elem.id == CMD.FIGHT) or (elem.id == CMD.GUARD) or (elem.id == CMD.PATROL)) then return end end local bd = UnitDefs[factDefID] if (not (bd and bd.isFactory)) then return end local x, y, z = GetUnitPosition(factID) local zc = 0 local xc = 0 local facDir = GetUnitBuildFacing(factID) if (facDir == 0) then zc = 100 xc = (20 - math.random(0,40)) elseif (facDir == 1) then xc = 100 zc = (20 - math.random(0,40)) elseif (facDir == 2) then zc = -100 xc = (20 - math.random(0,40)) elseif (facDir == 3) then xc = -100 zc = (20 - math.random(0,40)) end OrderUnit(unitID, CMD.MOVE, { (x + xc), y, (z + zc) }, { "" }) OrderUnit(unitID, CMD.FIGHT, { (x + (xc * 2)), y, (z + (zc * 2)) }, { "shift" }) end --------------------------------------------------------------------------------