1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-02-03 13:11:21 +02:00

refactor + burner drill bug fix

This commit is contained in:
grilledham 2018-07-19 13:28:00 +01:00
parent 1410b962f5
commit 26054e7f09

View File

@ -1,37 +1,47 @@
--Author: Valansch
local Event = require "utils.event"
local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Task = require 'utils.Task'
local function is_depleted(drill)
local function is_depleted(drill, entity)
local position = drill.position
local area = {}
if drill.name == "electric-mining-drill" then
area = {{position.x - 2, position.y - 2},{position.x + 2, position.y + 2}}
local area
if drill.name == 'electric-mining-drill' then
area = {{position.x - 2.5, position.y - 2.5}, {position.x + 2.5, position.y + 2.5}}
else
area = {{position.x - 1, position.y - 1},{position.x + 1, position.y + 1}}
area = {{position.x - 1, position.y - 1}, {position.x + 1, position.y + 1}}
end
local count = -1
for _,resource in pairs(drill.surface.find_entities_filtered{type="resource", area = area}) do
if resource.name ~= "crude-oil" then
count = count + 1
for _, resource in pairs(drill.surface.find_entities_filtered {type = 'resource', area = area}) do
if resource ~= entity and resource.name ~= 'crude-oil' then
return false
end
end
return count == 0
return true
end
local function mark_if_depleted(drill)
if is_depleted(drill) then
local callback =
Token.register(
function(drill)
if drill.valid then
drill.order_deconstruction(drill.force)
end
end
end
)
local function on_resource_depleted(event)
if event.entity.name == "uranium-ore" then return nil end
local area = {{event.entity.position.x-1, event.entity.position.y-1}, {event.entity.position.x+1, event.entity.position.y + 1}}
local drills = event.entity.surface.find_entities_filtered{area = area, type="mining-drill"}
for _,drill in pairs(drills) do
if drill.name ~= "pumpjack" then
mark_if_depleted(drill)
local entity = event.entity
if entity.name == 'uranium-ore' then
return nil
end
local position = entity.position
local area = {{position.x - 1, position.y - 1}, {position.x + 1, position.y + 1}}
local drills = event.entity.surface.find_entities_filtered {area = area, type = 'mining-drill'}
for _, drill in ipairs(drills) do
if drill.name ~= 'pumpjack' and is_depleted(drill, entity) then
Task.set_timeout_in_ticks(5, callback, drill)
end
end
end