Advertisement
Guest User

Untitled

a guest
Oct 19th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. local pad = piece "bauplattform"
  2. local nano = piece "flare2"
  3. local transporter = piece "transporter"
  4. local geruest = piece "geruest"
  5.  
  6. local storedUnits = {}
  7. --storedUnits[1] = "dgheavytank"
  8. --storedUnits[2] = "dgbike"
  9. --storedUnits[3] = "dgheavytank"
  10.  
  11. local maxUnits = 8
  12. local unloadRadius = 100
  13.  
  14. function script.Create(unitID) 
  15.     Spring.Echo ("spaceport here")
  16.     Hide (geruest)
  17.     Move (transporter, y_axis, 1000)
  18.     Move (pad, y_axis, -200)
  19.     --Hide (transporter)
  20.     StartThread (loop)
  21. end
  22.  
  23. function script.QueryBuildInfo() return pad end
  24.  
  25. function script.QueryNanoPiece() return nano end
  26.  
  27. function script.Activate()
  28.     SetUnitValue(COB.YARD_OPEN, 1)
  29.     SetUnitValue(COB.INBUILDSTANCE, 1)
  30.     SetUnitValue(COB.BUGGER_OFF, 1)
  31.     return 1
  32. end
  33.  
  34. function script.Deactivate()   
  35.     SetUnitValue(COB.YARD_OPEN, 0)
  36.     SetUnitValue(COB.INBUILDSTANCE, 0)
  37.     SetUnitValue(COB.BUGGER_OFF, 0)
  38.     return 0
  39. end
  40.  
  41. function loop () --for testing
  42.     while (true) do
  43.         Spring.Echo ("que:" .. #Spring.GetFullBuildQueue(unitID) .. "  #storedUnits:" .. #storedUnits)
  44.         Sleep (1000)
  45.     end
  46. end
  47.  
  48. function script.StartBuilding()
  49.     bID = Spring.GetUnitIsBuilding (unitID)
  50. end
  51.  
  52. function script.StopBuilding() 
  53.     local _,  _,  _, _,  buildprogress = Spring.GetUnitHealth (bID)
  54.     if (buildprogress==1) then
  55.         storeUnit (unitName (bID))
  56.         Spring.DestroyUnit (bID,false,true)
  57.     end
  58.     StartThread (shouldWeDeliver)   --seems not to work without this. maybe buildque only gets cleared once StopBuilding returns?
  59. end
  60.  
  61. function shouldWeDeliver ()
  62.     Sleep (500)
  63.     if (#storedUnits > 8 or (#Spring.GetFullBuildQueue(unitID)==0 and #storedUnits >0)) then deliverUnits () end   
  64. end
  65.  
  66. function unitName (uID)
  67.     if (not Spring.ValidUnitID (uID)) then return "invalid unitID in unitName()" end
  68.     local udID =Spring.GetUnitDefID(uID)
  69.     local uDef = UnitDefs [udID]
  70.     return uDef.name
  71. end
  72.  
  73. function deliverUnits ()
  74.     Move (transporter, y_axis, 0, 100)
  75.     WaitForMove (transporter, y_axis)
  76.    
  77.     if (#storedUnits == 0) then return end
  78.     local x,y,z = Spring.GetUnitPosition (unitID)
  79.     local teamID = Spring.GetUnitTeam (unitID)
  80.     Spring.Echo ("#storedUnits:" .. #storedUnits)
  81.     local step = (math.pi*2)/#storedUnits
  82.     for i=1, #storedUnits do
  83.         dx = x + math.sin (step*i)*unloadRadius
  84.         dz = z + math.cos (step*i)*unloadRadius
  85.         Spring.CreateUnit (storedUnits[i], dx,y,dz, 0, teamID)
  86.         Spring.Echo ("deliver:" .. storedUnits[i])
  87.     end
  88.     storedUnits = {}
  89.    
  90.     Move (transporter, y_axis, 1000, 100)
  91. end
  92.  
  93. function storeUnit (unitname)
  94.     storedUnits[#storedUnits+1] = unitname
  95. end
  96.  
  97. ---------------------------------
  98. function script.Killed(recentDamage, maxHealth)
  99.     return 0
  100. end
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement