mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Merge pull request #79 from Valansch/dev_autodecon
Implemented autodeconstruct. Closes #70
This commit is contained in:
commit
310660695b
27
autodeconstruct.lua
Normal file
27
autodeconstruct.lua
Normal file
@ -0,0 +1,27 @@
|
||||
--Author: Valansch
|
||||
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
|
||||
return #drill.surface.find_entities_filtered{type="resource", area = area} == 1
|
||||
end
|
||||
|
||||
local function mark_if_depleted(drill)
|
||||
if is_depleted(drill) then
|
||||
drill.order_deconstruction(drill.force)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_resource_depleted(event)
|
||||
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
|
||||
mark_if_depleted(drill)
|
||||
end
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_resource_depleted, on_resource_depleted)
|
@ -21,6 +21,7 @@ require "follow"
|
||||
require "wells"
|
||||
require "custom_commands"
|
||||
require "tasklist"
|
||||
require "autodeconstruct"
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
@ -6,4 +6,5 @@ return
|
||||
["mbas"] = "",
|
||||
["selen"] = "",
|
||||
["sholvo"] = "",
|
||||
["Animal"] = "",
|
||||
}
|
||||
|
@ -100,4 +100,15 @@ return
|
||||
["pietloke"] = "",
|
||||
["bloodydevil"] = "",
|
||||
["mike-_-"] = "",
|
||||
["asddsa76"] = "",
|
||||
["tomymy"] = "",
|
||||
["geckozila"] = "",
|
||||
["starlite"] = "",
|
||||
["ducktaperules"] = "",
|
||||
["tvardero"] = "",
|
||||
["thethane"] = "",
|
||||
["lejnel"] = "",
|
||||
["griffinonetwo"] = "",
|
||||
["stat0x00"] = "",
|
||||
["gynox"] = "",
|
||||
}
|
Loading…
Reference in New Issue
Block a user