/** * Get the value of all cell flags at a position. * @param L Lua context. * @return Number of results of the call. */ static int l_map_getcellflags(lua_State *L) { THMap* pMap = luaT_testuserdata<THMap>(L); int iX = static_cast<int>(luaL_checkinteger(L, 2) - 1); // Lua arrays start at 1 - pretend int iY = static_cast<int>(luaL_checkinteger(L, 3) - 1); // the map does too. THMapNode* pNode = pMap->getNode(iX, iY); if(pNode == nullptr) return luaL_argerror(L, 2, "Map co-ordinates out of bounds"); if(lua_type(L, 4) != LUA_TTABLE) { lua_settop(L, 3); lua_createtable(L, 0, 1); } else { lua_settop(L, 4); } // Fill Lua table with the flags and numbers of the node. for (auto val : lua_node_flag_map) { add_cellflag(L, pNode, val.second, val.first); } add_cellint(L, pNode->iRoomId, "roomId"); add_cellint(L, pNode->iParcelId, "parcelId"); add_cellint(L, pNode->iFlags >> 24, "thob"); return 1; }
/** * Get the value of all cell flags at a position. * @param L Lua context. * @return Number of results of the call. */ static int l_map_getcellflags(lua_State *L) { level_map* pMap = luaT_testuserdata<level_map>(L); int iX = static_cast<int>(luaL_checkinteger(L, 2) - 1); // Lua arrays start at 1 - pretend int iY = static_cast<int>(luaL_checkinteger(L, 3) - 1); // the map does too. map_tile* pNode = pMap->get_tile(iX, iY); if(pNode == nullptr) return luaL_argerror(L, 2, "Map co-ordinates out of bounds"); if(lua_type(L, 4) != LUA_TTABLE) { lua_settop(L, 3); lua_createtable(L, 0, 1); } else { lua_settop(L, 4); } // Fill Lua table with the flags and numbers of the tile. for (auto val : lua_tile_flag_map) { add_cellflag(L, pNode, val.second, val.first); } add_cellint(L, pNode->iRoomId, "roomId"); add_cellint(L, pNode->iParcelId, "parcelId"); add_cellint(L, pMap->get_tile_owner(pNode), "owner"); add_cellint(L, static_cast<int>(pNode->objects.empty() ? object_type::no_object : pNode->objects.front()), "thob"); return 1; }