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

SeaLabs Build Above Water #3982

Draft
wants to merge 3 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
59 changes: 59 additions & 0 deletions luarules/gadgets/unit_shipyard_waterline_build.lua
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,
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@sprunk sprunk Nov 29, 2024

Choose a reason for hiding this comment

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

  1. requires LUS afaik, but factories are a great porting target anyway (their script code is simple and they are rare enough for perf not to be a concern). Calling 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
  2. stuff blowing up is good, how else are yall gonna learn?

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

could check movedef, it has an explicit submarine bool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from what i can find, unitDef.moveDef.subMarine? or would it be moveDef.smClass?

Copy link
Collaborator

Choose a reason for hiding this comment

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

isSubmarine, also make sure not to index the movedef without a nil check because immobiles/aircraft don't have one

local md = unitDef.moveDef
if md and md.isSubmarine then

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
4 changes: 2 additions & 2 deletions scripts/Units/corasy.bos
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ Deactivate()

QueryBuildInfo(piecenum)
{
piecenum = base;
piecenum = pad;
}

SweetSpot(piecenum)
{
piecenum = pad;
piecenum = base;
}

Killed(severity, corpsetype)
Expand Down
Binary file modified scripts/Units/corasy.cob
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/Units/corasy_clean.bos
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Deactivate()

QueryBuildInfo(pieceIndex)
{
pieceIndex = base;
pieceIndex = pad;
}


Expand Down
Binary file modified scripts/Units/corasy_clean.cob
Binary file not shown.