mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-07 12:54:00 +00:00
Handle actors processing range in Lua
This commit is contained in:
parent
0e4a599656
commit
40c8783790
@ -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;
|
||||
};
|
||||
|
||||
addActorStatsBindings(actor, context);
|
||||
addActorMagicBindings(actor, context);
|
||||
|
@ -15,6 +15,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
|
||||
|
Loading…
Reference in New Issue
Block a user