-
Notifications
You must be signed in to change notification settings - Fork 312
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
SeaLabs Build Above Water #3982
base: master
Are you sure you want to change the base?
Changes from all commits
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,59 @@ | ||
function gadget:GetInfo() | ||
return { | ||
name = "Shipyards Build at Waterline", | ||
desc = "Move the build position depending on unit needs.", | ||
author = "robert the pie", | ||
layer = 0, | ||
enabled = true, | ||
} | ||
end | ||
|
||
if not gadgetHandler:IsSyncedCode() then return false end | ||
|
||
|
||
local shipyardsDefIDPads = {} | ||
local shipyardsDefIDWaterlines = {} | ||
local subDefIDs = {} | ||
do | ||
local shipyardsNamesToPads = { | ||
corsy = 4, | ||
corasy = 8, | ||
armsy = 14, | ||
armasy = 2, | ||
} | ||
for name, pad in pairs(shipyardsNamesToPads) do | ||
if UnitDefNames[name] then | ||
shipyardsDefIDPads[UnitDefNames[name].id] = pad | ||
shipyardsDefIDWaterlines[UnitDefNames[name].id] = UnitDefNames[name].waterline | ||
end | ||
end | ||
end | ||
|
||
for unitDefID, unitDef in pairs(UnitDefs) do | ||
if unitDef.waterline and unitDef.minWaterDepth and unitDef.waterline >= 30 then | ||
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. could check movedef, it has an explicit submarine bool 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. from what i can find, 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.
|
||
subDefIDs[unitDefID] = (unitDef.waterline) | ||
end | ||
end | ||
|
||
function gadget:AllowUnitCreation(unitDefID, builderID, builderTeam, x, y, z, facing) | ||
-- allow unit creation is called before and not after, otherwise only consecutive builds are adjusted, for some reason | ||
--function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID) | ||
local builderDefID = Spring.GetUnitDefID(builderID) | ||
if shipyardsDefIDPads[builderDefID] then | ||
local piece = shipyardsDefIDPads[builderDefID] | ||
local waterDebth = subDefIDs[unitDefID] | ||
if waterDebth then | ||
waterDebth = waterDebth + shipyardsDefIDWaterlines[builderDefID] | ||
waterDebth = waterDebth / 8 | ||
else | ||
waterDebth = 0 | ||
end | ||
Spring.SetUnitPieceMatrix(builderID, piece, { | ||
1,0,0,0, | ||
0,1,0,0, | ||
0,0,1,0, | ||
0,waterDebth,0,1} | ||
) | ||
end | ||
return true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ Deactivate() | |
|
||
QueryBuildInfo(pieceIndex) | ||
{ | ||
pieceIndex = base; | ||
pieceIndex = pad; | ||
} | ||
|
||
|
||
|
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.
put piece name as a customparam imo
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 originally wanted to call the
QueryBuildInfo
but unfortunately:1: I couldn't figure out how to get the call to work to get the return param back, if that is even possible.
2: Knowing some of our code malpractices around (me), this could potentially backfire one day.
Will move it to a custom param once i figure out the cases under which the unit goes underground.
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.
QueryBuildInfo
here in the gadget would be a bad idea though because the piece can change and then you'd leave the previous one at a different height, but when you have LUS you can just put the logic in each shipyard's script