Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Force move rearming planes #4474

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion LuaRules/Gadgets/unit_bomber_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ local function CancelAirpadReservation(unitID)
GG.LandAborted(unitID)
end

local queue = spGetCommandQueue(unitID, -1)
if queue then
local index = #queue + 1
for i = 1, #queue do
if queue[i].id == CMD_REARM or queue[i].id == CMD_FIND_PAD then -- already have set rearm point, we have nothing left to do here
spGiveOrderToUnit(unitID, CMD_REMOVE, index, 0)
end
end

--value greater than 1 for icon state:
if spGetUnitRulesParam(unitID, "noammo") == 3 then -- repairing
local env = Spring.UnitScript.GetScriptEnv(unitID)
Expand Down Expand Up @@ -519,7 +528,9 @@ local function CancelAirpadReservation(unitID)
-- totalReservedPad = totalReservedPad -1
reservations.units[unitID] = nil
reservations.count = math.max(reservations.count - 1, 0)
spSetUnitRulesParam(targetPad,"unreservedPad",math.max(0,airpadsData[targetPad].cap-reservations.count)) --hint widgets
if not excludedPads[targetPad] then -- Don't mark excluded pads as unreserved
spSetUnitRulesParam(targetPad,"unreservedPad",math.max(0,airpadsData[targetPad].cap-reservations.count)) --hint widgets
end
end
end

Expand Down Expand Up @@ -550,6 +561,9 @@ local function ToggleExclusion(padID, teamID)
if not excludedPads[teamID][padID] then
excludedPads[teamID][padID] = true
Spring.SetUnitRulesParam(padID, "padExcluded" .. teamID, 1)
for bomberID in pairs(airpadsData[padID].reservations.units) do
CancelAirpadReservation(bomberID) -- send anyone who was going here elsewhere
end
else
--Already exists, remove
Spring.SetUnitRulesParam(padID, "padExcluded" .. teamID, 0)
Expand Down Expand Up @@ -765,6 +779,20 @@ function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdO
ToggleExclusion(cmdParams[1], unitTeam)
return false
end
if cmdID == CMD_RAW_MOVE then
local targetPad
if bomberToPad[unitID] then -- unit is going toward an airpad
targetPad = bomberToPad[unitID].padID
elseif bomberLanding[unitID] then -- unit is on the airpad
targetPad = bomberLanding[unitID].padID
end
if targetPad then
ToggleExclusion(targetPad, Spring.GetUnitTeam(unitID))

CancelAirpadReservation(unitID)
return true
end
end
local noAmmo = spGetUnitRulesParam(unitID, "noammo")
if not noAmmo or noAmmo == 0 then
local health, maxHealth = Spring.GetUnitHealth(unitID)
Expand Down