1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-24 09:39:51 +00:00

Add grace periods for player greeting.

Add delay for NPC greating. NPC ignores greeted player after some time.
Fixes bug 1503.
This commit is contained in:
Michał Ściubidło 2014-07-28 23:41:37 +01:00
parent d47bfbe69c
commit bd3729a6cb
2 changed files with 19 additions and 5 deletions

View File

@ -22,6 +22,9 @@ namespace MWMechanics
{ {
static const int COUNT_BEFORE_RESET = 200; // TODO: maybe no longer needed static const int COUNT_BEFORE_RESET = 200; // TODO: maybe no longer needed
static const float DOOR_CHECK_INTERVAL = 1.5f; 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<unsigned char>& idle, bool repeat): AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat):
mDistance(distance), mDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle), mRepeat(repeat) mDistance(distance), mDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle), mRepeat(repeat)
@ -44,6 +47,7 @@ namespace MWMechanics
mRotate = false; mRotate = false;
mTargetAngle = 0; mTargetAngle = 0;
mSaidGreeting = Greet_None; mSaidGreeting = Greet_None;
greetingTimer = 0;
mHasReturnPosition = false; mHasReturnPosition = false;
mReturnPosition = Ogre::Vector3(0,0,0); mReturnPosition = Ogre::Vector3(0,0,0);
@ -221,14 +225,14 @@ namespace MWMechanics
} }
mReaction += duration; mReaction += duration;
if(mReaction < 0.25f) // FIXME: hard coded constant if(mReaction < REACTION_INTERVAL)
{ {
return false; return false;
} }
else else
mReaction = 0; 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(); MWBase::World *world = MWBase::Environment::get().getWorld();
if(mDuration) if(mDuration)
@ -424,16 +428,22 @@ namespace MWMechanics
if (mSaidGreeting == Greet_None) if (mSaidGreeting == Greet_None)
{ {
// TODO: check if actor is aware / has line of sight
if (playerDistSqr <= helloDistance*helloDistance) if (playerDistSqr <= helloDistance*helloDistance)
greetingTimer++;
// TODO: check if actor is aware / has line of sight
if (greetingTimer >= GREETING_SHOULD_START)
{ {
mSaidGreeting = Greet_InProgress; mSaidGreeting = Greet_InProgress;
MWBase::Environment::get().getDialogueManager()->say(actor, "hello"); MWBase::Environment::get().getDialogueManager()->say(actor, "hello");
greetingTimer = 0;
} }
} }
if(mSaidGreeting == Greet_InProgress) if(mSaidGreeting == Greet_InProgress)
{ {
greetingTimer++;
if(mWalking) if(mWalking)
{ {
stopWalking(actor); 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) if (mSaidGreeting == MWMechanics::AiWander::Greet_Done)
@ -473,7 +487,6 @@ namespace MWMechanics
} }
// Check if idle animation finished // Check if idle animation finished
// FIXME: don't stay forever
if(!checkIdle(actor, mPlayedIdle) && (playerDistSqr > helloDistance*helloDistance || mSaidGreeting == MWMechanics::AiWander::Greet_Done)) if(!checkIdle(actor, mPlayedIdle) && (playerDistSqr > helloDistance*helloDistance || mSaidGreeting == MWMechanics::AiWander::Greet_Done))
{ {
mPlayedIdle = 0; mPlayedIdle = 0;

View File

@ -68,6 +68,7 @@ namespace MWMechanics
Greet_Done Greet_Done
}; };
GreetingState mSaidGreeting; GreetingState mSaidGreeting;
int greetingTimer;
bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position, bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position,
// if we had the actor in the AiWander constructor... // if we had the actor in the AiWander constructor...