Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --the amazing dropship factory by knorke
- local testing = false
- local pad = piece "bauplattform"
- local nano = piece "flare2"
- local geruest = piece "geruest"
- local radar = piece "radart2"
- local transporter = piece "transporter"
- local antrieb = piece "antrieb"
- local turm = piece "turm"
- local waffe = piece "waffe"
- local storedUnits = {}
- --storedUnits[1] = "dgheavytank"
- --storedUnits[2] = "dgbike"
- --storedUnits[3] = "dgheavytank"
- local maxUnits = 8
- local unloadRadius = 90
- local busy = false
- function script.Create(unitID)
- if (testing) then Spring.Echo ("spaceport here!") end
- Hide (geruest)
- Move (transporter, y_axis, 1000)
- Move (pad, y_axis, -50) --move build pad underground but hovercrafts ignore it so that is useless
- hideTransporter()
- if (testing) then StartThread (loop) end
- end
- function script.QueryBuildInfo() return pad end
- --no nano bubbling
- --function script.QueryNanoPiece() return nano end
- function script.Activate()
- SetUnitValue(COB.YARD_OPEN, 1)
- SetUnitValue(COB.INBUILDSTANCE, 1)
- SetUnitValue(COB.BUGGER_OFF, 1)
- return 1
- end
- function script.Deactivate()
- SetUnitValue(COB.YARD_OPEN, 0)
- SetUnitValue(COB.INBUILDSTANCE, 0)
- SetUnitValue(COB.BUGGER_OFF, 0)
- return 0
- end
- function loop () --for testing
- while (true) do
- Spring.Echo ("que:" .. #Spring.GetFullBuildQueue(unitID) .. " #storedUnits:" .. #storedUnits)
- Sleep (1000)
- end
- end
- function script.StartBuilding()
- bID = Spring.GetUnitIsBuilding (unitID)
- hideUnitPieces (bID)
- Spring.SetUnitNoSelect (bID, true)
- --local x,y,z = Spring.GetUnitPosition (unitID)
- --Spring.SetUnitPosition (bID, x,100,z)
- end
- function script.StopBuilding()
- local _, _, _, _, buildprogress = Spring.GetUnitHealth (bID)
- if (buildprogress==1) then
- storeUnit (unitName (bID))
- Spring.DestroyUnit (bID,false,true)
- end
- if (not busy) then StartThread (shouldWeDeliver) end --seems not to work without this. maybe buildque only gets cleared once StopBuilding returns?
- end
- function shouldWeDeliver ()
- Sleep (500)
- if (#storedUnits >= maxUnits or (#Spring.GetFullBuildQueue(unitID)==0 and #storedUnits >0)) then deliverUnits () end
- end
- function unitName (uID)
- if (not Spring.ValidUnitID (uID)) then return "invalid unitID in unitName()" end
- local udID =Spring.GetUnitDefID(uID)
- local uDef = UnitDefs [udID]
- return uDef.name
- end
- function deliverUnits ()
- busy = true
- while (#storedUnits >= maxUnits or (#Spring.GetFullBuildQueue(unitID)==0 and #storedUnits >0)) do
- if (#storedUnits == 0) then return end
- showTransporter()
- Move (transporter, y_axis, 0, 100)
- Spin (radar, y_axis, 2)
- WaitForMove (transporter, y_axis)
- local x,y,z = Spring.GetUnitPosition (unitID)
- local teamID = Spring.GetUnitTeam (unitID)
- if (testing) then Spring.Echo ("#storedUnits:" .. #storedUnits) end
- local n = #storedUnits
- if (n > maxUnits) then n = maxUnits end
- local step = (math.pi*2)/n
- for i=1, n do
- dx = x + math.sin (step*i)*unloadRadius
- dz = z + math.cos (step*i)*unloadRadius
- local newUnit = Spring.CreateUnit (storedUnits[i], dx,y,dz, 0, teamID)
- copyMoveOrders (unitID, newUnit)
- if (testing) then Spring.Echo (i .. " deliver:" .. storedUnits[i]) end
- end
- local sUold = #storedUnits
- for i=sUold,1,-1 do
- if (i <= n) then
- storedUnits[i] = storedUnits[i+n]
- storedUnits[i+n] = nil
- end
- end
- --storedUnits = {}
- Move (transporter, y_axis, 1000, 100)
- WaitForMove (transporter, y_axis)
- hideTransporter()
- StopSpin (radar, y_axis,1)
- end
- busy = false
- end
- function storeUnit (unitname)
- storedUnits[#storedUnits+1] = unitname
- end
- ---------------------------------
- function script.Killed(recentDamage, maxHealth)
- if (busy) then explodeTransporter() end
- return 0
- end
- function explodeTransporter ()
- Explode (transporter, SFX.FIRE)
- Explode (waffe, SFX.FIRE)
- Explode (turm, SFX.FIRE)
- Explode (antrieb, SFX.SHATTER)
- end
- function hideTransporter()
- Hide (transporter)
- Hide (antrieb)
- Hide (turm)
- Hide (waffe)
- end
- function showTransporter()
- Show (transporter)
- Show (antrieb)
- Show (turm)
- Show (waffe)
- end
- --make a unit invisible by hiding all its pieces...lol
- function hideUnitPieces (uID)
- local allpieces = Spring.GetUnitPieceList (uID)
- local piece_n = table.getn (allpieces)
- --Spring.Echo ("unit has " .. piece_n .. " pieces")
- for pID=1, piece_n,1 do
- --Spring.Echo ("pID:" .. pID)
- Spring.UnitScript.CallAsUnit(uID, Spring.UnitScript.Hide, pID)
- end
- end
- function copyMoveOrders (unitA, unitB)
- local commands = Spring.GetUnitCommands(unitA)
- for i = 1, #commands do
- local cmd = commands[i]
- if (cmd.id == CMD.MOVE or cmd.id == CMD.FIGHT or cmd.id == CMD.PATROL) then --only copy some commands
- Spring.GiveOrderToUnit(unitB, cmd.id, cmd.params, cmd.options.coded)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement