-
Notifications
You must be signed in to change notification settings - Fork 231
Fixing Cyclops futily slow beaming a stinger by instead making it inch forwards #4698
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| 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 cyclopsDefID = UnitDefNames["tankheavyassault"].id | ||
| local spGetUnitWeaponTestRange = Spring.GetUnitWeaponTestRange | ||
| local spGetUnitWeaponTarget = Spring.GetUnitWeaponTarget | ||
| local spGiveOrderToUnit = Spring.GiveOrderToUnit | ||
| local spGetUnitPosition = Spring.GetUnitPosition | ||
| local spGetTeamUnitsByDefs = Spring.GetTeamUnitsByDefs | ||
| local Echo = Spring.Echo | ||
|
||
| local spGetUnitCommands = Spring.GetUnitCommands | ||
|
|
||
|
|
||
| function gadget:UnitCreated(unitID, unitDefID, teamId) | ||
| if unitDefID == cyclopsDefID then | ||
|
||
| cyclopsi[unitID] = true | ||
| end | ||
| end | ||
|
|
||
|
|
||
| function gadget:UnitDestroyed(unitID, unitDefID, teamId) | ||
| if unitDefID == cyclopsDefID then | ||
| cyclopsi[unitID] = nil | ||
| end | ||
| end | ||
|
|
||
| function gadget:UnitGiven(unitID, unitDefID, newTeamID, teamID) | ||
|
||
| if unitDefID == cyclopsDefID then | ||
| cyclopsi[unitID] = true | ||
| end | ||
| end | ||
|
|
||
| function gadget:Initialize() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved |
||
| for _,teamID in ipairs(Spring.GetTeamList()) do | ||
| for _, unitID in ipairs(spGetTeamUnitsByDefs(teamID, cyclopsDefID)) do | ||
| cyclopsi[unitID] = true | ||
| end | ||
| end | ||
| end | ||
|
|
||
| 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 | ||
| --Echo("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)) | ||
| local cmd1 = spGetUnitCommands(cyclopsId, 1)[1] | ||
|
||
| if cmd1 and cmd1.options.internal then | ||
| spGiveOrderToUnit(cyclopsId, CMD.REMOVE, {1, cmd1.tag}, {"ctrl"}) | ||
| end | ||
| spGiveOrderToUnit(cyclopsId, CMD.INSERT, {0, CMD.MOVE, CMD.OPT_INTERNAL, nx, ny, nz}, CMD.OPT_ALT) | ||
| end | ||
|
||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be a customParam so that people could make similar units use the same behaviour, or so that modders could easily remove this behaviour if they're using cyclops for a different purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched