diff options
author | Ablu <ablu.erikschilling@googlemail.com> | 2011-06-26 14:32:36 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-07-02 00:14:07 +0200 |
commit | d779224809cefad7a4df27873e92f5251fd132f7 (patch) | |
tree | 2f0f518ecf9020896e8a383c8f0cee692665ad14 /src/scripting/lua.cpp | |
parent | 30b9a7ddb40c0c383cbb710a67d8c6491ef13782 (diff) | |
download | manaserv-d779224809cefad7a4df27873e92f5251fd132f7.tar.gz manaserv-d779224809cefad7a4df27873e92f5251fd132f7.tar.bz2 manaserv-d779224809cefad7a4df27873e92f5251fd132f7.tar.xz manaserv-d779224809cefad7a4df27873e92f5251fd132f7.zip |
Added LUA function get_beings_in_rectangle.
Reviewed-by: Bertram.
Resolves: Mana-Mantis #369.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index ab5d6566..d55fb132 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1302,6 +1302,44 @@ static int get_beings_in_circle(lua_State *s) } /** + * Gets a LUA table with the being IDs of all beings + * inside of a recangular area of the current map. + * mana.get_beings_in_rectangle (x, y, width, height) + */ +static int get_beings_in_rectangle(lua_State *s) +{ + const int x = luaL_checkint(s, 1); + const int y = luaL_checkint(s, 2); + const int w = luaL_checkint(s, 3); + const int h = luaL_checkint(s, 4); + + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast<Script *>(lua_touserdata(s, -1)); + MapComposite *m = t->getMap(); + + //create a lua table with the beings in the given area. + lua_newtable(s); + int tableStackPosition = lua_gettop(s); + int tableIndex = 1; + Rectangle rect = {x, y ,w, h}; + for (BeingIterator i( + m->getInsideRectangleIterator(rect)); i; ++i) + { + char t = (*i)->getType(); + if (t == OBJECT_NPC || t == OBJECT_CHARACTER || t == OBJECT_MONSTER) + { + Being *b = static_cast<Being *> (*i); + lua_pushinteger(s, tableIndex); + lua_pushlightuserdata (s, b); + lua_settable (s, tableStackPosition); + tableIndex++; + } + } + return 1; + } + +/** * Gets the post for the character */ static int chr_get_post(lua_State *s) @@ -1885,6 +1923,7 @@ LuaScript::LuaScript(): { "trigger_create", &trigger_create }, { "chatmessage", &chatmessage }, { "get_beings_in_circle", &get_beings_in_circle }, + { "get_beings_in_rectangle", &get_beings_in_rectangle }, { "being_register", &being_register }, { "effect_create", &effect_create }, { "chr_shake_screen", &chr_shake_screen }, |