mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 22:15:37 +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:
commit
3ea14e904d
2 changed files with 26 additions and 0 deletions
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
#include <components/detournavigator/agentbounds.hpp>
|
#include <components/detournavigator/agentbounds.hpp>
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
|
#include <components/settings/values.hpp>
|
||||||
|
|
||||||
#include "apps/openmw/mwbase/mechanicsmanager.hpp"
|
#include "apps/openmw/mwbase/mechanicsmanager.hpp"
|
||||||
#include "apps/openmw/mwbase/windowmanager.hpp"
|
#include "apps/openmw/mwbase/windowmanager.hpp"
|
||||||
|
#include "apps/openmw/mwmechanics/actorutil.hpp"
|
||||||
#include "apps/openmw/mwmechanics/creaturestats.hpp"
|
#include "apps/openmw/mwmechanics/creaturestats.hpp"
|
||||||
#include "apps/openmw/mwmechanics/drawstate.hpp"
|
#include "apps/openmw/mwmechanics/drawstate.hpp"
|
||||||
#include "apps/openmw/mwworld/class.hpp"
|
#include "apps/openmw/mwworld/class.hpp"
|
||||||
|
@ -374,6 +376,24 @@ namespace MWLua
|
||||||
result["halfExtents"] = agentBounds.mHalfExtents;
|
result["halfExtents"] = agentBounds.mHalfExtents;
|
||||||
return result;
|
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 {
|
actor["getEncumbrance"] = [](const Object& actor) -> float {
|
||||||
const MWWorld::Ptr ptr = actor.ptr();
|
const MWWorld::Ptr ptr = actor.ptr();
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
-- @param openmw.core#GameObject actor
|
-- @param openmw.core#GameObject actor
|
||||||
-- @return #table with `shapeType` and `halfExtents`
|
-- @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.
|
-- Whether the object is an actor.
|
||||||
-- @function [parent=#Actor] objectIsInstance
|
-- @function [parent=#Actor] objectIsInstance
|
||||||
|
|
Loading…
Reference in a new issue