2019-10-06 17:50:50 +00:00
-- #################
-- # Constants #
-- #################
2019-10-04 17:20:34 +00:00
2019-10-07 19:43:54 +00:00
local INTERVAL = 20
-- #####################
-- # Local handles #
-- #####################
local air_filtered_chunks = { }
2019-10-06 12:36:40 +00:00
2019-10-04 17:20:34 +00:00
2019-10-06 17:50:50 +00:00
-- #################
-- # Utilities #
-- #################
2019-10-05 20:08:15 +00:00
2019-10-06 17:50:50 +00:00
function starts_with ( str , start )
return str : sub ( 1 , # start ) == start
2019-10-05 20:08:15 +00:00
end
2019-10-08 13:13:56 +00:00
function sign ( x )
2019-10-07 19:43:54 +00:00
if x == 0 then
return 1
else
return x / math.abs ( x )
end
end
2019-10-08 13:13:56 +00:00
function manhattan ( x , y )
2019-10-07 19:43:54 +00:00
-- Manhattan distance from origin to xy.
return math.abs ( x ) + math.abs ( y )
2019-10-06 19:04:25 +00:00
end
2019-10-08 13:13:56 +00:00
function positionToChunk ( position )
2019-10-06 17:50:50 +00:00
return { x = math.floor ( position.x / 32 ) , y = math.floor ( position.y / 32 ) }
2019-10-04 17:20:34 +00:00
end
2019-10-06 12:36:40 +00:00
function getBasePurificationRate ( entity )
2019-10-06 20:50:58 +00:00
-- Depends mostly on recipe (optimal recipe used per machine). Should be multiplied by crafting speed to achieve actual max purification rate
2019-10-06 12:36:40 +00:00
if entity.name == " air-filter-machine-1 " then
2019-10-07 17:11:28 +00:00
return 2 * INTERVAL / 60 -- max pollution cleaning per second among mk1 recipes
2019-10-06 12:36:40 +00:00
elseif entity.name == " air-filter-machine-2 " or entity.name == " air-filter-machine-3 " then
2019-10-08 18:41:57 +00:00
return 4 * INTERVAL / 60 -- max pollution cleaning for mk2 and mk3 recipes TODO: change if fluid filtering is implemented
2019-10-06 12:36:40 +00:00
else
return 0
end
end
2019-10-05 20:08:15 +00:00
2019-10-06 20:50:58 +00:00
function energyCraftingModifier ( entity )
-- Approximation to speed modifier for machine running out of power
if entity.electric_buffer_size then
return entity.energy / entity.electric_buffer_size
else
return 1
end
end
2019-10-06 12:36:40 +00:00
function getSuctionRate ( entity )
if not entity.is_crafting ( ) and getSpaceForPollution ( entity ) == 0 then
return 0
else
return getBasePurificationRate ( entity ) * entity.crafting_speed * energyCraftingModifier ( entity )
end
2019-10-04 17:20:34 +00:00
end
2019-10-06 17:50:50 +00:00
function getAbsorptionRate ( entity )
return math.min ( getSpaceForPollution ( entity ) , getSuctionRate ( entity ) )
end
2019-10-08 13:13:56 +00:00
function pollutionInPollutedWater ( amount )
return amount * 6 / 10
end
2019-10-05 20:08:15 +00:00
2019-10-06 12:36:40 +00:00
function getSpaceForPollution ( entity )
if # entity.fluidbox < 1 then
return 0
end
local capacity = entity.fluidbox . get_capacity ( 1 )
local pollutionFluid = entity.fluidbox [ 1 ]
local pollution = 0
if pollutionFluid then
pollution = pollutionFluid.amount
end
return capacity - pollution
2019-10-04 17:20:34 +00:00
end
2019-10-08 13:13:56 +00:00
function inRadius ( filter , radius )
2019-10-06 17:50:50 +00:00
if filter.name == " air-filter-machine-1 " then
return radius <= 0
elseif filter.name == " air-filter-machine-2 " then
return radius <= 2
elseif filter.name == " air-filter-machine-3 " then
return radius <= 3
else
return false
end
end
2019-10-06 20:50:58 +00:00
2019-10-06 17:50:50 +00:00
-- #####################
-- # Update script #
-- #####################
2019-10-08 19:08:10 +00:00
--function updateInserters(event)
--for _, surface in pairs(game.surfaces) do
-- local inserters = surface.find_entities_filtered({type="inserter"})
-- for _, inserter in pairs(inserters) do
-- updateInserter(inserter)
-- end
--end
--end
--function updateInserter(inserter)
--game.print(serpent.line(inserter.position))
--local drop_target = inserter.drop_target
--if drop_target == nil then return end
--local pickup_target = inserter.pickup_target
--if pickup_target == nil then return end
--local burnt_result_inventory = pickup_target.get_burnt_result_inventory()
--if burnt_result_inventory == nil then return end
--if burnt_result_inventory.is_empty() then return end
--if inserter.get_item_count() > 0 then return end
--
--
--local contents = burnt_result_inventory.get_contents()
--
--
--for item_name, count in pairs (contents) do
-- fuel_item_name = item_name
--end
--
--if inserter.get_item_count() < 1 then
-- if inserter.held_stack.valid_for_read == false then
-- if pickup_target.get_item_count(fuel_item_name) > 0 then
-- inserter.held_stack.set_stack({name = fuel_item_name, count = 1})
-- pickup_target.remove_item({name = fuel_item_name, count = 1})
-- return
-- end
-- end
--end
--end
2019-10-06 19:04:25 +00:00
function absorbPollution ( event )
2019-10-08 13:13:56 +00:00
-- game.print("insertPollution")
2019-10-07 19:43:54 +00:00
for _ , c in pairs ( air_filtered_chunks ) do
2019-10-06 17:50:50 +00:00
absorbChunk ( c )
end
end
function absorbChunk ( chunk )
if chunk : get_pollution ( ) == 0 then
return
end
2019-10-06 20:50:58 +00:00
local totalAbsorptionRate = chunk : getTotalAbsorptionRate ( )
2019-10-06 17:50:50 +00:00
2019-10-12 09:53:07 +00:00
--game.print("totalAbsorptionRate: " .. totalAbsorptionRate)
--game.print("filter count: " .. #chunk.filters)
2019-10-06 20:50:58 +00:00
if totalAbsorptionRate == 0 then
2019-10-06 17:50:50 +00:00
return
end
2019-10-08 13:13:56 +00:00
local toAbsorb = math.min ( chunk : get_pollution ( ) , totalAbsorptionRate )
-- game.print("To absorb: " .. toAbsorb)
2019-10-06 17:50:50 +00:00
local totalInsertedAmount = 0.0
2019-10-09 10:45:02 +00:00
for _ , filter in pairs ( chunk : getFilters ( ) ) do
2019-10-06 20:50:58 +00:00
local toInsert = ( getAbsorptionRate ( filter ) / totalAbsorptionRate ) * toAbsorb
2019-10-06 17:50:50 +00:00
if toInsert > 0 then
local insertedAmount = filter.insert_fluid ( { name = " pollution " , amount = toInsert } )
2019-10-09 10:45:02 +00:00
game.pollution_statistics . on_flow ( filter.name , - insertedAmount )
2019-10-06 17:50:50 +00:00
totalInsertedAmount = totalInsertedAmount + insertedAmount
end
end
chunk : pollute ( - totalInsertedAmount )
2019-10-07 19:43:54 +00:00
-- game.print("Total inserted: " .. totalInsertedAmount)
if math.abs ( toAbsorb - totalInsertedAmount ) > 0.01 then
2019-10-08 13:13:56 +00:00
game.print ( " Error with inserting pollution in air filter machine. Different amounts absorbed/inserted: " .. toAbsorb .. " absorbed and " .. totalInsertedAmount .. " inserted. " )
2019-10-07 19:43:54 +00:00
end
end
2019-10-08 13:13:56 +00:00
function stepsToOrigin ( x , y )
2019-10-07 19:43:54 +00:00
-- Provide coordinates of possible 1-steps toward (0, 0)
local steps = { }
if x ~= 0 then
2019-10-08 13:13:56 +00:00
table.insert ( steps , { x = x - sign ( x ) , y = y } )
2019-10-07 19:43:54 +00:00
end
if y ~= 0 then
2019-10-08 13:13:56 +00:00
table.insert ( steps , { x = x , y = y - sign ( y ) } )
2019-10-07 19:43:54 +00:00
end
return steps
2019-10-06 17:50:50 +00:00
end
2019-10-08 13:13:56 +00:00
function suctionUpdateChunk ( chunkTo , dx , dy )
2019-10-07 19:43:54 +00:00
local totalSuction = chunkTo : getTotalSuctionRate ( manhattan ( dx , dy ) )
2019-10-06 20:50:58 +00:00
2019-10-07 19:43:54 +00:00
if totalSuction == 0 then
return
end
2019-10-06 20:50:58 +00:00
2019-10-08 13:13:56 +00:00
-- game.print("From " .. dx .. ", " .. dy)
-- game.print("suction: " .. totalSuction)
2019-10-06 20:50:58 +00:00
2019-10-07 19:43:54 +00:00
local chunkFrom = getFilteredChunk ( chunkTo.surface , chunkTo.x + dx , chunkTo.y + dy )
local test = chunkFrom : getTotalSuctionRate ( 0 )
local pollution = chunkFrom : get_pollution ( )
if pollution > 0 then
local toPollute = math.min ( pollution , totalSuction )
local chunksVia = { }
for _ , step in pairs ( stepsToOrigin ( dx , dy ) ) do
local chunk = getFilteredChunk ( chunkTo.surface , chunkTo.x + step.x , chunkTo.y + step.y )
table.insert ( chunksVia , chunk )
end
2019-10-06 20:50:58 +00:00
2019-10-08 13:13:56 +00:00
-- game.print("Moving " .. toPollute .. " pollution")
-- game.print("From: " .. chunkFrom.x .. ", " .. chunkFrom.y)
2019-10-07 19:43:54 +00:00
for _ , chunkVia in pairs ( chunksVia ) do
2019-10-08 13:13:56 +00:00
-- game.print("To: " .. chunkVia.x .. ", " .. chunkVia.y)
2019-10-07 19:43:54 +00:00
chunkVia : pollute ( toPollute / # chunksVia )
end
chunkFrom : pollute ( - toPollute )
end
2019-10-06 20:50:58 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-08 13:13:56 +00:00
function generateSuctionFunction ( dx , dy )
2019-10-06 19:04:25 +00:00
local function suctionUpdate ( event )
2019-10-08 13:13:56 +00:00
-- game.print("suck pollution " .. dx .. ", " .. dy)
2019-10-07 19:43:54 +00:00
for _ , chunkTo in pairs ( air_filtered_chunks ) do
2019-10-06 20:50:58 +00:00
suctionUpdateChunk ( chunkTo , dx , dy )
end
2019-10-06 19:04:25 +00:00
end
return suctionUpdate
end
2019-10-08 13:13:56 +00:00
function generateRadiusCoordinates ( radius )
2019-10-06 19:04:25 +00:00
local coords = { }
for signR = - 1 , 1 , 2 do
for signX = - 1 , 1 , 2 do
for dx = - radius , radius do
2019-10-07 19:43:54 +00:00
if not ( sign ( signX ) * sign ( dx ) == signR ) then
if not ( math.abs ( dx ) == radius and signR == 1 ) then
2019-10-06 19:04:25 +00:00
local dy = ( signR * radius ) + ( signX * dx )
2019-10-08 13:13:56 +00:00
table.insert ( coords , { dx = dx , dy = dy } )
2019-10-06 19:04:25 +00:00
end
end
end
end
end
return coords
end
2019-10-08 13:13:56 +00:00
function generateRadiusSuctionFunctions ( radius )
2019-10-06 19:04:25 +00:00
local functions = { }
for _ , offset in pairs ( generateRadiusCoordinates ( radius ) ) do
local f = generateSuctionFunction ( offset.dx , offset.dy )
table.insert ( functions , f )
end
return functions
2019-10-06 17:50:50 +00:00
end
2019-10-08 13:13:56 +00:00
function generateFunctions ( )
2019-10-06 12:36:40 +00:00
local functions = { }
2019-10-06 19:04:25 +00:00
table.insert ( functions , absorbPollution )
2019-10-06 17:50:50 +00:00
for radius = 1 , 4 do
2019-10-06 19:04:25 +00:00
for _ , f in pairs ( generateRadiusSuctionFunctions ( radius ) ) do
2019-10-06 17:50:50 +00:00
table.insert ( functions , f )
2019-10-06 12:36:40 +00:00
end
end
2019-10-08 19:08:10 +00:00
--table.insert(functions, updateInserters)
2019-10-06 12:36:40 +00:00
return functions
end
2019-10-08 13:13:56 +00:00
function spreadOverTicks ( functions , interval )
2019-10-06 12:36:40 +00:00
local tickMap = { }
local funcs = { }
for index , f in pairs ( functions ) do
-- amount of functions to be inserted in this tick update to fit them all in the remaining interval
local functionsPerTick = math.ceil ( ( # functions - index ) / ( interval - # tickMap - 1 ) )
table.insert ( funcs , f )
if # funcs >= functionsPerTick then
table.insert ( tickMap , funcs )
funcs = { }
end
end
if # funcs > 0 then
table.insert ( tickMap , funcs )
funcs = { }
end
local function onTick ( event )
local step = ( event.tick % interval ) + 1
local funcs = tickMap [ step ]
if funcs ~= nil then
for _ , f in pairs ( funcs ) do
f ( event )
end
end
2019-10-08 13:13:56 +00:00
-- if step == 1 then
-- game.print("================================")
-- end
2019-10-06 12:36:40 +00:00
end
return onTick
end
2019-10-06 20:50:58 +00:00
-- #####################
-- # FilteredChunk #
-- #####################
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
local FilteredChunk = {
surface = nil ,
x = 0 ,
y = 0 ,
2019-10-09 10:45:02 +00:00
--filters = {}
2019-10-06 20:50:58 +00:00
}
2019-10-07 19:43:54 +00:00
function FilteredChunk : new ( o )
o = o or { }
setmetatable ( o , self )
self.__index = self
2019-10-09 10:45:02 +00:00
o.filters = o.filters or { }
2019-10-07 19:43:54 +00:00
return o
end
function createFilteredChunk ( surface , x , y )
local chunk = FilteredChunk : new ( nil )
chunk.surface = surface
chunk.x = x
chunk.y = y
return chunk
end
2019-10-06 20:50:58 +00:00
function FilteredChunk : equal ( other )
return self.surface . name == other.surface . name and self.x == other.x and self.y == other.y
end
2019-10-06 17:50:50 +00:00
2019-10-09 10:45:02 +00:00
function FilteredChunk : getFilters ( )
local filters = { }
for _ , filter in pairs ( self.filters ) do
if filter.valid then
table.insert ( filters , filter )
end
end
self.filters = filters
return filters
end
2019-10-06 20:50:58 +00:00
function FilteredChunk : addToMap ( )
2019-10-09 10:45:02 +00:00
--game.print("Active chunks before: ")
--for i, c in pairs(air_filtered_chunks) do
-- game.print(serpent.line(c))
--end
--game.print(serpent.block(global.air_filtered_chunks_map))
2019-10-08 18:41:57 +00:00
--game.print("Adding chunk to map")
2019-10-06 20:50:58 +00:00
local chunkListX = global.air_filtered_chunks_map [ self.surface . name ] or { }
local chunkListY = chunkListX [ self.x ] or { }
assert ( chunkListY [ y ] == nil , " Chunklist entry should not exist yet. " )
chunkListY [ self.y ] = self
chunkListX [ self.x ] = chunkListY
global.air_filtered_chunks_map [ self.surface . name ] = chunkListX
2019-10-07 19:43:54 +00:00
table.insert ( air_filtered_chunks , self )
2019-10-09 10:45:02 +00:00
--game.print("Active chunks after: ")
--for i, c in pairs(air_filtered_chunks) do
-- game.print(serpent.line(c))
--end
--game.print(serpent.block(global.air_filtered_chunks_map))
2019-10-06 20:50:58 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : removeFromMap ( )
2019-10-08 18:41:57 +00:00
--game.print("Removing chunk from map")
2019-10-09 10:45:02 +00:00
global.air_filtered_chunks_map [ self.surface . name ] [ self.x ] [ self.y ] = nil
2019-10-07 19:43:54 +00:00
for i , c in pairs ( air_filtered_chunks ) do
2019-10-06 20:50:58 +00:00
if self : equal ( c ) then
2019-10-08 18:41:57 +00:00
--game.print("Removing chunk from list")
2019-10-09 10:45:02 +00:00
table.remove ( air_filtered_chunks , i )
2019-10-06 20:50:58 +00:00
break
2019-10-06 17:50:50 +00:00
end
end
2019-10-09 10:45:02 +00:00
--local i = 1
--while i <= #air_filtered_chunks do
-- local c = air_filtered_chunks[i]
-- if self:equal(c) then
-- --game.print("Removing chunk from list")
-- table.remove(air_filtered_chunks, i)
-- else
-- i = i + 1
-- end
--end
--game.print("Remaining chunks: ")
--for _, c in pairs(air_filtered_chunks) do
-- game.print(serpent.line(c))
--end
2019-10-06 20:50:58 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : getTotalAbsorptionRate ( )
local totalAbsorptionRate = 0.0
2019-10-09 10:45:02 +00:00
for _ , filter in pairs ( self : getFilters ( ) ) do
2019-10-06 20:50:58 +00:00
local absorptionRate = getAbsorptionRate ( filter )
totalAbsorptionRate = totalAbsorptionRate + absorptionRate
2019-10-06 17:50:50 +00:00
end
2019-10-06 20:50:58 +00:00
return totalAbsorptionRate
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : getTotalSuctionRate ( distance )
local totalSuctionRate = 0.0
2019-10-09 10:45:02 +00:00
for _ , filter in pairs ( self : getFilters ( ) ) do
2019-10-06 20:50:58 +00:00
if inRadius ( filter , distance ) then
local suctionRate = getSuctionRate ( filter )
totalSuctionRate = totalSuctionRate + suctionRate
end
2019-10-06 17:50:50 +00:00
end
2019-10-08 13:13:56 +00:00
return totalSuctionRate * ( 1 / 4 ) ^ distance
2019-10-06 20:50:58 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : get_pollution ( )
return self.surface . get_pollution ( self : toPosition ( ) )
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : pollute ( amount )
self.surface . pollute ( self : toPosition ( ) , amount )
end
function FilteredChunk : toPosition ( )
return { x = self.x * 32 , y = self.y * 32 }
end
function FilteredChunk : addFilter ( filter )
table.insert ( self.filters , filter )
if # self.filters == 1 then
self : addToMap ( )
2019-10-06 17:50:50 +00:00
end
2019-10-06 20:50:58 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function FilteredChunk : removeFilter ( filter )
for i , f in pairs ( self.filters ) do
if f.unit_number == filter.unit_number then
table.remove ( self.filters , i )
break
2019-10-06 17:50:50 +00:00
end
end
2019-10-06 20:50:58 +00:00
if # self.filters == 0 then
self : removeFromMap ( )
end
end
function getFilteredChunk ( surface , x , y )
2019-10-06 17:50:50 +00:00
local chunkListX = global.air_filtered_chunks_map [ surface.name ]
if chunkListX ~= nil then
local chunkListY = chunkListX [ x ]
if chunkListY ~= nil then
local chunk = chunkListY [ y ]
if chunk ~= nil then
return chunk
end
end
end
2019-10-06 20:50:58 +00:00
return createFilteredChunk ( surface , x , y )
2019-10-06 17:50:50 +00:00
end
-- #################
-- # callbacks #
-- #################
function isAirFilterMachine ( entity )
return starts_with ( entity.name , " air-filter-machine- " )
end
2019-10-08 13:13:56 +00:00
function onEntityCreated ( event )
2019-10-06 17:50:50 +00:00
if isAirFilterMachine ( event.created_entity ) then
local chunkPos = positionToChunk ( event.created_entity . position )
local chunk = getFilteredChunk ( event.created_entity . surface , chunkPos.x , chunkPos.y )
chunk : addFilter ( event.created_entity )
end
end
2019-10-08 13:13:56 +00:00
function onEntityRemoved ( event )
-- Update map of air filters
2019-10-06 17:50:50 +00:00
if isAirFilterMachine ( event.entity ) then
local chunkPos = positionToChunk ( event.entity . position )
local chunk = getFilteredChunk ( event.entity . surface , chunkPos.x , chunkPos.y )
chunk : removeFilter ( event.entity )
end
2019-10-08 13:13:56 +00:00
-- Disperse pollution back
local pollution = 0
-- from pollution (fluid)
pollution = pollution + event.entity . get_fluid_count ( " pollution " )
-- from polluted water (fluid)
local pollutedWater = event.entity . get_fluid_count ( " polluted-water " )
pollution = pollution + pollutionInPollutedWater ( pollutedWater )
-- from current crafting op
--local crafting = "No"
--if event.entity.is_crafting() then crafting = "Yes" end
--game.print("crafting? " .. crafting)
--local recipe = event.entity.get_recipe()
--if recipe ~= nil and event.entity.is_crafting() then
-- for _, ingredient in pairs(recipe.ingredients) do
-- game.print("Ingredient: " .. ingredient.name)
-- if ingredient.name == "pollution" then
-- pollution = pollution + ingredient.amount
-- elseif ingredient.name == "polluted-water" then
-- pollution = pollution + pollutionInPollutedWater(ingredient.amount)
-- end
-- end
--end
if pollution > 0 then
2019-10-08 18:41:57 +00:00
--game.print("Dispersing " .. pollution .. " pollution back")
2019-10-08 13:13:56 +00:00
event.entity . surface.pollute ( event.entity . position , pollution )
2019-10-09 10:45:02 +00:00
game.pollution_statistics . on_flow ( event.entity . name , pollution )
2019-10-08 13:13:56 +00:00
end
2019-10-06 17:50:50 +00:00
end
2019-10-08 13:13:56 +00:00
function preEntityRemoved ( event )
local isCrafting = event.entity . type == " assembling-machine " and event.entity . is_crafting ( )
-- disperse pollution in recipe back
if isCrafting then
local pollution = 0
local recipe = event.entity . get_recipe ( )
if recipe ~= nil then
for _ , ingredient in pairs ( recipe.ingredients ) do
if ingredient.name == " pollution " then
pollution = pollution + ingredient.amount
elseif ingredient.name == " polluted-water " then
pollution = pollution + pollutionInPollutedWater ( ingredient.amount )
end
end
end
2019-10-06 17:50:50 +00:00
2019-10-08 13:13:56 +00:00
if pollution > 0 then
2019-10-08 18:41:57 +00:00
--game.print("Dispersing " .. pollution .. " pollution back")
2019-10-08 13:13:56 +00:00
event.entity . surface.pollute ( event.entity . position , pollution )
2019-10-09 10:45:02 +00:00
game.pollution_statistics . on_flow ( event.entity . name , pollution )
2019-10-08 13:13:56 +00:00
end
end
-- On entity died has no pre version -> call onEntityRemoved manually
if event.name == defines.events . on_entity_died then
onEntityRemoved ( event )
end
end
2019-10-06 17:50:50 +00:00
2019-10-06 20:50:58 +00:00
function refreshMetatables ( )
2019-10-07 19:43:54 +00:00
for _ , chunkListX in pairs ( global.air_filtered_chunks_map ) do
for x , chunkListY in pairs ( chunkListX ) do
for y , chunk in pairs ( chunkListY ) do
chunk = FilteredChunk : new ( chunk ) -- resets metatable
table.insert ( air_filtered_chunks , chunk )
end
end
2019-10-06 20:50:58 +00:00
end
end
2019-10-06 17:50:50 +00:00
function init ( )
-- gather all filters on every surface
global.air_filtered_chunks_map = { }
for _ , surface in pairs ( game.surfaces ) do
local filters = surface.find_entities_filtered {
name = { " air-filter-machine-1 " , " air-filter-machine-2 " , " air-filter-machine-3 " }
}
for _ , filter in pairs ( filters ) do
local chunkPos = positionToChunk ( filter.position )
local chunk = getFilteredChunk ( surface , chunkPos.x , chunkPos.y )
chunk : addFilter ( filter )
end
end
2019-10-07 19:43:54 +00:00
end
2019-10-06 17:50:50 +00:00
2019-10-07 19:43:54 +00:00
function load ( )
2019-10-06 20:50:58 +00:00
refreshMetatables ( )
2019-10-08 13:13:56 +00:00
end
2019-10-06 20:50:58 +00:00
2019-10-06 12:36:40 +00:00
2019-10-08 13:13:56 +00:00
-- Set up callbacks
script.on_event ( { defines.events . on_built_entity , defines.events . on_robot_built_entity } , onEntityCreated )
-- on_entity_died should trigger both functions -> called manually
script.on_event ( { defines.events . on_player_mined_entity , defines.events . on_robot_mined_entity , defines.events . on_entity_died } , onEntityRemoved )
script.on_event ( { defines.events . on_pre_player_mined_item , defines.events . on_pre_robot_mined_item , defines.events . on_entity_died } , preEntityRemoved )
local functions = generateFunctions ( )
local onTick = spreadOverTicks ( functions , INTERVAL )
script.on_event ( defines.events . on_tick , onTick )
2019-10-07 19:43:54 +00:00
script.on_load ( load )
script.on_init ( init )
script.on_configuration_changed ( init )
2019-10-04 17:20:34 +00:00