summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-12-19 00:13:35 +0100
committerWuzzy <almikes@aol.com>2016-12-19 00:13:35 +0100
commitfc6826670142eab80577a2381e73b82020257825 (patch)
tree3e7442929b9637105c2b45b36e7fc5e24c8da59c
parente0c33f6db8af1a5d75c4634ad4a12170c035ce96 (diff)
Roughly sort misc. tools by durability
-rw-r--r--init.lua25
1 files changed, 20 insertions, 5 deletions
diff --git a/init.lua b/init.lua
index fc06db1..ad0f19e 100644
--- a/init.lua
+++ b/init.lua
@@ -923,12 +923,26 @@ doc.new_category("tools", {
-- Hand beats all
if entries[1].eid == "" then return true end
if entries[2].eid == "" then return false end
- -- No tool capabilities = instant loser
- if entries[1].data.def.tool_capabilities == nil then return false end
- if entries[2].data.def.tool_capabilities == nil then return true end
+
local comp = {}
for e=1, 2 do
comp[e] = {}
+ end
+ -- No tool capabilities: Instant loser
+ if entries[1].data.def.tool_capabilities == nil and entries[2].data.def.tool_capabilities ~= nil then return false end
+ if entries[2].data.def.tool_capabilities == nil and entries[1].data.def.tool_capabilities ~= nil then return true end
+ -- No tool capabilities for both: Compare by uses
+ if entries[1].data.def.tool_capabilities == nil and entries[2].data.def.tool_capabilities == nil then
+ for e=1, 2 do
+ if type(entries[e].data.def._doc_items_durability) == "number" then
+ comp[e].uses = entries[e].data.def._doc_items_durability
+ else
+ comp[e].uses = 0
+ end
+ end
+ return comp[1].uses > comp[2].uses
+ end
+ for e=1, 2 do
comp[e].gc = entries[e].data.def.tool_capabilities.groupcaps
end
-- No group capabilities = instant loser
@@ -937,7 +951,8 @@ doc.new_category("tools", {
for e=1, 2 do
local groups = {}
local gc = comp[e].gc
- local group, mintime = nil, nil
+ local group = nil
+ local mintime = nil
local groupcount = 0
local uses = nil
for k,v in pairs(gc) do
@@ -963,7 +978,7 @@ doc.new_category("tools", {
comp[e].count = groupcount
comp[e].group = group
comp[e].mintime = mintime
- if uses then
+ if uses ~= nil then
comp[e].uses = uses
elseif type(entries[e].data.def._doc_items_durability) == "number" then
comp[e].uses = entries[e].data.def._doc_items_durability