Fixed previously-incorrect values used by self-repairing tools

I was in a rush yesterday and made a big oversight when calculating the repair values used by the Termite and Cobble Eater buffs. This time, not only should the values be correct, but the process explaining where the values come from was been thoroughly documented.
master
Alexand(er|ra) Yst 2020-12-28 01:40:40 -08:00
parent 39738ab9bc
commit 323c0e9d7a
1 changed files with 75 additions and 2 deletions

View File

@ -609,8 +609,81 @@ for node, tool in next, {
}
end
local termite_regen = 1040
local cobbleeater_regen = 2253
local termite_regen
local cobbleeater_regen
-- This is done in a conditional block not because we want it to
-- conditionally execute, but to get Lua to clean up all the variables
-- we used when we're done. We could instead precompute these values,
-- as they're entirely static, but showing the calculations allows us
-- to see the logic behind the values we arrive at.
if true then
-- In wooden tools, the declared number of uses is ten, but we multiply
-- that by three to the first power (simply three) to account for the
-- fact that wooden tools have a maximum level of one while most nodes
-- have a level of zero. A level difference of one means we take three
-- to the first power. We then multiply by 1.02 to account for the tool
-- repair bonus. In a way, the first wooden tool doesn't get this bonus
-- when repairing tools, but every single wooden tool after it does.
local actual_wood_tool_uses = 10 * 3^1 * 1.02
-- The Termite and Cobble Eater buffs only apply to axes and picks,
-- respectively. In both cases, wooden tools take three full wood nodes
-- and two sticks - each of which is a quarter wood node - to craft.
-- Because essentially only one material is used and we know that there
-- are three and a half of it in the craft, we can determine the amount
-- of uses each wood node contributes to the tool by dividing the
-- number of uses by 3.5. We'll need this number to calculate the
-- amount of repair the Termite buff performs.
local uses_per_wood = actual_wood_tool_uses / 3.5
-- In stone tools, the declared number of uses is twenty, but we
-- multiply that by three to the first power (simply three) to account
-- for the fact that stone tools have a maximum level of one while most
-- nodes have a level of zero. A level difference of one means we take
-- three to the first power. We then multiply by 1.02 to account for
-- the tool repair bonus. In a way, the first stone tool doesn't get
-- this bonus when repairing tools, but every single stone tool after
-- it does.
local actual_stone_tool_uses = 20 * 3^1 * 1.02
-- We know how much wood contributes to pick durability because we
-- calculated it above. We need to subtract one seventh of the number
-- of uses a wooden pick has from the number of uses a stone pick has
-- because stone tools have one seventh the amount of wood a wooden
-- tool has, then divide the result by three to figure out how much
-- durability each of the three cobble contributes to the durability of
-- a stone pick. We'll need this number for calculating the repair
-- performed by the Cobble Eater buff.
local uses_per_cobble = (actual_stone_tool_uses - (actual_wood_tool_uses / 7)) / 3
-- We now have the number of uses that each material should add to the
-- tool it repairs, but Minetest doesn't operate on those numbers.
-- Instead, it operates on wear points. Every tool has the same number
-- of wear points it can accumulate, at which point it breaks.
-- Durability is basically a way to think of the amount of wear points
-- accumulated after each node is dug, with more durable tools taking
-- less wear each time. So, we need to calculate the amount of wear a
-- runic pick/axe takes each time it's used, so we can multiply that
-- number by the number of uses each buff is supposed to add to the
-- tool. To do that, we first calculate the number of uses a runic tool
-- has. Runic digging tools have a declared number of uses equal to
-- twenty, like stone tools, but have a maximum level of uses equal to
-- three. We use the same equation as we did for calculating the number
-- of uses a stone pick has, but this time, we take three to the third
-- power instead of the first.
local actual_runic_tool_uses = 20 * 3^3 * 1.02
-- The number of wear points a tool can take before breaking is 65536
-- (that's 2^16). We then apply the repair bonus by multiplying it by
-- 1.02 as before. Finally, we divide this figure by the number of uses
-- that we calculated in the last variable. This gives us a conversion
-- factor, which is just the number of wear points that a runic tool
-- will accumulate each time a player uses it to dig.
local conversion_factor = 65536 * 1.02 / actual_runic_tool_uses
-- Lastly, we just multiply the conversion factor by each respective
-- material's number of uses it adds to the tool to get the amount of
-- repair each buff should perform. Because wear is stored as an
-- integer, we should floor the result to reduce the risk of odd
-- behaviour.
termite_regen = math.floor(conversion_factor * uses_per_wood)
cobbleeater_regen = math.floor(conversion_factor * uses_per_cobble)
end
local logs = {
["default:acacia_tree"] = true,