-
Notifications
You must be signed in to change notification settings - Fork 213
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
danfireman
wants to merge
2
commits into
ZeroK-RTS:master
Choose a base branch
from
danfireman:cyclopsAttackMoveFix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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() | ||
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 |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Moved