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:
parent
1410b962f5
commit
26054e7f09
@ -1,39 +1,49 @@
|
||||
--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 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}}
|
||||
else
|
||||
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
|
||||
local function is_depleted(drill, entity)
|
||||
local position = drill.position
|
||||
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}}
|
||||
end
|
||||
end
|
||||
return count == 0
|
||||
|
||||
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 true
|
||||
end
|
||||
|
||||
local function mark_if_depleted(drill)
|
||||
if is_depleted(drill) then
|
||||
drill.order_deconstruction(drill.force)
|
||||
end
|
||||
end
|
||||
local callback =
|
||||
Token.register(
|
||||
function(drill)
|
||||
if drill.valid then
|
||||
drill.order_deconstruction(drill.force)
|
||||
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
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_resource_depleted, on_resource_depleted)
|
||||
|
Loading…
x
Reference in New Issue
Block a user