diff --git a/CMakeLists.txt b/CMakeLists.txt index a00dafc7ef..b7904ddab8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 50) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 81) +set(OPENMW_LUA_API_REVISION 82) set(OPENMW_POSTPROCESSING_API_REVISION 3) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/openmw/mwlua/cellbindings.cpp b/apps/openmw/mwlua/cellbindings.cpp index 933dba3fda..202186d119 100644 --- a/apps/openmw/mwlua/cellbindings.cpp +++ b/apps/openmw/mwlua/cellbindings.cpp @@ -61,6 +61,10 @@ namespace sol struct is_automagical : std::false_type { }; + template <> + struct is_automagical : std::false_type + { + }; } namespace MWLua @@ -126,6 +130,14 @@ namespace MWLua return sol::nullopt; }); + cellT["pathGrid"] = sol::readonly_property([](const CellT& c) -> const ESM::Pathgrid* { + const ESM::Pathgrid* grid + = MWBase::Environment::get().getESMStore()->get().search(*c.mStore->getCell()); + if (grid && grid->mPoints.empty()) + return nullptr; + return grid; + }); + if constexpr (std::is_same_v) { // only for global scripts cellT["getAll"] = [ids = getPackageToTypeTable(view)](const CellT& cell, sol::optional type) { @@ -286,6 +298,36 @@ namespace MWLua return GObjectList{ std::move(res) }; }; } + + if (view["openmw_cellbindings"] != sol::nil) + return; // Only add the usertype once + + auto pathGridT = view.new_usertype("ESM3_PathGrid"); + pathGridT[sol::meta_function::to_string] = [](const ESM::Pathgrid& rec) -> std::string { + return "ESM3_PathGrid[" + rec.mCell.toDebugString() + "]"; + }; + pathGridT["getPoints"] = [](sol::this_state lua, const ESM::Pathgrid& rec) -> sol::table { + sol::table points(lua, sol::create); + for (const ESM::Pathgrid::Point& point : rec.mPoints) + { + sol::table table(lua, sol::create); + table["autoGenerated"] = point.mAutogenerated == 0; + table["relativePosition"] = osg::Vec3f(point.mX, point.mY, point.mZ); + sol::table edges(lua, sol::create); + table["connections"] = edges; + points.add(table); + } + for (const ESM::Pathgrid::Edge& edge : rec.mEdges) + { + sol::table p1 = points[edge.mV0 + 1]; + sol::table p2 = points[edge.mV1 + 1]; + p1.get("connections").add(p2); + p2.get("connections").add(p1); + } + return points; + }; + + view["openmw_cellbindings"] = true; } void initCellBindingsForLocalScripts(const Context& context) diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 1ef2c806b0..94fefb2b6d 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -295,13 +295,14 @@ -- @field #string id Unique record ID of the cell, based on cell name for interiors and the worldspace for exteriors, or the formID of the cell for ESM4 cells. -- @field #string region Region of the cell. -- @field #boolean isExterior Whether the cell is an exterior cell. "Exterior" means grid of cells where the player can seamless walk from one cell to another without teleports. QuasiExterior (interior with sky) is not an exterior. --- @field #boolean isQuasiExterior (DEPRECATED, use `hasTag("QuasiExterior")`) Whether the cell is a quasi exterior (like interior but with the sky and the wheather). +-- @field #boolean isQuasiExterior (DEPRECATED, use `hasTag("QuasiExterior")`) Whether the cell is a quasi exterior (like interior but with the sky and the weather). -- @field #number gridX Index of the cell by X (only for exteriors). -- @field #number gridY Index of the cell by Y (only for exteriors). -- @field #string worldSpaceId Id of the world space. -- @field #boolean hasWater True if the cell contains water. -- @field #number waterLevel The water level of the cell. (nil if cell has no water). -- @field #boolean hasSky True if in this cell sky should be rendered. +-- @field #PathGrid pathGrid The cell's @{#PathGrid} if it has one. --- -- Returns true if the cell has given tag. @@ -334,6 +335,23 @@ -- local all = cell:getAll() -- local weapons = cell:getAll(types.Weapon) +--- +-- A cell's path grid marking traversable paths. +-- @type PathGrid + +--- +-- Get all points in this path grid. +-- @function [parent=#PathGrid] getPoints +-- @param self +-- @return #list<#PathGridPoint> A list of @{#PathGridPoint}s. + +--- +-- A point in a cell's path grid. +-- @type PathGridPoint +-- @field #boolean autoGenerated True if this node was automatically generated in the editor. +-- @field openmw.util#Vector3 relativePosition The point's position relative to the cell's origin. An exterior cell's origin is its southwest corner. +-- @field #list<#PathGridPoint> connections A list of points connected to this point. + --- -- @type ActiveSpell -- @field #string name The spell or item display name