1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 09:15:38 +00:00

Merge branch 'actors_range' into 'master'

Handle actors processing range in Lua

See merge request OpenMW/openmw!3458
This commit is contained in:
psi29a 2023-09-28 08:33:46 +00:00
commit 3ea14e904d
2 changed files with 26 additions and 0 deletions

View file

@ -4,9 +4,11 @@
#include <components/detournavigator/agentbounds.hpp>
#include <components/lua/luastate.hpp>
#include <components/settings/values.hpp>
#include "apps/openmw/mwbase/mechanicsmanager.hpp"
#include "apps/openmw/mwbase/windowmanager.hpp"
#include "apps/openmw/mwmechanics/actorutil.hpp"
#include "apps/openmw/mwmechanics/creaturestats.hpp"
#include "apps/openmw/mwmechanics/drawstate.hpp"
#include "apps/openmw/mwworld/class.hpp"
@ -374,6 +376,24 @@ namespace MWLua
result["halfExtents"] = agentBounds.mHalfExtents;
return result;
};
actor["isInActorsProcessingRange"] = [](const Object& o) {
const MWWorld::Ptr player = MWMechanics::getPlayer();
const auto& target = o.ptr();
if (target == player)
return true;
if (!target.getClass().isActor())
throw std::runtime_error("Actor expected");
if (target.getCell()->getCell()->getWorldSpace() != player.getCell()->getCell()->getWorldSpace())
return false;
const int actorsProcessingRange = Settings::game().mActorsProcessingRange;
const osg::Vec3f playerPos = player.getRefData().getPosition().asVec3();
const float dist = (playerPos - target.getRefData().getPosition().asVec3()).length();
return dist <= actorsProcessingRange;
};
actor["getEncumbrance"] = [](const Object& actor) -> float {
const MWWorld::Ptr ptr = actor.ptr();

View file

@ -21,6 +21,12 @@
-- @param openmw.core#GameObject actor
-- @return #table with `shapeType` and `halfExtents`
---
-- Check if given actor is in the actors processing range.
-- @function [parent=#Actor] isInActorsProcessingRange
-- @param openmw.core#GameObject actor
-- @return #boolean
---
-- Whether the object is an actor.
-- @function [parent=#Actor] objectIsInstance