mirror of
https://github.com/PHIDIAS0303/factorio-mod-PHI.git
synced 2026-06-27 05:46:22 +09:00
.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 3.0.151
|
||||
Date: 2026-07-05
|
||||
|
||||
Changes:
|
||||
- [GM] Generic Code layout restructure.
|
||||
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 3.0.150
|
||||
Date: 2026-07-05
|
||||
|
||||
+74
-4
@@ -1,4 +1,5 @@
|
||||
local cargo_landing = require('control/cargo-landing')
|
||||
local inserter = require('control/inserter')
|
||||
local pump = require('control/pump')
|
||||
local rail_support = require('control/rail-support')
|
||||
local trash = require('control/trash')
|
||||
@@ -13,18 +14,87 @@ if (settings.startup['PHI-MI'].value and settings.startup['PHI-MI-GENERIC'].valu
|
||||
script.on_event({defines.events.on_player_cheat_mode_enabled, defines.events.on_player_cheat_mode_disabled}, pump.recipe_hidden)
|
||||
end
|
||||
|
||||
local function gui_create(player)
|
||||
if player.gui.relative.phi_cl_inserter_config then
|
||||
player.relative.phi_cl_inserter_config.destroy()
|
||||
end
|
||||
|
||||
if player.gui.relative.phi_cl_combinator_config then
|
||||
player.gui.relative.phi_cl_combinator_config.destroy()
|
||||
end
|
||||
|
||||
do
|
||||
local frame = player.gui.relative.add({type = 'frame', name = 'phi_cl_inserter', anchor = {gui = defines.relative_gui_type.inserter_gui, position = defines.relative_gui_position.right, type = 'inserter', ghost_mode = 'both'}})
|
||||
frame.add({type = 'label', name = 'inserter_throughput', caption = 0, style = 'heading_2_label'})
|
||||
end
|
||||
end
|
||||
|
||||
local function gui_update(player, entity)
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if entity.type and entity.type ~= 'inserter' then
|
||||
return
|
||||
end
|
||||
|
||||
if entity.type and entity.type == 'entity-ghost' and entity.ghost_type ~= 'inserter' then
|
||||
return
|
||||
end
|
||||
|
||||
player.gui.relative.phi_cl_inserter['inserter_throughput'].caption = string.format('%.2f', inserter.calc(entity))
|
||||
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
|
||||
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
|
||||
end)
|
||||
|
||||
if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then
|
||||
script.on_event(defines.events.on_player_created, function(event)
|
||||
if not event.player_index or not game.players[event.player_index] then
|
||||
return
|
||||
end
|
||||
|
||||
if game.players[event.player_index].gui.relative.phi_cl_inserter_config then
|
||||
game.players[event.player_index].gui.relative.phi_cl_inserter_config.destroy()
|
||||
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 game.players[event.player_index] then
|
||||
return
|
||||
end
|
||||
|
||||
if game.players[event.player_index].gui.relative.phi_cl_combinator_config then
|
||||
game.players[event.player_index].gui.relative.phi_cl_combinator_config.destroy()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if event.entity and player.opened and player.opened == event.entity then
|
||||
gui_update(player, event.entity)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event({defines.events.on_player_rotated_entity, defines.events.on_player_flipped_entity}, function(event)
|
||||
if not event.player_index or not game.players[event.player_index] then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if event.entity and player.opened == event.entity then
|
||||
gui_update(player, player.opened)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
local main = {}
|
||||
|
||||
function main.get_belt_penalty(belt_speed, stack_size)
|
||||
local penalty = 0
|
||||
stack_size = stack_size - 1
|
||||
local item_center_offset = belt_speed
|
||||
local acted = true
|
||||
|
||||
while stack_size > 0 do
|
||||
if item_center_offset > 0 then
|
||||
stack_size = stack_size - 1
|
||||
item_center_offset = item_center_offset - 0.25
|
||||
acted = true
|
||||
end
|
||||
|
||||
item_center_offset = item_center_offset + belt_speed
|
||||
|
||||
if not acted and (item_center_offset > 0) then
|
||||
stack_size = stack_size - 1
|
||||
item_center_offset = item_center_offset - 0.25
|
||||
acted = true
|
||||
end
|
||||
|
||||
penalty = penalty + 1
|
||||
acted = false
|
||||
end
|
||||
|
||||
return penalty
|
||||
end
|
||||
|
||||
function main.calc(entity)
|
||||
local prototype = entity.type == 'entity-ghost' and entity.ghost_prototype or entity.prototype
|
||||
local pickup_target = entity.pickup_target and entity.pickup_target or entity.surface.find_entities_filtered{position = entity.pickup_position, limit = 1}[1]
|
||||
local pickup_belt_speed = pickup_target and (pickup_target.type == 'entity-ghost' and pickup_target.ghost_prototype.belt_speed or pickup_target.prototype.belt_speed) or nil
|
||||
local drop_target = entity.drop_target and entity.drop_target or entity.surface.find_entities_filtered{position = entity.drop_position, limit = 1}[1]
|
||||
local drop_belt_speed = drop_target and (drop_target.type == 'entity-ghost' and drop_target.ghost_prototype.belt_speed or drop_target.prototype.belt_speed) or nil
|
||||
local pickup_length = math.sqrt((entity.pickup_position.x - entity.position.x) * (entity.pickup_position.x - entity.position.x) + (entity.pickup_position.y - entity.position.y) * (entity.pickup_position.y - entity.position.y))
|
||||
local drop_length = math.sqrt((entity.drop_position.x - entity.position.x) * (entity.drop_position.x - entity.position.x) + (entity.drop_position.y - entity.position.y) * (entity.drop_position.y - entity.position.y))
|
||||
local angle = 0
|
||||
local stack_size = entity.inserter_stack_size_override
|
||||
|
||||
if stack_size == 0 then
|
||||
stack_size = 1 + prototype.inserter_stack_size_bonus + ((prototype.bulk and entity.force.bulk_inserter_capacity_bonus) or entity.force.inserter_stack_size_bonus)
|
||||
end
|
||||
|
||||
if pickup_length > 0 and drop_length > 0 then
|
||||
local ratio = ((entity.pickup_position.x - entity.position.x) * (entity.drop_position.x - entity.position.x) + (entity.pickup_position.y - entity.position.y) * (entity.drop_position.y - entity.position.y)) / (pickup_length * drop_length)
|
||||
|
||||
if ratio > 1 then
|
||||
ratio = 1
|
||||
|
||||
elseif ratio < -1 then
|
||||
ratio = -1
|
||||
end
|
||||
|
||||
angle = math.acos(ratio)
|
||||
end
|
||||
|
||||
local ticks_per_cycle = 2 * math.ceil((angle / (math.pi * 2) - 0.001) / prototype.get_inserter_rotation_speed(entity.quality))
|
||||
local extension_time = 2 * math.ceil(math.abs(pickup_length - drop_length) / prototype.get_inserter_extension_speed(entity.quality))
|
||||
|
||||
if ticks_per_cycle < extension_time then
|
||||
ticks_per_cycle = extension_time
|
||||
end
|
||||
|
||||
if ticks_per_cycle < 2 then
|
||||
ticks_per_cycle = 2
|
||||
end
|
||||
|
||||
if pickup_belt_speed and (stack_size > 1) then
|
||||
ticks_per_cycle = ticks_per_cycle + main.get_belt_penalty(pickup_belt_speed, stack_size)
|
||||
end
|
||||
|
||||
if drop_belt_speed and (stack_size > 1) then
|
||||
ticks_per_cycle = ticks_per_cycle + main.get_belt_penalty(drop_belt_speed, stack_size)
|
||||
end
|
||||
|
||||
if drop_belt_speed then
|
||||
local max = drop_belt_speed * ticks_per_cycle * 4
|
||||
stack_size = (stack_size > max and max) or stack_size
|
||||
end
|
||||
|
||||
if pickup_belt_speed then
|
||||
local max = pickup_belt_speed * ticks_per_cycle * 8
|
||||
stack_size = (stack_size > max and max) or stack_size
|
||||
end
|
||||
|
||||
return stack_size * 60 / ticks_per_cycle
|
||||
end
|
||||
|
||||
return main
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "PHI-CL",
|
||||
"version": "3.0.150",
|
||||
"version": "3.0.151",
|
||||
"factorio_version": "2.0",
|
||||
"date": "2026-07-05",
|
||||
"title": "Phidias Collection",
|
||||
|
||||
Reference in New Issue
Block a user