-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved fighters attackSafetyDistance code from airunitsturnradius gadg…
…et into a new dedicated gadget: "Air AttackSafetyDistance"
- Loading branch information
Showing
2 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function gadget:GetInfo() | ||
return { | ||
name = "Air AttackSafetyDistance", | ||
desc = "sets attackSafetyDistance for fighters", | ||
author = "Doo, Floris", | ||
date = "Sept 19th 2017", | ||
license = "GNU GPL, v2 or later", | ||
layer = 0, | ||
enabled = true | ||
} | ||
end | ||
|
||
--[[ | ||
Wiki: "attackSafetyDistance" movetypedata: Fighters abort dive toward target if within attackSafetyDistance and | ||
try to climb back to normal altitude while still moving toward target. It's disabled by default. Set to half of | ||
the minimum weapon range to avoid collisions, enemy fire, AOE damage. If set to greater than the weapon range, | ||
the unit will fly over the target like a bomber. | ||
]]-- | ||
|
||
if not gadgetHandler:IsSyncedCode() then | ||
return | ||
end | ||
|
||
local isFighter = {} | ||
for udid, ud in pairs(UnitDefs) do | ||
if ud.canFly and ud.customParams.fighter then | ||
isFighter[udid] = true | ||
end | ||
end | ||
|
||
function gadget:Initialize() | ||
gadgetHandler:RegisterAllowCommand(CMD.ANY) | ||
for ct, unitID in pairs(Spring.GetAllUnits()) do | ||
gadget:UnitCreated(unitID, Spring.GetUnitDefID(unitID)) | ||
end | ||
end | ||
|
||
function gadget:UnitCreated(unitID, unitDefID) | ||
if isFighter[unitDefID] then | ||
local curMoveCtrl = Spring.MoveCtrl.IsEnabled(unitID) | ||
if curMoveCtrl then | ||
Spring.MoveCtrl.Disable(unitID) | ||
end | ||
Spring.MoveCtrl.SetAirMoveTypeData(unitID, "attackSafetyDistance", 300) | ||
if curMoveCtrl then | ||
Spring.MoveCtrl.Enable(unitID) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters