mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-09 12:25:17 -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;
|
||||
|
||||
// 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.
|
||||
constexpr int minimumWanderDistance = destinationTolerance * 2;
|
||||
constexpr unsigned minimumWanderDistance = destinationTolerance * 2;
|
||||
|
||||
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)
|
||||
: TypedAiPackage<AiWander>(repeat)
|
||||
, mDistance(std::max(0, distance))
|
||||
, mDuration(std::max(0, duration))
|
||||
, mDistance(static_cast<unsigned>(std::max(0, distance)))
|
||||
, mDuration(static_cast<unsigned>(std::max(0, duration)))
|
||||
, mRemainingDuration(duration)
|
||||
, mTimeOfDay(timeOfDay)
|
||||
, mIdle(getInitialIdle(idle))
|
||||
@ -259,9 +259,6 @@ namespace MWMechanics
|
||||
|
||||
bool AiWander::reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos)
|
||||
{
|
||||
if (mDistance <= 0)
|
||||
storage.mCanWanderAlongPathGrid = false;
|
||||
|
||||
if (isPackageCompleted())
|
||||
{
|
||||
stopWalking(actor);
|
||||
@ -915,10 +912,10 @@ namespace MWMechanics
|
||||
float length = delta.length();
|
||||
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
|
||||
distance = std::min(distance, static_cast<int>(length));
|
||||
distance = std::min(distance, static_cast<unsigned>(length));
|
||||
delta *= distance;
|
||||
storage.mAllowedNodes.push_back(PathFinder::makePathgridPoint(vectorStart + delta));
|
||||
}
|
||||
@ -970,8 +967,8 @@ namespace MWMechanics
|
||||
|
||||
AiWander::AiWander(const ESM::AiSequence::AiWander* wander)
|
||||
: TypedAiPackage<AiWander>(makeDefaultOptions().withRepeat(wander->mData.mShouldRepeat != 0))
|
||||
, mDistance(std::max(static_cast<short>(0), wander->mData.mDistance))
|
||||
, mDuration(std::max(static_cast<short>(0), wander->mData.mDuration))
|
||||
, mDistance(static_cast<unsigned>(std::max(static_cast<short>(0), wander->mData.mDistance)))
|
||||
, mDuration(static_cast<unsigned>(std::max(static_cast<short>(0), wander->mData.mDuration)))
|
||||
, mRemainingDuration(wander->mDurationData.mRemainingDuration)
|
||||
, mTimeOfDay(wander->mData.mTimeOfDay)
|
||||
, mIdle(getInitialIdle(wander->mData.mIdle))
|
||||
|
@ -147,8 +147,8 @@ namespace MWMechanics
|
||||
void completeManualWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
||||
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 int mDuration;
|
||||
const unsigned mDistance; // how far the actor can wander from the spawn point
|
||||
const unsigned mDuration;
|
||||
float mRemainingDuration;
|
||||
const int mTimeOfDay;
|
||||
const std::vector<unsigned char> mIdle;
|
||||
|
Loading…
x
Reference in New Issue
Block a user