mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-10 12:59:58 -04:00
Make sure distance and duration are not negative
This commit is contained in:
parent
4a3ffb2073
commit
20bd1491a7
@ -46,10 +46,10 @@ namespace MWMechanics
|
|||||||
constexpr float idlePositionCheckInterval = 1.5f;
|
constexpr float idlePositionCheckInterval = 1.5f;
|
||||||
|
|
||||||
// to prevent overcrowding
|
// to prevent overcrowding
|
||||||
constexpr int destinationTolerance = 64;
|
constexpr unsigned destinationTolerance = 64;
|
||||||
|
|
||||||
// distance must be long enough that NPC will need to move to get there.
|
// distance must be long enough that NPC will need to move to get there.
|
||||||
constexpr int minimumWanderDistance = destinationTolerance * 2;
|
constexpr unsigned minimumWanderDistance = destinationTolerance * 2;
|
||||||
|
|
||||||
constexpr std::size_t maxIdleSize = 8;
|
constexpr std::size_t maxIdleSize = 8;
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ namespace MWMechanics
|
|||||||
|
|
||||||
AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat)
|
AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat)
|
||||||
: TypedAiPackage<AiWander>(repeat)
|
: TypedAiPackage<AiWander>(repeat)
|
||||||
, mDistance(std::max(0, distance))
|
, mDistance(static_cast<unsigned>(std::max(0, distance)))
|
||||||
, mDuration(std::max(0, duration))
|
, mDuration(static_cast<unsigned>(std::max(0, duration)))
|
||||||
, mRemainingDuration(duration)
|
, mRemainingDuration(duration)
|
||||||
, mTimeOfDay(timeOfDay)
|
, mTimeOfDay(timeOfDay)
|
||||||
, mIdle(getInitialIdle(idle))
|
, mIdle(getInitialIdle(idle))
|
||||||
@ -259,9 +259,6 @@ namespace MWMechanics
|
|||||||
|
|
||||||
bool AiWander::reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos)
|
bool AiWander::reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos)
|
||||||
{
|
{
|
||||||
if (mDistance <= 0)
|
|
||||||
storage.mCanWanderAlongPathGrid = false;
|
|
||||||
|
|
||||||
if (isPackageCompleted())
|
if (isPackageCompleted())
|
||||||
{
|
{
|
||||||
stopWalking(actor);
|
stopWalking(actor);
|
||||||
@ -915,10 +912,10 @@ namespace MWMechanics
|
|||||||
float length = delta.length();
|
float length = delta.length();
|
||||||
delta.normalize();
|
delta.normalize();
|
||||||
|
|
||||||
int distance = std::max(mDistance / 2, minimumWanderDistance);
|
unsigned distance = std::max(mDistance / 2, minimumWanderDistance);
|
||||||
|
|
||||||
// must not travel longer than distance between waypoints or NPC goes past waypoint
|
// must not travel longer than distance between waypoints or NPC goes past waypoint
|
||||||
distance = std::min(distance, static_cast<int>(length));
|
distance = std::min(distance, static_cast<unsigned>(length));
|
||||||
delta *= distance;
|
delta *= distance;
|
||||||
storage.mAllowedNodes.push_back(PathFinder::makePathgridPoint(vectorStart + delta));
|
storage.mAllowedNodes.push_back(PathFinder::makePathgridPoint(vectorStart + delta));
|
||||||
}
|
}
|
||||||
@ -970,8 +967,8 @@ namespace MWMechanics
|
|||||||
|
|
||||||
AiWander::AiWander(const ESM::AiSequence::AiWander* wander)
|
AiWander::AiWander(const ESM::AiSequence::AiWander* wander)
|
||||||
: TypedAiPackage<AiWander>(makeDefaultOptions().withRepeat(wander->mData.mShouldRepeat != 0))
|
: TypedAiPackage<AiWander>(makeDefaultOptions().withRepeat(wander->mData.mShouldRepeat != 0))
|
||||||
, mDistance(std::max(static_cast<short>(0), wander->mData.mDistance))
|
, mDistance(static_cast<unsigned>(std::max(static_cast<short>(0), wander->mData.mDistance)))
|
||||||
, mDuration(std::max(static_cast<short>(0), wander->mData.mDuration))
|
, mDuration(static_cast<unsigned>(std::max(static_cast<short>(0), wander->mData.mDuration)))
|
||||||
, mRemainingDuration(wander->mDurationData.mRemainingDuration)
|
, mRemainingDuration(wander->mDurationData.mRemainingDuration)
|
||||||
, mTimeOfDay(wander->mData.mTimeOfDay)
|
, mTimeOfDay(wander->mData.mTimeOfDay)
|
||||||
, mIdle(getInitialIdle(wander->mData.mIdle))
|
, mIdle(getInitialIdle(wander->mData.mIdle))
|
||||||
|
@ -147,8 +147,8 @@ namespace MWMechanics
|
|||||||
void completeManualWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
void completeManualWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
||||||
bool isNearAllowedNode(const MWWorld::Ptr& actor, const AiWanderStorage& storage, float distance) const;
|
bool isNearAllowedNode(const MWWorld::Ptr& actor, const AiWanderStorage& storage, float distance) const;
|
||||||
|
|
||||||
const int mDistance; // how far the actor can wander from the spawn point
|
const unsigned mDistance; // how far the actor can wander from the spawn point
|
||||||
const int mDuration;
|
const unsigned mDuration;
|
||||||
float mRemainingDuration;
|
float mRemainingDuration;
|
||||||
const int mTimeOfDay;
|
const int mTimeOfDay;
|
||||||
const std::vector<unsigned char> mIdle;
|
const std::vector<unsigned char> mIdle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user