less drain and groupByChunk function
This commit is contained in:
parent
f99f4aaaa4
commit
d984fd890d
|
@ -1,12 +1,12 @@
|
||||||
function onTick(event)
|
function onTick(event)
|
||||||
for radius = 0, 4 do
|
local maxRadius = 4
|
||||||
if event.tick % 30 == radius then
|
local radius = event.tick % 30
|
||||||
for _, surface in pairs(game.surfaces) do
|
if radius <= maxRadius then
|
||||||
local filters = surface.find_entities_filtered {
|
for _, surface in pairs(game.surfaces) do
|
||||||
name = {"air-filter-machine-1", "air-filter-machine-2", "air-filter-machine-3"}
|
local filters = surface.find_entities_filtered {
|
||||||
}
|
name = {"air-filter-machine-1", "air-filter-machine-2", "air-filter-machine-3"}
|
||||||
updateAirFilters(surface, filters, radius)
|
}
|
||||||
end
|
updateAirFilters(surface, filters, radius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,25 +24,51 @@ function updateAirFilters(surface, filters, radius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function iteratePerChunk(filters)
|
function groupByChunk(entities)
|
||||||
-- TODO implement
|
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
|
end
|
||||||
|
|
||||||
function movePollution(chunkFrom, chunkTo, amount)
|
function movePollution(chunkFrom, chunkTo, amount)
|
||||||
-- TODO should make machine consume power to move?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function getPurificationRate(entity)
|
function getPurificationRate(entity)
|
||||||
-- TODO implement
|
-- TODO implement
|
||||||
-- 0 if not able to run
|
-- 0 if not able to run
|
||||||
-- based on crafting speed and amount of power (if possible)
|
-- 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
|
end
|
||||||
|
|
||||||
-- TODO
|
-- TODO
|
||||||
-- Make multiple filters in same chunk absorb balanced amount of pollution (not iterative)
|
|
||||||
-- Make more efficient
|
-- Make more efficient
|
||||||
--
|
-- flow rate of machines
|
||||||
|
|
||||||
script.on_event(defines.events.on_tick, onTick)
|
script.on_event(defines.events.on_tick, onTick)
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ data:extend({
|
||||||
fixed_recipe = "filter-air",
|
fixed_recipe = "filter-air",
|
||||||
ingredient_count = 1,
|
ingredient_count = 1,
|
||||||
module_slots = 0,
|
module_slots = 0,
|
||||||
allowed_effects=nill
|
allowed_effects=nil
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "assembling-machine",
|
type = "assembling-machine",
|
||||||
|
@ -160,12 +160,12 @@ data:extend({
|
||||||
{
|
{
|
||||||
type = "electric",
|
type = "electric",
|
||||||
usage_priority = "secondary-input",
|
usage_priority = "secondary-input",
|
||||||
drain="150kW",
|
drain="100kW",
|
||||||
},
|
},
|
||||||
energy_usage = "150kW",
|
energy_usage = "50kW",
|
||||||
ingredient_count = 1,
|
ingredient_count = 1,
|
||||||
module_slots = 0,
|
module_slots = 0,
|
||||||
allowed_effects=nill
|
allowed_effects=nil
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "assembling-machine",
|
type = "assembling-machine",
|
||||||
|
@ -252,10 +252,10 @@ data:extend({
|
||||||
usage_priority = "secondary-input",
|
usage_priority = "secondary-input",
|
||||||
drain="200kW",
|
drain="200kW",
|
||||||
},
|
},
|
||||||
energy_usage = "200kW",
|
energy_usage = "100kW",
|
||||||
ingredient_count = 1,
|
ingredient_count = 1,
|
||||||
module_slots = 0,
|
module_slots = 0,
|
||||||
allowed_effects=nill
|
allowed_effects=nil
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "highlight-box",
|
type = "highlight-box",
|
||||||
|
|
|
@ -46,7 +46,7 @@ data:extend({
|
||||||
order = "g[plastic-bar]-g[unused-air-filter]",
|
order = "g[plastic-bar]-g[unused-air-filter]",
|
||||||
stack_size = 10,
|
stack_size = 10,
|
||||||
fuel_category = "pollution-filter",
|
fuel_category = "pollution-filter",
|
||||||
burnt_result = nill,
|
burnt_result = nil,
|
||||||
fuel_value = "60MW",
|
fuel_value = "60MW",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Reference in New Issue