fixed desync

This commit is contained in:
TheAIBot committed 2016-08-23 21:12:02 +02:00
1 parent 62c07c77f2
commit 11ff85ca74
2 files changed
+55 -21

No files matched your search

+53 -19
View File
@@ -8,23 +8,39 @@ function OnBuiltEntity(event)
local entity = event.created_entity local entity = event.created_entity
--only add entities that are not ghosts --only add entities that are not ghosts
if entity.type ~= "entity-ghost" then if entity.type ~= "entity-ghost" then
if entity.name == INPUT_CHEST_NAME then
global.inputChests = global.inputChests or {} end
--add the chests to a lists if these chests so they can be interated over end
global.inputChests[HashPosition(entity.position)] = entity
elseif entity.name == OUTPUT_CHEST_NAME then function AddAllEntitiesOfName(name)
global.outputChests = global.outputChests or {} for k, surface in pairs(game.surfaces) do
--add the chests to a lists if these chests so they can be interated over AddEntities(surface.find_entities_filtered({["name"] = name}))
global.outputChests[HashPosition(entity.position)] = entity end
elseif entity.name == INPUT_TANK_NAME then end
global.inputTanks = global.inputTanks or {}
--add the chests to a lists if these chests so they can be interated over function AddEntities(entities)
global.inputTanks[HashPosition(entity.position)] = entity for k, entity in pairs(entities) do
elseif entity.name == OUTPUT_TANK_NAME then AddEntity(entity)
global.outputTanks = global.outputTanks or {} end
--add the chests to a lists if these chests so they can be interated over end
global.outputTanks[HashPosition(entity.position)] = entity
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
end end
end end
@@ -66,9 +82,8 @@ script.on_event(defines.events.on_preplayer_mined_item, function(event)
end) end)
script.on_event(defines.events.on_tick, function(event) script.on_event(defines.events.on_tick, function(event)
global.inputChests = global.inputChests or {} global.inputChests = global.inputChests or {}
global.outputChests = global.outputChests or {} global.outputChests = global.outputChests or {}
global.inputTanks = global.inputTanks or {} global.inputTanks = global.inputTanks or {}
@@ -78,6 +93,23 @@ script.on_event(defines.events.on_tick, function(event)
local todo = game.tick % UPATE_RATE local todo = game.tick % UPATE_RATE
if global.previousPlayerCount == nil or global.previousPlayerCount ~= #game.players then
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)
print("reset")
end
if todo == 0 then if todo == 0 then
HandleInputChests() HandleInputChests()
elseif todo == 1 then elseif todo == 1 then
@@ -91,6 +123,8 @@ script.on_event(defines.events.on_tick, function(event)
elseif todo == 5 then elseif todo == 5 then
ExportOutputList() ExportOutputList()
end end
global.previousPlayerCount = global.previousPlayerCount or #game.players
end) end)
function HandleInputChests() function HandleInputChests()
+2 -2
View File
@@ -20,7 +20,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
entity.icon = iconPath or entity.icon entity.icon = iconPath or entity.icon
-- add the entity to a technology so it can be unlocked -- 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( data:extend(
{ {
@@ -34,7 +34,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
--shouldn't be enabled to begin with. --shouldn't be enabled to begin with.
--but if the recipe isn't attached to a tech then it should --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 --be enabled to begin with because otherwise the player can never use the item ingame
enabled = not wasAddedToTech, enabled = true,
ingredients = ingredients =
{ {
{"steel-chest", 1}, {"steel-chest", 1},