summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2014-04-22 17:04:18 +0100
committerShadowNinja <shadowninja@minetest.net>2014-04-22 12:48:55 -0400
commitdb202503713ddd1084f188a5eac506be665e9c44 (patch)
tree31b222e6ac4bd7f361703079f328da59b08063b7
parent44dbc75b6115d5235ba0538925e44484037459a1 (diff)
Fix laser discharging
Commit a6dae893d66319739e8dfe962f67285221eb9b91 introduced per-version charge cost for firing mining lasers, but applies this in addition to the old fixed cost which it was meant to replace. Fix by removing the application of the fixed cost. The same commit did successfully change the check for a laser having sufficient charge to fire, so that's based purely on the variable cost. As a consequence, firing a laser that has just enough charge to cover the variable cost could cause its charge to go negative. (For example, by fully charging a Mk1 laser and then firing it until it empties, resulting in a charge of -400.) It turned out that set_RE_wear handled that badly, producing an over-100% wear value that would wrap to a *low* wear value, leading to the laser's wear bar looking as if it's fully charged. To protect against silly wear values, make set_RE_wear clamp the wear value to avoid wrapping. Handle specially the case of a fully-discharged tool, where there was desirable wrapping to zero.
-rw-r--r--technic/register.lua9
-rw-r--r--technic/tools/mining_lasers.lua1
2 files changed, 8 insertions, 2 deletions
diff --git a/technic/register.lua b/technic/register.lua
index 288db57..0b55282 100644
--- a/technic/register.lua
+++ b/technic/register.lua
@@ -44,7 +44,14 @@ end
-- Wear down a tool depending on the remaining charge.
function technic.set_RE_wear(itemstack, item_load, max_load)
- local temp = 65536 - math.floor(item_load / max_load * 65535)
+ local temp
+ if item_load == 0 then
+ temp = 0
+ else
+ temp = 65536 - math.floor(item_load / max_load * 65535)
+ if temp > 65535 then temp = 65535 end
+ if temp < 1 then temp = 1 end
+ end
itemstack:set_wear(temp)
return itemstack
end
diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua
index b80e878..4a4ed2f 100644
--- a/technic/tools/mining_lasers.lua
+++ b/technic/tools/mining_lasers.lua
@@ -178,7 +178,6 @@ for _, m in pairs(mining_lasers_list) do
if meta.charge >= m[4] then
meta.charge = meta.charge - m[4]
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
- meta.charge = meta.charge - 400
technic.set_RE_wear(itemstack, meta.charge, m[3])
itemstack:set_metadata(minetest.serialize(meta))
end