Skip to content

Commit

Permalink
0.1.12
Browse files Browse the repository at this point in the history
Updated for 0.17
  • Loading branch information
softmix committed Dec 29, 2019
1 parent bfce0c0 commit c45bd30
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
14 changes: 5 additions & 9 deletions autodeconstruct.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require "util"
autodeconstruct = {}

local function find_resources(surface, position, range, resource_category, mining_power)
local function find_resources(surface, position, range, resource_category)

local resource_category = resource_category or 'basic-solid'
local mining_power = mining_power or 2.5 -- base value for burner drill
local top_left = {x = position.x - range, y = position.y - range}
local bottom_right = {x = position.x + range, y = position.y + range}

local resources = surface.find_entities_filtered{area={top_left, bottom_right}, type='resource'}
categorized = {}
for _, resource in pairs(resources) do
if resource.prototype.resource_category == resource_category and resource.prototype.mineable_properties["hardness"] <= mining_power then
if resource.prototype.resource_category == resource_category then
table.insert(categorized, resource)
end
end
Expand Down Expand Up @@ -116,20 +115,17 @@ function autodeconstruct.check_drill(drill)

if mining_drill_radius == nil then return end

local mining_power = drill.prototype.mining_power
if mining_power == nil then return end

resources = find_resources(drill.surface, drill.position, mining_drill_radius, 'basic-solid', mining_power)
resources = find_resources(drill.surface, drill.position, mining_drill_radius, 'basic-solid')
for i = 1, #resources do
if resources[i].amount > 0 then return end
end
if global.debug then msg_all({"autodeconstruct-debug", util.positiontostr(drill.position) .. " found no resources, deconstructing"}) end
autodeconstruct.order_deconstruction(drill)
end

function autodeconstruct.on_canceled_deconstruction(event)
function autodeconstruct.on_cancelled_deconstruction(event)
if event.player_index ~= nil or event.entity.type ~= 'mining-drill' then return end
if global.debug then msg_all({"autodeconstruct-debug", "on_canceled_deconstruction", util.positiontostr(event.entity.position) .. " deconstruction timed out, checking again"}) end
if global.debug then msg_all({"autodeconstruct-debug", "on_cancelled_deconstruction", util.positiontostr(event.entity.position) .. " deconstruction timed out, checking again"}) end
autodeconstruct.check_drill(event.entity)
end

Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 0.1.12
Date: 2019-02-28
Changes:
- Updated for 0.17
---------------------------------------------------------------------------------------------------
Version: 0.1.11
Date: 2018-02-22
Changes:
Expand Down
6 changes: 3 additions & 3 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ script.on_configuration_changed(function()
if err then msg_all({"autodeconstruct-err-generic", err}) end
end)

script.on_event(defines.events.on_canceled_deconstruction, function(event)
local _, err = pcall(autodeconstruct.on_canceled_deconstruction, event)
if err then msg_all({"autodeconstruct-err-specific", "on_canceled_deconstruction", err}) end
script.on_event(defines.events.on_cancelled_deconstruction, function(event)
local _, err = pcall(autodeconstruct.on_cancelled_deconstruction, event)
if err then msg_all({"autodeconstruct-err-specific", "on_cancelled_deconstruction", err}) end
end)

script.on_event(defines.events.on_resource_depleted, function(event)
Expand Down
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "AutoDeconstruct",
"version": "0.1.11",
"factorio_version":"0.16",
"version": "0.1.12",
"factorio_version":"0.17",
"title": "Auto Deconstruct",
"author": "mindmix",
"homepage": "",
Expand Down
Binary file added thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c45bd30

Please sign in to comment.