|
|
|
@ -31,6 +31,18 @@ namespace MWMechanics
|
|
|
|
|
static const int GREETING_SHOULD_START = 4; //how many reaction intervals should pass before NPC can greet player
|
|
|
|
|
static const int GREETING_SHOULD_END = 10;
|
|
|
|
|
|
|
|
|
|
const std::string AiWander::sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1] =
|
|
|
|
|
{
|
|
|
|
|
std::string("idle2"),
|
|
|
|
|
std::string("idle3"),
|
|
|
|
|
std::string("idle4"),
|
|
|
|
|
std::string("idle5"),
|
|
|
|
|
std::string("idle6"),
|
|
|
|
|
std::string("idle7"),
|
|
|
|
|
std::string("idle8"),
|
|
|
|
|
std::string("idle9"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// \brief This class holds the variables AiWander needs which are deleted if the package becomes inactive.
|
|
|
|
|
struct AiWanderStorage : AiTemporaryBase
|
|
|
|
|
{
|
|
|
|
@ -205,7 +217,7 @@ namespace MWMechanics
|
|
|
|
|
// Are we there yet?
|
|
|
|
|
bool& chooseAction = storage.mChooseAction;
|
|
|
|
|
if(walking &&
|
|
|
|
|
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2], 64.f))
|
|
|
|
|
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], 64.f))
|
|
|
|
|
{
|
|
|
|
|
stopWalking(actor, storage);
|
|
|
|
|
moveNow = false;
|
|
|
|
@ -580,44 +592,24 @@ namespace MWMechanics
|
|
|
|
|
|
|
|
|
|
void AiWander::playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect)
|
|
|
|
|
{
|
|
|
|
|
if(idleSelect == 2)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle2", 0, 1);
|
|
|
|
|
else if(idleSelect == 3)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle3", 0, 1);
|
|
|
|
|
else if(idleSelect == 4)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle4", 0, 1);
|
|
|
|
|
else if(idleSelect == 5)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle5", 0, 1);
|
|
|
|
|
else if(idleSelect == 6)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle6", 0, 1);
|
|
|
|
|
else if(idleSelect == 7)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle7", 0, 1);
|
|
|
|
|
else if(idleSelect == 8)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle8", 0, 1);
|
|
|
|
|
else if(idleSelect == 9)
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle9", 0, 1);
|
|
|
|
|
if ((GroupIndex_MinIdle <= idleSelect) && (idleSelect <= GroupIndex_MaxIdle))
|
|
|
|
|
{
|
|
|
|
|
const std::string& groupName = sIdleSelectToGroupName[idleSelect - GroupIndex_MinIdle];
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, groupName, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AiWander::checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect)
|
|
|
|
|
{
|
|
|
|
|
if(idleSelect == 2)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle2");
|
|
|
|
|
else if(idleSelect == 3)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle3");
|
|
|
|
|
else if(idleSelect == 4)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle4");
|
|
|
|
|
else if(idleSelect == 5)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle5");
|
|
|
|
|
else if(idleSelect == 6)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle6");
|
|
|
|
|
else if(idleSelect == 7)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle7");
|
|
|
|
|
else if(idleSelect == 8)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle8");
|
|
|
|
|
else if(idleSelect == 9)
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, "idle9");
|
|
|
|
|
if ((GroupIndex_MinIdle <= idleSelect) && (idleSelect <= GroupIndex_MaxIdle))
|
|
|
|
|
{
|
|
|
|
|
const std::string& groupName = sIdleSelectToGroupName[idleSelect - GroupIndex_MinIdle];
|
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->checkAnimationPlaying(actor, groupName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AiWander::setReturnPosition(const Ogre::Vector3& position)
|
|
|
|
@ -694,7 +686,8 @@ namespace MWMechanics
|
|
|
|
|
// If there is no path this actor doesn't go anywhere. See:
|
|
|
|
|
// https://forum.openmw.org/viewtopic.php?t=1556
|
|
|
|
|
// http://www.fliggerty.com/phpBB3/viewtopic.php?f=30&t=5833
|
|
|
|
|
if(!pathgrid || pathgrid->mPoints.empty())
|
|
|
|
|
// Note: In order to wander, need at least two points.
|
|
|
|
|
if(!pathgrid || (pathgrid->mPoints.size() < 2))
|
|
|
|
|
mDistance = 0;
|
|
|
|
|
|
|
|
|
|
// A distance value passed into the constructor indicates how far the
|
|
|
|
@ -738,12 +731,37 @@ namespace MWMechanics
|
|
|
|
|
}
|
|
|
|
|
mCurrentNode = mAllowedNodes[index];
|
|
|
|
|
mAllowedNodes.erase(mAllowedNodes.begin() + index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In vanilla Morrowind, sometimes distance is too small to include at least two points,
|
|
|
|
|
// in which case, we will take the two closest points regardless of the wander distance
|
|
|
|
|
// This is a backup option, as std::sort is potentially O(n^2) in time.
|
|
|
|
|
if (mAllowedNodes.empty())
|
|
|
|
|
{
|
|
|
|
|
// Start with list of PathGrid nodes, sorted by distance from actor
|
|
|
|
|
std::vector<PathDistance> nodeDistances;
|
|
|
|
|
for (unsigned int counter = 0; counter < pathgrid->mPoints.size(); counter++)
|
|
|
|
|
{
|
|
|
|
|
float distance = npcPos.squaredDistance(PathFinder::MakeOgreVector3(pathgrid->mPoints[counter]));
|
|
|
|
|
nodeDistances.push_back(std::make_pair(distance, &pathgrid->mPoints.at(counter)));
|
|
|
|
|
}
|
|
|
|
|
std::sort(nodeDistances.begin(), nodeDistances.end(), sortByDistance);
|
|
|
|
|
|
|
|
|
|
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
|
|
|
|
// make closest node the current node
|
|
|
|
|
mCurrentNode = *nodeDistances[0].second;
|
|
|
|
|
|
|
|
|
|
// give Actor a 2nd node to walk to
|
|
|
|
|
mAllowedNodes.push_back(*nodeDistances[1].second);
|
|
|
|
|
}
|
|
|
|
|
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AiWander::sortByDistance(const PathDistance& left, const PathDistance& right)
|
|
|
|
|
{
|
|
|
|
|
return left.first < right.first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AiWander::writeState(ESM::AiSequence::AiSequence &sequence) const
|
|
|
|
|
{
|
|
|
|
|
std::auto_ptr<ESM::AiSequence::AiWander> wander(new ESM::AiSequence::AiWander());
|
|
|
|
|