summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dat/clua/ziggurat.lua32
-rw-r--r--crawl-ref/source/dat/ziggurat.des25
-rw-r--r--crawl-ref/source/hiscores.cc4
-rw-r--r--crawl-ref/source/hiscores.h1
-rw-r--r--crawl-ref/source/luadgn.cc106
-rw-r--r--crawl-ref/source/travel.h12
6 files changed, 177 insertions, 3 deletions
diff --git a/crawl-ref/source/dat/clua/ziggurat.lua b/crawl-ref/source/dat/clua/ziggurat.lua
index 3696a99d3b..29aa01d6fc 100644
--- a/crawl-ref/source/dat/clua/ziggurat.lua
+++ b/crawl-ref/source/dat/clua/ziggurat.lua
@@ -291,6 +291,35 @@ local function ziggurat_create_loot(c)
end
end
+local function ziggurat_place_pillars(c)
+ local range = crawl.random_range
+
+ local function pillar_spot()
+ local floor = dgn.fnum("floor")
+ for i = 1, 100 do
+ local place = { x = c.x + range(-30, 30), y = c.y + range(-30, 30) }
+ if (dgn.grid(place.x, place.y) == floor) then
+ return place
+ end
+ end
+ return nil
+ end
+
+ local function place_pillar(p)
+ local map = dgn.map_by_tag("ziggurat_pillar")
+ if map then
+ dgn.place_map(map, false, true, p.x, p.y)
+ end
+ end
+
+ for i = 1, crawl.random_range(1,3) do
+ local p = pillar_spot()
+ if p then
+ place_pillar(p)
+ end
+ end
+end
+
local function ziggurat_rectangle_builder(e)
local grid = dgn.grid
@@ -302,6 +331,7 @@ local function ziggurat_rectangle_builder(e)
dgn.fill_area(unpack( util.catlist(flip_rectangle(x1, y1, x2, y2),
{ "floor" }) ) )
+ local cx = math.floor((x1 + x2) / 2)
local cy = math.floor((y1 + y2) / 2)
local entry = { x = x1, y = cy }
@@ -316,6 +346,8 @@ local function ziggurat_rectangle_builder(e)
grid(exit.x, exit.y + 1, "exit_portal_vault")
grid(exit.x, exit.y - 1, "exit_portal_vault")
+ ziggurat_place_pillars { x = cx, y = cy }
+
ziggurat_create_loot(exit)
ziggurat_create_monsters(exit)
diff --git a/crawl-ref/source/dat/ziggurat.des b/crawl-ref/source/dat/ziggurat.des
index 73ce42e5ff..886f7514f1 100644
--- a/crawl-ref/source/dat/ziggurat.des
+++ b/crawl-ref/source/dat/ziggurat.des
@@ -15,6 +15,31 @@ MAP
O
ENDMAP
+#######################################################################
+# Pillars for ziggurats.
+#######################################################################
+NAME: ziggurat_pillar_a
+TAGS: ziggurat_pillar
+SUBST: c : cxv
+MAP
+c
+ENDMAP
+
+NAME: ziggurat_pillar_b
+TAGS: ziggurat_pillar
+SUBST: c : cxv
+MAP
+cc
+cc
+ENDMAP
+
+NAME: ziggurat_pillar_c
+TAGS: ziggurat_pillar
+MAP
+lll
+lGl
+lll
+ENDMAP
NAME: ziggurat1
: ziggurat_level(_G)
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 9938e379b0..14d598fd77 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -587,7 +587,7 @@ const char *level_area_type_name(int level_type)
return ("");
}
-static level_area_type _str_to_level_area_type(const std::string &s)
+level_area_type str_to_level_area_type(const std::string &s)
{
for (int i = 0; i < NUM_LEVEL_AREA_TYPES; ++i)
if (s == level_type_names[i])
@@ -616,7 +616,7 @@ void scorefile_entry::init_with_fields()
branch = str_to_branch(fields->str_field("br"), BRANCH_MAIN_DUNGEON);
dlvl = fields->int_field("lvl");
- level_type = _str_to_level_area_type(fields->str_field("ltyp"));
+ level_type = str_to_level_area_type(fields->str_field("ltyp"));
final_hp = fields->int_field("hp");
final_max_hp = fields->int_field("mhp");
diff --git a/crawl-ref/source/hiscores.h b/crawl-ref/source/hiscores.h
index 7016f55f4a..ef16d58da3 100644
--- a/crawl-ref/source/hiscores.h
+++ b/crawl-ref/source/hiscores.h
@@ -40,6 +40,7 @@ std::string hiscores_format_single_long( const scorefile_entry &se,
bool verbose = false );
const char *level_area_type_name(int level_type);
+level_area_type str_to_level_area_type(const std::string &s);
#ifdef DGL_MILESTONES
void mark_milestone(const std::string &type, const std::string &milestone);
diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc
index 60834c3c64..7a0d1bddfc 100644
--- a/crawl-ref/source/luadgn.cc
+++ b/crawl-ref/source/luadgn.cc
@@ -2159,6 +2159,106 @@ BRANCHFN(parent_branch, string,
br.parent_branch == NUM_BRANCHES ? ""
: branches[br.parent_branch].abbrevname)
+static void push_level_id(lua_State *ls, const level_id &lid)
+{
+ // We're skipping the constructor; naughty, but level_id has no
+ // virtual methods and no dynamically allocated memory.
+ level_id *nlev =
+ static_cast<level_id*>(lua_newuserdata(ls, sizeof(level_id)));
+ *nlev = lid;
+}
+
+static level_id _lua_level_id(lua_State *ls, int ndx)
+{
+ if (lua_isstring(ls, ndx))
+ {
+ const char *s = lua_tostring(ls, 1);
+ try
+ {
+ return level_id::parse_level_id(s);
+ }
+ catch (const std::string &err)
+ {
+ luaL_error(ls, err.c_str());
+ }
+ }
+ else if (lua_isuserdata(ls, ndx))
+ {
+ const level_id *lid = static_cast<level_id*>(lua_touserdata(ls, ndx));
+ return (*lid);
+ }
+
+ luaL_argerror(ls, ndx, "Expected level_id");
+ // Never gets here.
+ return level_id();
+}
+
+LUAFN(dgn_level_id)
+{
+ const int nargs = lua_gettop(ls);
+ if (!nargs)
+ push_level_id(ls, level_id::current());
+ else if (nargs == 1)
+ push_level_id(ls, _lua_level_id(ls, 1));
+ return (1);
+}
+
+static inline bool _lua_boolean(lua_State *ls, int ndx, bool defval)
+{
+ return lua_isnone(ls, ndx)? defval : lua_toboolean(ls, ndx);
+}
+
+static int _lua_push_map(lua_State *ls, const map_def *map)
+{
+ if (map)
+ lua_pushlightuserdata(ls, const_cast<map_def*>(map));
+ else
+ lua_pushnil(ls);
+ return (1);
+}
+
+LUAFN(dgn_map_by_tag)
+{
+ if (const char *tag = luaL_checkstring(ls, 1))
+ {
+ const bool mini = _lua_boolean(ls, 2, true);
+ const bool check_depth = _lua_boolean(ls, 3, true);
+ return _lua_push_map(ls, random_map_for_tag(tag, mini, check_depth));
+ }
+ return (0);
+}
+
+LUAFN(dgn_map_in_depth)
+{
+ const level_id lid = _lua_level_id(ls, 1);
+ const bool mini = _lua_boolean(ls, 2, true);
+ return _lua_push_map(ls, random_map_in_depth(lid, mini));
+}
+
+LUAFN(dgn_map_by_place)
+{
+ const level_id lid = _lua_level_id(ls, 1);
+ const bool mini = _lua_boolean(ls, 2, true);
+ return _lua_push_map(ls, random_map_for_place(lid, mini));
+}
+
+LUAFN(_dgn_place_map)
+{
+ if (!lua_isuserdata(ls, 1))
+ luaL_argerror(ls, 1, "Expected map");
+ const map_def *map = static_cast<map_def *>(lua_touserdata(ls, 1));
+ const bool clobber = _lua_boolean(ls, 2, false);
+ const bool no_exits = _lua_boolean(ls, 3, false);
+ coord_def where(-1, -1);
+ if (lua_isnumber(ls, 4) && lua_isnumber(ls, 5))
+ {
+ COORDS(c, 4, 5);
+ where = c;
+ }
+ lua_pushboolean(ls, dgn_place_map(map, clobber, no_exits, where));
+ return (1);
+}
+
static int dgn_debug_dump_map(lua_State *ls)
{
const int pos = lua_isuserdata(ls, 1) ? 2 : 1;
@@ -2270,6 +2370,12 @@ static const struct luaL_reg dgn_lib[] =
{ "br_has_uniques", dgn_br_has_uniques },
{ "br_parent_branch", dgn_br_parent_branch },
+ { "level_id", dgn_level_id },
+ { "map_by_tag", dgn_map_by_tag },
+ { "map_in_depth", dgn_map_in_depth },
+ { "map_by_place", dgn_map_by_place },
+ { "place_map", _dgn_place_map },
+
{ "debug_dump_map", dgn_debug_dump_map },
{ NULL, NULL }
diff --git a/crawl-ref/source/travel.h b/crawl-ref/source/travel.h
index c5a12529dc..65e2bcd08a 100644
--- a/crawl-ref/source/travel.h
+++ b/crawl-ref/source/travel.h
@@ -179,7 +179,9 @@ enum explore_stop_type
////////////////////////////////////////////////////////////////////////////
// Structs for interlevel travel.
-// Identifies a level.
+// Identifies a level. Should never include virtual methods or
+// dynamically allocated memory (see code to push level_id onto Lua
+// stack in luadgn.cc)
class level_id
{
public:
@@ -233,6 +235,14 @@ public:
|| level_type != LEVEL_DUNGEON;
}
+ const level_id &operator = (const level_id &id)
+ {
+ branch = id.branch;
+ depth = id.depth;
+ level_type = id.level_type;
+ return (*this);
+ }
+
bool operator == ( const level_id &id ) const
{
return (level_type == id.level_type