less drain and groupByChunk function
This commit is contained in:
parent
f99f4aaaa4
commit
d984fd890d
|
@ -1,6 +1,7 @@
|
|||
function onTick(event)
|
||||
for radius = 0, 4 do
|
||||
if event.tick % 30 == radius then
|
||||
local maxRadius = 4
|
||||
local radius = event.tick % 30
|
||||
if radius <= maxRadius then
|
||||
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"}
|
||||
|
@ -9,7 +10,6 @@ function onTick(event)
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function updateAirFilters(surface, filters, radius)
|
||||
-- Carefull not to suck in more pollution than can process
|
||||
|
@ -24,25 +24,51 @@ function updateAirFilters(surface, filters, radius)
|
|||
end
|
||||
end
|
||||
|
||||
function iteratePerChunk(filters)
|
||||
-- TODO implement
|
||||
function groupByChunk(entities)
|
||||
local chunks = {}
|
||||
for _, e in pairs(entities) do
|
||||
local chunk = positionToChunk(e.position)
|
||||
local chunkListX = chunks[chunk.x] or {}
|
||||
local chunkList = chunkListX[chunk.y] or {}
|
||||
table.insert(chunkList, e)
|
||||
chunkListX[chunk.y] = chunkList
|
||||
chunks[chunk.x] = chunkListX
|
||||
end
|
||||
local pretty_chunks = {}
|
||||
for chunkX, t in pairs(chunks) do
|
||||
for chunkY, l in pairs(t) do
|
||||
print(t)
|
||||
table.insert(pretty_chunks, {chunk={x = chunkX, y = chunkY}, entities=l})
|
||||
end
|
||||
end
|
||||
return pretty_chunks
|
||||
end
|
||||
|
||||
function positionToChunk(position)
|
||||
return {x=math.floor(position.x / 32), y=math.floor(position.y / 32)}
|
||||
end
|
||||
|
||||
function chunkToPosition(chunk)
|
||||
return {x=chunk.x *32, y=chunk.y*32}
|
||||
end
|
||||
|
||||
function movePollution(chunkFrom, chunkTo, amount)
|
||||
-- TODO should make machine consume power to move?
|
||||
|
||||
end
|
||||
|
||||
function getPurificationRate(entity)
|
||||
-- TODO implement
|
||||
-- 0 if not able to run
|
||||
-- based on crafting speed and amount of power (if possible)
|
||||
-- based on recipe? Maybe not -> machine not stronger/weaker
|
||||
end
|
||||
|
||||
function getSucktionRate(entity)
|
||||
return 1/4 * getPurificationRate(entity)
|
||||
end
|
||||
|
||||
-- TODO
|
||||
-- Make multiple filters in same chunk absorb balanced amount of pollution (not iterative)
|
||||
-- Make more efficient
|
||||
--
|
||||
-- flow rate of machines
|
||||
|
||||
script.on_event(defines.events.on_tick, onTick)
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ data:extend({
|
|||
fixed_recipe = "filter-air",
|
||||
ingredient_count = 1,
|
||||
module_slots = 0,
|
||||
allowed_effects=nill
|
||||
allowed_effects=nil
|
||||
},
|
||||
{
|
||||
type = "assembling-machine",
|
||||
|
@ -160,12 +160,12 @@ data:extend({
|
|||
{
|
||||
type = "electric",
|
||||
usage_priority = "secondary-input",
|
||||
drain="150kW",
|
||||
drain="100kW",
|
||||
},
|
||||
energy_usage = "150kW",
|
||||
energy_usage = "50kW",
|
||||
ingredient_count = 1,
|
||||
module_slots = 0,
|
||||
allowed_effects=nill
|
||||
allowed_effects=nil
|
||||
},
|
||||
{
|
||||
type = "assembling-machine",
|
||||
|
@ -252,10 +252,10 @@ data:extend({
|
|||
usage_priority = "secondary-input",
|
||||
drain="200kW",
|
||||
},
|
||||
energy_usage = "200kW",
|
||||
energy_usage = "100kW",
|
||||
ingredient_count = 1,
|
||||
module_slots = 0,
|
||||
allowed_effects=nill
|
||||
allowed_effects=nil
|
||||
},
|
||||
{
|
||||
type = "highlight-box",
|
||||
|
|
|
@ -46,7 +46,7 @@ data:extend({
|
|||
order = "g[plastic-bar]-g[unused-air-filter]",
|
||||
stack_size = 10,
|
||||
fuel_category = "pollution-filter",
|
||||
burnt_result = nill,
|
||||
burnt_result = nil,
|
||||
fuel_value = "60MW",
|
||||
},
|
||||
{
|
||||
|
|
Reference in New Issue