Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. local glPush = gl.PushMatrix
  2. local glPop = gl.PopMatrix
  3. local glColor = gl.Color
  4. local glDepthTest = gl.DepthTest
  5. local glDepthMask = gl.DepthMask
  6. local glTranslate = gl.Translate
  7. local glUnitShape = gl.UnitShape
  8.  
  9. local cmdStack = {}
  10. local myTeam = Spring.GetMyTeamID()
  11.  
  12. function widget:GameFrame(f)
  13.  
  14. for unitID, params in pairs(cmdStack) do -- for each unit
  15. local cmd = params
  16. local gap = cmd.gap
  17. repeat
  18. Spring.Echo("gap: "..cmd.gap)
  19. Spring.GiveOrderToUnit(unitID, CMD.INSERT,{gap * -1, cmd.id, 0, unpack(cmd.params)}, CMD.OPT_ALT)
  20. cmd = cmd.prev
  21. if cmd then gap = gap + cmd.gap end
  22. until not cmd
  23. cmdStack[unitID] = nil
  24. end
  25. end
  26.  
  27. -- draw the building on the frame the actual order is not yet issued to avoid confusion
  28. function widget:DrawWorldPreUnit()
  29. --if true then return end
  30. for unitID, params in pairs(cmdStack) do
  31. local cmd = params
  32. repeat
  33. local p = cmd.params
  34. glColor(1,1,1,0.5)
  35. glDepthTest(true)
  36. glDepthMask(true)
  37. glPush()
  38. glTranslate(p[1], p[2], p[3])
  39. glUnitShape(cmd.id * -1, myTeam)
  40. glPop()
  41. glColor(1,1,1,1)
  42. glDepthMask(false)
  43. glDepthTest(false)
  44. cmd = cmd.prev
  45. until not cmd
  46. end
  47. end
  48.  
  49. function widget:CommandNotify(cmdId, cmdParams, cmdOptions)
  50.  
  51. local selectedUnits = Spring.GetSelectedUnits()
  52.  
  53. for i = 1, #selectedUnits do
  54. local unitID = selectedUnits[i]
  55. if cmdStack[unitID] then
  56. if cmdOptions.shift then
  57. -- this cant be done right now because terraform orders always end up after other commands no matter what
  58. -- so we just ignore other queued orders altogether unless they override the que
  59. --cmdStack[unitID].gap = cmdStack[unitID].gap + 1
  60. else
  61. cmdStack[unitID] = nil
  62. end
  63. end
  64. end
  65.  
  66. if currentTerraformSelectedIndex > 1 then
  67. if cmdId < 0 then
  68. local unitDefId = -cmdId
  69.  
  70. if unitDefId == 37 or unitDefId == 275 then
  71.  
  72. local commandPos = {}
  73. commandPos.x = cmdParams[1]
  74. commandPos.y = cmdParams[2]
  75. commandPos.z = cmdParams[3]
  76.  
  77. local terraformHowMuch = 0 + currentTerraformSelectedValue
  78.  
  79. local unitWidth = 10
  80. local unitHeight = 10
  81.  
  82. local rect = GetTerraRectByParams(commandPos.x, commandPos.z, unitWidth, unitHeight, commandPos.y + terraformHowMuch, 0, 0)
  83.  
  84.  
  85. local myTeamId = Spring.GetMyTeamID()
  86. local volumeSelection = 0
  87. local terraformParams = GetTerraParameters(1, rect, selectedUnits, myTeamId, volumeSelection)
  88.  
  89. for i = 1, #selectedUnits do
  90. -- check for unit validty here, ie isBuilder etc
  91. local unitID = selectedUnits[i]
  92. Spring.GiveOrderToUnit(unitID, CMD_TERRAFORM_INTERNAL, terraformParams, {"shift"})
  93. if cmdStack[unitID] and cmdOptions.shift then
  94. local last = cmdStack[unitID]
  95. last.gap = last.gap + 1
  96. cmdStack[unitID] = {params = cmdParams, id = cmdId, prev = last, gap = 1}
  97. else
  98. cmdStack[unitID] = {params = cmdParams, id = cmdId, gap = 1}
  99. end
  100. -- +2
  101. end
  102.  
  103. return true
  104. else
  105. -- +1
  106. end
  107. else
  108. -- +1
  109. end
  110. end
  111. return false
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement