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

Fixing Cyclops futily slow beaming a stinger by instead making it inch forwards #4698

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
69 changes: 69 additions & 0 deletions LuaRules/Gadgets/unit_cyclops_range_fix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function gadget:GetInfo()
return {
name = "Cyclops attack move fixing",
desc = "Makes Cyclops move closer when it can't hit with canon",
author = "dyth68",
date = "2022-05-12",
license = "Public Domain",
layer = 83,
enabled = true
}
end

local cyclopsi = {}
local cyclopsDefIDs = {}
local spGetUnitWeaponTestRange = Spring.GetUnitWeaponTestRange
local spGetUnitWeaponTarget = Spring.GetUnitWeaponTarget
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local spGetUnitPosition = Spring.GetUnitPosition
local spGetTeamUnitsByDefs = Spring.GetTeamUnitsByDefs
local spEcho = Spring.Echo
local spGetUnitCommands = Spring.GetUnitCommands

function gadget:GameFrame(frame)
for cyclopsId, _ in pairs(cyclopsi) do
local _, _, canontargetID = spGetUnitWeaponTarget (cyclopsId, 1)
local targetType, _, slowBeamTargetID = spGetUnitWeaponTarget (cyclopsId, 2)
if (targetType == 1) and (canontargetID == nil) then
--spEcho("Retargetting Cyclops")
local x, y, z = spGetUnitPosition(cyclopsId)
local tx, ty, tz = spGetUnitPosition(slowBeamTargetID)
local nx, nz = x * 0.95 + tx * 0.05, z * 0.95 + tz * 0.05
local ny = math.max(0, Spring.GetGroundHeight(nx, nz))
-- Remove the inching command if it's already there
local cmds = spGetUnitCommands(cyclopsId, 1)
if #cmds > 0 then
local cmd1 = cmds[1]
if cmd1 and cmd1.options.internal then
spGiveOrderToUnit(cyclopsId, CMD.REMOVE, {1, cmd1.tag}, {"ctrl"})
end
end
spGiveOrderToUnit(cyclopsId, CMD.INSERT, {0, CMD.MOVE, CMD.OPT_INTERNAL, nx, ny, nz}, CMD.OPT_ALT)
end
end
end

function gadget:UnitCreated(unitID, unitDefID, teamId)
if cyclopsDefIDs[unitDefID] then
cyclopsi[unitID] = true
end
end

function gadget:UnitDestroyed(unitID, unitDefID, teamId)
if cyclopsDefIDs[unitDefID] then
cyclopsi[unitID] = nil
end
end

function gadget:Initialize()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to put Init at the bottom of the gadget, with create/destroy above, with more frequent logic and callins above that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

for udid, unitDef in pairs(UnitDefs) do
if unitDef.customParams.inch_forwards_for_cannon_range then
cyclopsDefIDs[udid] = true
for _,teamID in ipairs(Spring.GetTeamList()) do
for _, unitID in ipairs(spGetTeamUnitsByDefs(teamID, udid)) do
cyclopsi[unitID] = true
end
end
end
end
end
1 change: 1 addition & 0 deletions units/tankheavyassault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ return { tankheavyassault = {
outline_x = 110,
outline_y = 110,
outline_yoff = 13.5,
inch_forwards_for_cannon_range = true,
},

explodeAs = [[BIG_UNIT]],
Expand Down