diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2011-08-01 13:38:54 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-03 20:26:29 +0200 |
commit | 8a43d694173fa0197597ed54c4df4d89c3002e4f (patch) | |
tree | ae043fba2773cc0f741e6e406bc3dde805264835 /src/scripting/lua.cpp | |
parent | 23f2c4c4ac4f81f0410f26bfcb7fde8c640be684 (diff) | |
download | manaserv-8a43d694173fa0197597ed54c4df4d89c3002e4f.tar.gz manaserv-8a43d694173fa0197597ed54c4df4d89c3002e4f.tar.bz2 manaserv-8a43d694173fa0197597ed54c4df4d89c3002e4f.tar.xz manaserv-8a43d694173fa0197597ed54c4df4d89c3002e4f.zip |
Added is_walkable lua function.
mana.is_walkable(x, y) can now be used to check wether the pixel on the
current map is walkable or not.
Reviewed-by: Bertram.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index c3a38bf9..9a67c7c7 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1836,6 +1836,35 @@ static int get_map_property(lua_State *s) } /** + * bool mana.is_walkable(int x, int y) + * Returns whether the pixel on the map is walkable. + */ +static int is_walkable(lua_State *s) +{ + const int x = luaL_checkint(s, 1); + const int y = luaL_checkint(s, 2); + + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast<Script *>(lua_touserdata(s, -1)); + MapComposite *m = t->getMap(); + if (!m) + { + raiseScriptError(s, "is_walkable called outside a map."); + return 0; + } + Map *map = m->getMap(); + + // If the wanted warp place is unwalkable + if (map->getWalk(x / map->getTileWidth(), y / map->getTileHeight())) + lua_pushboolean(s, 1); + else + lua_pushboolean(s, 0); + + return 1; +} + +/** * Creates an item stack on the floor * mana.drop_item(x, y, id[, number]) */ @@ -2009,6 +2038,7 @@ LuaScript::LuaScript(): { "test_tableget", &test_tableget }, { "get_map_id", &get_map_id }, { "get_map_property", &get_map_property }, + { "is_walkable", &is_walkable }, { "item_drop", &item_drop }, { "npc_ask_integer", &npc_ask_integer }, { "npc_end", &npc_end }, |