forked from mirror/openmw-tes3mp
extracted playGreetingIfPlayerGetsTooClose()
This commit is contained in:
parent
df421fce92
commit
1ef78b1e56
2 changed files with 72 additions and 65 deletions
|
@ -431,9 +431,29 @@ namespace MWMechanics
|
|||
|
||||
// Allow interrupting a walking actor to trigger a greeting
|
||||
if(idleNow || walking)
|
||||
{
|
||||
playGreetingIfPlayerGetsTooClose(actor, storage);
|
||||
}
|
||||
|
||||
if(moveNow && mDistance)
|
||||
{
|
||||
// Construct a new path if there isn't one
|
||||
if(!storage.mPathFinder.isPathConstructed())
|
||||
{
|
||||
if (mAllowedNodes.size())
|
||||
{
|
||||
setPathToAnAllowedNode(actor, storage, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // AiWander package not yet completed
|
||||
}
|
||||
|
||||
void AiWander::playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage)
|
||||
{
|
||||
// Play a random voice greeting if the player gets too close
|
||||
int hello = cStats.getAiSetting(CreatureStats::AI_Hello).getModified();
|
||||
int hello = actor.getClass().getCreatureStats(actor).getAiSetting(CreatureStats::AI_Hello).getModified();
|
||||
float helloDistance = static_cast<float>(hello);
|
||||
static int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore()
|
||||
.get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt();
|
||||
|
@ -446,6 +466,7 @@ namespace MWMechanics
|
|||
float playerDistSqr = (playerPos - actorPos).length2();
|
||||
|
||||
int& greetingTimer = storage.mGreetingTimer;
|
||||
GreetingState& greetingState = storage.mSaidGreeting;
|
||||
if (greetingState == Greet_None)
|
||||
{
|
||||
if ((playerDistSqr <= helloDistance*helloDistance) &&
|
||||
|
@ -465,23 +486,23 @@ namespace MWMechanics
|
|||
{
|
||||
greetingTimer++;
|
||||
|
||||
if(walking)
|
||||
if (storage.mWalking)
|
||||
{
|
||||
stopWalking(actor, storage);
|
||||
moveNow = false;
|
||||
walking = false;
|
||||
storage.mMoveNow = false;
|
||||
storage.mWalking = false;
|
||||
mObstacleCheck.clear();
|
||||
idleNow = true;
|
||||
getRandomIdle(playedIdle);
|
||||
storage.mIdleNow = true;
|
||||
getRandomIdle(storage.mPlayedIdle);
|
||||
}
|
||||
|
||||
if(!rotate)
|
||||
if (!storage.mRotate)
|
||||
{
|
||||
osg::Vec3f dir = playerPos - actorPos;
|
||||
|
||||
float faceAngleRadians = std::atan2(dir.x(), dir.y());
|
||||
targetAngleRadians = faceAngleRadians;
|
||||
rotate = true;
|
||||
storage.mTargetAngleRadians = faceAngleRadians;
|
||||
storage.mRotate = true;
|
||||
}
|
||||
|
||||
if (greetingTimer >= GREETING_SHOULD_END)
|
||||
|
@ -499,21 +520,6 @@ namespace MWMechanics
|
|||
}
|
||||
}
|
||||
|
||||
if(moveNow && mDistance)
|
||||
{
|
||||
// Construct a new path if there isn't one
|
||||
if(!storage.mPathFinder.isPathConstructed())
|
||||
{
|
||||
if (mAllowedNodes.size())
|
||||
{
|
||||
setPathToAnAllowedNode(actor, storage, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // AiWander package not yet completed
|
||||
}
|
||||
|
||||
void AiWander::setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos)
|
||||
{
|
||||
unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size());
|
||||
|
|
|
@ -72,6 +72,7 @@ namespace MWMechanics
|
|||
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
|
||||
void getRandomIdle(unsigned short& playedIdle);
|
||||
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
|
||||
void playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
||||
|
||||
int mDistance; // how far the actor can wander from the spawn point
|
||||
int mDuration;
|
||||
|
|
Loading…
Reference in a new issue