From e1c83679ca1372d2116dae94f297f8f97de340ce Mon Sep 17 00:00:00 2001 From: dashodanger Date: Fri, 25 Oct 2024 08:24:02 -0600 Subject: [PATCH] Revert rounding tweaks --- games/doom/factory.lua | 4 +- games/doom/x_doom1.lua | 4 +- games/heretic/factory.lua | 4 +- games/noah/factory.lua | 8 +-- games/obc/factory.lua | 8 +-- games/wolf/factory.lua | 8 +-- games/wolf/x_spear.lua | 4 +- modules/export_map.lua | 2 +- modules/modded_game_extras.lua | 4 +- modules/procedural_gotcha_zdoom.lua | 6 +-- modules/zdoom_otex.lua | 8 +-- scripts/094/builder.lua | 84 ++++++++++++++--------------- scripts/094/monster.lua | 20 +++---- scripts/094/plan_dm.lua | 10 ++-- scripts/094/planner.lua | 14 ++--- scripts/094/writer.lua | 6 +-- scripts/area.lua | 4 +- scripts/brush.lua | 2 +- scripts/cave.lua | 14 ++--- scripts/grower.lua | 34 ++++++------ scripts/item.lua | 10 ++-- scripts/layout.lua | 20 +++---- scripts/level.lua | 16 +++--- scripts/monster.lua | 40 +++++++------- scripts/prefab.lua | 12 ++--- scripts/quest.lua | 12 ++--- scripts/render.lua | 12 ++--- scripts/room.lua | 10 ++-- scripts/seed.lua | 12 ++--- scripts/title_gen.lua | 38 ++++++------- scripts/util.lua | 10 ++-- 31 files changed, 220 insertions(+), 220 deletions(-) diff --git a/games/doom/factory.lua b/games/doom/factory.lua index 6e4745a88..c20822a92 100644 --- a/games/doom/factory.lua +++ b/games/doom/factory.lua @@ -9577,8 +9577,8 @@ function DOOM.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/doom/x_doom1.lua b/games/doom/x_doom1.lua index f9890faf5..b6ecea8a7 100644 --- a/games/doom/x_doom1.lua +++ b/games/doom/x_doom1.lua @@ -10595,8 +10595,8 @@ function ULTDOOM.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/heretic/factory.lua b/games/heretic/factory.lua index 9cc6e6833..bfcaae459 100644 --- a/games/heretic/factory.lua +++ b/games/heretic/factory.lua @@ -6004,8 +6004,8 @@ function HERETIC.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/noah/factory.lua b/games/noah/factory.lua index 9b5df0290..7aadcf0ea 100644 --- a/games/noah/factory.lua +++ b/games/noah/factory.lua @@ -5171,7 +5171,7 @@ function NOAH.get_factory_levels(episode) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -5209,7 +5209,7 @@ function NOAH.get_factory_levels(episode) local def_large = PARAM.float_level_upper_bound_wolf_3d - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: @@ -5364,8 +5364,8 @@ function NOAH.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/obc/factory.lua b/games/obc/factory.lua index 28704d7aa..35a473a26 100644 --- a/games/obc/factory.lua +++ b/games/obc/factory.lua @@ -5128,7 +5128,7 @@ function OBC.get_factory_levels(episode) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -5166,7 +5166,7 @@ function OBC.get_factory_levels(episode) local def_large = PARAM.float_level_upper_bound_wolf_3d - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: @@ -5321,8 +5321,8 @@ function OBC.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/wolf/factory.lua b/games/wolf/factory.lua index a697dd3ff..8e0c4a5e6 100644 --- a/games/wolf/factory.lua +++ b/games/wolf/factory.lua @@ -5580,7 +5580,7 @@ function WOLF.get_factory_levels(episode) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -5618,7 +5618,7 @@ function WOLF.get_factory_levels(episode) local def_large = PARAM.float_level_upper_bound_wolf_3d - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: @@ -5773,8 +5773,8 @@ function WOLF.factory_setup() error("Prefab not a multiple of four: " .. tostring(P.name)) end - P.long = math.round(f_long / 4) - P.deep = math.round(f_deep / 4) + P.long = math.floor(f_long / 4) + P.deep = math.floor(f_deep / 4) else error("Unsupported scale " .. tostring(P.scale) .. " in prefab: " .. tostring(P.name)) end diff --git a/games/wolf/x_spear.lua b/games/wolf/x_spear.lua index 3429c0278..513600947 100644 --- a/games/wolf/x_spear.lua +++ b/games/wolf/x_spear.lua @@ -306,7 +306,7 @@ function SPEAR.get_factory_levels(episode) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -344,7 +344,7 @@ function SPEAR.get_factory_levels(episode) local def_large = PARAM.float_level_upper_bound_wolf_3d - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: diff --git a/modules/export_map.lua b/modules/export_map.lua index 73f31d542..4a7b0f194 100644 --- a/modules/export_map.lua +++ b/modules/export_map.lua @@ -136,7 +136,7 @@ function EXPORT_MAP.add_entity(ent, model) end if origin then - export_printf("\"origin\" \"%d %d %d\"\n", math.round(origin.x) or 0, math.round(origin.y) or 0, math.round(origin.z) or 0) + export_printf("\"origin\" \"%d %d %d\"\n", math.floor(origin.x) or 0, math.floor(origin.y) or 0, math.floor(origin.z) or 0) end if light then diff --git a/modules/modded_game_extras.lua b/modules/modded_game_extras.lua index b70ac1773..83f2c7edd 100644 --- a/modules/modded_game_extras.lua +++ b/modules/modded_game_extras.lua @@ -1680,7 +1680,7 @@ function MODDED_GAME_EXTRAS.create_hn_info(self, LEVEL) end if R.lev_along and not R.is_start and #LEVEL.rooms > 2 then - goal_string = goal_string .. " (" .. math.round(R.lev_along * 100) .. "%%)" + goal_string = goal_string .. " (" .. math.floor(R.lev_along * 100) .. "%%)" end return goal_string @@ -2028,7 +2028,7 @@ function MODDED_GAME_EXTRAS.generate_hn_decorate() local thing_chunk = MODDED_GAME_EXTRAS.HELLSCAPE_NAVIGATOR_TEMPLATE.COPIES thing_chunk = string.gsub(thing_chunk, "NUMNUMNUM", editor_num) thing_chunk = string.gsub(thing_chunk, "NAMENAMENAME", name) - thing_chunk = string.gsub(thing_chunk, "SIZESIZESIZE", math.round(radius)) + thing_chunk = string.gsub(thing_chunk, "SIZESIZESIZE", math.floor(radius)) decorate_string = decorate_string .. thing_chunk end diff --git a/modules/procedural_gotcha_zdoom.lua b/modules/procedural_gotcha_zdoom.lua index f2c7f6e39..0736f2832 100644 --- a/modules/procedural_gotcha_zdoom.lua +++ b/modules/procedural_gotcha_zdoom.lua @@ -1429,7 +1429,7 @@ function PROCEDURAL_GOTCHA_FINE_TUNE_ZDOOM.grab_random_trait(btype, etraits) if einfo == info.name then stack = stack + 1 if PARAM.boss_gen_tmult < 0 then - tprob = math.round(tprob * 0.25) + tprob = math.floor(tprob * 0.25) elseif PARAM.boss_gen_tmult > 1 then tprob = tprob * 2 end @@ -1632,7 +1632,7 @@ function PROCEDURAL_GOTCHA_FINE_TUNE_ZDOOM.all_done() else mult=1.0 end end - hpcalc = math.round(rand.pick({5000,5200,5400,5600,5800,6000})*mult*PARAM.float_boss_gen_mult) + hpcalc = math.floor(rand.pick({5000,5200,5400,5600,5800,6000})*mult*PARAM.float_boss_gen_mult) if batk == "hitscan" and PARAM.boss_gen_dmult<3.0 then hpcalc = hpcalc*0.75 end @@ -1640,7 +1640,7 @@ function PROCEDURAL_GOTCHA_FINE_TUNE_ZDOOM.all_done() local sumcalc - sumcalc = math.round(rand.pick({400,450,500,550,600})*PARAM.boss_gen_rmult) + sumcalc = math.floor(rand.pick({400,450,500,550,600})*PARAM.boss_gen_rmult) bsummon = PROCEDURAL_GOTCHA_FINE_TUNE_ZDOOM.syntaxize(bsummon,sumcalc) end diff --git a/modules/zdoom_otex.lua b/modules/zdoom_otex.lua index 509b864a3..d02570f21 100644 --- a/modules/zdoom_otex.lua +++ b/modules/zdoom_otex.lua @@ -805,12 +805,12 @@ function OTEX_PROC_MODULE.synthesize_procedural_themes() end local scenic_fence_tab = table.copy(OTEX_SPECIAL_RESOURCES.rail_scenic_fences) for fence,prob in pairs(scenic_fence_tab.tech) do - GAME.THEMES.tech.scenic_fences[fence] = math.round(prob * 0.75) - GAME.THEMES.urban.scenic_fences[fence] = math.round(prob * 0.75) + GAME.THEMES.tech.scenic_fences[fence] = math.floor(prob * 0.75) + GAME.THEMES.urban.scenic_fences[fence] = math.floor(prob * 0.75) end for fence,prob in pairs(scenic_fence_tab.gothic) do - GAME.THEMES.hell.scenic_fences[fence] = math.round(prob * 0.75) - GAME.THEMES.urban.scenic_fences[fence] = math.round(prob * 0.75) + GAME.THEMES.hell.scenic_fences[fence] = math.floor(prob * 0.75) + GAME.THEMES.urban.scenic_fences[fence] = math.floor(prob * 0.75) end -- create liquid attachments diff --git a/scripts/094/builder.lua b/scripts/094/builder.lua index e9d356b07..a0dd03cf7 100644 --- a/scripts/094/builder.lua +++ b/scripts/094/builder.lua @@ -379,8 +379,8 @@ function B_prefab(c, fab,skin,parm, model,combo, x,y, dir,mirror_x,mirror_y) tx, ty = mid_x + tx, mid_y + ty - local bx = x + math.round(tx / 64) - local by = y + math.round(ty / 64) + local bx = x + math.floor(tx / 64) + local by = y + math.floor(ty / 64) local dx = (tx % 64) - 32 local dy = (ty % 64) - 32 @@ -996,8 +996,8 @@ function B_vista(src,dest, x1,y1, x2,y2, side, b_combo,kind) local sp_min = 2.0 + deep / 6.0 local sp_max = 2.0 + deep / 2.5 - local front_pillars = math.round( rand.range(fp_min, fp_max) + rand.skew()*0.5 ) - local side_pillars = math.round( rand.range(sp_min, sp_max) + rand.skew()*0.5 ) + local front_pillars = math.floor( rand.range(fp_min, fp_max) + rand.skew()*0.5 ) + local side_pillars = math.floor( rand.range(sp_min, sp_max) + rand.skew()*0.5 ) gui.debugf("VISTA %dx%d --> PILLARS front:%d side:%d\n", long, deep, front_pillars, side_pillars) @@ -1005,8 +1005,8 @@ function B_vista(src,dest, x1,y1, x2,y2, side, b_combo,kind) for fp = 1, front_pillars do local u = (fp - 1) / (front_pillars - 1) - local x = math.round(px1 + (px2-px1) * u) - local y = math.round(py1 + (py2-py1) * u) + local x = math.floor(px1 + (px2-px1) * u) + local y = math.floor(py1 + (py2-py1) * u) frag_fill(src, x,y, x,y, { solid=support }) end @@ -1014,13 +1014,13 @@ function B_vista(src,dest, x1,y1, x2,y2, side, b_combo,kind) for sp = 1, side_pillars do local u = (sp - 1) / (side_pillars - 1) - local x1 = math.round(px1 + (wx1-px1) * u) - local y1 = math.round(py1 + (wy1-py1) * u) + local x1 = math.floor(px1 + (wx1-px1) * u) + local y1 = math.floor(py1 + (wy1-py1) * u) frag_fill(src, x1,y1, x1,y1, { solid=support }) - local x2 = math.round(px2 + (wx2-px2) * u) - local y2 = math.round(py2 + (wy2-py2) * u) + local x2 = math.floor(px2 + (wx2-px2) * u) + local y2 = math.floor(py2 + (wy2-py2) * u) frag_fill(src, x2,y2, x2,y2, { solid=support }) end @@ -1255,8 +1255,8 @@ function make_chunks() local L, M, R if q_pos then - M = math.round((total+2) / 3) - L = math.round(total / 3) + M = math.floor((total+2) / 3) + L = math.floor(total / 3) R = total - M - L if q_pos == 1 then return M, L, R @@ -1350,9 +1350,9 @@ function make_chunks() local pos if link.where == -2 then pos = 0 - elseif link.where == -1 then pos = math.round((diff+2)/4) - elseif link.where == 0 then pos = math.round(diff / 2) - elseif link.where == 1 then pos = diff - math.round((diff+2)/4) + elseif link.where == -1 then pos = math.floor((diff+2)/4) + elseif link.where == 0 then pos = math.floor(diff / 2) + elseif link.where == 1 then pos = diff - math.floor((diff+2)/4) elseif link.where == 2 then pos = diff else error("Bad where value: " .. tostring(link.where)) @@ -1450,8 +1450,8 @@ function make_chunks() if (d_pos < d_min) then d_pos = d_min end if (d_pos > d_max) then d_pos = d_max end - local j1 = math.round((d_pos - 1) / JW) - local j2 = math.round((d_pos - 1 + link.long-1) / JW) + local j1 = math.floor((d_pos - 1) / JW) + local j2 = math.floor((d_pos - 1 + link.long-1) / JW) for j = j1,j2 do assert (0 <= j and j < KW) @@ -3292,7 +3292,7 @@ end -- -- -- pillar in middle of special arch -- if link.where == "wide" then --- long = math.round((long-1) / 2) +-- long = math.floor((long-1) / 2) -- x, y = x+long*ax, y+long*ay -- ex,ey = ex-long*ax, ey-long*ay -- @@ -3347,7 +3347,7 @@ end -- -- -- B_door(c, link, b_combo, x, y, c.floor_h, dir, --- 1 + math.round(info.w / 64), 1, info, door_kind, tag, key_tex) +-- 1 + math.floor(info.w / 64), 1, info, door_kind, tag, key_tex) -- else -- error("build_link: bad kind: " .. tostring(link.kind)) -- end @@ -3565,10 +3565,10 @@ end if spot.long >= 7 or (spot.long >= 5 and (WINDOW.c_h - WINDOW.f_h) < 72) then - local mx1 = math.round((x1+x2)/2) - local my1 = math.round((y1+y2)/2) - local mx2 = math.round((x1+x2+1)/2) - local my2 = math.round((y1+y2+1)/2) + local mx1 = math.floor((x1+x2)/2) + local my1 = math.floor((y1+y2)/2) + local mx2 = math.floor((x1+x2+1)/2) + local my2 = math.floor((y1+y2+1)/2) fill (c, mx1,my1, mx2,my2, { solid=D.combo.wall }) end else @@ -3739,7 +3739,7 @@ function build_grotto(c, x1,y1, x2,y2) local WALL = { solid=c.combo.wall } for y = y1+1, y2-1, 2 do - for x = x1+1+(math.round(y/2)%2)*2, x2-3, 4 do + for x = x1+1+(math.floor(y/2)%2)*2, x2-3, 4 do gap_fill(c, x-2,y, x-2,y, WALL) gap_fill(c, x+2,y, x+2,y, WALL) @@ -3770,8 +3770,8 @@ function build_pacman_level(c) local mid_fab = GAME.FACTORY.PREFABS[rand.pick(PACMAN_MID_FABS)] assert(mid_fab) - local mid_x = 32 - math.round(mid_fab.long/2) - local mid_y = 30 - math.round(mid_fab.deep/2) + local mid_x = 32 - math.floor(mid_fab.long/2) + local mid_y = 30 - math.floor(mid_fab.deep/2) local top_fab = GAME.FACTORY.PREFABS[rand.pick(PACMAN_CORN_FABS)] local bot_fab = GAME.FACTORY.PREFABS[rand.pick(PACMAN_CORN_FABS)] @@ -4605,7 +4605,7 @@ sel(B.on_path, "YES", "NO")) local skew = 1.0 + rand.skew() * 0.35 - local kill_blk = math.round(rec.total_blk * c.space_factor / 100 * skew) + local kill_blk = math.floor(rec.total_blk * c.space_factor / 100 * skew) if kill_blk >= rec.total_blk then for pos = 1,rec.long do @@ -4660,7 +4660,7 @@ sel(B.on_path, "YES", "NO")) local skew = 1.0 + rand.skew() * 0.35 - local kill_blk = math.round(rec.total_blk * c.space_factor / 100 * skew) + local kill_blk = math.floor(rec.total_blk * c.space_factor / 100 * skew) if kill_blk >= rec.total_blk then for pos = 1,rec.long do @@ -4698,7 +4698,7 @@ sel(B.on_path, "YES", "NO")) -- gui.printf("GUILLOTINE: SPACE:%d | min:%1.1f max:%1.1f @avg:%1.1f --> new_deep:%1.2f\n", -- (c.space_factor/10), t_min, t_max, t_avg, new_deep) - new_deep = math.round(new_deep) + new_deep = math.floor(new_deep) if new_deep <= 0 then for pos = 1,rec.long do @@ -4960,7 +4960,7 @@ gui.debugf(" CELL: (%d,%d) .. (%d,%d)\n", c.bx1,c.by1, c.bx2,c.by2) y = y1 + i*h/(count+1) end - local spot = add_special_pickup_spot(c, math.round(x), math.round(y), 32,32, 200) + local spot = add_special_pickup_spot(c, math.floor(x), math.floor(y), 32,32, 200) spot.vista_side = side end @@ -5411,7 +5411,7 @@ gui.debugf(" EDGE1:%s EDGE2:%s\n", edge1 or "OK", edge2 or "OK") -- limit width to reasonable values (128 or 256 units) if long == 3 then long = 2 elseif long >= 5 and rand.odds(95) then - local pos = math.round( (long - 4 + rand.irange(0,1)) / 2) + local pos = math.floor( (long - 4 + rand.irange(0,1)) / 2) x, y = x + pos*ax, y + pos*ay long = 4 end @@ -5491,8 +5491,8 @@ gui.debugf(" EDGE1:%s EDGE2:%s\n", edge1 or "OK", edge2 or "OK") local function link_walk_pos(L) local dx,dy = dir_to_delta(10-L.side) -- inwards - local x = math.round((L.link.x1 + L.link.x2) / 2) - local y = math.round((L.link.y1 + L.link.y2) / 2) + local x = math.floor((L.link.x1 + L.link.x2) / 2) + local y = math.floor((L.link.y1 + L.link.y2) / 2) return x+dx, y+dy end @@ -5613,8 +5613,8 @@ gui.debugf(" EDGE1:%s EDGE2:%s\n", edge1 or "OK", edge2 or "OK") if K.kind == "empty" then K.kind = "room" end -- TODO: prefer block is not on stair/lift - local rx = math.round((K.x1+K.x2)/2) - local ry = math.round((K.y1+K.y2)/2) + local rx = math.floor((K.x1+K.x2)/2) + local ry = math.floor((K.y1+K.y2)/2) for i = 1,#link_list do find_path("room", link_list[i], rx, ry) @@ -5635,12 +5635,12 @@ gui.debugf(" EDGE1:%s EDGE2:%s\n", edge1 or "OK", edge2 or "OK") if K.kx == 1 then qx = K.x2 elseif K.kx == 3 then qx = K.x1 - else qx = math.round((K.x1+K.x2) / 2) + else qx = math.floor((K.x1+K.x2) / 2) end if K.ky == 1 then qy = K.y2 elseif K.ky == 3 then qy = K.y1 - else qy = math.round((K.y1+K.y2) / 2) + else qy = math.floor((K.y1+K.y2) / 2) end find_path("room", rand.pick(link_list), qx, qy) @@ -6594,7 +6594,7 @@ gui.debugf("add_quest_object: %s @ (%d,%d)\n", name, x, y) if not info then error("Unknown boss: " .. name) end local count = 1 - if info.hp < 900 then count = math.round(1900/info.hp) end + if info.hp < 900 then count = math.floor(1900/info.hp) end for i = 1,count do add_quest_object(c, name) @@ -6716,8 +6716,8 @@ gui.debugf("add_wall_stuff: %s @ (%d,%d) block:(%d,%d) dir:%d\n", if c.quest.return_args then local dx,dy = dir_to_delta(dir) - local x = math.round((K.x1+K.x2) / 2) + dx * 4 - local y = math.round((K.y1+K.y2) / 2) + dy * 4 + local x = math.floor((K.x1+K.x2) / 2) + dx * 4 + local y = math.floor((K.y1+K.y2) / 2) + dy * 4 sort_fab_locs(c, "near", x, y) @@ -7037,8 +7037,8 @@ gui.debugf("add_prefab: %s dir:%d\n", def.name, dir) if (c.x==1 and c.y==1) or (c.x==PLAN.w and c.y==PLAN.h) then -- OK elseif math.max(PLAN.w,PLAN.h) >= 5 and - c.x == math.round(PLAN.w/2 + 0.6) and - c.y == math.round(PLAN.h/2 + 0.6) then + c.x == math.floor(PLAN.w/2 + 0.6) and + c.y == math.floor(PLAN.h/2 + 0.6) then -- OK else return end else diff --git a/scripts/094/monster.lua b/scripts/094/monster.lua index 8d6b740d3..ba450120b 100644 --- a/scripts/094/monster.lua +++ b/scripts/094/monster.lua @@ -112,7 +112,7 @@ function rectangle_to_spots(c, x,y, x2,y2) local spots = {} local function carve_it_up(x,y, w,h) - local w2, h2 = math.round(w/2), math.round(h/2) + local w2, h2 = math.floor(w/2), math.floor(h/2) if h > 2 then carve_it_up(x, y, w, h2) @@ -525,7 +525,7 @@ function simulate_battle(HM, mon_set, quest) assert(info) remain_shots = 1 + gui.random() + gui.random() - remain_shots = math.round(remain_shots * info.rate) + remain_shots = math.floor(remain_shots * info.rate) if remain_shots < 1 then remain_shots = 1 end @@ -939,7 +939,7 @@ function distribute_pickups(c, HM, backtrack) local idx = rand.index_by_probs(probs) local th_info = infos[idx] - local count = 1 + math.round(R / th_info.give) + local count = 1 + math.floor(R / th_info.give) if GAME.FACTORY.caps.blocky_items then count = 1 end if th_info.clu_max then count = math.min(count, th_info.clu_max) end @@ -1306,7 +1306,7 @@ function battle_in_cell(c) local probs = { 30 } for name,info in pairs(GAME.FACTORY.monsters) do - if (info.pow < T*2) and (fp >= math.round(info.fp)) then + if (info.pow < T*2) and (fp >= math.floor(info.fp)) then local prob = info.prob * (c.mon_prefs[name] or 1) @@ -1337,7 +1337,7 @@ function battle_in_cell(c) local function decide_monster_horde(info) local horde = 1 - local max_horde = 1 + math.round(T / info.pow) + local max_horde = 1 + math.floor(T / info.pow) if info.hp <= 500 and rand.odds(30) then horde = horde + 1 end if info.hp <= 100 then horde = horde + rand.index_by_probs { 90, 40, 10, 3, 0.5 } end @@ -1391,7 +1391,7 @@ function battle_in_cell(c) for name,info in pairs(GAME.FACTORY.monsters) do if (info.cage_fallback) or - ((info.pow < T*2/x_horde) and (fp >= math.round(info.fp))) + ((info.pow < T*2/x_horde) and (fp >= math.floor(info.fp))) then local prob = info.cage_prob or info.cage_fallback or 0 @@ -1455,8 +1455,8 @@ function battle_in_cell(c) local horde = decide_cage_horde(spot, info) for i = 1,horde do - local dx = math.round((i-1)%2) * 64 - local dy = math.round((i-1)/2) * 64 + local dx = math.floor((i-1)%2) * 64 + local dy = math.floor((i-1)/2) * 64 local angle = rand.irange(0,7) * 45 local options = { [SK]=true } @@ -1492,8 +1492,8 @@ function battle_in_cell(c) local horde = decide_cage_horde(spot, info) for i = 1,horde do - local dx = math.round((i-1)%2) * 64 - local dy = math.round((i-1)/2) * 64 + local dx = math.floor((i-1)%2) * 64 + local dy = math.floor((i-1)/2) * 64 local angle = delta_to_angle(5-(spot.x+dx/64), 5-(spot.y+dy/64)) local options = { [SK]=true } diff --git a/scripts/094/plan_dm.lua b/scripts/094/plan_dm.lua index d8459a310..a2674edfe 100644 --- a/scripts/094/plan_dm.lua +++ b/scripts/094/plan_dm.lua @@ -402,7 +402,7 @@ function plan_dm_arena(level) rand.shuffle(locs) - local num_f = math.round((PLAN.w + PLAN.h) / 4) + local num_f = math.floor((PLAN.w + PLAN.h) / 4) while #locs > 0 and num_f > 0 do @@ -483,7 +483,7 @@ function plan_dm_arena(level) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -521,7 +521,7 @@ function plan_dm_arena(level) local def_large = PARAM.float_level_upper_bound - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: @@ -585,8 +585,8 @@ function plan_dm_arena(level) PLAN.cells[pw][ph].require_player = true -- guarantee at least one weapon (central cell) - local mx = math.round((PLAN.w+1)/2) - local my = math.round((PLAN.h+1)/2) + local mx = math.floor((PLAN.w+1)/2) + local my = math.floor((PLAN.h+1)/2) PLAN.cells[mx][my].require_weapon = true diff --git a/scripts/094/planner.lua b/scripts/094/planner.lua index 2be350b45..8480eea6d 100644 --- a/scripts/094/planner.lua +++ b/scripts/094/planner.lua @@ -354,7 +354,7 @@ function std_decide_quests(Level, QUEST_TAB, LEN_PROBS) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) goto foundsize end @@ -392,7 +392,7 @@ function std_decide_quests(Level, QUEST_TAB, LEN_PROBS) local def_large = PARAM.float_level_upper_bound - def_small or 42 -- this basically ramps up - ob_size = math.round(def_small + along * def_large) + ob_size = math.floor(def_small + along * def_large) end ::foundsize:: @@ -1434,8 +1434,8 @@ c.along, Q.level, Q.sub_level, c.room_type.name) -- add very first room somewhere in lower-left quarter of map if not Q.parent and Q.level == 1 then - local x = rand.irange(1, math.round(PLAN.w / 2)) - local y = rand.irange(1, math.round(PLAN.h / 2)) + local x = rand.irange(1, math.floor(PLAN.w / 2)) + local y = rand.irange(1, math.floor(PLAN.h / 2)) local c = create_cell(x, y, Q, 1, Q.combo) @@ -1459,9 +1459,9 @@ c.along, Q.level, Q.sub_level, c.room_type.name) local want_len = Q.want_len if OB_CONFIG.game ~= "hexen" then if want_len >= 4 and Q.ob_size < 25 then - want_len = math.round(want_len * 0.85 - gui.random()) + want_len = math.floor(want_len * 0.85 - gui.random()) elseif Q.ob_size > 50 then - want_len = math.round(want_len * 1.35 + gui.random()) + want_len = math.floor(want_len * 1.35 + gui.random()) end end @@ -2041,7 +2041,7 @@ gui.debugf("qlist now:\n%s\n\n", table.tostr(qlist,2)) --T2 = GAME.FACTORY.themes["CAVE"] -- choose change-over point - local mid_q = math.round(#PLAN.quests / 2 + gui.random()) + local mid_q = math.floor(#PLAN.quests / 2 + gui.random()) if #PLAN.quests >= 4 then mid_q = mid_q + (rand.index_by_probs { 1,3,1 }) - 2 diff --git a/scripts/094/writer.lua b/scripts/094/writer.lua index af81ceab1..4ddc975b3 100644 --- a/scripts/094/writer.lua +++ b/scripts/094/writer.lua @@ -408,7 +408,7 @@ function write_level(lev_name) local function line_length(L) local dx = L.ex - L.sx local dy = L.ey - L.sy - return math.round(math.sqrt(dx*dx + dy*dy) + 0.5) + return math.floor(math.sqrt(dx*dx + dy*dy) + 0.5) end local function frag_pair(f,b,norm, x,y,dx,dy) @@ -940,11 +940,11 @@ function write_wolf_level() if kind.dirs and th.angle then if kind.dirs == "player" then - local offset = math.round((360 - th.angle + 135) / 90) % 4 + local offset = math.floor((360 - th.angle + 135) / 90) % 4 assert(0 <= offset and offset <= 3) obj = obj + offset else - local offset = math.round((th.angle + 45) / 90) % 4 + local offset = math.floor((th.angle + 45) / 90) % 4 assert(0 <= offset and offset <= 3) obj = obj + offset end diff --git a/scripts/area.lua b/scripts/area.lua index 0e0d2ce5f..686cc6e3e 100644 --- a/scripts/area.lua +++ b/scripts/area.lua @@ -1674,7 +1674,7 @@ function Area_locate_chunks(LEVEL, SEEDS) local function find_sized_chunks(A, seed_list, pass, LEVEL) - local dx = math.round(pass / 10) - 1 + local dx = math.floor(pass / 10) - 1 local dy = (pass % 10) - 1 local use_prob = USE_PROBS[pass] or 99 @@ -2908,7 +2908,7 @@ function Area_create_rooms(LEVEL, SEEDS) if SHAPE_GRAMMAR.force_level_size then LEVEL.map_W = SHAPE_GRAMMAR.force_level_size - LEVEL.map_H = 1 + math.round(LEVEL.map_W * 0.8) + LEVEL.map_H = 1 + math.floor(LEVEL.map_W * 0.8) SEEDS = Seed_init(LEVEL) end diff --git a/scripts/brush.lua b/scripts/brush.lua index 682cbe0ab..96530e060 100644 --- a/scripts/brush.lua +++ b/scripts/brush.lua @@ -1100,7 +1100,7 @@ function brushlib.reverse(brush) -- second, actually reverse the coord tables - for i = 1, math.round(#xy_coords / 2) do + for i = 1, math.floor(#xy_coords / 2) do local k = #xy_coords + 1 - i local C1 = brush[xy_coords[i].idx] diff --git a/scripts/cave.lua b/scripts/cave.lua index a307b7ffd..e87cfdbd0 100644 --- a/scripts/cave.lua +++ b/scripts/cave.lua @@ -371,8 +371,8 @@ end function Cave_cell_touches_map_edge(LEVEL, area, cx, cy) - local sx = area.base_sx + math.round((cx - 1) / 2) - local sy = area.base_sy + math.round((cy - 1) / 2) + local sx = area.base_sx + math.floor((cx - 1) / 2) + local sy = area.base_sy + math.floor((cy - 1) / 2) if (cx % 2) == 0 then if sx >= LEVEL.absolute_x2 then return true end @@ -398,8 +398,8 @@ function Cave_cell_touches_room(area, cx, cy, R, SEEDS) local nx, ny = geom.nudge(cx, cy, dir) -- get seed coordinate of neighbor cell - local sx = area.base_sx + math.round((nx - 1) / 2) - local sy = area.base_sy + math.round((ny - 1) / 2) + local sx = area.base_sx + math.floor((nx - 1) / 2) + local sy = area.base_sy + math.floor((ny - 1) / 2) if not Seed_valid(sx, sy) then goto continue end @@ -1483,7 +1483,7 @@ function Cave_bunch_areas(R, mode, LEVEL) setup() - local try_count = math.round(#area.walk_floors / rand.sel(50, 8, 14)) + local try_count = math.floor(#area.walk_floors / rand.sel(50, 8, 14)) for i = 1, try_count do local B1 = pick_start_area() @@ -2625,7 +2625,7 @@ function Cave_decorations(R) local quota = #locs * perc / 100 quota = quota * rand.range(0.8, 1.2) - quota = math.round(quota + gui.random()) + quota = math.floor(quota + gui.random()) -- very rarely add lots of torches if area.torch_mode ~= "few" and rand.odds(1) then @@ -3995,7 +3995,7 @@ function Cave_build_a_park(LEVEL, R, entry_h, SEEDS) -- extra health for damaging liquid if LEVEL.liquid.damage then - R.hazard_health = R.hazard_health + math.round(B.size / 4) + R.hazard_health = R.hazard_health + math.floor(B.size / 4) end end diff --git a/scripts/grower.lua b/scripts/grower.lua index 43242a597..2125de4c7 100644 --- a/scripts/grower.lua +++ b/scripts/grower.lua @@ -1083,11 +1083,11 @@ function Grower_decide_extents(LEVEL) end end - assert(math.round(LEVEL.map_W) < SEED_W) - assert(math.round(LEVEL.map_H) < SEED_H) + assert(math.floor(LEVEL.map_W) < SEED_W) + assert(math.floor(LEVEL.map_H) < SEED_H) - local map_x1 = 1 + math.round((SEED_W - LEVEL.map_W) / 2) - local map_y1 = 1 + math.round((SEED_H - LEVEL.map_H) / 2) + local map_x1 = 1 + math.floor((SEED_W - LEVEL.map_W) / 2) + local map_y1 = 1 + math.floor((SEED_H - LEVEL.map_H) / 2) local map_x2 = map_x1 + LEVEL.map_W - 1 local map_y2 = map_y1 + LEVEL.map_H - 1 @@ -1142,17 +1142,17 @@ function Grower_decide_extents(LEVEL) local base = (LEVEL.map_W - 12) * 0.72 - LEVEL.min_rooms = math.max(3, math.round(base / 3)) - LEVEL.max_rooms = math.max(6, math.round(base)) + LEVEL.min_rooms = math.max(3, math.floor(base / 3)) + LEVEL.max_rooms = math.max(6, math.floor(base)) -- add extra rooms based on extra size and area multiplier if LEVEL.size_multiplier then if LEVEL.size_multiplier < 1 then - LEVEL.max_rooms = math.round(LEVEL.max_rooms * ((1 - LEVEL.size_multiplier)+1) * 2/3) + LEVEL.max_rooms = math.floor(LEVEL.max_rooms * ((1 - LEVEL.size_multiplier)+1) * 2/3) end if LEVEL.area_multiplier < 1 then - LEVEL.max_rooms = math.round(LEVEL.max_rooms * ((1 - LEVEL.area_multiplier)+1) * 2/3) + LEVEL.max_rooms = math.floor(LEVEL.max_rooms * ((1 - LEVEL.area_multiplier)+1) * 2/3) end end @@ -1173,7 +1173,7 @@ function Grower_decide_extents(LEVEL) -- calculate the coverage target - LEVEL.min_coverage = math.round(LEVEL.map_W * LEVEL.map_H * 0.65) + LEVEL.min_coverage = math.floor(LEVEL.map_W * LEVEL.map_H * 0.65) if LEVEL.has_streets then gui.printf("--==| Streets Mode activated! |==--\n\n") @@ -1188,7 +1188,7 @@ function Grower_decide_extents(LEVEL) if PARAM.linear_start ~= "default" then if PARAM.linear_start == "all" then LEVEL.has_linear_start = true - elseif rand.odds(math.round(PARAM.linear_start)) then + elseif rand.odds(math.floor(PARAM.linear_start)) then LEVEL.has_linear_start = true end end @@ -2079,11 +2079,11 @@ stderrf("prelim_conn %s --> %s : S=%s dir=%d\n", c_out.R1.name, c_out.R2.name, S local function get_iteration_range(T) if is_create then - local dx = math.min(10, math.round(SEED_W / 4)) - local dy = math.min(10, math.round(SEED_H / 4)) + local dx = math.min(10, math.floor(SEED_W / 4)) + local dy = math.min(10, math.floor(SEED_H / 4)) - local mx = math.round(SEED_W / 2) - local my = math.round(SEED_H / 2) + local mx = math.floor(SEED_W / 2) + local my = math.floor(SEED_H / 2) -- the exit room is alway placed near top of map if cur_rule.absolute_pos == "top" or cur_rule.absolute_pos == "corner" then @@ -3161,9 +3161,9 @@ end -- check that it straddles at right spot if T.transpose then - if by1 ~= R.symmetry.y - math.round((W-1) / 2) then return false end + if by1 ~= R.symmetry.y - math.floor((W-1) / 2) then return false end else - if bx1 ~= R.symmetry.x - math.round((W-1) / 2) then return false end + if bx1 ~= R.symmetry.x - math.floor((W-1) / 2) then return false end end if match_or_install_pat_raw(what, T) then @@ -4051,7 +4051,7 @@ function Grower_sprout_room(SEEDS, LEVEL, R) Grower_grammatical_room(SEEDS, LEVEL, R, "sprout") end - if R.is_street and R:prelim_conn_num(LEVEL) < math.clamp(1, math.round(R.svolume/64), 10) then + if R.is_street and R:prelim_conn_num(LEVEL) < math.clamp(1, math.floor(R.svolume/64), 10) then Grower_grammatical_room(SEEDS, LEVEL, R, "sprout") end diff --git a/scripts/item.lua b/scripts/item.lua index e2aefdc5d..e12c0c4d8 100644 --- a/scripts/item.lua +++ b/scripts/item.lua @@ -141,7 +141,7 @@ function Player_give_stuff(hmodel, give_list) elseif give.ammo then gui.debugf("Giving [%s] ammo: %dx %s\n", - hmodel.class, math.round(give.count), give.ammo) + hmodel.class, math.floor(give.count), give.ammo) hmodel.stats[give.ammo] = (hmodel.stats[give.ammo] or 0) + give.count @@ -301,14 +301,14 @@ function Player_weapon_palettes(LEVEL) -- Note: result is often longer than strictly required - local num_low = math.round(total / 2 + gui.random()) + local num_low = math.floor(total / 2 + gui.random()) local num_high = total - num_low insert_multiple(list, num_low, Low) insert_multiple(list, num_high, High) if total >= 2 then - local num_very = math.round(total / 6 + gui.random()) + local num_very = math.floor(total / 6 + gui.random()) insert_multiple(list, num_very, Lowest) insert_multiple(list, num_very, Highest) @@ -341,7 +341,7 @@ function Player_weapon_palettes(LEVEL) local pal = {} -- decide number of "normal" weapons : at least one! - local normal_num = math.round(total / 3 + gui.random()) + local normal_num = math.floor(total / 3 + gui.random()) if normal_num < 1 then normal_num = 1 end got_weaps = table.copy(got_weaps) @@ -872,7 +872,7 @@ function Item_pickups_for_class(LEVEL, CL) elseif max_num * each_qty <= qty then count = max_num - rand.sel(20,1,0) else - count = 1 + math.round(qty / each_qty) + count = 1 + math.floor(qty / each_qty) end end diff --git a/scripts/layout.lua b/scripts/layout.lua index 3e86b777e..ffb07c851 100644 --- a/scripts/layout.lua +++ b/scripts/layout.lua @@ -1054,7 +1054,7 @@ gui.debugf("MonRelease in %s : kind --> %s\n", local qty = rand.index_by_probs({ 40,40,20,5 }) - if STYLE.traps == "few" then math.round((qty + 1) / 2) end + if STYLE.traps == "few" then math.floor((qty + 1) / 2) end if STYLE.traps == "more" then qty = qty + 1 end if STYLE.traps == "heaps" then qty = qty + 2 end @@ -2802,18 +2802,18 @@ function Layout_indoor_lighting(LEVEL) local LIGHT_LEVELS = { - bright = math.round(224 * PARAM.float_overall_lighting_mult), - normal = math.round(192 * PARAM.float_overall_lighting_mult), - dark = math.round(160 * PARAM.float_overall_lighting_mult), - verydark = math.round(128 * PARAM.float_overall_lighting_mult), + bright = math.floor(224 * PARAM.float_overall_lighting_mult), + normal = math.floor(192 * PARAM.float_overall_lighting_mult), + dark = math.floor(160 * PARAM.float_overall_lighting_mult), + verydark = math.floor(128 * PARAM.float_overall_lighting_mult), } local CAVE_LEVELS = { - bright = math.round(192 * PARAM.float_overall_lighting_mult), - normal = math.round(160 * PARAM.float_overall_lighting_mult), - dark = math.round(128 * PARAM.float_overall_lighting_mult), - verydark = math.round(96 * PARAM.float_overall_lighting_mult), + bright = math.floor(192 * PARAM.float_overall_lighting_mult), + normal = math.floor(160 * PARAM.float_overall_lighting_mult), + dark = math.floor(128 * PARAM.float_overall_lighting_mult), + verydark = math.floor(96 * PARAM.float_overall_lighting_mult), } local function sky_light_to_keyword() @@ -2848,7 +2848,7 @@ function Layout_indoor_lighting(LEVEL) local JITTER = {0, 0, 0, -16, 16} base_light = base_light + rand.pick(JITTER) else - local JITTER = {0, 0, 0, -math.round(base_light * 0.1), math.round(base_light * 0.1)} + local JITTER = {0, 0, 0, -math.floor(base_light * 0.1), math.floor(base_light * 0.1)} base_light = base_light + rand.pick(JITTER) end diff --git a/scripts/level.lua b/scripts/level.lua index a05b43983..90776079f 100644 --- a/scripts/level.lua +++ b/scripts/level.lua @@ -196,7 +196,7 @@ function Level_determine_map_size(LEV) end end - ob_size = math.clamp(low, math.round(rand.irange(low, high) * result_skew), high) + ob_size = math.clamp(low, math.floor(rand.irange(low, high) * result_skew), high) end if ob_size == gui.gettext("Episodic") or @@ -223,7 +223,7 @@ function Level_determine_map_size(LEV) local def_large = PARAM.float_level_upper_bound - def_small or 42 -- this basically ramps up - W = math.round(def_small + along * def_large) + W = math.floor(def_small + along * def_large) else -- Single Size -- @@ -244,7 +244,7 @@ function Level_determine_map_size(LEV) gui.printf("Initial size for " .. LEV.name .. ": " .. W .. "\n") - local H = 1 + math.round(W * 0.8) + local H = 1 + math.floor(W * 0.8) return W, H end @@ -1200,7 +1200,7 @@ function Episode_plan_weapons() end quota = quota * (PARAM.weapon_factor or 1) - quota = math.round(quota) + quota = math.floor(quota) if quota < 1 then quota = 1 end @@ -1352,7 +1352,7 @@ function Episode_plan_weapons() if rand.odds(30) then lev_idx = lev_idx + 1 end - lev_idx = math.round(lev_idx * rand.pick({ 1.0, 1.3, 1.6 })) + lev_idx = math.floor(lev_idx * rand.pick({ 1.0, 1.3, 1.6 })) end -- ensure it is valid @@ -1515,7 +1515,7 @@ function Episode_plan_weapons() local function reduce_weapon_gaps(level_list) local max_gap = 2 - max_gap = max_gap + math.round(#level_list / 20) + max_gap = max_gap + math.floor(#level_list / 20) if OB_CONFIG.weapons == "very_late" then max_gap = max_gap + 2 end if OB_CONFIG.weapons == "later" then max_gap = max_gap + 1 end @@ -2328,14 +2328,14 @@ function Level_choose_darkness(LEVEL) --prob = style_sel("darkness", 0, 10, 30, 90) --Original end - LEVEL.sky_light = math.round(rand.pick(SKY_LIGHT_NORMAL) * PARAM.float_overall_lighting_mult) + LEVEL.sky_light = math.floor(rand.pick(SKY_LIGHT_NORMAL) * PARAM.float_overall_lighting_mult) LEVEL.sky_shadow = 32 if rand.odds(prob) then gui.printf("Level is dark.\n") LEVEL.is_dark = true - LEVEL.sky_light = math.round(rand.pick(SKY_LIGHT_DARK) * PARAM.float_overall_lighting_mult) + LEVEL.sky_light = math.floor(rand.pick(SKY_LIGHT_DARK) * PARAM.float_overall_lighting_mult) LEVEL.sky_shadow = 32 end diff --git a/scripts/monster.lua b/scripts/monster.lua index 6abcead86..b1805cf23 100644 --- a/scripts/monster.lua +++ b/scripts/monster.lua @@ -450,13 +450,13 @@ function Monster_zone_palettes(LEVEL) skip_perc = skip_perc / 2 end - quants[0] = math.round(total * skip_perc / 100 + gui.random() * 0.7) + quants[0] = math.floor(total * skip_perc / 100 + gui.random() * 0.7) total = total - quants[0] - quants[2] = math.round(total * rand.range(0.3, 0.7) + gui.random()) + quants[2] = math.floor(total * rand.range(0.3, 0.7) + gui.random()) total = total - quants[2] - quants[1] = math.round(total * rand.range(0.3, 0.7) + gui.random()) + quants[1] = math.floor(total * rand.range(0.3, 0.7) + gui.random()) total = total - quants[1] quants[3] = total @@ -523,7 +523,7 @@ function Monster_zone_palettes(LEVEL) gui.debugf(" %-12s* %1.2f\n", mon, qty) end - gui.debugf(" TOUGHNESS: %d\n", math.round(palette_toughness(pal))) + gui.debugf(" TOUGHNESS: %d\n", math.floor(palette_toughness(pal))) end @@ -585,8 +585,8 @@ function Monster_split_spots(list, max_size) for _,spot in pairs(list) do local w, h = geom.box_size(spot.x1, spot.y1, spot.x2, spot.y2) - local XN = math.round(w / max_size) - local YN = math.round(h / max_size) + local XN = math.floor(w / max_size) + local YN = math.floor(h / max_size) if XN < 2 and YN < 2 then table.insert(new_list, spot) @@ -603,8 +603,8 @@ function Monster_split_spots(list, max_size) local new_spot = table.copy(spot) - new_spot.x1 = math.round(x1) ; new_spot.y1 = math.round(y1) - new_spot.x2 = math.round(x2) ; new_spot.y2 = math.round(y2) + new_spot.x1 = math.floor(x1) ; new_spot.y1 = math.floor(y1) + new_spot.x2 = math.floor(x2) ; new_spot.y2 = math.floor(y2) new_spot.marked = nil table.insert(new_list, new_spot) @@ -874,11 +874,11 @@ function Monster_fill_room(LEVEL, R, SEEDS) gui.debugf("raw number_of_kinds in %s : tally:%d / %d seeds | base:%1.2f factor:%1.2f ---> %1.2f\n", R.name, fodder_tally, R.svolume, base_num, factor, num) --]] - num = math.round(base_num) + num = math.floor(base_num) num = math.clamp(1, num, 5) - gui.debugf("number_of_kinds: %d (base: %d)\n", num, math.round(base_num)) + gui.debugf("number_of_kinds: %d (base: %d)\n", num, math.floor(base_num)) return num end @@ -1127,8 +1127,8 @@ function Monster_fill_room(LEVEL, R, SEEDS) for _,spot in pairs(spot_list) do local w, h = geom.box_size(spot.x1, spot.y1, spot.x2, spot.y2) - w = math.round(w / 64) ; if w < 1 then w = 1 end - h = math.round(h / 64) ; if h < 1 then h = 1 end + w = math.floor(w / 64) ; if w < 1 then w = 1 end + h = math.floor(h / 64) ; if h < 1 then h = 1 end count = count + w * h end @@ -1367,7 +1367,7 @@ function Monster_fill_room(LEVEL, R, SEEDS) num_kinds = rand.index_by_probs({ 20, 40, 60 }) else local size = math.sqrt(R.svolume) - num_kinds = math.round(size / 1.2) + num_kinds = math.floor(size / 1.2) end local list = {} @@ -1708,8 +1708,8 @@ function Monster_fill_room(LEVEL, R, SEEDS) local w, h = geom.box_size(spot.x1, spot.y1, spot.x2, spot.y2) - w = math.round(w / rr / 2) - h = math.round(h / rr / 2) + w = math.floor(w / rr / 2) + h = math.floor(h / rr / 2) return w * h end @@ -2078,7 +2078,7 @@ gui.debugf("wants =\n%s\n\n", table.tostr(wants)) local tally = fodder_tally tally = 3 * (1 + tally ^ 0.7) - want_total = math.round(tally * qty / 100 + gui.random()) + want_total = math.floor(tally * qty / 100 + gui.random()) -- determine how many of each kind of monster we want @@ -2208,7 +2208,7 @@ gui.debugf("wants =\n%s\n\n", table.tostr(wants)) elseif choice == "crazy" then min_val = spot_total else - min_val = math.round(min_val + (spot_total * tab[choice])) + min_val = math.floor(min_val + (spot_total * tab[choice])) end return min_val @@ -2219,8 +2219,8 @@ gui.debugf("wants =\n%s\n\n", table.tostr(wants)) -- determine maximum number that will fit local w, h = geom.box_size(spot.x1,spot.y1, spot.x2,spot.y2) - w = math.round(w / info.r / 2) - h = math.round(h / info.r / 2) + w = math.floor(w / info.r / 2) + h = math.floor(h / info.r / 2) assert(w >= 1 and h >= 1) @@ -2566,7 +2566,7 @@ function Monster_show_stats(LEVEL) local function get_stat(mon) local num = LEVEL.mon_stats[mon] or 0 - local div = math.round(num * 99.8 / total) + local div = math.floor(num * 99.8 / total) if div == 0 and num > 0 then div = 1 end return string.format("%02d", div) end diff --git a/scripts/prefab.lua b/scripts/prefab.lua index d6352b21b..b1991e413 100644 --- a/scripts/prefab.lua +++ b/scripts/prefab.lua @@ -1611,7 +1611,7 @@ function Fab_load_wad(def) angle = math.clamp(0, angle, 300) - return 112 + math.round(angle * 16 / 45) + return 112 + math.floor(angle * 16 / 45) end @@ -2249,7 +2249,7 @@ function Fab_replacements(LEVEL, fab) -- adjust X offset for split edges if C.u1 and C.u1 ~= "" and C.u1_along then - C.u1 = C.u1 + math.round(C.u1_along) + C.u1 = C.u1 + math.floor(C.u1_along) C.u1_along = nil end end @@ -2637,11 +2637,11 @@ function Fab_find_matches(LEVEL, reqs, match_state) end -- prefab definition defaults to 1 - local sw = math.round(def.seed_w or 1) - local sh = math.round(def.seed_h or 1) + local sw = math.floor(def.seed_w or 1) + local sh = math.floor(def.seed_h or 1) - local req_w = math.round(reqs.seed_w or 1) - local req_h = math.round(reqs.seed_h or 1) + local req_w = math.floor(reqs.seed_w or 1) + local req_h = math.floor(reqs.seed_h or 1) -- "diagonal" prefabs need an exact same square if def.where == "diagonal" then diff --git a/scripts/quest.lua b/scripts/quest.lua index 5cebe3680..adca0aa4d 100644 --- a/scripts/quest.lua +++ b/scripts/quest.lua @@ -912,7 +912,7 @@ function Quest_add_major_quests(LEVEL) local each_prob = style_sel("keys", 0, 40, 80, 100) -- decide maximum number - local max_num = 1 + math.round(#LEVEL.rooms / 5) + local max_num = 1 + math.floor(#LEVEL.rooms / 5) for name,_ in pairs(key_tab) do if rand.odds(each_prob) then @@ -938,7 +938,7 @@ function Quest_add_major_quests(LEVEL) if not rand.odds(any_prob) then return {} end -- decide maximum number - local max_num = 1 + math.round(#LEVEL.rooms / 5) + local max_num = 1 + math.floor(#LEVEL.rooms / 5) for i = 1, max_num do if rand.odds(each_prob) then @@ -1508,7 +1508,7 @@ function Quest_start_room(LEVEL) -- prefer no teleporter if not R:has_teleporter() then score = score + 1 end - gui.debugf("eval_start_room in %s --> space:%d dist:%d %1.2f\n", R.name, space, math.round(R.dist_to_exit or -1), score) + gui.debugf("eval_start_room in %s --> space:%d dist:%d %1.2f\n", R.name, space, math.floor(R.dist_to_exit or -1), score) -- tie breaker return score + gui.random() * 2 @@ -1703,7 +1703,7 @@ function Quest_order_by_visit(LEVEL) gui.printf("Quest list:\n") for _,Q in pairs(LEVEL.quests) do - gui.printf(" %s : svolume:%d\n", Q.name, math.round(Q.svolume)) + gui.printf(" %s : svolume:%d\n", Q.name, math.floor(Q.svolume)) end end @@ -3028,7 +3028,7 @@ function Quest_room_themes(LEVEL) local building_tab = collect_usable_themes("building") - local max_room_theme = math.round(PARAM.float_max_room_themes or 1) + local max_room_theme = math.floor(PARAM.float_max_room_themes or 1) if not PARAM.bool_avoid_room_theme_reuse or (PARAM.bool_avoid_room_theme_reuse and PARAM.bool_avoid_room_theme_reuse == 1) then for theme,odds in pairs(building_tab) do @@ -3054,7 +3054,7 @@ function Quest_room_themes(LEVEL) visit_room(LEVEL.start_room, nil, nil, building_tab) - local max_wall_groups = math.round(PARAM.float_max_indoor_wall_groups or 2) + local max_wall_groups = math.floor(PARAM.float_max_indoor_wall_groups or 2) local the_wall_group_tab = table.copy(LEVEL.theme.wall_groups) diff --git a/scripts/render.lua b/scripts/render.lua index 19fed8d85..a2a818d01 100644 --- a/scripts/render.lua +++ b/scripts/render.lua @@ -40,9 +40,9 @@ function Render_add_exit_sign(E, z, SEEDS, LEVEL) local len = geom.dist(x1,y1, x2,y2) - local ofs = math.round(len / 6) + local ofs = math.floor(len / 6) if len > 340 then - ofs = math.round(len / 4) + ofs = math.floor(len / 4) end local ax = x1 + ofs * (x2 - x1) / len @@ -3190,8 +3190,8 @@ function Render_all_street_traffic(LEVEL, SEEDS) for _,SPOT in pairs(LEVEL.road_street_traffic_spots) do -- stagger positions a bit - SPOT.x = SPOT.x + math.round(rand.range(-32,32)) - SPOT.y = SPOT.y + math.round(rand.range(-32,32)) + SPOT.x = SPOT.x + math.floor(rand.range(-32,32)) + SPOT.y = SPOT.y + math.floor(rand.range(-32,32)) local T = Trans.spot_transform(SPOT.x, SPOT.y, SPOT.z, SPOT.dir) local reqs = {} @@ -3676,7 +3676,7 @@ function Render_scenic_fabs(LEVEL, SEEDS) end end - for i = 1, math.round(area.svolume/32) do + for i = 1, math.floor(area.svolume/32) do try_decor_here(area) end end @@ -4328,7 +4328,7 @@ function Render_cells(LEVEL, area) assert(B) assert(B.floor_h) - return string.format("1-%5d-%5d", math.round(B.floor_h + 50000), math.round(50000 - (B.ceil_h or 0))) + return string.format("1-%5d-%5d", math.floor(B.floor_h + 50000), math.floor(50000 - (B.ceil_h or 0))) end diff --git a/scripts/room.lua b/scripts/room.lua index cf3359d3b..6c98c6ffe 100644 --- a/scripts/room.lua +++ b/scripts/room.lua @@ -2285,7 +2285,7 @@ function Room_choose_size(LEVEL, R, not_big) if not R.is_start or not R.is_secret then if LEVEL.area_multiplier then - R.floor_limit = math.round(R.floor_limit * LEVEL.area_multiplier) + R.floor_limit = math.floor(R.floor_limit * LEVEL.area_multiplier) end if LEVEL.has_absurd_new_area_rules then R.floor_limit = R.floor_limit * 4 @@ -2316,8 +2316,8 @@ function Room_choose_size(LEVEL, R, not_big) elseif not LEVEL.is_procedural_gotcha then if R.is_start then - R.size_limit = math.round(R.size_limit / 2) - R.floor_limit = math.round(R.floor_limit / 2) + R.size_limit = math.floor(R.size_limit / 2) + R.floor_limit = math.floor(R.floor_limit / 2) R.size_limit = math.clamp(rand.pick({4,8,12,16}),R.size_limit,EXTREME_H) end @@ -2333,8 +2333,8 @@ function Room_choose_size(LEVEL, R, not_big) -- tame teleporter trunks and hallway exits if (not R.grow_parent and not R.is_start) or (R.grow_parent and R.grow_parent.is_hallway) then - R.size_limit = math.round(R.size_limit / 5) - R.floor_limit = math.round(R.floor_limit / 2) + R.size_limit = math.floor(R.size_limit / 5) + R.floor_limit = math.floor(R.floor_limit / 2) R.is_big = false end end diff --git a/scripts/seed.lua b/scripts/seed.lua index 07f1d6e8a..faca5bd6c 100644 --- a/scripts/seed.lua +++ b/scripts/seed.lua @@ -364,8 +364,8 @@ function SEED_CLASS.calc_mid_point(S) my = (S.y2 + my) / 2 end - S.mid_x = math.round(mx) - S.mid_y = math.round(my) + S.mid_x = math.floor(mx) + S.mid_y = math.floor(my) end @@ -561,8 +561,8 @@ function Seed_init(LEVEL) BASE_X = 32 BASE_Y = 32 - BASE_X = 32 - math.round(SEED_W / 2) * SEED_SIZE - BASE_Y = 32 - math.round(SEED_H / 2) * SEED_SIZE + BASE_X = 32 - math.floor(SEED_W / 2) * SEED_SIZE + BASE_Y = 32 - math.floor(SEED_H / 2) * SEED_SIZE for sx = 1, SEED_W do for sy = 1, SEED_H do @@ -581,7 +581,7 @@ function Seed_init(LEVEL) local depot_y = BASE_Y + SEED_H * SEED_SIZE for row = 0, 2 do - for col = 0, math.round(SEED_W / 3) - 1 do + for col = 0, math.floor(SEED_W / 3) - 1 do local x = depot_x + col * 3 * SEED_SIZE local y = depot_y + row * 6 * SEED_SIZE + 64 @@ -985,7 +985,7 @@ function Seed_draw_minimap(SEEDS, LEVEL) y1 = (y1 - min_y + ofs_y) * map_H / size y2 = (y2 - min_y + ofs_y) * map_H / size - gui.minimap_draw_line(math.round(x1),math.round(y1), math.round(x2),math.round(y2), color) + gui.minimap_draw_line(math.floor(x1),math.floor(y1), math.floor(x2),math.floor(y2), color) end diff --git a/scripts/title_gen.lua b/scripts/title_gen.lua index ab8e2149c..3cd44cb7d 100644 --- a/scripts/title_gen.lua +++ b/scripts/title_gen.lua @@ -870,7 +870,7 @@ function Title_make_stroke(T, x1,y1, x2,y2) x1, y1 = T.func(T, x1, y1) x2, y2 = T.func(T, x2, y2) - gui.title_draw_line(math.round(x1 + T.ofs_x), math.round(y1 + T.ofs_y), math.round(x2 + T.ofs_x), math.round(y2 + T.ofs_y)) + gui.title_draw_line(math.floor(x1 + T.ofs_x), math.floor(y1 + T.ofs_y), math.floor(x2 + T.ofs_x), math.floor(y2 + T.ofs_y)) end @@ -1032,8 +1032,8 @@ function Title_centered_string(T, mx, my, text, style) T.ofs_y = base_ofs - i end - gui.title_prop("box_w", math.round(thick)) - gui.title_prop("box_h", math.round(thick)) + gui.title_prop("box_w", math.floor(thick)) + gui.title_prop("box_h", math.floor(thick)) Title_draw_string(T, text) end @@ -1055,12 +1055,12 @@ function Title_centered_string(T, mx, my, text, style) end if style.font_mode == "gradient" or style.font_mode == "gradient3" then - gui.title_prop("grad_y1", math.round(T.y - T.fh + 1)) - gui.title_prop("grad_y2", math.round(T.y - 1)) + gui.title_prop("grad_y1", math.floor(T.y - T.fh + 1)) + gui.title_prop("grad_y2", math.floor(T.y - 1)) end - gui.title_prop("box_w", math.round(T.thick)) - gui.title_prop("box_h", math.round(T.thick)) + gui.title_prop("box_w", math.floor(T.thick)) + gui.title_prop("box_h", math.floor(T.thick)) T.ofs_x = base_ofs T.ofs_y = base_ofs @@ -1110,9 +1110,9 @@ function Title_interp_color(list, ity, out) local A = list[pos] local B = list[pos+1] - out[1] = math.round(A[1] * (1 - ity) + B[1] * ity) - out[2] = math.round(A[2] * (1 - ity) + B[2] * ity) - out[3] = math.round(A[3] * (1 - ity) + B[3] * ity) + out[1] = math.floor(A[1] * (1 - ity) + B[1] * ity) + out[2] = math.floor(A[2] * (1 - ity) + B[2] * ity) + out[3] = math.floor(A[3] * (1 - ity) + B[3] * ity) return end @@ -1203,7 +1203,7 @@ function Title_gen_space_scene() local function draw_big_star(mx, my, r) - local r2 = math.round(r * 1.2) + local r2 = math.floor(r * 1.2) local DD = 0.09 @@ -1221,7 +1221,7 @@ function Title_gen_space_scene() if ity < 50 then goto continue end - ity = math.round(ity) + ity = math.floor(ity) gui.title_prop("color", { ity, ity, ity }) gui.title_draw_rect(x, y, 1, 1) @@ -1287,9 +1287,9 @@ function Title_gen_space_scene() else gui.title_draw_rect(mx, my, 1, 1) - col[1] = math.round(col[1] * 0.6) - col[2] = math.round(col[2] * 0.6) - col[3] = math.round(col[3] * 0.6) + col[1] = math.floor(col[1] * 0.6) + col[2] = math.floor(col[2] * 0.6) + col[3] = math.floor(col[3] * 0.6) gui.title_prop("color", col) @@ -1390,7 +1390,7 @@ function Title_gen_ray_burst() Title_interp_color(color_list, ity, col) gui.title_prop("color", col) - gui.title_draw_line(mx, my, math.round(x1), math.round(y1), col) + gui.title_draw_line(mx, my, math.floor(x1), math.floor(y1), col) end end end @@ -1434,7 +1434,7 @@ function Title_gen_wall_scene() local ity = math.exp(-d / 50) * 255 --- 255 - (d ^ 1.5) / 2.0, ity = math.clamp(0, ity, 255) - ity = math.round(ity) + ity = math.floor(ity) col[1] = ity col[2] = ity @@ -1536,7 +1536,7 @@ function Title_gen_cave_scene() Title_interp_color(color_list, ity, col) gui.title_prop("color", col) - gui.title_draw_rect(math.round(x), math.round(y), 1, 1) + gui.title_draw_rect(math.floor(x), math.floor(y), 1, 1) end ::continue:: end @@ -1598,7 +1598,7 @@ function Title_gen_tunnel_scene() Title_interp_color(color_list, ity, col) gui.title_prop("color", col) - gui.title_draw_disc(math.round(mx - r*x_mul), math.round(my - r*y_mul), math.round(r*1.2), math.round(r)) + gui.title_draw_disc(math.floor(mx - r*x_mul), math.floor(my - r*y_mul), math.floor(r*1.2), math.floor(r)) end end diff --git a/scripts/util.lua b/scripts/util.lua index 99021552d..7e5580d2e 100644 --- a/scripts/util.lua +++ b/scripts/util.lua @@ -201,7 +201,7 @@ function module_param_up(module) if opt.increment < 1 then PARAM[opt.name] = value else - PARAM[opt.name] = math.round(value) + PARAM[opt.name] = math.floor(value) end end elseif opt.valuator == "button" then @@ -348,7 +348,7 @@ end function table.reverse(t) if not t then return nil end - for x = 1, math.round(#t / 2) do + for x = 1, math.floor(#t / 2) do local y = #t - (x-1) -- swap 'em t[x], t[y] = t[y], t[x] @@ -710,7 +710,7 @@ function rand.irange(L,H) end function rand.int(val) - return math.round(val + gui.random()) + return math.floor(val + gui.random()) end function rand.skew(mid, dist) @@ -848,7 +848,7 @@ end -- where all the index values start at 1 function div_mod(x, mod) x = x - 1 - return 1 + math.round(x / mod), 1 + (x % mod) + return 1 + math.floor(x / mod), 1 + (x % mod) end function dir_to_delta(dir) @@ -1247,7 +1247,7 @@ end function geom.box_mid(x1,y1, x2,y2) - return math.round((x1 + x2) / 2), math.round((y1 + y2) / 2) + return math.floor((x1 + x2) / 2), math.floor((y1 + y2) / 2) end function geom.box_size(x1,y1, x2,y2)