mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Merged branch master into dev
This commit is contained in:
commit
6d12bac32a
4 files changed
+167
-32
No files matched your search
+96
-28
@@ -9,23 +9,40 @@ function OnBuiltEntity(event)
|
||||
local entity = event.created_entity
|
||||
--only add entities that are not ghosts
|
||||
if entity.type ~= "entity-ghost" then
|
||||
if entity.name == INPUT_CHEST_NAME then
|
||||
global.inputChests = global.inputChests or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.inputChests[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == OUTPUT_CHEST_NAME then
|
||||
global.outputChests = global.outputChests or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.outputChests[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == INPUT_TANK_NAME then
|
||||
global.inputTanks = global.inputTanks or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.inputTanks[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == OUTPUT_TANK_NAME then
|
||||
global.outputTanks = global.outputTanks or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.outputTanks[HashPosition(entity.position)] = entity
|
||||
end
|
||||
AddEntity(entity)
|
||||
end
|
||||
end
|
||||
|
||||
function AddAllEntitiesOfName(name)
|
||||
for k, surface in pairs(game.surfaces) do
|
||||
AddEntities(surface.find_entities_filtered({["name"] = name}))
|
||||
end
|
||||
end
|
||||
|
||||
function AddEntities(entities)
|
||||
for k, entity in pairs(entities) do
|
||||
AddEntity(entity)
|
||||
end
|
||||
end
|
||||
|
||||
function AddEntity(entity)
|
||||
if entity.name == INPUT_CHEST_NAME then
|
||||
global.inputChests = global.inputChests or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.inputChests[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == OUTPUT_CHEST_NAME then
|
||||
global.outputChests = global.outputChests or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.outputChests[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == INPUT_TANK_NAME then
|
||||
global.inputTanks = global.inputTanks or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.inputTanks[HashPosition(entity.position)] = entity
|
||||
elseif entity.name == OUTPUT_TANK_NAME then
|
||||
global.outputTanks = global.outputTanks or {}
|
||||
--add the chests to a lists if these chests so they can be interated over
|
||||
global.outputTanks[HashPosition(entity.position)] = entity
|
||||
entity.active = false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,9 +84,8 @@ script.on_event(defines.events.on_preplayer_mined_item, function(event)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
script.on_event(defines.events.on_tick, function(event)
|
||||
|
||||
global.inputChests = global.inputChests or {}
|
||||
global.outputChests = global.outputChests or {}
|
||||
global.inputTanks = global.inputTanks or {}
|
||||
@@ -79,6 +95,13 @@ script.on_event(defines.events.on_tick, function(event)
|
||||
|
||||
local todo = game.tick % UPATE_RATE
|
||||
|
||||
local onlinePlayers = GetOnlinePlayerCount()
|
||||
|
||||
if global.previousPlayerCount == nil or global.previousPlayerCount ~= onlinePlayers then
|
||||
Reset()
|
||||
end
|
||||
global.previousPlayerCount = onlinePlayers
|
||||
|
||||
if todo == 0 then
|
||||
HandleInputChests()
|
||||
elseif todo == 1 then
|
||||
@@ -94,6 +117,33 @@ script.on_event(defines.events.on_tick, function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
function GetOnlinePlayerCount()
|
||||
local onlinePlayers = 0
|
||||
for k, player in pairs(game.players) do
|
||||
if player.connected then
|
||||
onlinePlayers = onlinePlayers + 1
|
||||
end
|
||||
end
|
||||
return onlinePlayers
|
||||
end
|
||||
|
||||
function Reset()
|
||||
global.outputList = {}
|
||||
global.inputList = {}
|
||||
global.itemStorage = {}
|
||||
|
||||
global.inputChests = {}
|
||||
global.outputChests = {}
|
||||
global.inputTanks = {}
|
||||
global.outputTanks = {}
|
||||
|
||||
AddAllEntitiesOfName(INPUT_CHEST_NAME)
|
||||
AddAllEntitiesOfName(OUTPUT_CHEST_NAME)
|
||||
AddAllEntitiesOfName(INPUT_TANK_NAME)
|
||||
AddAllEntitiesOfName(OUTPUT_TANK_NAME)
|
||||
game.print("reset")
|
||||
end
|
||||
|
||||
function HandleInputChests()
|
||||
for k, v in pairs(global.inputChests) do
|
||||
if v.valid then
|
||||
@@ -114,9 +164,7 @@ function HandleInputTanks()
|
||||
if v.valid then
|
||||
--get the content of the chest
|
||||
local fluid = v.fluidbox[1]
|
||||
if fluid ~= nil and
|
||||
fluid.type == "crude-oil" and
|
||||
math.floor(fluid.amount) > 0 then
|
||||
if fluid ~= nil and math.floor(fluid.amount) > 0 then
|
||||
AddItemToInputList(fluid.type, math.floor(fluid.amount))
|
||||
fluid.amount = fluid.amount - math.floor(fluid.amount)
|
||||
end
|
||||
@@ -165,12 +213,23 @@ end
|
||||
function HandleOutputTanks()
|
||||
local MAX_FLUID_AMOUNT = 1000
|
||||
for k,v in pairs(global.outputTanks) do
|
||||
local fluid = v.fluidbox[1] or {type = "crude-oil", amount = 0}
|
||||
if fluid.type == "crude-oil" then
|
||||
--.recipe.products[1].name
|
||||
|
||||
if v.recipe ~= nil then
|
||||
local fluidName = v.recipe.products[1].name
|
||||
|
||||
local missingFluid = math.ceil(MAX_FLUID_AMOUNT - fluid.amount)
|
||||
--either get the fluid or reset it to the requested fluid
|
||||
local fluid = v.fluidbox[1] or {type = fluidName, amount = 0}
|
||||
if fluid.type ~= fluidName then
|
||||
fluid = {type = fluidName, amount = 0}
|
||||
end
|
||||
|
||||
--if any fluid is missing then request the fluid
|
||||
--from store and give either what it's missing or
|
||||
--the rest of the liquid in the system
|
||||
local missingFluid = math.max(math.ceil(MAX_FLUID_AMOUNT - fluid.amount), 0)
|
||||
if missingFluid > 0 then
|
||||
local fluidToInsert = RequestItemsFromStorage("crude-oil", missingFluid)
|
||||
local fluidToInsert = RequestItemsFromStorage(fluidName, missingFluid)
|
||||
if fluidToInsert > 0 then
|
||||
fluid.amount = fluid.amount + fluidToInsert
|
||||
else
|
||||
@@ -178,8 +237,9 @@ function HandleOutputTanks()
|
||||
AddItemToOutputList(fluid.type, fluidToRequestAmount)
|
||||
end
|
||||
end
|
||||
|
||||
v.fluidbox[1] = fluid
|
||||
end
|
||||
v.fluidbox[1] = fluid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -264,7 +324,15 @@ remote.add_interface("clusterio",
|
||||
GiveItemsToStorage(itemName, itemCount)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
printStorage = function()
|
||||
local items = ""
|
||||
for itemName, itemCount in pairs(global.itemStorage) do
|
||||
items = items.."\n"..itemName..": "..tostring(itemCount)
|
||||
end
|
||||
game.print(items)
|
||||
end,
|
||||
reset = Reset
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
||||
entity.icon = iconPath or entity.icon
|
||||
|
||||
-- add the entity to a technology so it can be unlocked
|
||||
local wasAddedToTech = AddEntityToTech("construction-robotics", name)
|
||||
--local wasAddedToTech = AddEntityToTech("construction-robotics", name)
|
||||
|
||||
data:extend(
|
||||
{
|
||||
@@ -34,7 +34,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
||||
--shouldn't be enabled to begin with.
|
||||
--but if the recipe isn't attached to a tech then it should
|
||||
--be enabled to begin with because otherwise the player can never use the item ingame
|
||||
enabled = not wasAddedToTech,
|
||||
enabled = true,
|
||||
ingredients =
|
||||
{
|
||||
{"steel-chest", 1},
|
||||
@@ -55,6 +55,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
||||
stack_size = 50
|
||||
}
|
||||
})
|
||||
return entity
|
||||
end
|
||||
|
||||
--adds a recipe to a tech and returns true or if that fails returns false
|
||||
@@ -83,7 +84,6 @@ MakeLogisticEntity(table.deepcopy(data.raw["logistic-container"]["logistic-chest
|
||||
MakeLogisticEntity(table.deepcopy(data.raw["container"]["iron-chest"]), INPUT_CHEST_NAME, INPUT_CHEST_PICTURE_PATH, { "picture" }, INPUT_CHEST_ICON_PATH)
|
||||
|
||||
--make tanks
|
||||
MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), OUTPUT_TANK_NAME, OUTPUT_TANK_PICTURE_PATH, { "pictures", "picture", "sheet" }, OUTPUT_TANK_ICON_PATH)
|
||||
MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), INPUT_TANK_NAME, INPUT_TANK_PICTURE_PATH, { "pictures", "picture", "sheet" }, INPUT_TANK_ICON_PATH)
|
||||
|
||||
|
||||
@@ -92,6 +92,73 @@ MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), IN
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------
|
||||
--[[This section is purely to create the output tank]]--
|
||||
--------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local CRAFING_FLUID_CATEGORY_NAME = "crafting-fluids"
|
||||
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
type = "recipe-category",
|
||||
name = CRAFING_FLUID_CATEGORY_NAME
|
||||
}
|
||||
})
|
||||
|
||||
local fluidCreator = MakeLogisticEntity(table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"]), OUTPUT_TANK_NAME, OUTPUT_TANK_PICTURE_PATH, { "animation" }, OUTPUT_TANK_ICON_PATH)
|
||||
fluidCreator.fluid_boxes =
|
||||
{
|
||||
{
|
||||
production_type = "output",
|
||||
pipe_picture = assembler3pipepictures(),
|
||||
pipe_covers = pipecoverspictures(),
|
||||
base_area = 250,
|
||||
base_level = 1,
|
||||
pipe_connections =
|
||||
{
|
||||
{
|
||||
type="output", position = {0, 2}
|
||||
}
|
||||
}
|
||||
},
|
||||
off_when_no_fluid_recipe = false
|
||||
}
|
||||
fluidCreator.crafting_categories = {CRAFING_FLUID_CATEGORY_NAME}
|
||||
fluidCreator.energy_usage = "1kW"
|
||||
fluidCreator.ingredient_count = 1
|
||||
fluidCreator.module_specification.module_slots = 0
|
||||
|
||||
for k,v in pairs(data.raw.fluid) do
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
type = "recipe",
|
||||
name = v.name,
|
||||
icon = v.icon,
|
||||
category = CRAFING_FLUID_CATEGORY_NAME,
|
||||
energy_required = 1,
|
||||
subgroup = "barrel",
|
||||
order = "b[fill-crude-oil-barrel]",
|
||||
enabled = true,
|
||||
ingredients = {},
|
||||
results=
|
||||
{
|
||||
{type="fluid", name=v.name, amount=-1}
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
@@ -6,6 +6,6 @@
|
||||
"date": "19-08-2016",
|
||||
"author": "Danielv123 & Keyboardhack",
|
||||
"dependencies": ["base >= 0.13"],
|
||||
"factorio_version": "0.13",
|
||||
"factorio_version": "0.14",
|
||||
"description": "Adds 2 chests to transfer items between saves and servers over the internet."
|
||||
}
|
||||
Reference in new issue
Block a user