summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorJude Brown <bookofjude@users.sourceforge.net>2010-01-12 22:09:51 +1000
committerJude Brown <bookofjude@users.sourceforge.net>2010-01-13 21:44:55 +1000
commited8f8e0dbefef13fc35572729c5f6b5cf70ebc1b (patch)
tree0edc1534af0ed08b6f4fae1cbec15807625f3203 /crawl-ref
parent2ee889338d8f6210ebedf62ad734dd838fa9b84e (diff)
downloadcrawl-ref-ed8f8e0dbefef13fc35572729c5f6b5cf70ebc1b.tar.gz
crawl-ref-ed8f8e0dbefef13fc35572729c5f6b5cf70ebc1b.zip
Convert _city_level to Lua.
This commit translates the original C++ _city_level code into Lua. It opens up the way for nicer Vault layouts, using a series of subvaults. Hopefully it doesn't break anything too much! Should be reverted if it does.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dat/layout.des125
-rw-r--r--crawl-ref/source/dungeon.cc82
2 files changed, 133 insertions, 74 deletions
diff --git a/crawl-ref/source/dat/layout.des b/crawl-ref/source/dat/layout.des
index a620e3bd0c..0d0cee8a28 100644
--- a/crawl-ref/source/dat/layout.des
+++ b/crawl-ref/source/dat/layout.des
@@ -383,3 +383,128 @@ TAGS: layout allow_dup
}}
MAP
ENDMAP
+
+##############################################################
+# layout_city
+#
+# This replaces dungeon.cc:_city_level().
+#
+NAME: layout_city
+ORIENT: encompass
+TAGS: layout allow_dup
+{{
+ function treasure_area (x1, y1, x2, y2)
+ x2 = x2 + 1
+ y2 = y2 + 1
+
+ if x2 <= x2 or y2 <= y2 then
+ return false
+ end
+
+ if (x2 - x1) * (y2 - y1) >= 40 then
+ return false
+ end
+
+ local tl = dgn.point(x1, y1)
+ local br = dgn.point(x2 - 1, y2 - 1)
+
+ for point in iter.rect_iterator(tl, br) do
+ if is_valid_coord {x = point.x, y = point.y } then
+ if is_passable_coord { x=point.x, y=point.y } or crawl.coinflip() then
+ mapgrd[point.x][point.y] = "|"
+ end
+ end
+ end
+
+ return true
+ end
+
+ local gxm, gym = dgn.max_bounds()
+
+ extend_map{width = gxm, height = gym, fill = 'x'}
+ fill_area{fill = 'x'}
+
+
+ local temp_rand = crawl.random2(8)
+ local wall_type_room
+ local wall_type
+ local rooms = {}
+
+ local xs = 0
+ local ys = 0
+ local ax1 = 0
+ local bx2 = 0
+ local ay1 = 0
+ local by2 = 0
+ local i, j
+
+ if temp_rand > 4 then
+ wall_type = 'x'
+ elseif temp_rand > 2 then
+ wall_type = 'c'
+ else
+ wall_type = 'v'
+ end
+
+ if crawl.one_chance_in(100) then
+ wall_type = 'b'
+ end
+
+ fill_area { x1=8, y1=8, x2=gxm-9, y2=gym-9, fill="." }
+
+ for i = 0, 5 do
+ for j = 0, 4 do
+ xs = 8 + (i * 13)
+ ys = 8 + (j * 14)
+ a1 = xs + crawl.random2avg(5, 2);
+ a2 = ys + crawl.random2avg(5, 2);
+ b1 = xs + 11 - crawl.random2avg(5, 2);
+ b2 = ys + 11 - crawl.random2avg(5, 2);
+
+ temp_rand = crawl.random2(280);
+
+ if temp_rand > 39 and is_valid_coord {x=a1, y=a2} and is_valid_coord{x=b1, y=b2} then
+ if temp_rand > 63 then
+ wall_type_room = wall_type
+ elseif temp_rand > 54 then
+ wall_type_room = "c"
+ elseif temp_rand > 45 then
+ wall_type_room = "x"
+ else
+ wall_type_room = "v"
+ end
+
+ if crawl.one_chance_in(250) then
+ wall_type_room = "b"
+ end
+
+ table.insert(rooms, {a1, a2, b1, b2})
+ make_box { x1=a1, y1=a2, x2=b1, y2=b2, wall=wall_type_room }
+
+ if b1 - a1 > 5 and b2 - a2 > 5 and crawl.one_chance_in(8) then
+ table.insert(rooms, {a1+2, a2+2, b1-2, b2-2})
+ make_box { x1=a1+2, y1=a2+2, x2=b1-2, y2=b2-2, wall=wall_type_room }
+
+ if crawl.one_chance_in(3) then
+ treasure_area(a1+3, a2+3, b1-3, b2-3)
+ end
+ end
+ end
+ end
+ end
+
+ for _, room in ipairs(rooms) do
+ local doors = 1 + crawl.random2(5) - crawl.random2(3)
+ if doors < 1 then
+ doors = 1
+ end
+
+ if doors > 3 and crawl.one_chance_in(3) then
+ doors = 2
+ end
+
+ make_box_doors {x1=room[1], y1=room[2], x2=room[3], y2=room[4], number=doors}
+ end
+}}
+MAP
+ENDMAP
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index c9a29e76e7..442ff363b1 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -2561,10 +2561,10 @@ static builder_rc_type _builder_normal(int level_number, char level_type,
if (player_in_branch( BRANCH_VAULTS ))
{
- if (one_chance_in(3))
- _city_level(level_number);
- else
- _plan_main(level_number, 4);
+ //if (one_chance_in(3))
+ _city_level(level_number);
+ //else
+ // _plan_main(level_number, 4);
return BUILD_SKIP;
}
@@ -7122,77 +7122,11 @@ static void _city_level(int level_number)
dgn_Build_Method += make_stringf(" city_level [%d]", level_number);
dgn_Layout_Type = "city";
- int temp_rand; // probability determination {dlb}
- // Remember, can have many wall types in one level.
- dungeon_feature_type wall_type;
- // Simplifies logic of innermost loop. {dlb}
- dungeon_feature_type wall_type_room;
-
- int xs = 0, ys = 0;
- int x1 = 0, x2 = 0;
- int y1 = 0, y2 = 0;
- int i,j;
-
- temp_rand = random2(8);
-
- wall_type = ((temp_rand > 4) ? DNGN_ROCK_WALL : // 37.5% {dlb}
- (temp_rand > 1) ? DNGN_STONE_WALL // 37.5% {dlb}
- : DNGN_METAL_WALL); // 25.0% {dlb}
-
- if (one_chance_in(100))
- wall_type = DNGN_GREEN_CRYSTAL_WALL;
-
- _make_box( 7, 7, GXM-7, GYM-7, DNGN_FLOOR );
-
- for (i = 0; i < 5; i++)
- for (j = 0; j < 4; j++)
- {
- xs = 8 + (i * 13);
- ys = 8 + (j * 14);
- x1 = xs + random2avg(5, 2);
- y1 = ys + random2avg(5, 2);
- x2 = xs + 11 - random2avg(5, 2);
- y2 = ys + 11 - random2avg(5, 2);
-
- temp_rand = random2(280);
-
- if (temp_rand > 39) // 85.7% draw room(s) {dlb}
- {
- wall_type_room = ((temp_rand > 63) ? wall_type : // 77.1%
- (temp_rand > 54) ? DNGN_STONE_WALL : // 3.2%
- (temp_rand > 45) ? DNGN_ROCK_WALL // 3.2%
- : DNGN_METAL_WALL); // 2.1%
-
- if (one_chance_in(250))
- wall_type_room = DNGN_GREEN_CRYSTAL_WALL;
-
- _box_room(x1, x2, y1, y2, wall_type_room);
-
- // Inner room - neat.
- if (x2 - x1 > 5 && y2 - y1 > 5 && one_chance_in(8))
- {
- _box_room(x1 + 2, x2 - 2, y1 + 2, y2 - 2, wall_type);
-
- // Treasure area... neat.
- if (one_chance_in(3))
- {
- _treasure_area(level_number, x1 + 3, x2 - 3,
- y1 + 3, y2 - 3);
- }
- }
- }
- }
-
- int stair_count = coinflip() ? 4 : 3;
-
- for (j = 0; j < stair_count; j++)
- for (i = 0; i < 2; i++)
- {
- _place_specific_stair( static_cast<dungeon_feature_type>(
- j + ((i == 0) ? DNGN_STONE_STAIRS_DOWN_I
- : DNGN_STONE_STAIRS_UP_I)) );
- }
+ const map_def *vault = find_map_by_name("layout_city");
+ ASSERT(vault);
+ bool success = _build_vaults(level_number, vault);
+ dgn_ensure_vault_placed(success, false);
}
static bool _treasure_area(int level_number, unsigned char ta1_x,