extracted playGreetingIfPlayerGetsTooClose()

sceneinput
dteviot 10 years ago
parent df421fce92
commit 1ef78b1e56

@ -431,9 +431,29 @@ namespace MWMechanics
// Allow interrupting a walking actor to trigger a greeting // Allow interrupting a walking actor to trigger a greeting
if(idleNow || walking) 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 // 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); float helloDistance = static_cast<float>(hello);
static int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore() static int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt(); .get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt();
@ -446,6 +466,7 @@ namespace MWMechanics
float playerDistSqr = (playerPos - actorPos).length2(); float playerDistSqr = (playerPos - actorPos).length2();
int& greetingTimer = storage.mGreetingTimer; int& greetingTimer = storage.mGreetingTimer;
GreetingState& greetingState = storage.mSaidGreeting;
if (greetingState == Greet_None) if (greetingState == Greet_None)
{ {
if ((playerDistSqr <= helloDistance*helloDistance) && if ((playerDistSqr <= helloDistance*helloDistance) &&
@ -465,23 +486,23 @@ namespace MWMechanics
{ {
greetingTimer++; greetingTimer++;
if(walking) if (storage.mWalking)
{ {
stopWalking(actor, storage); stopWalking(actor, storage);
moveNow = false; storage.mMoveNow = false;
walking = false; storage.mWalking = false;
mObstacleCheck.clear(); mObstacleCheck.clear();
idleNow = true; storage.mIdleNow = true;
getRandomIdle(playedIdle); getRandomIdle(storage.mPlayedIdle);
} }
if(!rotate) if (!storage.mRotate)
{ {
osg::Vec3f dir = playerPos - actorPos; osg::Vec3f dir = playerPos - actorPos;
float faceAngleRadians = std::atan2(dir.x(), dir.y()); float faceAngleRadians = std::atan2(dir.x(), dir.y());
targetAngleRadians = faceAngleRadians; storage.mTargetAngleRadians = faceAngleRadians;
rotate = true; storage.mRotate = true;
} }
if (greetingTimer >= GREETING_SHOULD_END) 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) void AiWander::setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos)
{ {
unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size()); unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size());

@ -72,6 +72,7 @@ namespace MWMechanics
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect); bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
void getRandomIdle(unsigned short& playedIdle); void getRandomIdle(unsigned short& playedIdle);
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos); 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 mDistance; // how far the actor can wander from the spawn point
int mDuration; int mDuration;

Loading…
Cancel
Save