|
|
|
@ -13,6 +13,8 @@
|
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwphysics/collisiontype.hpp"
|
|
|
|
|
|
|
|
|
|
#include "pathgrid.hpp"
|
|
|
|
|
#include "creaturestats.hpp"
|
|
|
|
|
#include "steering.hpp"
|
|
|
|
@ -45,6 +47,16 @@ namespace MWMechanics
|
|
|
|
|
std::string("idle9"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
inline int getCountBeforeReset(const MWWorld::ConstPtr& actor)
|
|
|
|
|
{
|
|
|
|
|
if (actor.getClass().isPureWaterCreature(actor) || actor.getClass().isPureFlyingCreature(actor))
|
|
|
|
|
return 1;
|
|
|
|
|
return COUNT_BEFORE_RESET;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat):
|
|
|
|
|
mDistance(distance), mDuration(duration), mRemainingDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle),
|
|
|
|
|
mRepeat(repeat), mStoredInitialActorPosition(false), mInitialActorPosition(osg::Vec3f(0, 0, 0)),
|
|
|
|
@ -298,7 +310,8 @@ namespace MWMechanics
|
|
|
|
|
const auto currentPosition = actor.getRefData().getPosition().asVec3();
|
|
|
|
|
|
|
|
|
|
std::size_t attempts = 10; // If a unit can't wander out of water, don't want to hang here
|
|
|
|
|
bool isWaterCreature = actor.getClass().isPureWaterCreature(actor);
|
|
|
|
|
const bool isWaterCreature = actor.getClass().isPureWaterCreature(actor);
|
|
|
|
|
const bool isFlyingCreature = actor.getClass().isPureFlyingCreature(actor);
|
|
|
|
|
do {
|
|
|
|
|
// Determine a random location within radius of original position
|
|
|
|
|
const float wanderRadius = (0.2f + Misc::Rng::rollClosedProbability() * 0.8f) * wanderDistance;
|
|
|
|
@ -309,22 +322,31 @@ namespace MWMechanics
|
|
|
|
|
mDestination = osg::Vec3f(destinationX, destinationY, destinationZ);
|
|
|
|
|
|
|
|
|
|
// Check if land creature will walk onto water or if water creature will swim onto land
|
|
|
|
|
if ((!isWaterCreature && !destinationIsAtWater(actor, mDestination)) ||
|
|
|
|
|
(isWaterCreature && !destinationThroughGround(currentPosition, mDestination)))
|
|
|
|
|
if (!isWaterCreature && destinationIsAtWater(actor, mDestination))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ((isWaterCreature || isFlyingCreature) && destinationThroughGround(currentPosition, mDestination))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (isWaterCreature || isFlyingCreature)
|
|
|
|
|
{
|
|
|
|
|
mPathFinder.buildStraightPath(mDestination);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(actor);
|
|
|
|
|
mPathFinder.buildPath(actor, currentPosition, mDestination, actor.getCell(),
|
|
|
|
|
getPathGridGraph(actor.getCell()), halfExtents, getNavigatorFlags(actor));
|
|
|
|
|
mPathFinder.addPointToPath(mDestination);
|
|
|
|
|
mPathFinder.buildPathByNavMesh(actor, currentPosition, mDestination, halfExtents,
|
|
|
|
|
getNavigatorFlags(actor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mPathFinder.isPathConstructed())
|
|
|
|
|
{
|
|
|
|
|
storage.setState(AiWanderStorage::Wander_Walking, true);
|
|
|
|
|
mHasDestination = true;
|
|
|
|
|
mUsePathgrid = false;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
if (mPathFinder.isPathConstructed())
|
|
|
|
|
{
|
|
|
|
|
storage.setState(AiWanderStorage::Wander_Walking, true);
|
|
|
|
|
mHasDestination = true;
|
|
|
|
|
mUsePathgrid = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
} while (--attempts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -342,8 +364,10 @@ namespace MWMechanics
|
|
|
|
|
* Returns true if the start to end point travels through a collision point (land).
|
|
|
|
|
*/
|
|
|
|
|
bool AiWander::destinationThroughGround(const osg::Vec3f& startPoint, const osg::Vec3f& destination) {
|
|
|
|
|
const int mask = MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap | MWPhysics::CollisionType_Door;
|
|
|
|
|
return MWBase::Environment::get().getWorld()->castRay(startPoint.x(), startPoint.y(), startPoint.z(),
|
|
|
|
|
destination.x(), destination.y(), destination.z());
|
|
|
|
|
destination.x(), destination.y(), destination.z(),
|
|
|
|
|
mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AiWander::completeManualWalking(const MWWorld::Ptr &actor, AiWanderStorage &storage) {
|
|
|
|
@ -479,7 +503,7 @@ namespace MWMechanics
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if stuck for sufficiently long, act like current location was the destination
|
|
|
|
|
if (storage.mStuckCount >= COUNT_BEFORE_RESET) // something has gone wrong, reset
|
|
|
|
|
if (storage.mStuckCount >= getCountBeforeReset(actor)) // something has gone wrong, reset
|
|
|
|
|
{
|
|
|
|
|
mObstacleCheck.clear();
|
|
|
|
|
stopWalking(actor, storage);
|
|
|
|
|