diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 20:24:42 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 20:24:42 +0100 |
commit | 0eb3a62c89500bc0bf48a6fdac65210b18a38e93 (patch) | |
tree | f8dc723410feba9659dfb70b6a7a6ea749a31f7e /crawl-ref/source/l_moninf.cc | |
parent | 5c2086ac6f8e8b53bfa9655cf02dca03c41850ce (diff) | |
download | crawl-ref-0eb3a62c89500bc0bf48a6fdac65210b18a38e93.tar.gz crawl-ref-0eb3a62c89500bc0bf48a6fdac65210b18a38e93.zip |
Add function to return monster info for a given coordinate.
Diffstat (limited to 'crawl-ref/source/l_moninf.cc')
-rw-r--r-- | crawl-ref/source/l_moninf.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/crawl-ref/source/l_moninf.cc b/crawl-ref/source/l_moninf.cc index db21ca0074..10a3bfbfbb 100644 --- a/crawl-ref/source/l_moninf.cc +++ b/crawl-ref/source/l_moninf.cc @@ -8,6 +8,7 @@ #include "l_libs.h" #include "cluautil.h" +#include "env.h" #include "mon-info.h" #define MONINF_METATABLE "monster.info" @@ -50,8 +51,52 @@ static const struct luaL_reg moninf_lib[] = { NULL, NULL } }; +// XXX: unify with directn.cc/h +// This uses relative coordinates with origin the player. +bool in_show_bounds(const coord_def &s) +{ + return (s.rdist() <= ENV_SHOW_OFFSET); +} + +coord_def _show2grid(const coord_def &s) +{ + return (you.pos() + s); +} + +coord_def _grid2show(const coord_def &g) +{ + return (g - you.pos()); +} + +#define COORDSHOW(c, p1, p2) \ + GETCOORD(c, p1, p2, in_show_bounds) + +LUAFN(mi_get_monster_at) +{ + COORDSHOW(s, 1, 2) + coord_def p = _show2grid(s); + if (!you.see_cell(p)) + return (0); + if (env.mgrid(p) == NON_MONSTER) + return (0); + monsters* m = &env.mons[env.mgrid(p)]; + if (!m->visible_to(&you)) + return (0); + monster_info *mi = new monster_info(m); + lua_push_moninf(ls, mi); + return (1); +} + +static const struct luaL_reg mon_lib[] = +{ + { "get_monster_at", mi_get_monster_at }, + + { NULL, NULL } +}; + void cluaopen_moninf(lua_State *ls) { clua_register_metatable(ls, MONINF_METATABLE, moninf_lib, lua_object_gc<monster_info>); + luaL_openlib(ls, "monster", mon_lib, 0); } |