From 2c1931a103ed51b5cc3b9ee203de22e74d5b6843 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Sat, 17 May 2008 17:46:48 +0000 Subject: Adding _plan_1() (the donut room) into layout.des. Vaults can now have zero size. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5099 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/dat/layout.des | 177 ++++++++++++++++++++++++++++++++++++++-- crawl-ref/source/dungeon.cc | 76 +++-------------- crawl-ref/source/mapdef.cc | 3 - 3 files changed, 180 insertions(+), 76 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/dat/layout.des b/crawl-ref/source/dat/layout.des index 0727074e79..366100d082 100644 --- a/crawl-ref/source/dat/layout.des +++ b/crawl-ref/source/dat/layout.des @@ -7,6 +7,8 @@ ############################################################################### lua {{ + -- TODO enne - most of these should probably get moved back into C++ + function fill_area(x1, y1, x2, y2, feature) for x = x1, x2 do for y = y1, y2 do @@ -15,18 +17,20 @@ lua {{ end end - function octa_room(x1, y1, x2, y2, oblique, floor) + function octa_room(x1, y1, x2, y2, oblique, fill) local ob_temp = oblique local rock_wall = dgn.feature_number("rock_wall") local shallow_water = dgn.feature_number("shallow_water") + local deep_water = dgn.feature_number("deep_water") + local floor = dgn.feature_number("floor") for x = x1, x2 do for y = y1 + ob_temp, y2 - ob_temp do if dgn.grid(x, y) == rock_wall then - dgn.grid(x, y, floor) + dgn.grid(x, y, fill) end - if dgn.grid(x, y) == floor and floor == shallow_water then + if dgn.grid(x, y) == floor and (fill == shallow_water or fill == deep_water) then dgn.grid(x, y, shallow_water) end end @@ -135,8 +139,162 @@ lua {{ return false end end + + function spotty_level(boxy, x1, y1, x2, y2) + local iterations + -- boxy levels have more clearing, so they get fewer iterations + if boxy then + iterations = 200 + crawl.random2(750) + else + iterations = 200 + crawl.random2(1500) + end + + make_spotty(iterations, boxy, x1, y1, x2, y2) + end + + -- randomly turns walls into floors + function make_spotty(iterations, boxy, x1, y1, x2, y2) + if x2 - x1 - 8 <= 0 or y2 - y1 - 8 <= 0 then + return + end + + local wall = dgn.feature_number("rock_wall") + local floor = dgn.feature_number("floor") + + for i = 1, iterations do + local x, y + repeat + x = crawl.random2(x2 - x1 - 7) + x1 + 4 + y = crawl.random2(y2 - y1 - 7) + y1 + 4 + until dgn.grid(x, y) ~= wall or + dgn.grid(x-1, y) ~= wall or + dgn.grid(x+1, y) ~= wall or + dgn.grid(x, y-1) ~= wall or + dgn.grid(x, y+1) ~= wall or + dgn.grid(x-2, y) ~= wall or + dgn.grid(x+2, y) ~= wall or + dgn.grid(x, y-2) ~= wall or + dgn.grid(x, y+2) ~= wall + + -- convenience function + function replace_grid(x, y, search, replace) + if dgn.grid(x, y) == search then + dgn.grid(x, y, replace) + end + end + + replace_grid(x, y, wall, floor) + replace_grid(x, y-1, wall, floor) + replace_grid(x, y+1, wall, floor) + replace_grid(x-1, y, wall, floor) + replace_grid(x+1, y, wall, floor) + + if boxy then + replace_grid(x-1, y-1, wall, floor) + replace_grid(x+1, y+1, wall, floor) + replace_grid(x-1, y+1, wall, floor) + replace_grid(x+1, y-1, wall, floor) + end + end + end + + -- randomly extends walls onto floors + function smear_feature(iterations, boxy, feature, x1, y1, x2, y2) + for i = 1, iterations do + local x, y + function check_box(x, y, feature) + return dgn.grid(x+1, y) == feature or + dgn.grid(x-1, y) == feature or + dgn.grid(x, y+1) == feature or + dgn.grid(x, y-1) == feature + end + function check_diagonal(x, y, feature) + return dgn.grid(x+1, y+1) == feature or + dgn.grid(x-1, y+1) == feature or + dgn.grid(x-1, y-1) == feature or + dgn.grid(x+1, y-1) == feature + end + + repeat + x = crawl.random2(x2 - x1 - 2) + x1 + 1 + y = crawl.random2(y2 - y1 - 2) + y1 + 1 + until dgn.grid(x, y) ~= feature and + (check_box(x, y, feature) or + not boxy and check_diagonal(x, y, feature)) + + dgn.grid(x, y, feature) + end + end }} +############################################################## +# layout_forbidden_doughnut +# +# This replaces dungeon.cc:_plan_1(). It usually creates a +# room with a large hole in the middle. +# +NAME: layout_forbidden_donut +ORIENT: encompass +TAGS: layout allow_dup + +{{ + local gxm, gym = dgn.max_bounds() + local wall = dgn.feature_number("rock_wall") + local floor = dgn.feature_number("floor") + fill_area(0, 0, gxm - 1, gym - 1, wall) + + local width = (10 - crawl.random2(7)) + + -- construct donut + fill_area(10, 10, gxm - 10, 10 + width, floor) + fill_area(10, 60 - width, gxm - 10, gym - 10, floor) + fill_area(10, 10, 10 + width, gym - 10, floor) + fill_area(60 - width, 10, gxm - 10, gym - 10, floor) + + local spotty = crawl.coinflip() + local smears = crawl.random2(300) + + -- sometimes add a hallway cross through center + if crawl.coinflip() then + local width2 = 1 + crawl.random2(5) + + fill_area(10, gym/2 - width2, gxm - 10, gym/2 + width2, floor) + fill_area(gxm/2 - width2, 10, gxm/2 + width2, gym - 10, floor) + + -- sometimes add a small octagon room + if crawl.coinflip() and crawl.random2(15) > 7 then + local oblique = 0 + if crawl.coinflip() then + oblique = 5 + crawl.random2(20) + end + + local feature_name = select_from_weighted_table({ + ["floor"] = 5, + ["deep_water"] = 1, + ["lava"] = 1, + }) + local feature_idx = dgn.feature_number(feature_name) + + octa_room(25, 25, gxm - 25, gym - 25, oblique, feature_idx) + + -- decrease spotty chance + spotty = crawl.one_chance_in(5) + end + end + + local spotty_boxy = crawl.coinflip() + local smear_boxy = crawl.coinflip() + + if spotty then + spotty_level(spotty_boxy, 0, 0, gxm - 1, gym - 1) + end + if not spotty and crawl.one_chance_in(4) or spotty then + smear_feature(smears, smear_boxy, wall, 0, 0, gxm - 1, gym - 1) + end +}} +MAP +ENDMAP + ############################################################## # layout_cross # @@ -185,13 +343,14 @@ TAGS: layout allow_dup fill_area(10, gym/2 - height, gxm - 10, gym/2 + height, floor) fill_area(gxm/2 - width, 10, gxm/2 + width, gym - 10, floor) - -- TODO enne - add lua function for spotty() + if not crawl.one_chance_in(4) then + spotty_level(crawl.coinflip(), 0, 0, gxm - 1, gym - 1) + end }} MAP -. ENDMAP -############################################################## +############################################################# # layout_big_octagon # # This replaces dungeon.cc:_plan_6(). It has an octagonal @@ -214,6 +373,11 @@ TAGS: layout allow_dup fill_area(0, 0, gxm - 1, gym - 1, wall) octa_room(10, 10, gxm - 10, gym - 10, oblique, floor) + if crawl.coinflip() then + local iterations = 100 + crawl.random2(200) + smear_feature(iterations, false, wall, 0, 0, gxm - 1, gym - 1) + end + -- Step 2: Add pillars -- pillar types and relative weights @@ -299,5 +463,4 @@ TAGS: layout allow_dup end }} MAP -. ENDMAP diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index 0e74a08826..b51759ba37 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -168,7 +168,7 @@ static void _build_lake(dungeon_feature_type lake_type); //mv static void _spotty_level(bool seeded, int iterations, bool boxy); static void _bigger_room(); static void _plan_main(int level_number, int force_plan); -static char _plan_1(); +static char _plan_1(int level_number); static char _plan_2(int level_number); static char _plan_3(); static char _plan_4(char forbid_x1, char forbid_y1, char forbid_x2, @@ -5770,7 +5770,7 @@ static void _plan_main(int level_number, int force_plan) if (!force_plan) force_plan = 1 + random2(12); - do_stairs = ((force_plan == 1) ? _plan_1() : + do_stairs = ((force_plan == 1) ? _plan_1(level_number) : (force_plan == 2) ? _plan_2(level_number) : (force_plan == 3) ? _plan_3() : (force_plan == 4) ? _plan_4(0, 0, 0, 0, NUM_FEATURES) : @@ -5799,74 +5799,18 @@ static void _plan_main(int level_number, int force_plan) _replace_area(0, 0, GXM-1, GYM-1, DNGN_ROCK_WALL, special_grid); } // end plan_main() -static char _plan_1() +static char _plan_1(int level_number) { dgn_Build_Method = "plan_1"; - int temp_rand = 0; // probability determination {dlb} - - unsigned char width = (10 - random2(7)); // value range of [4,10] {dlb} - - _replace_area(10, 10, (GXM - 10), (10 + width), DNGN_ROCK_WALL, DNGN_FLOOR); - _replace_area(10, (60 - width), (GXM - 10), (GYM - 10), - DNGN_ROCK_WALL, DNGN_FLOOR); - _replace_area(10, 10, (10 + width), (GYM - 10), DNGN_ROCK_WALL, DNGN_FLOOR); - _replace_area((60 - width), 10, (GXM - 10), (GYM - 10), - DNGN_ROCK_WALL, DNGN_FLOOR); - - // possible early returns {dlb}: - temp_rand = random2(4); - - if (temp_rand > 2) // 25% chance {dlb} - return 3; - else if (temp_rand > 1) // 25% chance {dlb} - return 2; - else // 50% chance {dlb} - { - unsigned char width2 = (coinflip()? (1 + random2(5)) : 5); - - _replace_area(10, (35 - width2), (GXM - 10), (35 + width2), - DNGN_ROCK_WALL, DNGN_FLOOR); - _replace_area((40 - width2), 10, (40 + width2), (GYM - 10), - DNGN_ROCK_WALL, DNGN_FLOOR); - } - - // possible early returns {dlb}: - temp_rand = random2(4); - - if (temp_rand > 2) // 25% chance {dlb} - return 3; - else if (temp_rand > 1) // 25% chance {dlb} - return 2; - else // 50% chance {dlb} - { - temp_rand = random2(15); - - if (temp_rand > 7) // 7 in 15 odds {dlb} - { - spec_room sr; - sr.x1 = 25; - sr.y1 = 25; - sr.x2 = (GXM - 25); - sr.y2 = (GYM - 25); - - int oblique_max = 0; - if (coinflip()) - oblique_max = 5 + random2(20); - - temp_rand = random2(7); + const int vault = random_map_for_tag("layout", false, true); + ASSERT(vault != -1); - dungeon_feature_type floor_type = - ((temp_rand > 1) ? DNGN_FLOOR : // 5/7 - (temp_rand > 0) ? DNGN_DEEP_WATER// 1/7 - : DNGN_LAVA); // 1/7 - _octa_room(sr, oblique_max, floor_type); - } - } + bool success = _build_vaults(level_number, vault); + _ensure_vault_placed(success); - // final return {dlb}: - return (one_chance_in(5) ? 3 : 2); -} // end plan_1() + return 0; +} // end plan_2() static char _plan_2(int level_number) { @@ -5878,7 +5822,7 @@ static char _plan_2(int level_number) bool success = _build_vaults(level_number, vault); _ensure_vault_placed(success); - return (one_chance_in(4) ? 0 : 1); + return 0; } // end plan_2() static char _plan_3() diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc index 35c95428b8..0e3c65d1da 100644 --- a/crawl-ref/source/mapdef.cc +++ b/crawl-ref/source/mapdef.cc @@ -1455,9 +1455,6 @@ std::string map_def::validate_map_def() } } - if (map.height() == 0) - return ("Must define map."); - switch (orient) { case MAP_NORTH: case MAP_SOUTH: -- cgit v1.2.3-54-g00ecf