Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local glPush = gl.PushMatrix
- local glPop = gl.PopMatrix
- local glColor = gl.Color
- local glDepthTest = gl.DepthTest
- local glDepthMask = gl.DepthMask
- local glTranslate = gl.Translate
- local glUnitShape = gl.UnitShape
- local cmdStack = {}
- local myTeam = Spring.GetMyTeamID()
- function widget:GameFrame(f)
- for unitID, params in pairs(cmdStack) do -- for each unit
- local cmd = params
- local gap = cmd.gap
- repeat
- Spring.Echo("gap: "..cmd.gap)
- Spring.GiveOrderToUnit(unitID, CMD.INSERT,{gap * -1, cmd.id, 0, unpack(cmd.params)}, CMD.OPT_ALT)
- cmd = cmd.prev
- if cmd then gap = gap + cmd.gap end
- until not cmd
- cmdStack[unitID] = nil
- end
- end
- -- draw the building on the frame the actual order is not yet issued to avoid confusion
- function widget:DrawWorldPreUnit()
- --if true then return end
- for unitID, params in pairs(cmdStack) do
- local cmd = params
- repeat
- local p = cmd.params
- glColor(1,1,1,0.5)
- glDepthTest(true)
- glDepthMask(true)
- glPush()
- glTranslate(p[1], p[2], p[3])
- glUnitShape(cmd.id * -1, myTeam)
- glPop()
- glColor(1,1,1,1)
- glDepthMask(false)
- glDepthTest(false)
- cmd = cmd.prev
- until not cmd
- end
- end
- function widget:CommandNotify(cmdId, cmdParams, cmdOptions)
- local selectedUnits = Spring.GetSelectedUnits()
- for i = 1, #selectedUnits do
- local unitID = selectedUnits[i]
- if cmdStack[unitID] then
- if cmdOptions.shift then
- -- this cant be done right now because terraform orders always end up after other commands no matter what
- -- so we just ignore other queued orders altogether unless they override the que
- --cmdStack[unitID].gap = cmdStack[unitID].gap + 1
- else
- cmdStack[unitID] = nil
- end
- end
- end
- if currentTerraformSelectedIndex > 1 then
- if cmdId < 0 then
- local unitDefId = -cmdId
- if unitDefId == 37 or unitDefId == 275 then
- local commandPos = {}
- commandPos.x = cmdParams[1]
- commandPos.y = cmdParams[2]
- commandPos.z = cmdParams[3]
- local terraformHowMuch = 0 + currentTerraformSelectedValue
- local unitWidth = 10
- local unitHeight = 10
- local rect = GetTerraRectByParams(commandPos.x, commandPos.z, unitWidth, unitHeight, commandPos.y + terraformHowMuch, 0, 0)
- local myTeamId = Spring.GetMyTeamID()
- local volumeSelection = 0
- local terraformParams = GetTerraParameters(1, rect, selectedUnits, myTeamId, volumeSelection)
- for i = 1, #selectedUnits do
- -- check for unit validty here, ie isBuilder etc
- local unitID = selectedUnits[i]
- Spring.GiveOrderToUnit(unitID, CMD_TERRAFORM_INTERNAL, terraformParams, {"shift"})
- if cmdStack[unitID] and cmdOptions.shift then
- local last = cmdStack[unitID]
- last.gap = last.gap + 1
- cmdStack[unitID] = {params = cmdParams, id = cmdId, prev = last, gap = 1}
- else
- cmdStack[unitID] = {params = cmdParams, id = cmdId, gap = 1}
- end
- -- +2
- end
- return true
- else
- -- +1
- end
- else
- -- +1
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement