Unifiy evadeObstacles() logic between AiWander and AiPackage

Can't use same code, but logic is now same.
sceneinput
dteviot 9 years ago
parent f59e918a3b
commit 31d82b6b0c

@ -92,30 +92,35 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
return true;
else
{
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
evadeObstacles(actor, duration, pos);
}
return false;
}
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
if(mObstacleCheck.check(actor, duration))
void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float duration, ESM::Position& pos)
{
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
if (mObstacleCheck.check(actor, duration))
{
// first check if we're walking into a door
MWWorld::Ptr door = getNearbyDoor(actor);
if (door != MWWorld::Ptr()) // NOTE: checks interior cells only
{
// first check if we're walking into a door
MWWorld::Ptr door = getNearbyDoor(actor);
if(door != MWWorld::Ptr()) // NOTE: checks interior cells only
{
if(!door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() && door.getClass().getDoorState(door) == 0) { //Open the door if untrapped
MWBase::Environment::get().getWorld()->activateDoor(door, 1);
}
}
else // probably walking into another NPC
{
movement.mPosition[0] = 1;
movement.mPosition[1] = 1;
if (!door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() && door.getClass().getDoorState(door) == 0) { //Open the door if untrapped
MWBase::Environment::get().getWorld()->activateDoor(door, 1);
}
}
else { //Not stuck, so reset things
movement.mPosition[1] = 1; //Just run forward
else // probably walking into another NPC
{
movement.mPosition[0] = 1;
movement.mPosition[1] = 1;
}
}
return false;
else { //Not stuck, so reset things
movement.mPosition[1] = 1; //Just run forward
}
}
bool MWMechanics::AiPackage::doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell)

@ -85,6 +85,10 @@ namespace MWMechanics
float mTimer;
ESM::Pathgrid::Point mPrevDest;
private:
void evadeObstacles(const MWWorld::Ptr& actor, float duration, ESM::Position& pos);
};
}

@ -381,11 +381,7 @@ namespace MWMechanics
else
{
// have not yet reached the destination
//... turn towards the next point in mPath
zTurn(actor, storage.mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
evadeObstacles(actor, storage, duration);
evadeObstacles(actor, storage, duration, pos);
}
}
@ -417,8 +413,12 @@ namespace MWMechanics
storage.mState = Wander_IdleNow;
}
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration)
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration, ESM::Position& pos)
{
// turn towards the next point in mPath
zTurn(actor, storage.mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
if (mObstacleCheck.check(actor, duration))
{
// first check if we're walking into a door
@ -435,11 +435,15 @@ namespace MWMechanics
{
// TODO: diagonal should have same animation as walk forward
// but doesn't seem to do that?
actor.getClass().getMovementSettings(actor).mPosition[0] = 1;
actor.getClass().getMovementSettings(actor).mPosition[1] = 0.1f;
movement.mPosition[0] = 1;
movement.mPosition[1] = 0.1f;
}
mStuckCount++; // TODO: maybe no longer needed
}
else
{
movement.mPosition[1] = 1;
}
//#if 0
// TODO: maybe no longer needed
if (mStuckCount >= COUNT_BEFORE_RESET) // something has gone wrong, reset

@ -83,7 +83,7 @@ namespace MWMechanics
short unsigned getRandomIdle();
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
void playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage);
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration);
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration, ESM::Position& pos);
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);

Loading…
Cancel
Save