diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 519cc8a61..27dad88cd 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -22,6 +22,9 @@ namespace MWMechanics { static const int COUNT_BEFORE_RESET = 200; // TODO: maybe no longer needed static const float DOOR_CHECK_INTERVAL = 1.5f; + static const float REACTION_INTERVAL = 0.25f; + static const int GREETING_SHOULD_START = 4; //how many reaction intervals should pass before NPC can greet player + static const int GREETING_SHOULD_END = 10; AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector& idle, bool repeat): mDistance(distance), mDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle), mRepeat(repeat) @@ -44,6 +47,7 @@ namespace MWMechanics mRotate = false; mTargetAngle = 0; mSaidGreeting = Greet_None; + greetingTimer = 0; mHasReturnPosition = false; mReturnPosition = Ogre::Vector3(0,0,0); @@ -221,14 +225,14 @@ namespace MWMechanics } mReaction += duration; - if(mReaction < 0.25f) // FIXME: hard coded constant + if(mReaction < REACTION_INTERVAL) { return false; } else mReaction = 0; - // NOTE: everything below get updated every 0.25 seconds + // NOTE: everything below get updated every REACTION_INTERVAL seconds MWBase::World *world = MWBase::Environment::get().getWorld(); if(mDuration) @@ -424,16 +428,22 @@ namespace MWMechanics if (mSaidGreeting == Greet_None) { - // TODO: check if actor is aware / has line of sight if (playerDistSqr <= helloDistance*helloDistance) + greetingTimer++; + + // TODO: check if actor is aware / has line of sight + if (greetingTimer >= GREETING_SHOULD_START) { mSaidGreeting = Greet_InProgress; MWBase::Environment::get().getDialogueManager()->say(actor, "hello"); + greetingTimer = 0; } } if(mSaidGreeting == Greet_InProgress) { + greetingTimer++; + if(mWalking) { stopWalking(actor); @@ -460,7 +470,11 @@ namespace MWMechanics } } - mSaidGreeting = Greet_Done; + if (greetingTimer >= GREETING_SHOULD_END) + { + mSaidGreeting = Greet_Done; + greetingTimer = 0; + } } if (mSaidGreeting == MWMechanics::AiWander::Greet_Done) @@ -473,7 +487,6 @@ namespace MWMechanics } // Check if idle animation finished - // FIXME: don't stay forever if(!checkIdle(actor, mPlayedIdle) && (playerDistSqr > helloDistance*helloDistance || mSaidGreeting == MWMechanics::AiWander::Greet_Done)) { mPlayedIdle = 0; diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index fdfd6f42e..9b579b24a 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -68,6 +68,7 @@ namespace MWMechanics Greet_Done }; GreetingState mSaidGreeting; + int greetingTimer; bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position, // if we had the actor in the AiWander constructor...