mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
extracted functions doPerFrameActionsForState() and onChooseActionStatePerFrameActions().
This commit is contained in:
parent
76f95eafe7
commit
9c0e3d6c28
2 changed files with 52 additions and 35 deletions
|
@ -193,39 +193,7 @@ namespace MWMechanics
|
|||
|
||||
ESM::Position pos = actor.getRefData().getPosition();
|
||||
|
||||
|
||||
WanderState& wanderState = storage.mState;
|
||||
|
||||
if (wanderState == Wander_IdleNow)
|
||||
{
|
||||
onIdleStatePerFrameActions(actor, duration, storage);
|
||||
}
|
||||
|
||||
if (wanderState == Wander_Walking)
|
||||
{
|
||||
onWalkingStatePerFrameActions(actor, duration, storage, pos);
|
||||
}
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
if (wanderState == Wander_ChooseAction)
|
||||
{
|
||||
short unsigned& idleAnimation = storage.mIdleAnimation;
|
||||
idleAnimation = getRandomIdle();
|
||||
|
||||
if(!idleAnimation && mDistance)
|
||||
{
|
||||
wanderState = Wander_MoveNow;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander:
|
||||
MWWorld::TimeStamp currentTime = world->getTimeStamp();
|
||||
mStartTime = currentTime;
|
||||
playIdle(actor, idleAnimation);
|
||||
wanderState = Wander_IdleNow;
|
||||
}
|
||||
}
|
||||
doPerFrameActionsForState(actor, duration, storage, pos);
|
||||
|
||||
playIdleDialogueRandomly(actor);
|
||||
|
||||
|
@ -243,7 +211,7 @@ namespace MWMechanics
|
|||
if(mDuration)
|
||||
{
|
||||
// End package if duration is complete or mid-night hits:
|
||||
MWWorld::TimeStamp currentTime = world->getTimeStamp();
|
||||
MWWorld::TimeStamp currentTime = MWBase::Environment::get().getWorld()->getTimeStamp();
|
||||
if((currentTime.getHour() >= mStartTime.getHour() + mDuration) ||
|
||||
(int(currentTime.getHour()) == 0 && currentTime.getDay() != mStartTime.getDay()))
|
||||
{
|
||||
|
@ -288,12 +256,13 @@ namespace MWMechanics
|
|||
|
||||
if(storage.mPathFinder.isPathConstructed())
|
||||
{
|
||||
wanderState = Wander_Walking;
|
||||
storage.mState = Wander_Walking;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allow interrupting a walking actor to trigger a greeting
|
||||
WanderState& wanderState = storage.mState;
|
||||
if ((wanderState == Wander_IdleNow) || (wanderState == Wander_Walking))
|
||||
{
|
||||
playGreetingIfPlayerGetsTooClose(actor, storage);
|
||||
|
@ -314,6 +283,32 @@ namespace MWMechanics
|
|||
return false; // AiWander package not yet completed
|
||||
}
|
||||
|
||||
void AiWander::doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos)
|
||||
{
|
||||
switch (storage.mState)
|
||||
{
|
||||
case Wander_IdleNow:
|
||||
onIdleStatePerFrameActions(actor, duration, storage);
|
||||
break;
|
||||
|
||||
case Wander_Walking:
|
||||
onWalkingStatePerFrameActions(actor, duration, storage, pos);
|
||||
break;
|
||||
|
||||
case Wander_ChooseAction:
|
||||
onChooseActionStatePerFrameActions(actor, storage);
|
||||
break;
|
||||
|
||||
case Wander_MoveNow:
|
||||
break; // nothing to do
|
||||
|
||||
default:
|
||||
// should never get here
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AiWander::onIdleStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage)
|
||||
{
|
||||
// Check if an idle actor is too close to a door - if so start walking
|
||||
|
@ -369,6 +364,26 @@ namespace MWMechanics
|
|||
}
|
||||
}
|
||||
|
||||
void AiWander::onChooseActionStatePerFrameActions(const MWWorld::Ptr& actor, AiWanderStorage& storage)
|
||||
{
|
||||
|
||||
short unsigned& idleAnimation = storage.mIdleAnimation;
|
||||
idleAnimation = getRandomIdle();
|
||||
|
||||
if (!idleAnimation && mDistance)
|
||||
{
|
||||
storage.mState = Wander_MoveNow;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander:
|
||||
MWWorld::TimeStamp currentTime = MWBase::Environment::get().getWorld()->getTimeStamp();
|
||||
mStartTime = currentTime;
|
||||
playIdle(actor, idleAnimation);
|
||||
storage.mState = Wander_IdleNow;
|
||||
}
|
||||
}
|
||||
|
||||
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration)
|
||||
{
|
||||
if (mObstacleCheck.check(actor, duration))
|
||||
|
|
|
@ -83,8 +83,10 @@ namespace MWMechanics
|
|||
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration);
|
||||
void playIdleDialogueRandomly(const MWWorld::Ptr& actor);
|
||||
void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage);
|
||||
void doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos);
|
||||
void onIdleStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage);
|
||||
void onWalkingStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos);
|
||||
void onChooseActionStatePerFrameActions(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