Attached Files |
layout_onion_city.txt [^] (5,062 bytes) 2014-05-17 06:03 [Show Content] [Hide Content]##############################################################
# layout_onion_city
#
# A map with many boxes, mostly inside each other.
#
NAME: layout_onion_city
DEPTH: Depths
WEIGHT: 10
ORIENT: encompass
TAGS: overwritable layout allow_dup unrand no_rotate no_hmirror no_vmirror
TAGS: layout_type_city
{{
local depth_fraction = you.depth_fraction()
local spacing_min = 1.9 + depth_fraction * 0.35
local spacing_range = 1 + crawl.random_real() * 1.5
local single_room_chance = crawl.random_range(1, 8 - depth_fraction * 5)
local further_subdivide_percent = crawl.random_range(40, 80)
- math.floor(depth_fraction * 30)
function onion_room (x1, y1, x2, y2)
local spacing = math.floor(spacing_min + crawl.random_real()*spacing_range)
local inner_size_min = spacing * 2 + 4 + spacing_min
local size_x = x2 - x1 + 1
local size_y = y2 - y1 + 1
-- center gap is included in room after division
local div_x_min = x1 + spacing + 2
local div_x_max = x2 - spacing * 2 - 2
local div_y_min = y1 + spacing + 2
local div_y_max = y2 - spacing * 2 - 2
local div_x_chance = math.max(0, div_x_max - div_x_min + 1)
local div_y_chance = math.max(0, div_y_max - div_y_min + 1)
local total_chance = single_room_chance + div_x_chance + div_y_chance
local chosen = crawl.random_range(0, total_chance - 1)
if (chosen < single_room_chance) then
-- place a single room
make_box { x1=x1, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2, number=1 }
if (size_x >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
elseif (chosen < single_room_chance + div_x_chance) then
-- place 2 rooms along x
local division = crawl.random_range(div_x_min, div_x_max)
local x2in = division
local x1in = division + spacing + 1
local size_x1 = x2in - x1 + 1
local size_x2 = x2 - x1in + 1
-- left room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2in, y2)
else
make_box { x1=x1, y1=y1, x2=x2in, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2in, y2=y2, number=1 }
if(size_x1 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2in - spacing - 1, y2 - spacing - 1)
end
end
-- right room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1in, y1, x2, y2)
else
make_box { x1=x1in, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1in, y1=y1, x2=x2, y2=y2, number=1 }
if(size_x2 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1in + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
else
-- place 2 rooms along y
local division = crawl.random_range(div_y_min, div_y_max)
local y2in = division
local y1in = division + spacing + 1
local size_y1 = y2in - y1 + 1
local size_y2 = y2 - y1in + 1
-- top room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2, y2in)
else
make_box { x1=x1, y1=y1, x2=x2, y2=y2in }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2in, number=1 }
if(size_x >= inner_size_min and size_y1 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2in - spacing - 1)
end
end
-- bottom room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1in, x2, y2)
else
make_box { x1=x1, y1=y1in, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1in, x2=x2, y2=y2, number=1 }
if(size_x >= inner_size_min and size_y2 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1in + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
end
end
local gxm, gym = dgn.max_bounds()
extend_map{width = gxm, height = gym, fill = 'x'}
local BORDER = 8
local MAX_X = gxm - BORDER - 1
local MAX_Y = gym - BORDER - 1
fill_area{fill = 'x'}
fill_area { x1 = BORDER, y1 = BORDER, x2 = MAX_X, y2 = MAX_Y, fill = "." }
local spacing = math.floor(spacing_min + crawl.random_real() * spacing_range)
onion_room (BORDER + spacing, BORDER + spacing,
MAX_X - spacing, MAX_Y - spacing)
-- the map is already connected in a tree, but more doors is nice
connect_adjacent_rooms { max = crawl.random_range(100, 250),
min = 50, replace = '+', check_empty = true }
}}
MAP
ENDMAP
onion-city-layouts.png [^] (20,845 bytes) 2014-05-17 06:03

