From 35a2f6e3ed24ae2fbeb37dcdafc8c1acfb25e4a4 Mon Sep 17 00:00:00 2001 From: copperwater Date: Sat, 29 Feb 2020 17:04:26 -0500 Subject: [PATCH] Convert math.random percentage computations into percent() --- dat/Val-goal.lua | 2 +- dat/astral.lua | 4 ++-- dat/baalz.lua | 2 +- dat/bigrm-1.lua | 2 +- dat/bigrm-10.lua | 2 +- dat/bigrm-8.lua | 2 +- dat/knox.lua | 6 +++--- dat/medusa-1.lua | 8 ++++---- dat/medusa-2.lua | 8 ++++---- dat/medusa-3.lua | 8 ++++---- dat/medusa-4.lua | 16 ++++++++-------- dat/minend-2.lua | 10 +++++----- dat/minetn-1.lua | 8 ++++---- dat/minetn-2.lua | 24 ++++++++++++------------ dat/minetn-5.lua | 14 +++++++------- dat/minetn-7.lua | 22 +++++++++++----------- dat/nhlib.lua | 2 +- dat/soko1-1.lua | 2 +- dat/soko1-2.lua | 2 +- dat/valley.lua | 6 +++--- dat/wizard3.lua | 2 +- 21 files changed, 76 insertions(+), 76 deletions(-) diff --git a/dat/Val-goal.lua b/dat/Val-goal.lua index f9237e5e4..d92917039 100644 --- a/dat/Val-goal.lua +++ b/dat/Val-goal.lua @@ -38,7 +38,7 @@ des.non_diggable(selection.area(00,00,34,16)) -- Drawbridges; northern one opens from the south (portcullis) to further -- north (lowered span), southern one from the north to further south des.drawbridge({ x=17, y=02, dir="south", state="random" }) -if math.random(0, 99) < 75 then +if percent(75) then des.drawbridge({ x=17, y=14, dir="north", state="open" }) else des.drawbridge({ x=17, y=14, dir="north", state="random" }) diff --git a/dat/astral.lua b/dat/astral.lua index 62ea0ec16..5a3a70286 100644 --- a/dat/astral.lua +++ b/dat/astral.lua @@ -40,7 +40,7 @@ for i=1,2 do -- 3.6.2: 60% twice == 36% chance that both sides open up, 24% left side -- only, 24% right side only, 16% that neither side opens up local hall; - if math.random(0, 99) < 60 then + if percent(60) then if i == 1 then des.terrain(selection.area(17,14, 30,18),".") des.wallify() @@ -60,7 +60,7 @@ for i=1,2 do -- extra monsters; was [6 + 3d4] when both wings were opened up at once for i=1,3 + math.random(2 - 1,2*3) do des.monster({ id="Angel", coord = { hall:rndcoord(1) }, align="noalign", peaceful=0 }) - if math.random(0,99) < 50 then + if percent(50) then des.monster({ coord = { hall:rndcoord(1) }, peaceful=0 }) end end diff --git a/dat/baalz.lua b/dat/baalz.lua index 33eb215ee..107c98719 100644 --- a/dat/baalz.lua +++ b/dat/baalz.lua @@ -33,7 +33,7 @@ des.non_diggable(selection.area(00,00,47,12)) des.mazewalk(00,06,"west") des.stair("down", 44,06) des.door("locked",00,06) -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(34,08,'-') des.terrain(34,04,'S') des.terrain(29,05,'|') diff --git a/dat/bigrm-1.lua b/dat/bigrm-1.lua index f449e6210..b86ca8cfe 100644 --- a/dat/bigrm-1.lua +++ b/dat/bigrm-1.lua @@ -24,7 +24,7 @@ des.map([[ ]]); -if math.random(0,99) < 75 then +if percent(75) then local terrains = { "-", "F", "L", "T", "C" }; local tidx = math.random(1, #terrains); local choice = math.random(0, 4); diff --git a/dat/bigrm-10.lua b/dat/bigrm-10.lua index 69403d8f9..e4eaf90f8 100644 --- a/dat/bigrm-10.lua +++ b/dat/bigrm-10.lua @@ -25,7 +25,7 @@ des.map([[ ....................................................................... ]]); -if math.random(0,99) < 40 then +if percent(40) then -- occasionally it's not a fog maze local terrain = { "L", "}", "T", "-", "F" }; local tidx = math.random(1, #terrain); diff --git a/dat/bigrm-8.lua b/dat/bigrm-8.lua index 2851b780d..500a970e7 100644 --- a/dat/bigrm-8.lua +++ b/dat/bigrm-8.lua @@ -24,7 +24,7 @@ des.map([[ ---------------------------------------------- ]]); -if math.random(0,99) < 40 then +if percent(40) then local terrain = { "L", "}", "T", ".", "-", "C" }; local tidx = math.random(1, #terrain); des.replace_terrain({ region={00,00, 74,17}, fromterrain="F", toterrain=terrain[tidx] }); diff --git a/dat/knox.lua b/dat/knox.lua index 87832a3a2..aa5ca4888 100644 --- a/dat/knox.lua +++ b/dat/knox.lua @@ -41,14 +41,14 @@ des.teleport_region({ region = {06,15,09,16}, dir="down" }) -- Throne room, with Croesus on the throne des.region({ x1=37,y1=08,x2=46,y2=11, lit=1, type="throne", prefilled=0 }) -- 50% chance each to move throne and/or fort's entry secret door up one row -if math.random(0, 99) < 50 then +if percent(50) then des.monster({ id = "Croesus", x=43, y=10, peaceful = 0 }) else des.monster({ id = "Croesus", x=43, y=09, peaceful = 0 }) des.terrain(43,09, "\\") des.terrain(43,10, ".") end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(47,09, "S") des.terrain(47,10, "|") end @@ -70,7 +70,7 @@ local treasury = selection.area(21,08,35,11); treasury:iterate(treasure_spot); -- Vault entrance also varies -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(36,09, "|") des.terrain(36,10, "S") end diff --git a/dat/medusa-1.lua b/dat/medusa-1.lua index 635763a5b..591e404d2 100644 --- a/dat/medusa-1.lua +++ b/dat/medusa-1.lua @@ -58,16 +58,16 @@ des.non_diggable(selection.area(30,06,46,13)) des.object({ id = "statue", x=36,y=10, buc="uncursed", montype="knight", historic=1, male = 1, name="Perseus", contents = function() - if math.random(0,99) < 75 then + if percent(75) then des.object({ id = "shield of reflection", buc="cursed", spe=0 }) end - if math.random(0,99) < 25 then + if percent(25) then des.object({ id = "levitation boots", spe=0 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object({ id = "scimitar", buc="blessed", spe=2 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object("sack") end end diff --git a/dat/medusa-2.lua b/dat/medusa-2.lua index 405627f63..17c2893ff 100644 --- a/dat/medusa-2.lua +++ b/dat/medusa-2.lua @@ -52,16 +52,16 @@ des.non_diggable(selection.area(60,02,73,17)) des.object({ id = "statue", x=68,y=10,buc="uncursed", montype="knight", historic=1, male=1,name="Perseus", contents = function() - if math.random(0,99) < 25 then + if percent(25) then des.object({ id = "shield of reflection", buc="cursed", spe=0 }) end - if math.random(0,99) < 75 then + if percent(75) then des.object({ id = "levitation boots", spe=0 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object({ id = "scimitar", buc="blessed", spe=2 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object("sack") end end diff --git a/dat/medusa-3.lua b/dat/medusa-3.lua index 65961b5e5..efc860ae5 100644 --- a/dat/medusa-3.lua +++ b/dat/medusa-3.lua @@ -64,16 +64,16 @@ local px, py = place:rndcoord(1); des.object({ id="statue",x=px, y=py, buc="uncursed", montype="knight", historic=1, male=1,name="Perseus", contents = function() - if math.random(0,99) < 75 then + if percent(75) then des.object({ id = "shield of reflection", buc="cursed", spe=0 }) end - if math.random(0,99) < 25 then + if percent(25) then des.object({ id = "levitation boots", spe=0 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object({ id = "scimitar", buc="blessed", spe=2 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object("sack") end end diff --git a/dat/medusa-4.lua b/dat/medusa-4.lua index b30540c51..73f6df286 100644 --- a/dat/medusa-4.lua +++ b/dat/medusa-4.lua @@ -67,16 +67,16 @@ local px, py = place:rndcoord(1); des.object({ id="statue",x=px, y=py, buc="uncursed", montype="knight", historic=1, male=1,name="Perseus", contents = function() - if math.random(0,99) < 75 then + if percent(75) then des.object({ id = "shield of reflection", buc="cursed", spe=0 }) end - if math.random(0,99) < 25 then + if percent(25) then des.object({ id = "levitation boots", spe=0 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object({ id = "scimitar", buc="blessed", spe=2 }) end - if math.random(0,99) < 50 then + if percent(50) then des.object("sack") end end @@ -102,17 +102,17 @@ des.monster("kraken", 07,07) -- -- the nesting dragon des.monster({ id = "yellow dragon", x=05, y=04, asleep=1 }) -if math.random(0,99) < 50 then +if percent(50) then des.monster({ id = "baby yellow dragon", x=04,y=04, asleep=1 }) end -if math.random(0,99) < 25 then +if percent(25) then des.monster({ id = "baby yellow dragon", x=04, y=05, asleep=1 }) end des.object({ id = "egg", x=05, y=04, montype="yellow dragon" }); -if math.random(0,99) < 50 then +if percent(50) then des.object({ id = "egg", x=05, y=04, montype="yellow dragon" }); end -if math.random(0,99) < 25 then +if percent(25) then des.object({ id = "egg", x=05, y=04, montype="yellow dragon" }); end -- diff --git a/dat/minend-2.lua b/dat/minend-2.lua index 39a7750eb..ced2b11f6 100644 --- a/dat/minend-2.lua +++ b/dat/minend-2.lua @@ -31,23 +31,23 @@ des.map([[ --------------------------------------------------------------------------- ]]); -if math.random(0, 99) < 50 then +if percent(50) then des.terrain({55,14},"-") des.terrain({56,14},"-") des.terrain({61,15},"|") des.terrain({52,5}, "S") des.door("locked", 52,5) end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain({18,1}, "|") des.terrain(selection.area(7,12, 8,13), ".") end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain({49,4}, "|") des.terrain({21,5}, ".") end -if math.random(0, 99) < 50 then - if math.random(0, 99) < 50 then +if percent(50) then + if percent(50) then des.terrain({22,1}, "|") else des.terrain({50,7}, "-") diff --git a/dat/minetn-1.lua b/dat/minetn-1.lua index fd1257c0e..39460ead3 100644 --- a/dat/minetn-1.lua +++ b/dat/minetn-1.lua @@ -89,7 +89,7 @@ des.object({ id = "corpse", montype="watch captain" }) -- Rubble! for i=1,9 + math.random(2 - 1,2*5) do - if math.random(0,99) < 90 then + if percent(90) then des.object("boulder") end des.object("rock") @@ -119,10 +119,10 @@ local inside = selection.floodfill(18,8) local near_temple = selection.area(17,8, 23,14) & inside for i=1,5 + math.random(1 - 1,1*10) do - if math.random(0, 99) < 50 then + if percent(50) then des.monster({ id = "orc-captain", coord = { inside:rndcoord(1) }, peaceful=0 }); else - if math.random(0, 99) < 80 then + if percent(80) then des.monster({ id = "Uruk-hai", coord = { inside:rndcoord(1) }, peaceful=0 }) else des.monster({ id = "Mordor orc", coord = { inside:rndcoord(1) }, peaceful=0 }) @@ -136,7 +136,7 @@ end -- these are not such a big deal -- to run into outside the bars for i=1,9 + math.random(2 - 1,2*5) do - if math.random(0, 99) < 90 then + if percent(90) then des.monster({ id = "hill orc", peaceful = 0 }) else des.monster({ id = "goblin", peaceful = 0 }) diff --git a/dat/minetn-2.lua b/dat/minetn-2.lua index 7031c280f..87e58a348 100644 --- a/dat/minetn-2.lua +++ b/dat/minetn-2.lua @@ -12,7 +12,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, des.feature("fountain", 17, 5) des.feature("fountain", 13, 8) - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", x=2,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="west" }) @@ -20,7 +20,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=0, x=5,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="south" }) @@ -28,7 +28,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", x=8,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="east" }) @@ -36,7 +36,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=1, x=16,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="west" }) @@ -44,7 +44,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=0, x=19,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="south" }) @@ -52,7 +52,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", x=22,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="south" }) @@ -61,7 +61,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=0, x=25,y=0, w=2,h=2, contents = function() des.door({ state="closed", wall="east" }) @@ -69,7 +69,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=1, x=2,y=5, w=2,h=2, contents = function() des.door({ state="closed", wall="north" }) @@ -77,7 +77,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=1, x=5,y=5, w=2,h=2, contents = function() des.door({ state="closed", wall="south" }) @@ -85,7 +85,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", x=8,y=5, w=2,h=2, contents = function() des.door({ state="locked", wall="north" }) @@ -118,7 +118,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, end }); - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=0, x=7,y=10, w=3,h=3, contents = function() des.door({ state="locked", wall="north" }) @@ -136,7 +136,7 @@ des.room({ type = "ordinary", lit=1, x=3, y=3, end }); - if math.random(0,99) < 75 then + if percent(75) then des.room({ type = "ordinary", lit=1, x=18,y=10, w=4,h=3, contents = function() des.door({ state="locked", wall="west" }) diff --git a/dat/minetn-5.lua b/dat/minetn-5.lua index 1f5974864..241c5b70d 100644 --- a/dat/minetn-5.lua +++ b/dat/minetn-5.lua @@ -33,31 +33,31 @@ des.map([[ ----- ------ ------- --------------- ]]); -if math.random(0, 99) < 75 then - if math.random(0, 99) < 50 then +if percent(75) then + if percent(50) then des.terrain(selection.line(25,8, 25,9), "|") else des.terrain(selection.line(16,13, 17,13), "-") end end -if math.random(0, 99) < 75 then - if math.random(0, 99) < 50 then +if percent(75) then + if percent(50) then des.terrain(selection.line(36,10, 36,11), "|") else des.terrain(selection.line(32,15, 33,15), "-") end end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(selection.area(21,4, 22,5), ".") des.terrain(selection.line(14,9, 14,10), "|") end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain({46,13}, "|") des.terrain(selection.line(43,5, 47,5), "-") des.terrain(selection.line(42,6, 46,6), ".") des.terrain(selection.line(46,7, 47,7), ".") end -if math.random(0,99) < 50 then +if percent(50) then des.terrain(selection.area(69,11, 71,11), "-") end diff --git a/dat/minetn-7.lua b/dat/minetn-7.lua index dae4a9148..eb4a7f56d 100644 --- a/dat/minetn-7.lua +++ b/dat/minetn-7.lua @@ -11,7 +11,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, des.feature("fountain", 12, 07) des.feature("fountain", 11, 13) - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=2,y=2, w=4,h=2, contents = function() des.door({ state = "closed", wall="south" }) @@ -19,7 +19,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=7,y=2, w=2,h=2, contents = function() des.door({ state = "closed", wall="north" }) @@ -27,7 +27,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=7,y=5, w=2,h=2, contents = function() des.door({ state = "closed", wall="south" }) @@ -35,7 +35,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", lit=1, x=10,y=2, w=3,h=4, contents = function() des.monster("gnome") @@ -47,7 +47,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=14,y=2, w=4,h=2, contents = function() des.door({ state = "closed", wall="south", pos=0 }) @@ -56,7 +56,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=16,y=5, w=2,h=2, contents = function() des.door({ state = "closed", wall="south" }) @@ -64,7 +64,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", lit=0, x=19,y=2, w=2,h=2, contents = function() des.door({ state = "locked", wall="east" }) @@ -79,7 +79,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, end }) - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=2,y=7, w=2,h=2, contents = function() des.door({ state = "closed", wall="east" }) @@ -99,7 +99,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, end }) - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=11,y=10, w=2,h=2, contents = function() des.door({ state = "locked", wall="west" }) @@ -114,7 +114,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, end }) - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=17,y=11, w=4,h=2, contents = function() des.door({ state = "closed", wall="north" }) @@ -122,7 +122,7 @@ des.room({ type="ordinary", lit=1, x=3,y=3, }) end - if math.random(0,99) < 75 then + if percent(75) then des.room({ type="ordinary", x=22,y=11, w=2,h=2, contents = function() des.door({ state = "closed", wall="south" }) diff --git a/dat/nhlib.lua b/dat/nhlib.lua index 983542b5b..a07ff4a41 100644 --- a/dat/nhlib.lua +++ b/dat/nhlib.lua @@ -39,5 +39,5 @@ end -- percent(20) returns true 20% of the time function percent(threshold) - return math.random(0,99) < threshold + return math.random(0, 99) < threshold end diff --git a/dat/soko1-1.lua b/dat/soko1-1.lua index d05d5ee27..b281975b5 100644 --- a/dat/soko1-1.lua +++ b/dat/soko1-1.lua @@ -98,7 +98,7 @@ des.region({ region={18,10, 22,16}, lit = 1, type = "zoo", prefilled = 0, irregular = 1 }); px, py = selection.rndcoord(place); -if math.random(0, 99) < 75 then +if percent(75) then des.object({ id="bag of holding", x=px, y=py, buc="not-cursed", achievement=1 }); else diff --git a/dat/soko1-2.lua b/dat/soko1-2.lua index 7ad218b39..9a8002852 100644 --- a/dat/soko1-2.lua +++ b/dat/soko1-2.lua @@ -100,7 +100,7 @@ des.region({ region={18,09, 22,15}, lit = 1, type = "zoo", prefilled = 0, irregular = 1 }); px, py = selection.rndcoord(place); -if math.random(0, 99) < 25 then +if percent(25) then des.object({ id="bag of holding", x=px, y=py, buc="not-cursed", achievement=1 }); else diff --git a/dat/valley.lua b/dat/valley.lua index 5e78e71be..adcd4e80f 100644 --- a/dat/valley.lua +++ b/dat/valley.lua @@ -34,16 +34,16 @@ des.map([[ -- Make the path somewhat unpredictable -- If you get "lucky", you may have to go through all three graveyards. -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(selection.line(50,8, 53,8), '-') des.terrain(selection.line(40,8, 43,8), 'B') end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain({ x=27, y=12, typ='|' }) des.terrain(selection.line(27,3, 29,3), 'B') des.terrain({ x=28, y=2, typ='-' }) end -if math.random(0, 99) < 50 then +if percent(50) then des.terrain(selection.line(16,10, 16,11), '|') des.terrain(selection.line(9,13, 14,13), 'B') end diff --git a/dat/wizard3.lua b/dat/wizard3.lua index f5da68944..a7b53a340 100644 --- a/dat/wizard3.lua +++ b/dat/wizard3.lua @@ -34,7 +34,7 @@ des.region({ region={17,06, 18,11}, lit=0, type="beehive" }) des.region({ region={20,06,26,11},lit=0,type="ordinary",prefilled=1, contents = function() local w = "north"; - if math.random(0,99) < 50 then w = "west" end + if percent(50) then w = "west" end des.door({ state="secret", wall=w }) end }); -- 2.50.1