1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-26 03:52:00 +02:00

Implemented autodeconstruct. Closes #70

This commit is contained in:
Valansch 2017-10-01 15:58:10 +02:00
parent d8ce30400e
commit 34813dbd3c
2 changed files with 31 additions and 3 deletions

27
autodeconstruct.lua Normal file
View 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)

View File

@ -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]
@ -37,7 +38,7 @@ end
local hodor_messages = {{"Hodor.", 16}, {"Hodor?", 16},{"Hodor!", 16}, {"Hodor! Hodor! Hodor! Hodor!", 4}, {"Hodor :(",4}, {"Hodor :)",4}, {"HOOOODOOOR!", 4}, {"( ͡° ͜ʖ ͡°)",1}, {"☉ ‿ ⚆",1}}
local message_weight_sum = 0
for _,w in pairs(hodor_messages) do
for _,w in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + w[2]
end
@ -45,10 +46,10 @@ function hodor(event)
local message = event.message:lower()
if message:match("hodor") then
local index = math.random(1, message_weight_sum)
local message_weight_sum = 0
local message_weight_sum = 0
for _,m in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + m[2]
if message_weight_sum >= index then
if message_weight_sum >= index then
game.print("Hodor: " .. m[1])
return
end