1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 18:18:52 +00:00

Merge branch 'lua_travel_dest_2' into 'master'

Expose cell ID, Add actor travel destinations to types.Actor.record.servicesOffered

See merge request OpenMW/openmw!3592
This commit is contained in:
psi29a 2024-06-19 21:38:27 +00:00
commit 3a686dd8af
6 changed files with 57 additions and 0 deletions

View File

@ -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(

View File

@ -7,9 +7,14 @@
#include <components/esm3/loadclas.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/utilpackage.hpp>
#include <components/misc/convert.hpp>
#include <components/resource/resourcesystem.hpp>
#include "apps/openmw/mwbase/environment.hpp"
#include "apps/openmw/mwworld/esmstore.hpp"
#include <components/esm3/loadclas.hpp>
#include <components/esm3/loadnpc.hpp>
#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

View File

@ -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<GCell>())

View File

@ -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).

View File

@ -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

View File

@ -68,6 +68,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