summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-20 10:15:35 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-20 10:15:35 +0200
commit29aa709171aebafc39ed2074983d0f1976583baa (patch)
treebd67f59231eb02db05daa794829e303e87012b56 /crawl-ref/source
parent40c9bc160056918a6807b986d951dba707e33338 (diff)
downloadcrawl-ref-29aa709171aebafc39ed2074983d0f1976583baa.tar.gz
crawl-ref-29aa709171aebafc39ed2074983d0f1976583baa.zip
Split level and branch functions out of l_dgn.cc.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/dlua.cc1
-rw-r--r--crawl-ref/source/l_dgn.cc148
-rw-r--r--crawl-ref/source/l_dgnlvl.cc160
-rw-r--r--crawl-ref/source/l_libs.h2
-rw-r--r--crawl-ref/source/makefile.obj1
5 files changed, 167 insertions, 145 deletions
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc
index b120ac9244..81a97cc485 100644
--- a/crawl-ref/source/dlua.cc
+++ b/crawl-ref/source/dlua.cc
@@ -309,6 +309,7 @@ void init_dungeon_lua()
luaL_openlib(dlua, "dgn", dgn_lib, 0);
luaL_openlib(dlua, "dgn", dgn_event_lib, 0);
luaL_openlib(dlua, "dgn", dgn_item_lib, 0);
+ luaL_openlib(dlua, "dgn", dgn_level_lib, 0);
luaL_openlib(dlua, "dgn", dgn_mons_lib, 0);
luaL_openlib(dlua, "dgn", dgn_tile_lib, 0);
// Add additional function to the Crawl module.
diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc
index 7d65aa1ec5..994d44c75a 100644
--- a/crawl-ref/source/l_dgn.cc
+++ b/crawl-ref/source/l_dgn.cc
@@ -1916,137 +1916,6 @@ LUAFN(dgn_with_map_anchors)
return (1);
}
-#define BRANCH(br, pos) \
-const char *branch_name = luaL_checkstring(ls, pos); \
-branch_type req_branch_type = str_to_branch(branch_name); \
-if (req_branch_type == NUM_BRANCHES) \
-luaL_error(ls, "Expected branch name"); \
-Branch &br = branches[req_branch_type]
-
-#define BRANCHFN(name, type, expr) \
-LUAFN(dgn_br_##name) { \
-BRANCH(br, 1); \
-PLUARET(type, expr); \
-}
-
-BRANCHFN(floorcol, number, br.floor_colour)
-BRANCHFN(rockcol, number, br.rock_colour)
-BRANCHFN(has_shops, boolean, br.has_shops)
-BRANCHFN(has_uniques, boolean, br.has_uniques)
-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);
-}
-
-LUAFN(dgn_level_name)
-{
- const level_id lid(_lua_level_id(ls, 1));
- lua_pushstring(ls, lid.describe().c_str());
- return (1);
-}
-
-LUAFN(dgn_set_level_type_name)
-{
- if (you.level_type != LEVEL_PORTAL_VAULT)
- {
- luaL_error(ls, "Can only set level type name on portal vaults");
- return(0);
- }
-
- if (!lua_isstring(ls, 1))
- {
- luaL_argerror(ls, 1, "Expected string for level type name");
- return(0);
- }
-
- you.level_type_name = luaL_checkstring(ls, 1);
-
- return(0);
-}
-
-LUAFN(dgn_set_level_type_name_abbrev)
-{
- if (you.level_type != LEVEL_PORTAL_VAULT)
- {
- luaL_error(ls, "Can only set level type name abbreviation on "
- "portal vaults");
- return(0);
- }
-
- if (!lua_isstring(ls, 1))
- {
- luaL_argerror(ls, 1, "Expected string for level type name "
- "abbreviation");
- return(0);
- }
-
- you.level_type_name_abbrev = luaL_checkstring(ls, 1);
-
- return(0);
-}
-
-LUAFN(dgn_set_level_type_origin)
-{
- if (you.level_type != LEVEL_PORTAL_VAULT)
- {
- luaL_error(ls, "Can only set level type origin on portal vaults");
- return(0);
- }
-
- if (!lua_isstring(ls, 1))
- {
- luaL_argerror(ls, 1, "Expected string for level type origin");
- return(0);
- }
-
- you.level_type_origin = luaL_checkstring(ls, 1);
-
- return(0);
-}
-
static int _lua_push_map(lua_State *ls, const map_def *map)
{
if (map)
@@ -2068,17 +1937,17 @@ LUAFN(dgn_map_by_tag)
LUAFN(dgn_map_in_depth)
{
- const level_id lid = _lua_level_id(ls, 1);
+ const level_id lid = dlua_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 level_id lid = dlua_level_id(ls, 1);
const bool mini = _lua_boolean(ls, 2, false);
return _lua_push_map(ls, random_map_for_place(lid, mini));
-}
+}
LUAFN(_dgn_place_map)
{
@@ -2331,17 +2200,6 @@ const struct luaL_reg dgn_lib[] =
{ "with_map_bounds_fn", dgn_with_map_bounds_fn },
{ "with_map_anchors", dgn_with_map_anchors },
-{ "br_floorcol", dgn_br_floorcol },
-{ "br_rockcol", dgn_br_rockcol },
-{ "br_has_shops", dgn_br_has_shops },
-{ "br_has_uniques", dgn_br_has_uniques },
-{ "br_parent_branch", dgn_br_parent_branch },
-
-{ "level_id", dgn_level_id },
-{ "level_name", dgn_level_name },
-{ "set_level_type_name", dgn_set_level_type_name },
-{ "set_level_type_name_abbrev", dgn_set_level_type_name_abbrev },
-{ "set_level_type_origin", dgn_set_level_type_origin },
{ "map_by_tag", dgn_map_by_tag },
{ "map_in_depth", dgn_map_in_depth },
{ "map_by_place", dgn_map_by_place },
diff --git a/crawl-ref/source/l_dgnlvl.cc b/crawl-ref/source/l_dgnlvl.cc
new file mode 100644
index 0000000000..c72b09174e
--- /dev/null
+++ b/crawl-ref/source/l_dgnlvl.cc
@@ -0,0 +1,160 @@
+/*
+ * File: l_dgnlvl.cc
+ * Summary: Level and branch bindings (library "dgn").
+ */
+
+#include "AppHdr.h"
+
+#include "dlua.h"
+#include "l_libs.h"
+
+#include "branch.h"
+
+#define BRANCH(br, pos) \
+const char *branch_name = luaL_checkstring(ls, pos); \
+branch_type req_branch_type = str_to_branch(branch_name); \
+if (req_branch_type == NUM_BRANCHES) \
+luaL_error(ls, "Expected branch name"); \
+Branch &br = branches[req_branch_type]
+
+#define BRANCHFN(name, type, expr) \
+LUAFN(dgn_br_##name) { \
+BRANCH(br, 1); \
+PLUARET(type, expr); \
+}
+
+BRANCHFN(floorcol, number, br.floor_colour)
+BRANCHFN(rockcol, number, br.rock_colour)
+BRANCHFN(has_shops, boolean, br.has_shops)
+BRANCHFN(has_uniques, boolean, br.has_uniques)
+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;
+}
+
+level_id dlua_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, dlua_level_id(ls, 1));
+ return (1);
+}
+
+LUAFN(dgn_level_name)
+{
+ const level_id lid(dlua_level_id(ls, 1));
+ lua_pushstring(ls, lid.describe().c_str());
+ return (1);
+}
+
+LUAFN(dgn_set_level_type_name)
+{
+ if (you.level_type != LEVEL_PORTAL_VAULT)
+ {
+ luaL_error(ls, "Can only set level type name on portal vaults");
+ return(0);
+ }
+
+ if (!lua_isstring(ls, 1))
+ {
+ luaL_argerror(ls, 1, "Expected string for level type name");
+ return(0);
+ }
+
+ you.level_type_name = luaL_checkstring(ls, 1);
+
+ return(0);
+}
+
+LUAFN(dgn_set_level_type_name_abbrev)
+{
+ if (you.level_type != LEVEL_PORTAL_VAULT)
+ {
+ luaL_error(ls, "Can only set level type name abbreviation on "
+ "portal vaults");
+ return(0);
+ }
+
+ if (!lua_isstring(ls, 1))
+ {
+ luaL_argerror(ls, 1, "Expected string for level type name "
+ "abbreviation");
+ return(0);
+ }
+
+ you.level_type_name_abbrev = luaL_checkstring(ls, 1);
+
+ return(0);
+}
+
+LUAFN(dgn_set_level_type_origin)
+{
+ if (you.level_type != LEVEL_PORTAL_VAULT)
+ {
+ luaL_error(ls, "Can only set level type origin on portal vaults");
+ return(0);
+ }
+
+ if (!lua_isstring(ls, 1))
+ {
+ luaL_argerror(ls, 1, "Expected string for level type origin");
+ return(0);
+ }
+
+ you.level_type_origin = luaL_checkstring(ls, 1);
+
+ return(0);
+}
+
+const struct luaL_reg dgn_level_lib[] =
+{
+{ "br_floorcol", dgn_br_floorcol },
+{ "br_rockcol", dgn_br_rockcol },
+{ "br_has_shops", dgn_br_has_shops },
+{ "br_has_uniques", dgn_br_has_uniques },
+{ "br_parent_branch", dgn_br_parent_branch },
+
+{ "level_id", dgn_level_id },
+{ "level_name", dgn_level_name },
+{ "set_level_type_name", dgn_set_level_type_name },
+{ "set_level_type_name_abbrev", dgn_set_level_type_name_abbrev },
+{ "set_level_type_origin", dgn_set_level_type_origin },
+
+{ NULL, NULL }
+};
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h
index e939758d2f..fa5f0561d0 100644
--- a/crawl-ref/source/l_libs.h
+++ b/crawl-ref/source/l_libs.h
@@ -16,6 +16,7 @@ extern const struct luaL_reg crawl_lib[];
extern const struct luaL_reg dgn_lib[];
extern const struct luaL_reg dgn_event_lib[];
extern const struct luaL_reg dgn_item_lib[];
+extern const struct luaL_reg dgn_level_lib[];
extern const struct luaL_reg dgn_mons_lib[];
extern const struct luaL_reg dgn_tile_lib[];
extern const struct luaL_reg file_lib[];
@@ -74,5 +75,6 @@ class map_lines;
int dgn_map_add_transform(lua_State *ls,
std::string (map_lines::*add)(const std::string &s));
unsigned int get_tile_idx(lua_State *ls, int arg);
+level_id dlua_level_id(lua_State *ls, int ndx);
#endif
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index 08962099d6..242a5370c4 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -42,6 +42,7 @@ l_crawl.o \
l_dgn.o \
l_dgnevt.o \
l_dgnit.o \
+l_dgnlvl.o \
l_dgnmon.o \
l_dgntil.o \
l_dgn_bf.o \