Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper rounding implementation #23

Merged
merged 8 commits into from
Mar 23, 2024
3 changes: 2 additions & 1 deletion src/common.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("stdext")
local data = require("data")
local schema = require("schema")

Expand Down Expand Up @@ -501,7 +502,7 @@ function common.schaden.render(tp)
elseif tp.die ~= nil then
tex.sprint(-2, "+")
end
tex.sprint(-2, common.round(math.abs(tp.num)))
tex.sprint(-2, math.round(math.abs(tp.num)))
end
end

Expand Down
5 changes: 3 additions & 2 deletions src/frontseite.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local data = require("data")
local common = require("common")
local schema = require("schema")
require("stdext")

local frontseite = {}

Expand Down Expand Up @@ -213,7 +214,7 @@ function eigenschaften.rechts(self)
if data.Nachteile.Glasknochen then
base = base - 2
end
tex.sprint(-2, common.round(base))
tex.sprint(-2, math.round(base))
end
end
tex.sprint([[\\\hline\end{tabular}}\egroup\par]])
Expand Down Expand Up @@ -261,4 +262,4 @@ end

frontseite.eigenschaften = eigenschaften

return frontseite
return frontseite
11 changes: 6 additions & 5 deletions src/kampfbogen.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("stdext")
local data = require("data")
local common = require("common")
local schemadef = require("schemadef")
Expand All @@ -14,7 +15,7 @@ local function calc_be(input)
if string.find(input, "^BEx") then
return be * input:sub(4)
elseif string.find(input, "^BE%-") then
return common.round(math.max(0, be - tonumber(input:sub(4))))
return math.round(math.max(0, be - tonumber(input:sub(4))))
elseif string.find(input, "^BE") then
return be
else
Expand Down Expand Up @@ -158,14 +159,14 @@ nahkampf_render[11]= {false, function(v, talent, ebe)
if talent == nil or #talent < 4 or atb == "" or #v < 8 then
return
end
tex.sprint(-2, atpa_mod(atb - common.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM AT"], art(v), talent.Spezialisierungen))
tex.sprint(-2, atpa_mod(atb - math.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM AT"], art(v), talent.Spezialisierungen))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.round hat den zweiten Parameter nicht mehr, ist also an der Stelle falsch und müsste statt dessen math.floor sein.

Sonst wird bei einer ungeraden eBE ein Punkt zu viel von der AT abgezogen.

end}
nahkampf_render[12]= {false, function(v, talent, ebe)
local pab = data:cur("PA")
if talent == nil or #talent < 5 or pab == "" or #v < 9 then
return
end
tex.sprint(-2, atpa_mod(pab - common.round(ebe/2), data.PA(talent), v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM PA"], art(v), talent.Spezialisierungen))
tex.sprint(-2, atpa_mod(pab - math.round(ebe/2), data.PA(talent), v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM PA"], art(v), talent.Spezialisierungen))
end}
nahkampf_render[13]= {false, function(v, talent, ebe)
if #v < 6 then
Expand Down Expand Up @@ -252,7 +253,7 @@ local waffenlos_render = {
added = added + 1
end
end
tex.sprint(-2, atpa_mod(atb - common.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], 0))
tex.sprint(-2, atpa_mod(atb - math.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], 0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selbe Geschichte wie oben.

end},
[6]= {false, function(v, talent, ebe)
local pab = data:cur("PA")
Expand All @@ -266,7 +267,7 @@ local waffenlos_render = {
added = added + 1
end
end
tex.sprint(-2, atpa_mod(pab - common.round(ebe/2), data.PA(talent), v["TP/KK Schwelle"], v["TP/KK Schritt"], 0))
tex.sprint(-2, atpa_mod(pab - math.round(ebe/2), data.PA(talent), v["TP/KK Schwelle"], v["TP/KK Schritt"], 0))
end},
[7]= {false, function(v, talent, ebe)
tp = common.schaden.mod({dice=1, die=6, num=0}, v["TP/KK Schwelle"], v["TP/KK Schritt"])
Expand Down
5 changes: 3 additions & 2 deletions src/talentbogen.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local schema = require("schema")
local data = require("data")
local common = require("common")
require("stdext")

local talent = {}

Expand Down Expand Up @@ -187,7 +188,7 @@ function talent.meta(v)
::found::
end
if sum ~= nil and #v[5] > 0 then
tex.sprint(-2, common.round(sum / #v[5]))
tex.sprint(-2, math.round(sum / #v[5]))
end
end

Expand Down Expand Up @@ -379,4 +380,4 @@ function talentbogen.gruppen()
end


return talentbogen
return talentbogen
5 changes: 3 additions & 2 deletions src/values.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("stdext")
local d = require("schemadef")
local schema = assert(loadfile("schema.lua", "t"))(false)
local skt = require("skt")
Expand Down Expand Up @@ -134,7 +135,7 @@ function getter_map.sparse(val, div)
if val == 0 then
return ""
end
return tonumber(string.format("%.0f", val/div + 0.0001)) -- round up at 0.5
return math.round(val / div)
end

values.sparse = getter_map.sparse
Expand Down Expand Up @@ -1213,4 +1214,4 @@ for _, e in ipairs(schema.Ereignisse:instance()) do
table.insert(values.Ereignisse, event)
end

return values
return values