summaryrefslogtreecommitdiff
path: root/disengage.lua
diff options
context:
space:
mode:
Diffstat (limited to 'disengage.lua')
-rw-r--r--disengage.lua46
1 files changed, 31 insertions, 15 deletions
diff --git a/disengage.lua b/disengage.lua
index edbdf7a..8536fac 100644
--- a/disengage.lua
+++ b/disengage.lua
@@ -8,6 +8,8 @@
-- unit prematurely when executing sweaty micro. Once a unit is re-engaged
-- (reaches the fallback points or is given a new command or stopped) it will be
-- added back to the unit group and become selectable again.
+--
+-- Units will inherit the fallback position from their factory or builder.
function widget:GetInfo()
return {
@@ -74,10 +76,11 @@ local function disengageUnit(uid)
local pos = unitFallbackPosition[uid]
if not pos then
-- By default, run back to base.
- pos = spGetTeamStartPosition(0)
- if not pos then
+ local x, y, z = spGetTeamStartPosition(0)
+ if x == 0 then
return false
end
+ pos = { x = x, y = y, z = z }
end
spGiveOrderToUnit(uid, CMD_MOVE, { pos.x, pos.y, pos.z }, 0)
@@ -120,6 +123,7 @@ end
-- end
-- end
+-- Returns a list of positions for the fallback position.
local function getLocationsForFront(n, center, right)
-- The command give the center point and the rightmost point. We'll normalize
-- this so the leftmost point is at the origin and this normalized vector is
@@ -204,13 +208,13 @@ end
-- When the Unit is done executing a command, the unit is then considered
-- re-engaged.
-function widget:UnitCmdDone(uid)
- reengageUnit(uid)
+function widget:UnitCmdDone(uid, _, _, cmdid)
+ if cmdid ~= CMD_DISENGAGE then
+ reengageUnit(uid)
+ end
end
function widget:UnitCommand(uid, _, _, cid)
- Spring.Echo("Unit Command: " .. uid .. ", " .. cid)
-
if cid == CMD_DISENGAGE then
disengageUnit(uid)
return true
@@ -218,8 +222,6 @@ function widget:UnitCommand(uid, _, _, cid)
end
function widget:CommandNotify(id, params, options)
- Spring.Echo("Command Notify: " .. id)
-
if id == CMD_SET_FALLBACK_POSITION then
-- Sets the unit's fallback point.
--
@@ -227,7 +229,7 @@ function widget:CommandNotify(id, params, options)
-- the fallback point for disengaged units.
local selectedUnits = Spring.GetSelectedUnits()
if #params < 6 then
- for _, uid in selectedUnits do
+ for _, uid in pairs(selectedUnits) do
unitFallbackPosition[uid] = { x = params[1], y = params[2], z = params[3] }
end
else
@@ -251,7 +253,7 @@ function widget:CommandNotify(id, params, options)
disengageUnits()
return true
else
- -- If the command is neither FALLBACK or SET_FALLBACK, re-engage the unit.
+ -- If the command is neither DISENGAGE or SET_FALLBACK, re-engage the unit.
for _, u in pairs(spGetSelectedUnits()) do
reengageUnit(u)
end
@@ -259,6 +261,20 @@ function widget:CommandNotify(id, params, options)
end
end
+function widget:UnitFromFactory(unitId, _, _, factId)
+ -- Units inherit the fallback position of their factory.
+ if unitFallbackPosition[factId] then
+ unitFallbackPosition[unitId] = unitFallbackPosition[factId]
+ end
+end
+
+function widget:UnitCreated(unitID, _, _, builderID)
+ -- Units built inherit the fallback positions of their builder.
+ if unitFallbackPosition[builderID] then
+ unitFallbackPosition[unitID] = unitFallbackPosition[builderID]
+ end
+end
+
local function drawGroundQuad(x,y,z,size)
gl.TexCoord(0,0)
gl.Vertex(x-size,y,z-size)
@@ -274,9 +290,9 @@ local dotImage = "LuaUI/Images/formationDot.dds"
local function drawCircle(pos, size, disengaged)
if disengaged == true then
- glColor(1, 0.6, 0.6, 0.85)
+ glColor(1, 0.6, 0.6, 0.65)
else
- glColor(0.75, 0.75, 0.75, 0.75)
+ glColor(0.75, 0.75, 0.75, 0.55)
end
gl.Texture(dotImage)
gl.BeginEnd(GL.QUADS,drawGroundQuad, pos[1], pos[2], pos[3], size)
@@ -339,13 +355,13 @@ function widget:CommandsChanged()
local customCommands = widgetHandler.customCommands
for i = 1, #selectedUnits do
local udid = Spring.GetUnitDefID(selectedUnits[i])
- if UnitDefs[udid].canMove then
+ if UnitDefs[udid].canMove or UnitDefs[udid].isFactory then
customCommands[#customCommands + 1] = {
id = CMD_SET_FALLBACK_POSITION,
type = CMDTYPE.ICON_FRONT,
tooltip = 'Set a fallback position for this unit.',
name = 'SetFallback',
- cursor = 'areamex',
+ cursor = 'fight',
action = 'setfallback',
}
@@ -354,7 +370,7 @@ function widget:CommandsChanged()
type = CMDTYPE.ICON,
tooltip = 'Disengage and fallback to a previously defined fallback position',
name = 'Disengage',
- cursor = 'areamex',
+ cursor = 'fight',
action = 'disengage',
}
return