1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-19 16:39:41 +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 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):
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;

View file

@ -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...