Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pad = piece "bauplattform"
- local nano = piece "flare2"
- local transporter = piece "transporter"
- local geruest = piece "geruest"
- local storedUnits = {}
- --storedUnits[1] = "dgheavytank"
- --storedUnits[2] = "dgbike"
- --storedUnits[3] = "dgheavytank"
- local maxUnits = 8
- local unloadRadius = 100
- function script.Create(unitID)
- Spring.Echo ("spaceport here")
- Hide (geruest)
- Move (transporter, y_axis, 1000)
- Move (pad, y_axis, -200)
- --Hide (transporter)
- StartThread (loop)
- end
- function script.QueryBuildInfo() return pad end
- 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)
- end
- function script.StopBuilding()
- local _, _, _, _, buildprogress = Spring.GetUnitHealth (bID)
- if (buildprogress==1) then
- storeUnit (unitName (bID))
- Spring.DestroyUnit (bID,false,true)
- end
- StartThread (shouldWeDeliver) --seems not to work without this. maybe buildque only gets cleared once StopBuilding returns?
- end
- function shouldWeDeliver ()
- Sleep (500)
- if (#storedUnits > 8 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 ()
- Move (transporter, y_axis, 0, 100)
- WaitForMove (transporter, y_axis)
- if (#storedUnits == 0) then return end
- local x,y,z = Spring.GetUnitPosition (unitID)
- local teamID = Spring.GetUnitTeam (unitID)
- Spring.Echo ("#storedUnits:" .. #storedUnits)
- local step = (math.pi*2)/#storedUnits
- for i=1, #storedUnits do
- dx = x + math.sin (step*i)*unloadRadius
- dz = z + math.cos (step*i)*unloadRadius
- Spring.CreateUnit (storedUnits[i], dx,y,dz, 0, teamID)
- Spring.Echo ("deliver:" .. storedUnits[i])
- end
- storedUnits = {}
- Move (transporter, y_axis, 1000, 100)
- end
- function storeUnit (unitname)
- storedUnits[#storedUnits+1] = unitname
- end
- ---------------------------------
- function script.Killed(recentDamage, maxHealth)
- return 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement