Skip to content
Open
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
2 changes: 1 addition & 1 deletion data/lang/equipment-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@
},
"UNOCCUPIED_CABIN": {
"description": "",
"message": "Extra Passenger Cabin"
"message": "Passenger Cabin"
},
"UNOCCUPIED_CABIN_DESCRIPTION": {
"description": "",
Expand Down
2 changes: 1 addition & 1 deletion data/lang/module-searchrescue/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
},
"UNOCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "unoccupied passenger cabins"
"message": "unoccupied passenger berths"
},
"WHERE_IS_THE_TARGET": {
"description": "",
Expand Down
40 changes: 24 additions & 16 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"ALL_UP_WEIGHT": {
"description": "",
"message": "All-up weight"
"message": "Current total weight"
},
"AMOUNT": {
"description": "",
Expand Down Expand Up @@ -125,7 +125,7 @@
},
"CABINS": {
"description": "For passengers",
"message": "Cabins"
"message": "Berths"
},
"CABIN_FREE": {
"description": "Free capacity for passengers",
Expand Down Expand Up @@ -629,12 +629,16 @@
},
"EQUIPMENT_CAPACITY": {
"description": "The equipment capacity of a ship",
"message": "Equipment Capacity"
"message": "Equipment capacity"
},
"EQUIPMENT_MARKET": {
"description": "",
"message": "Equipment Market"
},
"EQUIPMENT_USED": {
"description": "",
"message": "Equipment space used"
},
"EQUIPPED": {
"description": "",
"message": "Equipped"
Expand Down Expand Up @@ -1819,6 +1823,10 @@
"description": "",
"message": "Notes:"
},
"NOT_ENOUGH_SPACE_FOR_EQUIPMENT": {
"description": "",
"message": "Not enough space to install this equipment"
},
"NOTORIETY": {
"description": "Character parameter",
"message": "Notoriety"
Expand Down Expand Up @@ -1863,21 +1871,13 @@
"description": "",
"message": "{range} light years ({maxRange} max)"
},
"N_OCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "{quantity} Occupied Passenger Cabins"
},
"N_SHIELD_GENERATORS": {
"description": "",
"message": "{quantity} Shield Generators"
},
"N_UNOCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "{quantity} Unoccupied Passenger Cabins"
},
"OCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "Occupied Passenger Cabins"
"message": "Occupied passenger berths"
},
"OFF": {
"description": "",
Expand Down Expand Up @@ -1969,7 +1969,7 @@
},
"PASSENGER_CABIN_CAPACITY": {
"description": "Entry for ship info",
"message": "Passenger cabin capacity"
"message": "Max passenger capacity"
},
"PASTE": {
"description": "As for clipboard",
Expand All @@ -1991,6 +1991,14 @@
"description": "",
"message": "Pay fine of {amount}"
},
"PAYLOAD": {
"description": "Carry mass (short label)",
"message": "Payload"
},
"PAYLOAD_WEIGHT": {
"description": "Carry mass (long label)",
"message": "Payload weight"
},
"PENDING_RETURN": {
"description": "Status if the mission has not yet been fully completed",
"message": "Pending Return"
Expand Down Expand Up @@ -2745,7 +2753,7 @@
},
"UNOCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "Unoccupied Passenger Cabins"
"message": "Unoccupied passenger berths"
},
"UNPROFITABLE_TRADE": {
"description": "Indicates an unprofitable trade route.",
Expand All @@ -2764,8 +2772,8 @@
"message": "Up acceleration"
},
"USED": {
"description": "",
"message": "Used"
"description": "Usually shown with FREE as a pair, e.g. 4t used / 7t free",
"message": "used"
},
"VERY_HIGH": {
"description": "Game settings option: graphic resolution",
Expand Down
4 changes: 2 additions & 2 deletions data/libs/CargoManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
--
-- Returns the available amount of cargo space currently present on the vessel.
function CargoManager:GetFreeSpace()
return self:GetTotalSpace() - self.usedCargoSpace
return self.ship:GetPayloadFree()
end

-- Method: GetUsedSpace
Expand Down Expand Up @@ -99,7 +99,7 @@ function CargoManager:AddCommodity(type, count)
-- TODO: use a cargo volume metric with variable mass instead of fixed 1t == 1m^3
local required_space = (type.mass or 1) * (count or 1)

if self:GetFreeSpace() < required_space then
if self.ship:GetPayloadFree() < required_space then
return false
end

Expand Down
19 changes: 19 additions & 0 deletions data/libs/EquipSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,15 @@ end
function EquipSet:CanInstallInSlot(slotHandle, equipment)
local equipped = self:GetItemInSlot(slotHandle)
local freeVolume = self:GetFreeVolume() + (equipped and equipped.volume or 0)
local freeMass = self.ship:GetPayloadFree()
local newMass = self:GetEquipPayloadMass(equipment)
local oldMass = equipped and self:GetEquipPayloadMass(equipped) or 0.0
local massDelta = newMass - oldMass

return (equipment.slot or false)
and EquipSet.CompatibleWithSlot(equipment, slotHandle)
and (freeVolume >= equipment.volume)
and (freeMass >= massDelta)
end

-- Method: CanInstallLoose
Expand All @@ -435,6 +440,7 @@ end
function EquipSet:CanInstallLoose(equipment)
return not equipment.slot
and self:GetFreeVolume() >= equipment.volume
and self.ship:GetPayloadFree() >= self:GetEquipPayloadMass(equipment)
end

-- Method: AddListener
Expand Down Expand Up @@ -634,6 +640,19 @@ function EquipSet:_RemoveInternal(equipment)
self.ship:UpdateEquipStats()
end

-- Payload mass for an equipment item.
-- Hyperdrives are counted at full reservoir equivalent.
---@param equip EquipType
---@return number
function EquipSet:GetEquipPayloadMass(equip)
local mass = equip.mass or 0.0
-- Hyperdrive instances expose both GetMaxFuel() and storedFuel
if equip.GetMaxFuel and equip.storedFuel then
mass = mass + (equip:GetMaxFuel() - equip.storedFuel)
end
return mass
end

-- Populate the slot cache
---@private
function EquipSet:BuildSlotCache()
Expand Down
68 changes: 68 additions & 0 deletions data/libs/HullConfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

local ShipDef = require 'ShipDef'
local Serializer = require 'Serializer'
local Equipment = require 'Equipment'
require 'modules.Equipment.Internal'

local utils = require 'utils'

Expand Down Expand Up @@ -44,6 +46,7 @@ local HullConfig = utils.proto("HullConfig")
HullConfig.id = ""
HullConfig.path = ""
HullConfig.equipCapacity = 0
HullConfig.maxPayload = 0

-- Default slot config for a new shipdef
-- Individual shipdefs can redefine slots or remove them by setting the slot to 'false'
Expand All @@ -63,13 +66,76 @@ Serializer:RegisterClass("HullConfig.Slot", Slot)

--==============================================================================

-- Function: AddAutoCabinSlots
--
-- Instead of meticulously filling out all ship definitions with cabin slots
-- add them automatically according to the payload capacity of the ship.
local function AddAutoCabinSlots(newShip, def)

-- Remove any existing cabin slots that don't have unique keys.
for name, slot in pairs(newShip.slots) do
if slot.type == "cabin" then
if slot.i18n_key == nul then
newShip.slots[name] = nil
end
end
end

local space = def.cargo or 0
local biggest = 0

-- Start with the largest possible cabin size and work down
for size = 4, 1, -1 do

local eq = Equipment.new["misc.cabin_s" .. tostring(size)]
local slot_mass = eq and eq.mass or math.huge

local slot_target = math.floor(space / slot_mass)

if size == biggest - 1 then
-- Whatever the biggest size cabin we can add is, we also want to add
-- at least one of the next size down, to ensure that the user always
-- has some extra cabin options to play with
if slot_target == 0 then
slot_target = 1
end
end

local slot_count = 0
for _, slot in pairs(newShip.slots) do
if slot.type == "cabin" and slot.size == size then
slot_count = slot_count + 1
end
end

local slot_need = math.max(0, slot_target - slot_count)
for i = 1, slot_need do
local name = string.format("auto_cabin_s%d_%02d", size, i)
newShip.slots[name] = Slot:clone {
id = name,
type = "cabin",
size = size,
size_min = 1,
i18n_key = "SLOT_CABIN",
}
end

if slot_target > 0 and biggest == 0 then
biggest = size
end

space = space - (slot_mass * slot_target)
end
end

local function CreateShipConfig(def)
local newShip = HullConfig:clone()
Serializer:RegisterPersistent("ShipDef." .. def.id, newShip)

newShip.id = def.id
newShip.path = def.path
newShip.equipCapacity = def.equipCapacity
newShip.maxPayload = def.cargo

table.merge(newShip.slots, def.raw.equipment_slots or {}, function(name, slotDef)
if slotDef == false then return name, nil end
Expand All @@ -83,6 +149,8 @@ local function CreateShipConfig(def)
slot.id = name
end

AddAutoCabinSlots(newShip, def)

return newShip
end

Expand Down
32 changes: 20 additions & 12 deletions data/libs/Passengers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,33 @@ end
---@return integer
function Passengers.GetMaxPassengersForHull(hull, maxMass)
local numPassengers = 0
local availMass = maxMass or math.huge
local availMass = maxMass or hull.maxPayload or math.huge

---@type Equipment.CabinType
local cabins = utils.to_array(Equipment.new, function(equip)
return equip:IsA('Equipment.CabinType')
end)

-- Get a list of the cabin slots available to this hull type
local cabinSlots = utils.to_array(hull.slots, function(slot)
return EquipSet.SlotTypeMatches(slot.type, "cabin") and slot or nil
end)

-- Sort the cabin slots in order of largest size to smallest
table.sort(cabinSlots, function(a, b)
return (a.size or 0) > (b.size or 0)
end)

-- Compute the theoretical maximum number of passengers
for _, slot in pairs(hull.slots) do
if EquipSet.SlotTypeMatches(slot.type, "cabin") then
local cabin, passengers = utils.best_score(cabins, function(_, equip)
return EquipSet.CompatibleWithSlot(equip, slot)
and (availMass - equip.mass > 0)
and equip.capabilities.cabin or nil
end)
if cabin then
numPassengers = numPassengers + passengers
availMass = availMass - cabin.mass
end
for _, slot in ipairs(cabinSlots) do
local cabin, passengers = utils.best_score(cabins, function(_, equip)
return EquipSet.CompatibleWithSlot(equip, slot)
and (availMass - equip.mass >= 0)
and equip.capabilities.cabin or nil
end)
if cabin then
numPassengers = numPassengers + passengers
availMass = availMass - cabin.mass
end
end

Expand Down
Loading