diff --git a/angelsbioprocessing/control.lua b/angelsbioprocessing/control.lua deleted file mode 100644 index 7aa31de15..000000000 --- a/angelsbioprocessing/control.lua +++ /dev/null @@ -1,187 +0,0 @@ --- control behaviour to prevent agriculture modules from being used in research labs -local angels_bio_modules = { - ["angels-bio-yield-module"] = true, - ["angels-bio-yield-module-2"] = true, - ["angels-bio-yield-module-3"] = true, - ["angels-bio-yield-module-4"] = true, - ["angels-bio-yield-module-5"] = true, - ["angels-bio-yield-module-6"] = true, - ["angels-bio-yield-module-7"] = true, - ["angels-bio-yield-module-8"] = true -} - -function on_ghost_build(ghost_entity) - if not (ghost_entity and ghost_entity.valid) then return end - local item_request_proxy = ghost_entity.item_requests - for module_name, _ in pairs(angels_bio_modules) do - item_request_proxy[module_name] = nil - end - ghost_entity.item_requests = item_request_proxy -end - -script.on_event(defines.events.on_built_entity, function(event) - on_ghost_build(event.created_entity) -end, { - {filter = "ghost_type", type = "lab"}, - {filter = "ghost_type", type = "mining-drill"} -}) - -script.on_event(defines.events.on_robot_built_entity, function(event) - on_ghost_build(event.created_entity) -end, { - {filter = "ghost_type", type = "lab"}, - {filter = "ghost_type", type = "mining-drill"} -}) - -script.on_event(defines.events.on_entity_cloned, function(event) - on_ghost_build(event.source) -- you never know where the source came from... - on_ghost_build(event.destination) -end, { - {filter = "ghost_type", type = "lab"}, - {filter = "ghost_type", type = "mining-drill"} -}) - -script.on_event(defines.events.script_raised_revive, function(event) - on_ghost_build(event.entity) -end, { - {filter = "ghost_type", type = "lab"}, - {filter = "ghost_type", type = "mining-drill"} -}) - -script.on_event(defines.events.script_raised_built, function(event) - on_ghost_build(event.entity) -end, { - {filter = "ghost_type", type = "lab"}, - {filter = "ghost_type", type = "mining-drill"} -}) - -script.on_event(defines.events.on_player_fast_transferred, function(event) - if not event.from_player then return end - - local entity = event.entity - if not (entity.type == "lab" or entity.type == "mining-drill") then return end - - local player = game.get_player(event.player_index) - local player_cursor_stack = player.cursor_stack - if not player_cursor_stack then return end - - local module_inventory = entity.get_module_inventory() - if not module_inventory then return end - - local module_inventory_content = module_inventory.get_contents() - for module_name, module_count in pairs(module_inventory_content) do - if angels_bio_modules[module_name] then -- module_count > 0 - local remaining = module_inventory.remove{ - name = module_name, - count = module_count - } - if player_cursor_stack.valid_for_read then - if player_cursor_stack.name == module_name then - local player_cursor_stack_count = player_cursor_stack.count - player_cursor_stack.set_stack{name=module_name, count=player_cursor_stack_count + remaining} - remaining = remaining - (player_cursor_stack.count - player_cursor_stack_count) - end - else - if player_cursor_stack.can_set_stack{name=module_name, count=1} then - player_cursor_stack.set_stack{name=module_name, count=remaining} - if player_cursor_stack.valid_for_read and player_cursor_stack.name == module_name then - remaining = remaining - player_cursor_stack.count - end - end - end - if remaining > 0 then - remaining = remaining - player.insert{ - name = module_name, - count = remaining - } - if remaining > 0 then - player.surface.spill_item_stack(player.position, { - name = module_name, - count = remaining - }, true, entity.force, false) - end - end - end - end -end) - -script.on_event(defines.events.on_player_cursor_stack_changed, function(event) - local player = game.get_player(event.player_index) - local opened_entity = player.opened - if not (opened_entity and opened_entity.valid) then return end - if opened_entity.object_name == 'LuaEquipmentGrid' or opened_entity.object_name == 'LuaPlayer' then return end - if not (opened_entity.type == "lab" or opened_entity.type == "mining-drill") then return end - - local player_cursor_stack = player.cursor_stack - if not player_cursor_stack then return end - - local module_inventory = opened_entity.get_module_inventory() - if not module_inventory then return end - - local module_inventory_content = module_inventory.get_contents() - for module_name, module_count in pairs(module_inventory_content) do - if angels_bio_modules[module_name] then -- count > 0 - local remaining = module_inventory.remove{ - name = module_name, - count = module_count - } - if player_cursor_stack.valid_for_read then - if player_cursor_stack.name == module_name then - local player_cursor_stack_count = player_cursor_stack.count - player_cursor_stack.set_stack{name=module_name, count=player_cursor_stack_count + remaining} - remaining = remaining - (player_cursor_stack.count - player_cursor_stack_count) - end - else - if player_cursor_stack.can_set_stack{name=module_name, count=1} then - player_cursor_stack.set_stack{name=module_name, count=remaining} - if player_cursor_stack.valid_for_read and player_cursor_stack.name == module_name then - remaining = remaining - player_cursor_stack.count - end - end - end - if remaining > 0 then - remaining = remaining - player.insert{ - name = module_name, - count = remaining - } - if remaining > 0 then - player.surface.spill_item_stack(player.position, { - name = module_name, - count = remaining - }, true, opened_entity.force, false) - end - end - end - end -end) - -script.on_event(defines.events.on_player_main_inventory_changed, function(event) - local player = game.get_player(event.player_index) - local opened_entity = player.opened - if not (opened_entity and opened_entity.valid) then return end - if opened_entity.object_name == 'LuaEquipmentGrid' or opened_entity.object_name == 'LuaPlayer' then return end - if not (opened_entity.type == "lab" or opened_entity.type == "mining-drill") then return end - - local module_inventory = opened_entity.get_module_inventory() - if not module_inventory then return end - - local module_inventory_content = module_inventory.get_contents() - for module_name, module_count in pairs(module_inventory_content) do - if angels_bio_modules[module_name] then -- count > 0 - local remaining = module_inventory.remove{ - name = module_name, - count = module_count - } - remaining = remaining - player.insert{ - name = module_name, - count = remaining - } - if remaining > 0 then - player.surface.spill_item_stack(player.position, { - name = module_name, - count = remaining - }, true, opened_entity.force, false) - end - end - end -end) diff --git a/angelsbioprocessing/data-updates.lua b/angelsbioprocessing/data-updates.lua index c51630b53..40c1e079b 100644 --- a/angelsbioprocessing/data-updates.lua +++ b/angelsbioprocessing/data-updates.lua @@ -2,6 +2,9 @@ require("prototypes.bio-processing-override") require("prototypes.bio-processing-generate") require("prototypes.tips-and-tricks.tips-and-tricks") +-- AGRICULTURE MODULES +require("prototypes.overrides.bio-processing-override-agriculture-modules") + -- hoggers are not implemented, hide them in the meantime angelsmods.functions.add_flag("bio-hogger-1", "hidden") angelsmods.functions.add_flag("bio-hogger-2", "hidden") diff --git a/angelsbioprocessing/prototypes/overrides/bio-processing-override-agriculture-modules.lua b/angelsbioprocessing/prototypes/overrides/bio-processing-override-agriculture-modules.lua new file mode 100644 index 000000000..50993b7b9 --- /dev/null +++ b/angelsbioprocessing/prototypes/overrides/bio-processing-override-agriculture-modules.lua @@ -0,0 +1,59 @@ +-- Disallow pollution modules from miners, labs, and furnaces +-- This will prevent agriculture modules being used where they shouldn't +-- +-- Beacons will generally not be affected here as don't normally allow productivity +-- If productivity in beacons has been enabled, then beacons will not accept pollution modules +local categories = {"mining-drill", "lab", "furnace", "beacon"} + +for _, category_name in pairs(categories) do + local category = data.raw[category_name] + if category then + for entity_name, entity in pairs(category) do + if entity.allowed_effects == nil then + entity.allowed_effects = {"speed", "productivity", "consumption"} + elseif type(entity.allowed_effects) == "table" then + -- If effects includes pollution and productivity + -- then remove pollution + local allowPollution = false + local allowProductivity = false + for _, effect_name in pairs(entity.allowed_effects) do + if effect_name == "pollution" then + allowPollution = true + elseif effect_name == "productivity" then + allowProductivity = true + end + end + if allowProductivity and allowPollution then + for i = #entity.allowed_effects, 1, -1 do + if entity.allowed_effects[i] == "pollution" then + table.remove(entity.allowed_effects, i) + end + end + end + end + end + end +end + +local modules = { + "productivity-module", + "productivity-module-2", + "productivity-module-3", + "productivity-module-4", + "productivity-module-5", + "productivity-module-6", + "productivity-module-7", + "productivity-module-8", + "god-module-1", + "god-module-2", + "god-module-3", + "god-module-4", + "god-module-5" +} + +for _, module_name in pairs(modules) do + local module = data.raw["module"][module_name] + if module then + module.effect.pollution = nil + end +end