From 533ce499e0d61171a9642560129741b0efb09c12 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 19 Jun 2024 21:38:27 +0000 Subject: [PATCH] Expose cell ID, Add actor travel destinations to types.Actor.record.servicesOffered --- apps/openmw/mwlua/cellbindings.cpp | 2 ++ apps/openmw/mwlua/types/actor.hpp | 37 +++++++++++++++++++++++++++++ apps/openmw/mwlua/worldbindings.cpp | 4 ++++ files/lua_api/openmw/core.lua | 1 + files/lua_api/openmw/types.lua | 7 ++++++ files/lua_api/openmw/world.lua | 6 +++++ 6 files changed, 57 insertions(+) diff --git a/apps/openmw/mwlua/cellbindings.cpp b/apps/openmw/mwlua/cellbindings.cpp index 2bc8f57ee2..eded0d0387 100644 --- a/apps/openmw/mwlua/cellbindings.cpp +++ b/apps/openmw/mwlua/cellbindings.cpp @@ -84,6 +84,8 @@ namespace MWLua }; cellT["name"] = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getNameId(); }); + cellT["id"] + = sol::readonly_property([](const CellT& c) { return c.mStore->getCell()->getId().serializeText(); }); cellT["region"] = sol::readonly_property( [](const CellT& c) -> std::string { return c.mStore->getCell()->getRegion().serializeText(); }); cellT["worldSpaceId"] = sol::readonly_property( diff --git a/apps/openmw/mwlua/types/actor.hpp b/apps/openmw/mwlua/types/actor.hpp index 6700b4a403..0ea0a89747 100644 --- a/apps/openmw/mwlua/types/actor.hpp +++ b/apps/openmw/mwlua/types/actor.hpp @@ -7,9 +7,14 @@ #include #include #include +#include +#include +#include #include "apps/openmw/mwbase/environment.hpp" #include "apps/openmw/mwworld/esmstore.hpp" +#include +#include #include "../context.hpp" @@ -46,6 +51,38 @@ namespace MWLua providedServices["Travel"] = !rec.getTransport().empty(); return LuaUtil::makeReadOnly(providedServices); }); + + record["travelDestinations"] = sol::readonly_property([context](const T& rec) -> sol::table { + sol::state_view& lua = context.mLua->sol(); + sol::table travelDests(lua, sol::create); + if (!rec.getTransport().empty()) + { + + int index = 1; + for (const auto& dest : rec.getTransport()) + { + + sol::table travelDest(lua, sol::create); + + ESM::RefId cellId; + if (dest.mCellName.empty()) + { + const ESM::ExteriorCellLocation cellIndex + = ESM::positionToExteriorCellLocation(dest.mPos.pos[0], dest.mPos.pos[1]); + cellId = ESM::RefId::esm3ExteriorCell(cellIndex.mX, cellIndex.mY); + } + else + cellId = ESM::RefId::stringRefId(dest.mCellName); + travelDest["rotation"] = LuaUtil::asTransform(Misc::Convert::makeOsgQuat(dest.mPos.rot)); + travelDest["position"] = dest.mPos.asVec3(); + travelDest["cellId"] = cellId.serializeText(); + + travelDests[index] = LuaUtil::makeReadOnly(travelDest); + index++; + } + } + return LuaUtil::makeReadOnly(travelDests); + }); } } #endif // MWLUA_ACTOR_H diff --git a/apps/openmw/mwlua/worldbindings.cpp b/apps/openmw/mwlua/worldbindings.cpp index 4c09500788..16a287c30a 100644 --- a/apps/openmw/mwlua/worldbindings.cpp +++ b/apps/openmw/mwlua/worldbindings.cpp @@ -79,6 +79,10 @@ namespace MWLua api["getCellByName"] = [](std::string_view name) { return GCell{ &MWBase::Environment::get().getWorldModel()->getCell(name, /*forceLoad=*/false) }; }; + api["getCellById"] = [](std::string_view stringId) { + return GCell{ &MWBase::Environment::get().getWorldModel()->getCell( + ESM::RefId::deserializeText(stringId), /*forceLoad=*/false) }; + }; api["getExteriorCell"] = [](int x, int y, sol::object cellOrName) { ESM::RefId worldspace; if (cellOrName.is()) diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 4b9c56d844..b75f22748b 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -292,6 +292,7 @@ -- A cell of the game world. -- @type Cell -- @field #string name Name of the cell (can be empty string). +-- @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). diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index b711053c3b..39a3df579a 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -844,6 +844,7 @@ -- @field #number stealthSkill The base stealth skill of the creature. This is the skill value used for all skills with a 'stealth' specialization -- @field #list<#number> attack A table of the 3 randomly selected attacks used by creatures that do not carry weapons. The table consists of 6 numbers split into groups of 2 values corresponding to minimum and maximum damage in that order. -- @field #map<#string, #boolean> servicesOffered The services of the creature, in a table. Value is if the service is provided or not, and they are indexed by: Spells, Spellmaking, Enchanting, Training, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel. +-- @field #list<#TravelDestination> travelDestinations A list of @{#TravelDestination}s for this creature. --- @{#NPC} functions @@ -1121,7 +1122,13 @@ -- @field #number baseDisposition NPC's starting disposition -- @field #bool isMale The gender setting of the NPC -- @field #map<#string, #boolean> servicesOffered The services of the NPC, in a table. Value is if the service is provided or not, and they are indexed by: Spells, Spellmaking, Enchanting, Training, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel. +-- @field #list<#TravelDestination> travelDestinations A list of @{#TravelDestination}s for this NPC. +--- +-- @type TravelDestination +-- @field #string cellId ID of the Destination cell for this TravelDestination, Can be used with @{openmw_world#(world).getCellById}. +-- @field openmw.util#Vector3 position Destination position for this TravelDestination. +-- @field openmw.util#Transform rotation Destination rotation for this TravelDestination. -------------------------------------------------------------------------------- -- @{#Player} functions diff --git a/files/lua_api/openmw/world.lua b/files/lua_api/openmw/world.lua index 4e67fd4c7c..01eb4485a7 100644 --- a/files/lua_api/openmw/world.lua +++ b/files/lua_api/openmw/world.lua @@ -67,6 +67,12 @@ -- @param #string cellName -- @return openmw.core#Cell +--- +-- Loads a cell by ID provided +-- @function [parent=#world] getCellById +-- @param #string cellId +-- @return openmw.core#Cell + --- -- Loads an exterior cell by grid indices -- @function [parent=#world] getExteriorCell