Skip to content

Commit

Permalink
Merge branch 'lua_travel_dest_2' into 'master'
Browse files Browse the repository at this point in the history
Expose cell ID, Add actor travel destinations to types.Actor.record.servicesOffered

See merge request OpenMW/openmw!3592
  • Loading branch information
psi29a committed Jun 19, 2024
2 parents 6653502 + 533ce49 commit 3a686dd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/openmw/mwlua/cellbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions apps/openmw/mwlua/types/actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions apps/openmw/mwlua/worldbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>())
Expand Down
1 change: 1 addition & 0 deletions files/lua_api/openmw/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions files/lua_api/openmw/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions files/lua_api/openmw/world.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a686dd

Please sign in to comment.