From 9aa992eede3d6e0ee711eac7fcf9709b94bf4fca Mon Sep 17 00:00:00 2001 From: "glassmancody.info" Date: Wed, 27 Sep 2023 17:19:08 -0700 Subject: [PATCH] add more lua bindings for encumbrance and capacity --- apps/openmw/mwlua/types/actor.cpp | 5 +++++ apps/openmw/mwlua/types/container.cpp | 6 ++++-- apps/openmw/mwlua/types/npc.cpp | 4 ++++ files/lua_api/openmw/types.lua | 16 ++++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 6edb363cd0..0de5603ecf 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -375,6 +375,11 @@ namespace MWLua return result; }; + actor["getEncumbrance"] = [](const Object& actor) -> float { + const MWWorld::Ptr ptr = actor.ptr(); + return ptr.getClass().getEncumbrance(ptr); + }; + addActorStatsBindings(actor, context); addActorMagicBindings(actor, context); } diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index dd246a73d5..25a1c1adce 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -31,14 +31,16 @@ namespace MWLua container["content"] = sol::overload([](const LObject& o) { return Inventory{ o }; }, [](const GObject& o) { return Inventory{ o }; }); container["inventory"] = container["content"]; - container["encumbrance"] = [](const Object& obj) -> float { + container["getEncumbrance"] = [](const Object& obj) -> float { const MWWorld::Ptr& ptr = containerPtr(obj); return ptr.getClass().getEncumbrance(ptr); }; - container["capacity"] = [](const Object& obj) -> float { + container["encumbrance"] = container["getEncumbrance"]; // for compatibility; should be removed later + container["getCapacity"] = [](const Object& obj) -> float { const MWWorld::Ptr& ptr = containerPtr(obj); return ptr.getClass().getCapacity(ptr); }; + container["capacity"] = container["getCapacity"]; // for compatibility; should be removed later auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index a3bb82098d..25997b6468 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -305,5 +305,9 @@ namespace MWLua return res; }; + npc["getCapacity"] = [](const Object& actor) -> float { + const MWWorld::Ptr ptr = actor.ptr(); + return ptr.getClass().getCapacity(ptr); + }; } } diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index df6e17c6f4..e44673e13a 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -9,6 +9,12 @@ --- Common functions for Creature, NPC, and Player. -- @type Actor +--- +-- Get the total weight of everything the actor is carrying, plus modifications from magic effects. +-- @function [parent=#Actor] getEncumbrance +-- @param openmw.core#GameObject actor +-- @return #number + --- -- Agent bounds to be used for pathfinding functions. -- @function [parent=#Actor] getPathfindingAgentBounds @@ -855,6 +861,12 @@ -- @param openmw.core#GameObject player The player that you want to check the disposition for. -- @return #number +--- +-- Get the total weight that the actor can carry. +-- @function [parent=#NPC] getCapacity +-- @param openmw.core#GameObject actor +-- @return #number + --- -- Whether the NPC or player is in the werewolf form at the moment. -- @function [parent=#NPC] isWerewolf @@ -1639,13 +1651,13 @@ --- -- Returns the total weight of everything in a container --- @function [parent=#Container] encumbrance +-- @function [parent=#Container] getEncumbrance -- @param openmw.core#GameObject object -- @return #number --- -- Returns the capacity of a container --- @function [parent=#Container] capacity +-- @function [parent=#Container] getCapacity -- @param openmw.core#GameObject object -- @return #number