git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7564 c06c8d41-db1a-0410-9941-cceddc491573
4N5PW5S3OV25HFN634NNWMMYX26NA2TB6TVFG4UMYSZ2VBJWKE4QC KTRWLM6WDL4GAAJZNLQEEA3TGY2OKYZZUAAT4TCAVKRTR2NQBWUQC SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC T4IH76FA5TWHFOZUJFHLQXQJENJHWTUZZP4EGNA7D4GTZY7D4ZKAC DKRSOHZXL6EPSLKOKHF7GJXSZEJVY7CXGACSHWLM5B5FTRETWWCAC 6HG6JFO47Y3BZLU7Y6G3R2CX6JFGN4X5PKK6S5IGUXUYQ5GVZYFQC NKONHW4JNY6HP2M63MNPM3H64ZWSUNUT5FX2STW4KTS4AMXJXXVQC AUXHSGS4EFOPZ6TVZYWNVOUDO7NYKUKE3HBKGQQWTALSVFOE3HAAC RN242L3YZK35BFY7JRTCSYWD6FWDCRFUFDI7PKYFUCA2UPX6ZEAQC X7MFMKQTNZ2IWBFVGS6WQV7NRNKJ3DWQAW2X7IQMFQQXW24AHPZQC GQL5SIGBHLU3FMCE54XVGLRY5AZHRM6DUEB722REA2DPLGJSN6EQC TV3ZC6WOZKSQQJQN26JIVKCHK6UK7WMDBYZDUYRWEAZ4JB4YVNAAC K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC WRPGGZRVGWWYCBWL5W5HMAM7CWLYICKZ6A36ZGQ3UEDW5O25FMOQC RISMOCQM6BKK4XSIRKYLOBB2UPDYJNDAL6OGIIR5GGNZQAK5YSZAC 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));elselua_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);}
endendendlocal function ziggurat_place_pillars(c)local range = crawl.random_rangelocal function pillar_spot()local floor = dgn.fnum("floor")for i = 1, 100 dolocal place = { x = c.x + range(-30, 30), y = c.y + range(-30, 30) }if (dgn.grid(place.x, place.y) == floor) thenreturn placeendendreturn nilendlocal function place_pillar(p)local map = dgn.map_by_tag("ziggurat_pillar")if map thendgn.place_map(map, false, true, p.x, p.y)endendfor i = 1, crawl.random_range(1,3) dolocal p = pillar_spot()if p thenplace_pillar(p)