Convert math.random percentage computations into percent()

This commit is contained in:
copperwater
2020-02-29 17:04:26 -05:00
committed by Pasi Kallinen
parent c4bb3c904f
commit 35a2f6e3ed
21 changed files with 76 additions and 76 deletions

View File

@@ -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" })

View File

@@ -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

View File

@@ -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,'|')

View File

@@ -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);

View File

@@ -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);

View File

@@ -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] });

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
--

View File

@@ -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}, "-")

View File

@@ -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 })

View File

@@ -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" })

View File

@@ -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

View File

@@ -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" })

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
});