extracted playGreetingIfPlayerGetsTooClose()

sceneinput
dteviot 10 years ago
parent df421fce92
commit 1ef78b1e56

@ -432,86 +432,92 @@ 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)
{ {
// Play a random voice greeting if the player gets too close playGreetingIfPlayerGetsTooClose(actor, storage);
int hello = cStats.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();
helloDistance *= iGreetDistanceMultiplier;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
osg::Vec3f playerPos(player.getRefData().getPosition().asVec3());
osg::Vec3f actorPos(actor.getRefData().getPosition().asVec3());
float playerDistSqr = (playerPos - actorPos).length2();
int& greetingTimer = storage.mGreetingTimer; if(moveNow && mDistance)
if (greetingState == Greet_None) {
// Construct a new path if there isn't one
if(!storage.mPathFinder.isPathConstructed())
{ {
if ((playerDistSqr <= helloDistance*helloDistance) && if (mAllowedNodes.size())
!player.getClass().getCreatureStats(player).isDead() && MWBase::Environment::get().getWorld()->getLOS(player, actor)
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, actor))
greetingTimer++;
if (greetingTimer >= GREETING_SHOULD_START)
{ {
greetingState = Greet_InProgress; setPathToAnAllowedNode(actor, storage, pos);
MWBase::Environment::get().getDialogueManager()->say(actor, "hello");
greetingTimer = 0;
} }
} }
}
if(greetingState == Greet_InProgress) return false; // AiWander package not yet completed
{ }
greetingTimer++;
if(walking) void AiWander::playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage)
{ {
stopWalking(actor, storage); // Play a random voice greeting if the player gets too close
moveNow = false; int hello = actor.getClass().getCreatureStats(actor).getAiSetting(CreatureStats::AI_Hello).getModified();
walking = false; float helloDistance = static_cast<float>(hello);
mObstacleCheck.clear(); static int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore()
idleNow = true; .get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt();
getRandomIdle(playedIdle);
}
if(!rotate) helloDistance *= iGreetDistanceMultiplier;
{
osg::Vec3f dir = playerPos - actorPos;
float faceAngleRadians = std::atan2(dir.x(), dir.y()); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
targetAngleRadians = faceAngleRadians; osg::Vec3f playerPos(player.getRefData().getPosition().asVec3());
rotate = true; osg::Vec3f actorPos(actor.getRefData().getPosition().asVec3());
} float playerDistSqr = (playerPos - actorPos).length2();
if (greetingTimer >= GREETING_SHOULD_END) int& greetingTimer = storage.mGreetingTimer;
{ GreetingState& greetingState = storage.mSaidGreeting;
greetingState = Greet_Done; if (greetingState == Greet_None)
greetingTimer = 0; {
} if ((playerDistSqr <= helloDistance*helloDistance) &&
} !player.getClass().getCreatureStats(player).isDead() && MWBase::Environment::get().getWorld()->getLOS(player, actor)
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, actor))
greetingTimer++;
if (greetingState == MWMechanics::AiWander::Greet_Done) if (greetingTimer >= GREETING_SHOULD_START)
{ {
float resetDist = 2*helloDistance; greetingState = Greet_InProgress;
if (playerDistSqr >= resetDist*resetDist) MWBase::Environment::get().getDialogueManager()->say(actor, "hello");
greetingState = Greet_None; greetingTimer = 0;
} }
} }
if(moveNow && mDistance) if (greetingState == Greet_InProgress)
{ {
// Construct a new path if there isn't one greetingTimer++;
if(!storage.mPathFinder.isPathConstructed())
if (storage.mWalking)
{ {
if (mAllowedNodes.size()) stopWalking(actor, storage);
{ storage.mMoveNow = false;
setPathToAnAllowedNode(actor, storage, pos); storage.mWalking = false;
} mObstacleCheck.clear();
storage.mIdleNow = true;
getRandomIdle(storage.mPlayedIdle);
}
if (!storage.mRotate)
{
osg::Vec3f dir = playerPos - actorPos;
float faceAngleRadians = std::atan2(dir.x(), dir.y());
storage.mTargetAngleRadians = faceAngleRadians;
storage.mRotate = true;
}
if (greetingTimer >= GREETING_SHOULD_END)
{
greetingState = Greet_Done;
greetingTimer = 0;
} }
} }
return false; // AiWander package not yet completed if (greetingState == MWMechanics::AiWander::Greet_Done)
{
float resetDist = 2 * helloDistance;
if (playerDistSqr >= resetDist*resetDist)
greetingState = Greet_None;
}
} }
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)

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