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
30 changes: 27 additions & 3 deletions modfiles/backend/data/ModuleSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ local ModuleSet = Object.methods()
ModuleSet.__index = ModuleSet
script.register_metatable("ModuleSet", ModuleSet)

-- Compute the effective module limit for a parent object, taking into account
-- prototype-level flags and quality-level bonuses when applicable.
local function compute_module_limit(parent)
local base = parent.proto.module_limit or 0
local proto = parent.proto
local quality = parent.quality_proto

if not proto.quality_affects_module_slots or not quality then return base end

local bonus = 0
local category = proto.prototype_category or proto.category
if category == "beacon" then
bonus = quality.beacon_module_slots_bonus or 0
elseif category == "lab" then
bonus = quality.lab_module_slots_bonus or 0
elseif category == "mining_drill" then
bonus = quality.mining_drill_module_slots_bonus or 0
elseif category == "furnace" or category == "assembling_machine" then
bonus = quality.crafting_machine_module_slots_bonus or 0
end

return base + (bonus or 0)
end

---@param parent ModuledObject
---@return ModuleSet
local function init(parent)
Expand All @@ -22,8 +46,8 @@ local function init(parent)

module_count = 0,
-- 0 as placeholder for simplified parents
module_limit = parent.proto.module_limit or 0,
empty_slots = parent.proto.module_limit or 0,
module_limit = compute_module_limit(parent),
empty_slots = compute_module_limit(parent),

parent = parent
}, "ModuleSet", ModuleSet) --[[@as ModuleSet]]
Expand Down Expand Up @@ -100,7 +124,7 @@ end

---@param features ModuleNormalizeFeatures
function ModuleSet:normalize(features)
self.module_limit = self.parent.proto.module_limit
self.module_limit = compute_module_limit(self.parent)

if features.compatibility then self:verify_compatibility() end
if features.trim then self:trim() end
Expand Down
8 changes: 7 additions & 1 deletion modfiles/backend/handlers/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function generator.machines.generate()
allowed_effects = proto.allowed_effects or {},
allowed_module_categories = proto.allowed_module_categories,
module_limit = (proto.module_inventory_size or 0),
quality_affects_module_slots = proto.quality_affects_module_slots,
surface_conditions = proto.surface_conditions,
uses_force_mining_productivity_bonus = proto.uses_force_mining_productivity_bonus
}
Expand Down Expand Up @@ -1218,6 +1219,7 @@ function generator.beacons.generate()
allowed_effects = proto.allowed_effects,
allowed_module_categories = proto.allowed_module_categories,
module_limit = proto.module_inventory_size,
quality_affects_module_slots = proto.quality_affects_module_slots,
effectivity = proto.distribution_effectivity,
quality_bonus = proto.distribution_effectivity_bonus_per_quality_level,
profile = (#proto.profile == 0) and {1} or proto.profile,
Expand Down Expand Up @@ -1374,7 +1376,11 @@ function generator.qualities.generate()
level = proto.level,
always_show = proto.draw_sprite_by_default,
beacon_power_usage_multiplier = proto.beacon_power_usage_multiplier,
mining_drill_resource_drain_multiplier = proto.mining_drill_resource_drain_multiplier
mining_drill_resource_drain_multiplier = proto.mining_drill_resource_drain_multiplier,
beacon_module_slots_bonus = proto.beacon_module_slots_bonus,
lab_module_slots_bonus = proto.lab_module_slots_bonus,
crafting_machine_module_slots_bonus = proto.crafting_machine_module_slots_bonus,
mining_drill_module_slots_bonus = proto.mining_drill_module_slots_bonus
}
insert_prototype(qualities, quality, nil)
end
Expand Down