Skip to content

Commit 91a6936

Browse files
committed
Add immediate takeoff command
This command forces air units to take off from the airpad.
1 parent 53f0163 commit 91a6936

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

LuaRules/Configs/customcmds.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ local commands = {
9999
FIELD_FAC_SELECT = 38693,
100100
FIELD_FAC_UNIT_TYPE = 38694,
101101
FIELD_FAC_QUEUELESS = 38695,
102-
102+
IMMEDIATETAKEOFF = 39384, -- Airpad abort.
103+
103104
-- terraform
104105
RAMP = 39734,
105106
LEVEL = 39736,

LuaRules/Gadgets/unit_refuel_pad_handler.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ local mcSetPosition = Spring.MoveCtrl.SetPosition
3737
local mcSetRotation = Spring.MoveCtrl.SetRotation
3838
local mcDisable = Spring.MoveCtrl.Disable
3939
local mcEnable = Spring.MoveCtrl.Enable
40+
local CMD_IMMEDIATETAKEOFF = Spring.Utilities.CMD.IMMEDIATETAKEOFF
4041

4142
local coroutine = coroutine
4243
local Sleep = coroutine.yield
@@ -59,6 +60,24 @@ local min = math.min
5960

6061
local mobilePadDefs = {}
6162

63+
local takeoffCMD = {
64+
id = CMD_IMMEDIATETAKEOFF,
65+
name = "Takeoff",
66+
action = "takeoff",
67+
cursor = 'Repair',
68+
type = CMDTYPE.ICON,
69+
}
70+
71+
local giveTakeOffCommandToUnits = {}
72+
73+
for i = 1, #UnitDefs do
74+
local unitDef = UnitDefs[i]
75+
local movetype = Spring.Utilities.getMovetype(unitDef)
76+
if (movetype == 1 or movetype == 0) and (not Spring.Utilities.tobool(unitDef.customParams.cantuseairpads)) then
77+
giveTakeOffCommandToUnits[i] = true
78+
end
79+
end
80+
6281
for unitDefID, ud in pairs(UnitDefs) do
6382
if ud.customParams.ispad and (not ud.isImmobile) then
6483
mobilePadDefs[unitDefID] = true
@@ -608,3 +627,27 @@ end
608627
function gadget:GameFrame(f)
609628
UpdateCoroutines()
610629
end
630+
631+
function gadget:AllowCommand_GetWantedCommand()
632+
return {[CMD_IMMEDIATETAKEOFF] = true}
633+
end
634+
635+
function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions)
636+
--local isMoveCommand = (cmdID == CMD.MOVE or cmdID == CMD_RAW_MOVE)
637+
if landingUnit[unitID] then -- not one of us.
638+
GG.LandAborted(unitID)
639+
local cmdID, _, cmdTag = Spring.GetUnitCurrentCommand(unitID)
640+
if cmdID == CMD_REARM or cmdID == CMD_FIND_PAD then
641+
Spring.GiveOrderToUnit(unitID, CMD.REMOVE, cmdTag, 0)
642+
end
643+
end
644+
return false
645+
--elseif isMoveCommand and cmdOptions.shift == false and not landingUnit.landed then -- user wants to move somewhere else.
646+
--landingUnit[unitID].abort = true
647+
end
648+
649+
function gadget:UnitCreated(unitID, unitDefID, unitTeam)
650+
if giveTakeOffCommandToUnits[unitDefID] then
651+
Spring.InsertUnitCmdDesc(unitID, takeoffCMD)
652+
end
653+
end

LuaUI/Configs/integral_menu_commands_orders.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ local cmdPosDef = {
6060
[CMD_EMBARK] = {pos = 13, priority = 5},
6161
[CMD_DISEMBARK] = {pos = 13, priority = 6},
6262
[CMD_EXCLUDE_PAD] = {pos = 13, priority = 7},
63+
[CMD_IMMEDIATETAKEOFF] = {pos = 13, priority = 8},
6364

6465
-- States
6566
[CMD.REPEAT] = {pos = 1, priority = 1},

LuaUI/Configs/integral_menu_config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ local commandDisplayConfig = {
8383
[CMD_JUMP] = {texture = imageDir .. 'Bold/jump.png'},
8484

8585
[CMD_FIND_PAD] = {texture = imageDir .. 'Bold/rearm.png', tooltip = "Resupply: Return to nearest Airpad for repairs and, for bombers, ammo."},
86+
[CMD_IMMEDIATETAKEOFF] = {texture = imageDir .. 'takeoff.png', tooltip = "Abort Landing\nImmediately take off from airpads or abort landing."},
8687

8788
[CMD_EXCLUDE_PAD] = {texture = imageDir .. 'Bold/excludeairpad.png', tooltip = "Exclude Airpad: Toggle whether any of your aircraft use the targeted airpad."},
8889
[CMD_FIELD_FAC_SELECT] = {texture = imageDir .. 'Bold/fac_select.png', tooltip = "Copy Factory Blueprint: Copy a production option from target functional friendly factory."},
@@ -93,7 +94,7 @@ local commandDisplayConfig = {
9394
[CMD_ONECLICK_WEAPON] = {},--texture = imageDir .. 'Bold/action.png'},
9495
[CMD_UNIT_SET_TARGET_CIRCLE] = {texture = imageDir .. 'Bold/settarget.png'},
9596
[CMD_UNIT_CANCEL_TARGET] = {texture = imageDir .. 'Bold/canceltarget.png'},
96-
97+
9798
[CMD_ABANDON_PW] = {texture = imageDir .. 'Bold/drop_beacon.png'},
9899

99100
[CMD_PLACE_BEACON] = {texture = imageDir .. 'Bold/drop_beacon.png'},

LuaUI/Images/commands/takeoff.png

3.97 KB
Loading

0 commit comments

Comments
 (0)