diff --git a/luarules/gadgets/unit_shipyard_waterline_build.lua b/luarules/gadgets/unit_shipyard_waterline_build.lua new file mode 100644 index 00000000000..6805446a098 --- /dev/null +++ b/luarules/gadgets/unit_shipyard_waterline_build.lua @@ -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 + 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 diff --git a/scripts/Units/corasy.bos b/scripts/Units/corasy.bos index 9f4bc6d5f5e..766ef172f2b 100644 --- a/scripts/Units/corasy.bos +++ b/scripts/Units/corasy.bos @@ -227,12 +227,12 @@ Deactivate() QueryBuildInfo(piecenum) { - piecenum = base; + piecenum = pad; } SweetSpot(piecenum) { - piecenum = pad; + piecenum = base; } Killed(severity, corpsetype) diff --git a/scripts/Units/corasy.cob b/scripts/Units/corasy.cob index 5090af14762..360fb108725 100644 Binary files a/scripts/Units/corasy.cob and b/scripts/Units/corasy.cob differ diff --git a/scripts/Units/corasy_clean.bos b/scripts/Units/corasy_clean.bos index c203d996feb..9e1fa35847d 100644 --- a/scripts/Units/corasy_clean.bos +++ b/scripts/Units/corasy_clean.bos @@ -95,7 +95,7 @@ Deactivate() QueryBuildInfo(pieceIndex) { - pieceIndex = base; + pieceIndex = pad; } diff --git a/scripts/Units/corasy_clean.cob b/scripts/Units/corasy_clean.cob index eaa71e1c178..cc44ce6af63 100644 Binary files a/scripts/Units/corasy_clean.cob and b/scripts/Units/corasy_clean.cob differ