diff --git a/PHI-CL/changelog.txt b/PHI-CL/changelog.txt index 079d356..b5e8ebd 100644 --- a/PHI-CL/changelog.txt +++ b/PHI-CL/changelog.txt @@ -4,6 +4,8 @@ Date: 2026-07-05 Changes: - [GM] Generic code layout restructure. + - [GM] Removed super combinator, and its function like research control. + - [CT] Removed proxy chest on lab for reading its content. --------------------------------------------------------------------------------------------------- Version: 3.0.149 diff --git a/PHI-CL/control.lua b/PHI-CL/control.lua index 9ecabb9..d2a32b0 100644 --- a/PHI-CL/control.lua +++ b/PHI-CL/control.lua @@ -1,6 +1,4 @@ local cargo_landing = require('control/cargo-landing') -local combinator = require('control/combinator') -local lab = require('control/lab') local pump = require('control/pump') local rail_support = require('control/rail-support') local trash = require('control/trash') @@ -10,45 +8,17 @@ local function gui_create(player) player.gui.relative.phi_cl_inserter_config.destroy() end - combinator.gui_create(player) -end - -local function gui_update(player, entity) - lab.open(player) - combinator.gui_update(player, entity) + if player.gui.relative.phi_cl_combinator_config then + player.gui.relative.phi_cl_combinator_config.destroy() + end end local function entity_build(event) cargo_landing.build(event) - lab.build(event) rail_support.build(event) trash.build(event) end -script.on_init(function() - if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then - for _, player in pairs(game.players) do - gui_create(player) - end - end - - combinator.storage_init() -end) - -script.on_configuration_changed(function() - if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then - for _, player in pairs(game.players) do - gui_create(player) - - if player.opened and player.opened.valid and player.opened.object_name == 'LuaEntity' then - gui_update(player, player.opened.entity) - end - end - end - - combinator.storage_init() -end) - if (settings.startup['PHI-MI'].value and settings.startup['PHI-MI-GENERIC'].value) or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then script.on_event({defines.events.on_player_cheat_mode_enabled, defines.events.on_player_cheat_mode_disabled}, pump.recipe_hidden) end @@ -62,25 +32,8 @@ if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and set gui_create(game.players[event.player_index]) end) - script.on_event(defines.events.on_gui_opened, function(event) - if not event.player_index or not event.entity or not game.players[event.player_index] or not game.players[event.player_index].opened or game.players[event.player_index].opened ~= event.entity then - return - end - - gui_update(game.players[event.player_index], event.entity) - end) - - script.on_event(defines.events.on_gui_selection_state_changed, combinator.on_gui_selection_state_changed) - - script.on_event({defines.events.on_player_rotated_entity, defines.events.on_player_flipped_entity}, function(event) - if not event.player_index or not event.entity or not game.players[event.player_index] or not game.players[event.player_index].opened or game.players[event.player_index].opened ~= event.entity then - return - end - - gui_update(game.players[event.player_index], game.players[event.player_index].opened) - end) - script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity, defines.events.on_space_platform_built_entity, defines.events.script_raised_built, defines.events.script_raised_revive}, entity_build) + script.on_event({defines.events.on_entity_died, defines.events.on_player_mined_entity, defines.events.on_robot_pre_mined, defines.events.script_raised_destroy}, rail_support.destroy) script.on_event(defines.events.on_entity_cloned, function(event) if not event.destination then @@ -89,13 +42,4 @@ if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and set entity_build({entity=event.destination}) end) - - - script.on_event({defines.events.on_entity_died, defines.events.on_player_mined_entity, defines.events.on_robot_pre_mined, defines.events.script_raised_destroy}, function(event) - lab.destroy(event) - rail_support.destroy(event) - end) end - -script.on_nth_tick(1800, combinator.on_nth_tick_1800) -script.on_nth_tick(10, combinator.on_nth_tick_10) diff --git a/PHI-CL/control/combinator.lua b/PHI-CL/control/combinator.lua deleted file mode 100644 index 560e308..0000000 --- a/PHI-CL/control/combinator.lua +++ /dev/null @@ -1,235 +0,0 @@ -local main = {} - -function main.storage_init() - if not storage.phi_cl then - storage.phi_cl = {} - end - - if not storage.phi_cl.loop then - storage.phi_cl.loop = { - combinator = false - } - end - - if not storage.phi_cl.combinator then - storage.phi_cl.combinator = { - combinator_list = {}, - research_queue = {}, - research_queue_set = {}, - research_progress = 0, - last_writer = nil - } - end - - storage.phi_cl.loop.combinator = ((settings.startup['PHI-MI'].value and settings.startup['PHI-MI-GENERIC'].value) or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '')) -end - -function main.gui_create(player) - if player.gui.relative.phi_cl_combinator_config then - player.gui.relative.phi_cl_combinator_config.destroy() - end - - local frame = player.gui.relative.add({type = 'frame', name = 'phi_cl_combinator_config', anchor = {gui = defines.relative_gui_type.constant_combinator_gui, position = defines.relative_gui_position.right, name = 'super-combinator', ghost_mode = 'only_real'}}) - local table = frame.add({type = 'table', name = 'default', column_count = 1, style = 'table'}) - table.add({type = 'label', name = 'read_type', caption = {'gui-control-behavior-modes.read-contents'}, style = 'heading_2_label'}) - local table_research_queue = table.add({type = 'table', name = 'table_research_queue', column_count = 2, style = 'table'}) - table_research_queue.add({type = 'label', name = 'research_queue_label', caption = {'gui-technology-queue.title'}, style = 'heading_2_label'}) - table_research_queue.add({type = 'drop-down', name = 'research_queue_dropdown', items = {'[virtual-signal=signal-deny]', '[virtual-signal=signal-RA]', '[virtual-signal=signal-WA]', '[virtual-signal=signal-check]'}, selected_index = 1}) -end - -function main.gui_update(player, entity) - if not entity.valid or not entity.type or entity.type ~= 'constant-combinator' or entity.name ~= 'super-combinator' then - return - end - - local circuit_oc = player.opened.get_or_create_control_behavior() - - if circuit_oc and circuit_oc.sections_count and circuit_oc.sections_count == 0 then - circuit_oc.add_section() - end - - circuit_oc = circuit_oc.sections[1] - local cs1 = circuit_oc.get_slot(1) - - if not cs1 or not cs1.value or not cs1.value.name or cs1.value.name ~= 'signal-SA' then - return - end - - local val = cs1.min or 0 - - if not player.gui.relative.phi_cl_combinator_config or not player.gui.relative.phi_cl_combinator_config['default'] or not player.gui.relative.phi_cl_combinator_config['default']['table_research_queue'] then - return - end - - local dropdown = player.gui.relative.phi_cl_combinator_config['default']['table_research_queue']['research_queue_dropdown'] - - if not dropdown then - return - end - - dropdown.selected_index = ((val < 0 or val > 3) and 1) or (val + 1) -end - -function main.on_gui_selection_state_changed(event) - local player = game.players[event.player_index] - - if not player.opened or not player.opened.object_name or not player.opened.valid or player.opened.object_name ~= 'LuaEntity' or not player.opened.type or player.opened.type ~= 'constant-combinator' or not player.opened.name or player.opened.name ~= 'super-combinator' or not player.gui.relative.phi_cl_combinator_config then - return - end - - local circuit_oc = player.opened.get_or_create_control_behavior() - - if circuit_oc and circuit_oc.sections_count and circuit_oc.sections_count == 0 then - circuit_oc.add_section() - end - - circuit_oc = circuit_oc.sections[1] - circuit_oc.set_slot(1, {value = {type = 'virtual', name = 'signal-SA', quality = 'normal'}, min = event.element.parent.parent['table_research_queue']['research_queue_dropdown'].selected_index - 1}) -end - -function main.handle_research_queue(entity, combinator) - local combinator_slot = combinator.get_slot(1) - - if not combinator_slot or not combinator_slot.value or not combinator_slot.value.name or combinator_slot.value.name ~= 'signal-SA' then - combinator.set_slot(1, {value = {type = 'virtual', name = 'signal-SA', quality = 'normal'}, min = 0}) - return - end - - local combinator_slot_value = combinator_slot.min or 0 - - if combinator_slot_value < 0 or combinator_slot_value > 3 then - combinator.set_slot(1, {value = {type = 'virtual', name = 'signal-SA', quality = 'normal'}, min = 0}) - return - end - - if combinator_slot_value == 1 or combinator_slot_value == 3 then - -- research_queue_read - local n = 21 - - for rn, rv in pairs(storage.phi_cl.combinator.research_queue) do - combinator.set_slot(n, {value = {type = 'virtual', name = 'signal-' .. rn, quality = 'normal'}, min = rv}) - - n = n + 1 - end - - for i = n, 27 do - combinator.clear_slot(i) - end - - combinator.set_slot(28, {value = {type = 'virtual', name = 'signal-PA', quality = 'normal'}, min = storage.phi_cl.combinator.research_progress}) - end - - if combinator_slot_value == 2 or combinator_slot_value == 3 then - -- research_queue_write - if storage.phi_cl.combinator.last_writer and storage.phi_cl.combinator.last_writer ~= entity.unit_number then - -- Another combinator wrote recently - combinator.set_slot(1, {value = {type = 'virtual', name = 'signal-SA', quality = 'normal'}, min = ((combinator_slot_value == 3) and 1) or 0}) - return - end - - storage.phi_cl.combinator.last_writer = entity.unit_number - storage.phi_cl.combinator.research_queue_set = {} - - local s = entity.get_signals(defines.wire_connector_id.circuit_red, defines.wire_connector_id.circuit_green) - - if not s then - return - end - - for _, ss in pairs(s) do - if ss.signal and ss.signal.type and ss.signal.type == 'virtual' and ss.count > 0 and (not ss.signal.quality or ss.signal.quality == 'normal') then - local tn = ss.signal.name:sub(8) - - if prototypes.technology[tn] and prototypes.technology[tn].enabled and prototypes.technology[tn].max_level then - for i=1, 7 do - if math.floor(ss.count / (2 ^ (7 + i))) % 2 == 1 then - storage.phi_cl.combinator.research_queue_set[i] = tn - end - end - end - end - end - - local research_queue = {} - - for i=1,7 do - if storage.phi_cl.combinator.research_queue_set[i] then - table.insert(research_queue, storage.phi_cl.combinator.research_queue_set[i]) - end - end - - game.forces['player'].research_queue = research_queue - storage.phi_cl.combinator.last_writer = nil - end -end - -function main.on_nth_tick_1800() - if not storage.phi_cl or not storage.phi_cl.loop or not storage.phi_cl.loop.combinator or not game.forces['player'] then - return - end - - storage.phi_cl.combinator.research_progress = math.floor(game.forces['player'].research_progress * 1000) - storage.phi_cl.combinator.combinator_list = {} - storage.phi_cl.combinator.research_queue = {} - storage.phi_cl.combinator.research_queue_set = {} - local n = 1 - - for _, r in pairs(game.forces['player'].research_queue) do - if r.name and r.level and r.research_unit_count_formula then - storage.phi_cl.combinator.research_queue[r.name] = (storage.phi_cl.combinator.research_queue[r.name] or 0) + math.pow(2, n - 1) - end - - n = n + 1 - end - - if not prototypes.entity['super-combinator'] then - return - end - - for _, s in pairs(game.surfaces) do - local c = s.find_entities_filtered{type='constant-combinator', name='super-combinator'} - - if #c > 0 then - for _, entity in pairs(c) do - table.insert(storage.phi_cl.combinator.combinator_list, entity) - end - end - end -end - -function main.on_nth_tick_10() - if not storage.phi_cl or not storage.phi_cl.combinator or not storage.phi_cl.combinator.combinator_list then - return - end - - local head = #storage.phi_cl.combinator.combinator_list - - if head == 0 then - return - end - - local max_remove = math.floor(head / 100) + 1 - local remove_count = math.random(math.min(5, max_remove), max_remove) - - while remove_count > 0 and head > 0 do - local remove_index = math.random(1, head) - local entity = storage.phi_cl.combinator.combinator_list[remove_index] - storage.phi_cl.combinator.combinator_list[remove_index] = storage.phi_cl.combinator.combinator_list[head] - head = head - 1 - - if entity and entity.valid then - remove_count = remove_count - 1 - local combinator = entity.get_or_create_control_behavior() - - if combinator and combinator.sections_count then - if combinator.sections_count == 0 then - combinator.add_section() - end - - main.handle_research_queue(entity, combinator.sections[1]) - end - end - end -end - -return main diff --git a/PHI-CL/control/lab.lua b/PHI-CL/control/lab.lua deleted file mode 100644 index ae47919..0000000 --- a/PHI-CL/control/lab.lua +++ /dev/null @@ -1,64 +0,0 @@ -local main = {} - -function main.open(player) - if not player then - return - end - - if not player.opened then - return - end - - if not player.opened.valid then - return - end - - if player.opened.type ~= 'proxy-container' then - return - end - - if not player.opened.proxy_target_inventory then - return - end - - if player.opened.proxy_target_inventory ~= defines.inventory.lab_input then - return - end - - player.opened = nil -end - -function main.build(event) - if event.entity.type ~= 'lab' then - return - end - - if not prototypes.entity['proxy-container'] then - return - end - - local p = event.entity.surface.create_entity{name = 'proxy-container', position = {event.entity.position.x, event.entity.position.y}, force = 'neutral', quality = event.entity.quality.name} - p.destructible = false - p.proxy_target_entity = event.entity - p.proxy_target_inventory = defines.inventory.lab_input -end - -function main.destroy(event) - if event.entity.type ~= 'lab' then - return - end - - if not prototypes.entity['proxy-container'] then - return - end - - local p = event.entity.surface.find_entity({name = 'proxy-container', force = 'neutral', quality = event.entity.quality.name}, {event.entity.position.x, event.entity.position.y}) - - if not p then - return - end - - p.destroy() -end - -return main diff --git a/PHI-CL/data/b/mbe.lua b/PHI-CL/data/b/mbe.lua index da3138d..140dd03 100644 --- a/PHI-CL/data/b/mbe.lua +++ b/PHI-CL/data/b/mbe.lua @@ -54,15 +54,33 @@ local function tint_handle(item, tier, tl) end end -function tint_layer(p, t) - if p and p.layers then - for _, v in pairs(p.layers) do - if not v.draw_as_shadow then - v.tint = mod_tint[t] +function tint_layer(al, t) + for _, l in pairs(al) do + if not l.draw_as_shadow then + l.tint = mod_tint[t] + end + end +end + +function tint(i, p, t) + if not i then + return + end + + if p then + for _, c in pairs(p) do + if i[c] and i[c].layers then + tint_layer(i[c].layers, t) + end + + if c == 'picture' then + table.insert(i[c].layers, {icon = '__base__/graphics/icons/signal/signal_' .. t .. '.png', icon_size = 64, scale = 0.25, shift = {12, 12}}) end end - table.insert(p.layers, {icon = '__base__/graphics/icons/signal/signal_' .. t .. '.png', icon_size = 64, scale = 0.25, shift = {12, 12}}) + else + tint_layer(i.layers, t) + table.insert(i.layers, {icon = '__base__/graphics/icons/signal/signal_' .. t .. '.png', icon_size = 64, scale = 0.25, shift = {12, 12}}) end end @@ -72,9 +90,8 @@ function main_entity(source, tier) item.minable.result = item.name item.max_health = item.max_health * (tier - source.min + 2) item.next_upgrade = ((tier < source.max) and source.name .. '-' .. (tier + 1)) or nil - item.production = item.production and (((source.tech == 'compound-energy' and source.type == 'solar-panel') and (tonumber(string.match(item.production, '[%d%.]+')) * (settings.startup['PHI-MB-ENERGY-SOLAR-RATIO'].value ^ (tier - source.min + 1)) .. (string.match(item.production, '%a+') or ''))) or (tonumber(string.match(item.production, '[%d%.]+')) * (2 ^ (tier - source.min + 1)) .. (string.match(item.production, '%a+') or ''))) or nil - for _, v in pairs({'energy_usage', 'heating_energy', 'crane_energy_usage', 'energy_per_shot'}) do + for _, v in pairs({'energy_usage', 'heating_energy'}) do if not (source.tech == 'compound-energy' and (source.type == 'solar-panel' or source.type == 'accumulator')) and item[v] then item[v] = (tonumber(string.match(item[v], '[%d%.]+')) * (2 ^ (tier - source.min + 1))) .. (string.match(item[v], '%a+') or '') end @@ -102,12 +119,31 @@ function main_entity(source, tier) table.insert(item.surface_conditions, {property = 'gravity', min = 0.01}) end - if (source.type == 'accumulator') then + if (source.type == 'solar-panel') then + item.production = tonumber(string.match(item.production, '[%d%.]+')) * (settings.startup['PHI-MB-ENERGY-SOLAR-RATIO'].value ^ (tier - source.min + 1)) .. (string.match(item.production, '%a+') or '') + + if item['picture'] and item['picture'].layers then + for _, l in pairs(item['picture'].layers) do + if not l.draw_as_shadow then + l.tint = mod_tint[tier] + end + end + end + + elseif (source.type == 'accumulator') then + if item['chargable_graphics'] then + tint(item['chargable_graphics'], {'picture', 'charge_animation', 'discharge_animation'}, tier) + end + for _, v in pairs({'buffer_capacity', 'input_flow_limit', 'output_flow_limit'}) do item.energy_source[v] = (item.energy_source[v] and (tonumber(string.match(item.energy_source[v], '[%d%.]+')) * (settings.startup['PHI-MB-ENERGY-SOLAR-RATIO'].value ^ (tier - source.min + 1)) .. string.match(item.energy_source[v], '%a+'))) or nil end elseif (source.type == 'boiler') then + if item['picture'] then + tint(item['picture'], {'north', 'east', 'south', 'west'}, tier) + end + item.energy_consumption = tostring(tonumber(string.match(item.energy_consumption, '[%d%.]+')) * (2 * (tier - source.min + 1))) .. string.match(item.energy_consumption, '%a+') item.target_temperature = 15 + ((item.target_temperature - 15) * (2 * (tier - source.min + 1))) @@ -118,6 +154,12 @@ function main_entity(source, tier) end elseif (source.type == 'generator') then + for _, c in pairs({'horizontal_animation', 'vertical_animation'}) do + if item[c] then + tint(item[c], nil, tier) + end + end + item.max_power_output = (item.max_power_output and (tonumber(string.match(item.max_power_output, '[%d%.]+')) * (2 * (tier - source.min + 1))) .. string.match(item.max_power_output, '%a+')) or nil item.maximum_temperature = (item.maximum_temperature and 15 + ((item.maximum_temperature - 15) * (2 * (tier - source.min + 1)))) or nil @@ -136,58 +178,37 @@ function main_entity(source, tier) item.max_fluid_usage = item.max_fluid_usage * (2 * (tier - source.min + 1)) elseif (source.type == 'heat-pipe') then + for _, c in pairs({'connection_sprites', 'heat_glow_sprites'}) do + if item[c] then + tint(item[c], {'single', 'straight_vertical', 'straight_horizontal', 'corner_right_up', 'corner_left_up', 'corner_right_down', 'corner_left_down', 't_up', 't_down', 't_right', 't_left', 'cross', 'ending_up', 'ending_down', 'ending_right', 'ending_left'}, tier) + end + end + item.heat_buffer.max_temperature = item.heat_buffer.max_temperature * (2 * (tier - source.min + 1)) item.heat_buffer.max_transfer = tostring(tonumber(string.match(item.heat_buffer.max_transfer, '[%d%.]+')) * (2 * (tier - source.min + 1))) .. string.match(item.heat_buffer.max_transfer, '%a+') - tint_handle(item, tier, {'connection_sprites', 'heat_glow_sprites'}) end - -- picture: solar-panel - for _, v in pairs({'picture'}) do - if item[v] then - tint_layer(item[v], tier) - end + --[[ + nuclear-reactor + fusion-reactor + fusion-generator + heating-tower + + reactor + + tint(item, {'picture'}, tier) + + if item['heat_buffer'] then + tint(item['heat_buffer'], {'heat_picture'}, tier) end - -- chargable_graphics: accumulator - if item['chargable_graphics'] then - for _, v in pairs({'picture', 'charge_animation', 'discharge_animation'}) do - if item['chargable_graphics'][v] then - tint_layer(item['chargable_graphics'][v], tier) + for _, c in pairs({'horizontal_animation', 'vertical_animation'}) do + if item[c] then + tint(item[c], nil, tier) end end - end + ]] - tint_handle(item, tier, {'picture', 'pictures', 'animation', 'structure', 'integration_patch', 'horizontal_animation', 'vertical_animation'}) - - for _, v in pairs({'graphics_set', 'graphics_set_flipped'}) do - if item[v] then - tint_handle(item[v], tier, {'animation', 'idle_animation', 'frozen_patch'}) - - if item[v].working_visualisations then - tint_handle(item[v].working_visualisations, tier, {'north_animation', 'east_animation', 'south_animation', 'west_animation', 'animation'}) - end - end - end - - if item.idle_animation and item.idle_animation.layers then - local i = 1 - - while i < #item.idle_animation.layers do - if item.idle_animation.layers[i] then - item.idle_animation.layers[i].tint = mod_tint[tier] - end - - i = i + 2 - - if not item.idle_animation.layers[i] then - break - end - end - end - - if item.base_picture and item.base_picture.sheets then - item.base_picture.sheets[1].tint = mod_tint[tier] - end item.localised_name = (tier > 1 and {'phi-cl.combine', {'?', {'entity-name.' .. source.ref_name}, {'name.' .. source.ref_name}}, tostring(tier)}) or {'?', {'entity-name.' .. source.ref_name}, {'name.' .. source.ref_name}} item.localised_description = {'?', {'entity-description.' .. source.ref_name}, {'description.' .. source.ref_name}}