mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Cleanup miner decon (#377)
* Update miner.lua * Update miner.lua * Update miner.lua * Update miner.lua
This commit is contained in:
@@ -41,7 +41,7 @@ local function check_entity(entity)
|
||||
end
|
||||
|
||||
if not entity.minable then
|
||||
-- if it is minable
|
||||
-- if it is not minable
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -102,10 +102,6 @@ local function miner_check(entity)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
entity.status ~= defines.entity_status.no_minable_resources
|
||||
]]
|
||||
|
||||
if check_entity(entity) then
|
||||
return
|
||||
end
|
||||
@@ -113,32 +109,28 @@ local function miner_check(entity)
|
||||
local pipe_build = {}
|
||||
|
||||
if config.fluid and entity.fluidbox and #entity.fluidbox > 0 then
|
||||
-- if require fluid to mine
|
||||
table.insert(pipe_build, { x = 0, y = 0 })
|
||||
|
||||
local half = math.floor(entity.get_radius())
|
||||
local r = 1 + er
|
||||
|
||||
local rh = math.ceil(er / 2) - 1
|
||||
local r = er + 1
|
||||
local entities = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, type = { "mining-drill", "pipe", "pipe-to-ground" } }
|
||||
local entities_t = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, ghost_type = { "pipe", "pipe-to-ground" } }
|
||||
|
||||
table.insert_array(entities, entities_t)
|
||||
|
||||
for _, e in pairs(entities) do
|
||||
if (e.position.x > ep.x) and (e.position.y == ep.y) then
|
||||
for h = 1, half do
|
||||
for h = 1, rh do
|
||||
table.insert(pipe_build, { x = h, y = 0 })
|
||||
end
|
||||
elseif (e.position.x < ep.x) and (e.position.y == ep.y) then
|
||||
for h = 1, half do
|
||||
for h = 1, rh do
|
||||
table.insert(pipe_build, { x = -h, y = 0 })
|
||||
end
|
||||
elseif (e.position.x == ep.x) and (e.position.y > ep.y) then
|
||||
for h = 1, half do
|
||||
for h = 1, rh do
|
||||
table.insert(pipe_build, { x = 0, y = h })
|
||||
end
|
||||
elseif (e.position.x == ep.x) and (e.position.y < ep.y) then
|
||||
for h = 1, half do
|
||||
for h = 1, rh do
|
||||
table.insert(pipe_build, { x = 0, y = -h })
|
||||
end
|
||||
end
|
||||
@@ -152,7 +144,7 @@ local function miner_check(entity)
|
||||
table.insert(miner_data.queue, { t = game.tick + 5, e = entity })
|
||||
|
||||
for _, pos in ipairs(pipe_build) do
|
||||
es.create_entity{ name = "entity-ghost", position = { x = ep.x + pos.x, y = ep.y + pos.y }, force = ef, inner_name = "pipe", raise_built = true }
|
||||
es.create_entity{ name = "entity-ghost", position = { x = ep.x + pos.x, y = ep.y + pos.y }, force = ef, inner_name = "pipe" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -161,27 +153,27 @@ Event.add(defines.events.on_resource_depleted, function(event)
|
||||
return
|
||||
end
|
||||
|
||||
local entities = event.entity.surface.find_entities_filtered{ area = { { event.entity.position.x - 1, event.entity.position.y - 1 }, { event.entity.position.x + 1, event.entity.position.y + 1 } }, type = "mining-drill" }
|
||||
local resource = event.entity
|
||||
local drills = resource.surface.find_entities_filtered{ area = { { event.entity.position.x - 1, event.entity.position.y - 1 }, { event.entity.position.x + 1, event.entity.position.y + 1 } }, type = "mining-drill" }
|
||||
|
||||
if #entities == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
if ((math.abs(entity.position.x - event.entity.position.x) < entity.prototype.mining_drill_radius) and (math.abs(entity.position.y - event.entity.position.y) < entity.prototype.mining_drill_radius)) then
|
||||
for _, entity in pairs(drills) do
|
||||
local radius = entity.prototype.mining_drill_radius
|
||||
local dx = math.abs(entity.position.x - resource.position.x)
|
||||
local dy = math.abs(entity.position.y - resource.position.y)
|
||||
if dx <= radius and dy <= radius then
|
||||
miner_check(entity)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(10, function(event)
|
||||
for k, q in pairs(miner_data.queue) do
|
||||
for i = #miner_data.queue, 1, -1 do
|
||||
local q = miner_data.queue[i]
|
||||
if not q.e or not q.e.valid then
|
||||
table.remove(miner_data.queue, k)
|
||||
break
|
||||
table.remove(miner_data.queue, i)
|
||||
elseif event.tick >= q.t then
|
||||
q.e.order_deconstruction(q.e.force)
|
||||
table.remove(miner_data.queue, k)
|
||||
table.remove(miner_data.queue, i)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user