summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/dlua.cc1
-rw-r--r--crawl-ref/source/dlua.h23
-rw-r--r--crawl-ref/source/l_dgn.cc159
-rw-r--r--crawl-ref/source/l_libs.h50
-rw-r--r--crawl-ref/source/makefile.obj1
5 files changed, 54 insertions, 180 deletions
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc
index a14b88937e..b120ac9244 100644
--- a/crawl-ref/source/dlua.cc
+++ b/crawl-ref/source/dlua.cc
@@ -310,6 +310,7 @@ void init_dungeon_lua()
luaL_openlib(dlua, "dgn", dgn_event_lib, 0);
luaL_openlib(dlua, "dgn", dgn_item_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.
luaL_openlib(dlua, "crawl", crawl_lib, 0);
luaL_openlib(dlua, "file", file_lib, 0);
diff --git a/crawl-ref/source/dlua.h b/crawl-ref/source/dlua.h
index ebb90398f8..dc6a30f531 100644
--- a/crawl-ref/source/dlua.h
+++ b/crawl-ref/source/dlua.h
@@ -96,7 +96,6 @@ static void dlua_push_object_type(lua_State *ls, const char *meta, const T &data
void print_dlua_stack();
-
void luaopen_setmeta(lua_State *ls,
const char *global,
const luaL_reg *lua_lib,
@@ -104,28 +103,6 @@ void luaopen_setmeta(lua_State *ls,
#define LUAFN(name) static int name(lua_State *ls)
-#define GETCOORD(c, p1, p2, boundfn) \
- coord_def c; \
- c.x = luaL_checkint(ls, p1); \
- c.y = luaL_checkint(ls, p2); \
- if (!boundfn(c)) \
- luaL_error( \
- ls, \
- make_stringf("Point (%d,%d) is out of bounds", \
- c.x, c.y).c_str()); \
- else ;
-
-
-#define COORDS(c, p1, p2) \
- GETCOORD(c, p1, p2, in_bounds)
-
-#define MAP(ls, n, var) \
-map_def *var = *(map_def **) luaL_checkudata(ls, n, MAP_METATABLE)
-#define DEVENT(ls, n, var) \
-dgn_event *var = *(dgn_event **) luaL_checkudata(ls, n, DEVENT_METATABLE)
-#define MAPMARKER(ls, n, var) \
-map_marker *var = *(map_marker **) luaL_checkudata(ls, n, MAPMARK_METATABLE)
-
//////////////////////////////////////////////////////////////////////////
#endif
diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc
index e7792fe32f..7d65aa1ec5 100644
--- a/crawl-ref/source/l_dgn.cc
+++ b/crawl-ref/source/l_dgn.cc
@@ -363,9 +363,8 @@ static int dgn_orient(lua_State *ls)
PLUARET(string, map_section_name(map->orient));
}
-static int dgn_map_add_transform(
- lua_State *ls,
- std::string (map_lines::*add)(const std::string &s))
+int dgn_map_add_transform(lua_State *ls,
+ std::string (map_lines::*add)(const std::string &s))
{
MAP(ls, 1, map);
if (lua_gettop(ls) == 1)
@@ -1179,31 +1178,6 @@ static int dgn_fixup_stairs(lua_State *ls)
return (0);
}
-#ifdef USE_TILE
-static unsigned int _get_tile_idx(lua_State *ls, int arg)
-{
- if (!lua_isstring(ls, arg))
- {
- luaL_argerror(ls, arg, "Expected string for tile name");
- return 0;
- }
-
- const char *tile_name = luaL_checkstring(ls, arg);
-
- unsigned int idx;
- if (!tile_dngn_index(tile_name, idx))
- {
- std::string error = "Couldn't find tile '";
- error += tile_name;
- error += "'";
- luaL_argerror(ls, arg, error.c_str());
- return 0;
- }
-
- return idx;
-}
-#endif
-
static int dgn_floor_halo(lua_State *ls)
{
std::string error = "";
@@ -1261,7 +1235,7 @@ static int dgn_floor_halo(lua_State *ls)
}
#ifdef USE_TILE
- unsigned int tile = _get_tile_idx(ls, 3);
+ unsigned int tile = get_tile_idx(ls, 3);
if (!tile)
return (0);
if (tile_dngn_count(tile) != 9)
@@ -1963,16 +1937,6 @@ BRANCHFN(parent_branch, string,
br.parent_branch == NUM_BRANCHES ? ""
: branches[br.parent_branch].abbrevname)
-#define LEVEL(lev, br, pos) \
-const char *level_name = luaL_checkstring(ls, pos); \
-level_area_type lev = str_to_level_area_type(level_name); \
-if (lev == NUM_LEVEL_AREA_TYPES) \
-luaL_error(ls, "Expected level name"); \
-const char *branch_name = luaL_checkstring(ls, pos); \
-branch_type br = str_to_branch(branch_name); \
-if (lev == LEVEL_DUNGEON && br == NUM_BRANCHES) \
-luaL_error(ls, "Expected branch name");
-
static void push_level_id(lua_State *ls, const level_id &lid)
{
// We're skipping the constructor; naughty, but level_id has no
@@ -2243,114 +2207,6 @@ LUAFN(_dgn_reuse_map)
return (0);
}
-LUAFN(dgn_lev_floortile)
-{
-#ifdef USE_TILE
- LEVEL(lev, br, 1);
-
- tile_flavour flv;
- tile_default_flv(lev, br, flv);
-
- const char *tile_name = tile_dngn_name(flv.floor);
- PLUARET(string, tile_name);
-#else
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_lev_rocktile)
-{
-#ifdef USE_TILE
- LEVEL(lev, br, 1);
-
- tile_flavour flv;
- tile_default_flv(lev, br, flv);
-
- const char *tile_name = tile_dngn_name(flv.wall);
- PLUARET(string, tile_name);
-#else
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_lrocktile)
-{
- MAP(ls, 1, map);
-
-#ifdef USE_TILE
- unsigned short tile = _get_tile_idx(ls, 2);
- map->rock_tile = tile;
-
- const char *tile_name = tile_dngn_name(tile);
- PLUARET(string, tile_name);
-#else
- UNUSED(map);
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_lfloortile)
-{
- MAP(ls, 1, map);
-
-#ifdef USE_TILE
- unsigned short tile = _get_tile_idx(ls, 2);
- map->floor_tile = tile;
-
- const char *tile_name = tile_dngn_name(tile);
- PLUARET(string, tile_name);
-#else
- UNUSED(map);
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_change_rock_tile)
-{
-#ifdef USE_TILE
- unsigned short tile = _get_tile_idx(ls, 1);
- if (tile)
- env.tile_default.wall = tile;
-
- const char *tile_name = tile_dngn_name(tile);
- PLUARET(string, tile_name);
-#else
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_change_floor_tile)
-{
-#ifdef USE_TILE
- unsigned short tile = _get_tile_idx(ls, 1);
- if (tile)
- env.tile_default.floor = tile;
-
- const char *tile_name = tile_dngn_name(tile);
- PLUARET(string, tile_name);
-#else
- PLUARET(string, "invalid");
-#endif
-}
-
-LUAFN(dgn_ftile)
-{
-#ifdef USE_TILE
- return dgn_map_add_transform(ls, &map_lines::add_floortile);
-#else
- return 0;
-#endif
-}
-
-LUAFN(dgn_rtile)
-{
-#ifdef USE_TILE
- return dgn_map_add_transform(ls, &map_lines::add_rocktile);
-#else
- return 0;
-#endif
-}
-
LUAFN(dgn_dbg_dump_map)
{
const int pos = lua_isuserdata(ls, 1) ? 2 : 1;
@@ -2498,14 +2354,5 @@ const struct luaL_reg dgn_lib[] =
{ "get_special_room_info", dgn_get_special_room_info },
-{ "lrocktile", dgn_lrocktile },
-{ "lfloortile", dgn_lfloortile },
-{ "rtile", dgn_rtile },
-{ "ftile", dgn_ftile },
-{ "change_rock_tile", dgn_change_rock_tile },
-{ "change_floor_tile", dgn_change_floor_tile },
-{ "lev_floortile", dgn_lev_floortile },
-{ "lev_rocktile", dgn_lev_rocktile },
-
{ NULL, NULL }
};
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h
index f6903f5118..e939758d2f 100644
--- a/crawl-ref/source/l_libs.h
+++ b/crawl-ref/source/l_libs.h
@@ -8,11 +8,16 @@
#include "clua.h"
+/*
+ * Libraries and loaders, accessed from init_dungeon_lua().
+ */
+
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_mons_lib[];
+extern const struct luaL_reg dgn_tile_lib[];
extern const struct luaL_reg file_lib[];
extern const struct luaL_reg los_lib[];
extern const struct luaL_reg mapmarker_lib[];
@@ -26,5 +31,48 @@ void register_monslist(lua_State *ls);
void register_itemlist(lua_State *ls);
void register_builder_funcs(lua_State *ls);
-#endif
+/*
+ * Macros for processing object arguments.
+ */
+#define GETCOORD(c, p1, p2, boundfn) \
+ coord_def c; \
+ c.x = luaL_checkint(ls, p1); \
+ c.y = luaL_checkint(ls, p2); \
+ if (!boundfn(c)) \
+ luaL_error( \
+ ls, \
+ make_stringf("Point (%d,%d) is out of bounds", \
+ c.x, c.y).c_str()); \
+ else ;
+
+
+#define COORDS(c, p1, p2) \
+ GETCOORD(c, p1, p2, in_bounds)
+#define LEVEL(lev, br, pos) \
+const char *level_name = luaL_checkstring(ls, pos); \
+level_area_type lev = str_to_level_area_type(level_name); \
+if (lev == NUM_LEVEL_AREA_TYPES) \
+luaL_error(ls, "Expected level name"); \
+const char *branch_name = luaL_checkstring(ls, pos); \
+branch_type br = str_to_branch(branch_name); \
+if (lev == LEVEL_DUNGEON && br == NUM_BRANCHES) \
+luaL_error(ls, "Expected branch name");
+
+#define MAP(ls, n, var) \
+map_def *var = *(map_def **) luaL_checkudata(ls, n, MAP_METATABLE)
+#define DEVENT(ls, n, var) \
+dgn_event *var = *(dgn_event **) luaL_checkudata(ls, n, DEVENT_METATABLE)
+#define MAPMARKER(ls, n, var) \
+map_marker *var = *(map_marker **) luaL_checkudata(ls, n, MAPMARK_METATABLE)
+
+
+/*
+ * Some shared helper functions.
+ */
+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);
+
+#endif
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index 5ecacbcfc3..08962099d6 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -43,6 +43,7 @@ l_dgn.o \
l_dgnevt.o \
l_dgnit.o \
l_dgnmon.o \
+l_dgntil.o \
l_dgn_bf.o \
l_file.o \
l_los.o \