Skip to content

Commit

Permalink
wip fire once
Browse files Browse the repository at this point in the history
  • Loading branch information
sprunk committed Jun 10, 2019
1 parent bed6194 commit 26563f7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions LuaRules/Gadgets/unit_script.lua
Expand Up @@ -119,6 +119,13 @@ local sp_GetUnitWeaponState = Spring.GetUnitWeaponState
local sp_SetUnitWeaponState = Spring.SetUnitWeaponState
local sp_SetUnitShieldState = Spring.SetUnitShieldState

local spGetUnitWeaponTarget = Spring.GetUnitWeaponTarget
local spGetUnitCurrentCommand = Spring.GetUnitCurrentCommand
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local CMD_ATTACK = CMD.ATTACK
local CMD_REMOVE = CMD.REMOVE
local CMD_OPT_META = CMD.OPT_META

-- Keep local reference to engine's CallAsUnit/WaitForMove/WaitForTurn,
-- as we overwrite them with (safer) framework version later on.
local sp_CallAsUnit = Spring.UnitScript.CallAsUnit
Expand Down Expand Up @@ -637,6 +644,40 @@ local function Wrap_AimWeapon(unitID, callins)
end
end
local TARGET_UNIT = 1
local TARGET_POS = 2
local function Wrap_EndBurst(unitID, callins)
local EndBurst = callins.EndBurst
if not EndBurst then
return
end
local function EndBurstThread(weaponNum)
EndBurst(weaponNum)
local targetType, isUserTarget, targetID = spGetUnitWeaponTarget(unitID, weaponNum)
if not isUserTarget then
return
end
local cmdID, cmdOpt, cmdTag, cmdParam1, cmdParam2, cmdParam3 = spGetUnitCurrentCommand(unitID)
if cmdID ~= CMD_ATTACK or floor(cmdOpt / CMD_OPT_META) % 2 == 0 then
return
end
if (targetType ~= TARGET_UNIT or cmdParam2 or cmdParam1 ~= targetID)
and (targetType ~= TARGET_POS or cmdParam4 or cmdParam1 ~= targetID[1] or cmdParam2 ~= targetID[2] or cmdParam3 ~= targetID[3]) then
return
end
spGiveOrderToUnit(unitID, CMD_REMOVE, {cmdTag}, 0)
end
callins.EndBurst = function(weaponNum)
return StartThread(EndBurstThread, weaponNum)
end
end
local function Wrap_AimShield(unitID, callins)
local AimShield = callins["AimShield"]
Expand Down

0 comments on commit 26563f7

Please sign in to comment.