0001-Add-LUA-function-to-find-areas-around-primary-vault.patch [^] (9,079 bytes) 2014-06-20 01:58 [Show Content] [Hide Content]From 74f21feac4aa66cce4a822dfd0bffdea77e6136f Mon Sep 17 00:00:00 2001
From: infiniplex <infiniplex@hotmail.com>
Date: Thu, 19 Jun 2014 17:57:52 -0600
Subject: [PATCH] Add LUA function to find areas around primary vault
---
crawl-ref/source/dat/dlua/layout/layout.lua | 187 ++++++++++++++++++++++++++++
crawl-ref/source/l_dgnbld.cc | 60 +++++++++
2 files changed, 247 insertions(+)
diff --git a/crawl-ref/source/dat/dlua/layout/layout.lua b/crawl-ref/source/dat/dlua/layout/layout.lua
index a5c4051..ac0d11c 100644
--- a/crawl-ref/source/dat/dlua/layout/layout.lua
+++ b/crawl-ref/source/dat/dlua/layout/layout.lua
@@ -23,3 +23,190 @@ layout.area_in_bounds = function(bounds,opt)
x2 = bounds.x1 + minpadx + posx + sizex - 1, y2 = bounds.y1 + minpady + posy + sizey - 1 }
end
+
+
+--
+-- get_areas_around_primary_vault
+--
+-- This function divides the map into up to 4 rectangular areas
+-- around the primary vault.
+--
+-- Parameter(s):
+-- -> e: A reference to the gobal enviroment. Pass in _G.
+-- -> x1
+-- -> y1
+-- -> x2
+-- -> y2: The maximum dimensions of the area to consider.
+--
+-- Returns: An array containing the areas. If there is no
+-- primary vault, the array will contain one area
+-- bounded by x1, y1, x2, and y2. If the primary
+-- vault covers evrything (e.g. an encompass vault) the
+-- array will contain zero areas. Otherwise, the array
+-- will contain 1 or more areas composing a
+-- non-overlapping subset of the area bounded by x1,
+-- y1, x2, and y2.
+--
+-- The area data structure has
+-- -> x_min,
+-- x_max,
+-- y_min,
+-- y_max: The inclusive bounds of the area. The area
+-- includes position (x_max, y_max).
+-- -> x_min_is_soft,
+-- x_max_is_soft,
+-- y_min_is_soft,
+-- y_max_is_soft: Whether each of the walls is "soft"
+--
+-- The 4 edges of each area will each be designated "hard" or
+-- "soft". An edge that only borders another open area is
+-- soft, while all other edges are hard. The layout may
+-- want to treat soft edges differently.
+--
+-- Example of area division:
+-- /////////////////////////////////
+-- //+---------------------------+//
+-- //| |//
+-- //| AREA 1 |//
+-- //| |//
+-- //+--------+---------+--------+//
+-- //| |/////////| |//
+-- //| |/PRIMARY/| |//
+-- //| |/////////| AREA 4 |//
+-- //| |//VAULT//| |//
+-- //| AREA 2 |/////////| |//
+-- //| +---------+--------+//
+-- //| | |//
+-- //| | AREA 3 |//
+-- //| | |//
+-- //+--------+------------------+//
+-- /////////////////////////////////
+--
+-- In this example, the following edges are soft:
+-- -> Area 1: None
+-- -> Area 2: y_min (top)
+-- -> Area 3: x_min (left)
+-- -> Area 4: y_min (top) and y_max (bottom)
+--
+
+layout.get_areas_around_primary_vault = function(e, x1, y1, x2, y2)
+
+ function set_all_edges_soft (area)
+ area.x_min_is_soft = false
+ area.x_max_is_soft = false
+ area.y_min_is_soft = false
+ area.y_max_is_soft = false
+ end
+
+ local areas = {}
+
+ -- get dimensions of primary vault
+ local p_x_min, p_x_max, p_y_min, p_y_max = e.primary_vault_dimensions()
+
+ if (p_x_min == nil) then
+ -- if there is no primary vault, just use the total size
+
+ areas[1] = {}
+ areas[1].x_min = x1
+ areas[1].x_max = x2
+ areas[1].y_min = y1
+ areas[1].y_max = y2
+ set_all_edges_soft(areas[1])
+
+ else
+ -- if there is a primary vault, divide up the area
+
+ -- 1. Decide which areas we need
+
+ local area_x_min = nil
+ if (p_x_min > x1) then
+ area_x_min = {}
+ area_x_min.x_min = x1
+ area_x_min.x_max = p_x_min - 1
+ area_x_min.y_min = math.max(y1, p_y_min)
+ area_x_min.y_max = math.min(y2, p_y_max)
+ set_all_edges_soft(area_x_min)
+ areas[#areas + 1] = area_x_min
+ end
+
+ local area_x_max = nil
+ if (p_x_max < x2) then
+ area_x_max = {}
+ area_x_max.x_min = p_x_max + 1
+ area_x_max.x_max = x2
+ area_x_max.y_min = math.max(y1, p_y_min)
+ area_x_max.y_max = math.min(y2, p_y_max)
+ set_all_edges_soft(area_x_max)
+ areas[#areas + 1] = area_x_max
+ end
+
+ local area_y_min = nil
+ if (p_y_min > y1) then
+ area_y_min = {}
+ area_y_min.x_min = math.max(x1, p_x_min)
+ area_y_min.x_max = math.min(x2, p_x_max)
+ area_y_min.y_min = y1
+ area_y_min.y_max = p_y_min - 1
+ set_all_edges_soft(area_y_min)
+ areas[#areas + 1] = area_y_min
+ end
+
+ local area_y_max = nil
+ if (p_y_max < y2) then
+ area_y_max = {}
+ area_y_max.x_min = math.max(x1, p_x_min)
+ area_y_max.x_max = math.min(x2, p_x_max)
+ area_y_max.y_min = p_y_max + 1
+ area_y_max.y_max = y2
+ set_all_edges_soft(area_y_max)
+ areas[#areas + 1] = area_y_max
+ end
+
+ -- 2. Expand an area to cover each needed corner
+ -- -> we choose which area to expand at random
+ -- -> the unexpanded area gets a soft wall
+
+ if (area_x_min ~= nil and area_y_min ~= nil) then
+ if (crawl.coinflip()) then
+ area_x_min.y_min = area_y_min.y_min
+ area_y_min.x_min_is_soft = true
+ else
+ area_y_min.x_min = area_x_min.x_min
+ area_x_min.y_min_is_soft = true
+ end
+ end
+
+ if (area_x_min ~= nil and area_y_max ~= nil) then
+ if (crawl.coinflip()) then
+ area_x_min.y_max = area_y_max.y_max
+ area_y_max.x_min_is_soft = true
+ else
+ area_y_max.x_min = area_x_min.x_min
+ area_x_min.y_max_is_soft = true
+ end
+ end
+
+ if (area_x_max ~= nil and area_y_min ~= nil) then
+ if (crawl.coinflip()) then
+ area_x_max.y_min = area_y_min.y_min
+ area_y_min.x_max_is_soft = true
+ else
+ area_y_min.x_max = area_x_max.x_max
+ area_x_max.y_min_is_soft = true
+ end
+ end
+
+ if (area_x_max ~= nil and area_y_max ~= nil) then
+ if (crawl.coinflip()) then
+ area_x_max.y_max = area_y_max.y_max
+ area_y_max.x_max_is_soft = true
+ else
+ area_y_max.x_max = area_x_max.x_max
+ area_x_max.y_max_is_soft = true
+ end
+ end
+
+ end
+
+ return areas
+end
diff --git a/crawl-ref/source/l_dgnbld.cc b/crawl-ref/source/l_dgnbld.cc
index 7936dc1..dbd3f5a 100644
--- a/crawl-ref/source/l_dgnbld.cc
+++ b/crawl-ref/source/l_dgnbld.cc
@@ -565,6 +565,65 @@ LUAFN(dgn_height)
PLUARET(number, lines.height());
}
+LUAFN(dgn_primary_vault_dimensions)
+{
+ LINES(ls, 1, lines);
+
+ static const int NO_PRIMARY_VAULT = 99999;
+
+ int x_min = NO_PRIMARY_VAULT;
+ int x_max = -NO_PRIMARY_VAULT;
+ int y_min = NO_PRIMARY_VAULT;
+ int y_max = -NO_PRIMARY_VAULT;
+
+ for (int y = 0; y < lines.height(); y++)
+ for (int x = 0; x < lines.width(); x++)
+ {
+ if(env.level_map_mask(coord_def(x,y)) & MMT_VAULT)
+ {
+ if (x < x_min)
+ x_min = x;
+ if (x > x_max)
+ x_max = x;
+ if (y < y_min)
+ y_min = y;
+ if (y > y_max)
+ y_max = y;
+ }
+ }
+
+ if(x_min != NO_PRIMARY_VAULT)
+ {
+ if(x_max == -NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has x_min %d but no x_max", x_min);
+ if(y_min == NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has x_min %d but no y_min", x_min);
+ if(y_max == -NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has x_min %d but no y_max", x_min);
+
+ lua_pushnumber(ls, x_min);
+ lua_pushnumber(ls, x_max);
+ lua_pushnumber(ls, y_min);
+ lua_pushnumber(ls, y_max);
+ }
+ else // no primary vault found
+ {
+ if(x_max != -NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has x_max %d but no x_min", x_max);
+ if(y_min != NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has y_min %d but no x_min", y_min);
+ if(y_max != -NO_PRIMARY_VAULT)
+ return luaL_error(ls, "Primary vault has y_max %d but no x_min", y_max);
+
+ lua_pushnil(ls);
+ lua_pushnil(ls);
+ lua_pushnil(ls);
+ lua_pushnil(ls);
+ }
+
+ return 4;
+}
+
LUAFN(dgn_join_the_dots)
{
LINES(ls, 1, lines);
@@ -2097,6 +2156,7 @@ const struct luaL_reg dgn_build_dlib[] =
{ "fill_disconnected", &dgn_fill_disconnected },
{ "find_in_area", &dgn_find_in_area },
{ "height", dgn_height },
+ { "primary_vault_dimensions", &dgn_primary_vault_dimensions },
{ "join_the_dots", &dgn_join_the_dots },
{ "make_circle", &dgn_make_circle },
{ "make_diamond", &dgn_make_diamond },
--
1.8.1.2
layout_onion_city.des [^] (6,854 bytes) 2014-06-20 01:59 [Show Content] [Hide Content]: require("dlua/layout/layout.lua")
##############################################################
# layout_onion_city
#
# A map with many boxes for rooms, mostly inside each other.
#
NAME: layout_onion_city
DEPTH: Elf, Pan
WEIGHT: 20 (Elf), 5 (Pan)
ORIENT: encompass
TAGS: overwritable layout allow_dup layout_type_city
TAGS: unrand no_rotate no_hmirror no_vmirror
{{
local depth_fraction = you.depth_fraction()
-- spacing between rooms
local spacing_min = 1.9 + depth_fraction * 0.6
local spacing_range = 0.85 + crawl.random_real() * 1.15
-- the chance a room contains only a single smaller room
local single_room_chance = crawl.random_range(1, 2 + depth_fraction * 6)
-- the chance a room split into 2 splits into (at least) 3
local further_subdivide_percent = crawl.random_range(50, 80)
- math.floor(depth_fraction * 30)
-- Randomize all parameters in Pan
if (you.in_branch("pan")) then
spacing_min = 1.8 + crawl.random_real() * 0.95
spacing_range = 0.95 + crawl.random_real() * 1.05
single_room_chance = math.min(crawl.random_range(1, 10),
crawl.random_range(1, 10))
further_subdivide_percent = crawl.random_range(40, 90)
end
-- this function makes one or more rooms to fill the area
function onion_room (x1, y1, x2, y2)
local spacing = math.floor(spacing_min + crawl.random_real()*spacing_range)
local inner_size_min = spacing * 2 + 3 + spacing_min
local size_x = x2 - x1 + 1
local size_y = y2 - y1 + 1
-- center gap is included in room after division
local div_x_min = x1 + spacing + 2
local div_x_max = x2 - spacing * 2 - 2
local div_y_min = y1 + spacing + 2
local div_y_max = y2 - spacing * 2 - 2
local div_x_chance = math.max(0, div_x_max - div_x_min + 1)
local div_y_chance = math.max(0, div_y_max - div_y_min + 1)
local total_chance = single_room_chance + div_x_chance + div_y_chance
local chosen = crawl.random_range(0, total_chance - 1)
if (chosen < single_room_chance) then
-- place a single room
make_box { x1=x1, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2, number=1 }
if (size_x >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
elseif (chosen < single_room_chance + div_x_chance) then
-- place 2 rooms along x
local division = crawl.random_range(div_x_min, div_x_max)
local x2in = division
local x1in = division + spacing + 1
local size_x1 = x2in - x1 + 1
local size_x2 = x2 - x1in + 1
-- left room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2in, y2)
else
make_box { x1=x1, y1=y1, x2=x2in, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2in, y2=y2, number=1 }
if(size_x1 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2in - spacing - 1, y2 - spacing - 1)
end
end
-- right room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1in, y1, x2, y2)
else
make_box { x1=x1in, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1in, y1=y1, x2=x2, y2=y2, number=1 }
if(size_x2 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1in + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
else
-- place 2 rooms along y
local division = crawl.random_range(div_y_min, div_y_max)
local y2in = division
local y1in = division + spacing + 1
local size_y1 = y2in - y1 + 1
local size_y2 = y2 - y1in + 1
-- top room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2, y2in)
else
make_box { x1=x1, y1=y1, x2=x2, y2=y2in }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2in, number=1 }
if(size_x >= inner_size_min and size_y1 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2in - spacing - 1)
end
end
-- bottom room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1in, x2, y2)
else
make_box { x1=x1, y1=y1in, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1in, x2=x2, y2=y2, number=1 }
if(size_x >= inner_size_min and size_y2 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1in + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
end
end
local gxm, gym = dgn.max_bounds()
extend_map{width = gxm, height = gym, fill = 'x'}
local BORDER = 8
local MAX_X = gxm - BORDER - 1
local MAX_Y = gym - BORDER - 1
fill_area{fill = 'x'}
fill_area { x1 = BORDER, y1 = BORDER, x2 = MAX_X, y2 = MAX_Y, fill = "." }
local spacing = math.floor(spacing_min + crawl.random_real() * spacing_range)
local size_min = spacing_min + 3
local areas = layout.get_areas_around_primary_vault(_G, BORDER, BORDER,
MAX_X, MAX_Y)
for i = 1, #areas do
-- move soft edges inward so that they don't hit the walls
-- we don't move soft edges in
if (not areas[i].x_min_is_soft) then
areas[i].x_min = areas[i].x_min + spacing
end
if (not areas[i].x_max_is_soft) then
areas[i].x_max = areas[i].x_max - spacing
end
if (not areas[i].y_min_is_soft) then
areas[i].y_min = areas[i].y_min + spacing
end
if (not areas[i].y_max_is_soft) then
areas[i].y_max = areas[i].y_max - spacing
end
-- add the rooms if there is enough space
local size_x = areas[i].x_max - areas[i].x_min + 1
local size_y = areas[i].y_max - areas[i].y_min + 1
if(size_x >= size_min and size_y >= size_min) then
onion_room (areas[i].x_min, areas[i].y_min,
areas[i].x_max, areas[i].y_max)
end
end
-- the map is already connected in a tree, but more doors is nice
connect_adjacent_rooms { max = crawl.random_range(100, 250),
min = 50, replace = '+', check_empty = true }
-- add windows in Elf
if (you.in_branch("elf")) then
connect_adjacent_rooms { max = 400, min = 100,
replace = 'm', check_empty = false }
end
}}
MAP
ENDMAP
onion-city-layouts2.png [^] (23,486 bytes) 2014-06-20 01:59

layout_onion_city2.des [^] (6,861 bytes) 2014-06-20 02:06 [Show Content] [Hide Content]: require("dlua/layout/layout.lua")
##############################################################
# layout_onion_city
#
# A map with many boxes for rooms, mostly inside each other.
#
NAME: layout_onion_city
DEPTH: Elf, Pan
WEIGHT: 20 (Elf), 5 (Pan)
ORIENT: encompass
TAGS: overwritable layout allow_dup unrand layout_type_city
TAGS: unrand no_rotate no_hmirror no_vmirror
{{
local depth_fraction = you.depth_fraction()
-- spacing between rooms
local spacing_min = 1.9 + depth_fraction * 0.6
local spacing_range = 0.85 + crawl.random_real() * 1.15
-- the chance a room contains only a single smaller room
local single_room_chance = crawl.random_range(1, 2 + depth_fraction * 6)
-- the chance a room split into 2 splits into (at least) 3
local further_subdivide_percent = crawl.random_range(50, 80)
- math.floor(depth_fraction * 30)
-- Randomize all parameters in Pan
if (you.in_branch("pan")) then
spacing_min = 1.8 + crawl.random_real() * 0.95
spacing_range = 0.95 + crawl.random_real() * 1.05
single_room_chance = math.min(crawl.random_range(1, 10),
crawl.random_range(1, 10))
further_subdivide_percent = crawl.random_range(40, 90)
end
-- this function makes one or more rooms to fill the area
function onion_room (x1, y1, x2, y2)
local spacing = math.floor(spacing_min + crawl.random_real()*spacing_range)
local inner_size_min = spacing * 2 + 3 + spacing_min
local size_x = x2 - x1 + 1
local size_y = y2 - y1 + 1
-- center gap is included in room after division
local div_x_min = x1 + spacing + 2
local div_x_max = x2 - spacing * 2 - 2
local div_y_min = y1 + spacing + 2
local div_y_max = y2 - spacing * 2 - 2
local div_x_chance = math.max(0, div_x_max - div_x_min + 1)
local div_y_chance = math.max(0, div_y_max - div_y_min + 1)
local total_chance = single_room_chance + div_x_chance + div_y_chance
local chosen = crawl.random_range(0, total_chance - 1)
if (chosen < single_room_chance) then
-- place a single room
make_box { x1=x1, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2, number=1 }
if (size_x >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
elseif (chosen < single_room_chance + div_x_chance) then
-- place 2 rooms along x
local division = crawl.random_range(div_x_min, div_x_max)
local x2in = division
local x1in = division + spacing + 1
local size_x1 = x2in - x1 + 1
local size_x2 = x2 - x1in + 1
-- left room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2in, y2)
else
make_box { x1=x1, y1=y1, x2=x2in, y2=y2 }
make_box_doors { x1=x1, y1=y1, x2=x2in, y2=y2, number=1 }
if(size_x1 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2in - spacing - 1, y2 - spacing - 1)
end
end
-- right room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1in, y1, x2, y2)
else
make_box { x1=x1in, y1=y1, x2=x2, y2=y2 }
make_box_doors { x1=x1in, y1=y1, x2=x2, y2=y2, number=1 }
if(size_x2 >= inner_size_min and size_y >= inner_size_min) then
onion_room (x1in + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
else
-- place 2 rooms along y
local division = crawl.random_range(div_y_min, div_y_max)
local y2in = division
local y1in = division + spacing + 1
local size_y1 = y2in - y1 + 1
local size_y2 = y2 - y1in + 1
-- top room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1, x2, y2in)
else
make_box { x1=x1, y1=y1, x2=x2, y2=y2in }
make_box_doors { x1=x1, y1=y1, x2=x2, y2=y2in, number=1 }
if(size_x >= inner_size_min and size_y1 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1 + spacing + 1,
x2 - spacing - 1, y2in - spacing - 1)
end
end
-- bottom room
if (crawl.x_chance_in_y(further_subdivide_percent, 100)) then
onion_room (x1, y1in, x2, y2)
else
make_box { x1=x1, y1=y1in, x2=x2, y2=y2 }
make_box_doors { x1=x1, y1=y1in, x2=x2, y2=y2, number=1 }
if(size_x >= inner_size_min and size_y2 >= inner_size_min) then
onion_room (x1 + spacing + 1, y1in + spacing + 1,
x2 - spacing - 1, y2 - spacing - 1)
end
end
end
end
local gxm, gym = dgn.max_bounds()
extend_map{width = gxm, height = gym, fill = 'x'}
local BORDER = 8
local MAX_X = gxm - BORDER - 1
local MAX_Y = gym - BORDER - 1
fill_area{fill = 'x'}
fill_area { x1 = BORDER, y1 = BORDER, x2 = MAX_X, y2 = MAX_Y, fill = "." }
local spacing = math.floor(spacing_min + crawl.random_real() * spacing_range)
local size_min = spacing_min + 3
local areas = layout.get_areas_around_primary_vault(_G, BORDER, BORDER,
MAX_X, MAX_Y)
for i = 1, #areas do
-- move soft edges inward so that they don't hit the walls
-- we don't move soft edges in
if (not areas[i].x_min_is_soft) then
areas[i].x_min = areas[i].x_min + spacing
end
if (not areas[i].x_max_is_soft) then
areas[i].x_max = areas[i].x_max - spacing
end
if (not areas[i].y_min_is_soft) then
areas[i].y_min = areas[i].y_min + spacing
end
if (not areas[i].y_max_is_soft) then
areas[i].y_max = areas[i].y_max - spacing
end
-- add the rooms if there is enough space
local size_x = areas[i].x_max - areas[i].x_min + 1
local size_y = areas[i].y_max - areas[i].y_min + 1
if(size_x >= size_min and size_y >= size_min) then
onion_room (areas[i].x_min, areas[i].y_min,
areas[i].x_max, areas[i].y_max)
end
end
-- the map is already connected in a tree, but more doors is nice
connect_adjacent_rooms { max = crawl.random_range(100, 250),
min = 50, replace = '+', check_empty = true }
-- add windows in Elf
if (you.in_branch("elf")) then
connect_adjacent_rooms { max = 400, min = 100,
replace = 'm', check_empty = false }
end
}}
MAP
ENDMAP
|