mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 11:39:43 +00:00
Pulled duplicate code into function.
This commit is contained in:
parent
fae93e3d82
commit
9a02a85a24
2 changed files with 14 additions and 13 deletions
|
@ -498,14 +498,8 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
assert(mAllowedNodes.size());
|
assert(mAllowedNodes.size());
|
||||||
unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size());
|
unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size());
|
||||||
// NOTE: initially constructed with local (i.e. cell) co-ordinates
|
|
||||||
// convert dest to use world co-ordinates
|
|
||||||
ESM::Pathgrid::Point dest(mAllowedNodes[randNode]);
|
ESM::Pathgrid::Point dest(mAllowedNodes[randNode]);
|
||||||
if (currentCell->getCell()->isExterior())
|
ToWorldCoordinates(dest, currentCell->getCell());
|
||||||
{
|
|
||||||
dest.mX += currentCell->getCell()->mData.mX * ESM::Land::REAL_SIZE;
|
|
||||||
dest.mY += currentCell->getCell()->mData.mY * ESM::Land::REAL_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// actor position is already in world co-ordinates
|
// actor position is already in world co-ordinates
|
||||||
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
||||||
|
@ -537,6 +531,15 @@ namespace MWMechanics
|
||||||
return false; // AiWander package not yet completed
|
return false; // AiWander package not yet completed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AiWander::ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell)
|
||||||
|
{
|
||||||
|
if (cell->isExterior())
|
||||||
|
{
|
||||||
|
point.mX += cell->mData.mX * ESM::Land::REAL_SIZE;
|
||||||
|
point.mY += cell->mData.mY * ESM::Land::REAL_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AiWander::trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes,
|
void AiWander::trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes,
|
||||||
const PathFinder& pathfinder)
|
const PathFinder& pathfinder)
|
||||||
{
|
{
|
||||||
|
@ -643,12 +646,7 @@ namespace MWMechanics
|
||||||
// apply a slight offset to prevent overcrowding
|
// apply a slight offset to prevent overcrowding
|
||||||
dest.mX += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64);
|
dest.mX += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64);
|
||||||
dest.mY += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64);
|
dest.mY += static_cast<int>(Misc::Rng::rollProbability() * 128 - 64);
|
||||||
|
ToWorldCoordinates(dest, actor.getCell()->getCell());
|
||||||
if (actor.getCell()->isExterior())
|
|
||||||
{
|
|
||||||
dest.mX += actor.getCell()->getCell()->mData.mX * ESM::Land::REAL_SIZE;
|
|
||||||
dest.mY += actor.getCell()->getCell()->mData.mY * ESM::Land::REAL_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX),
|
MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX),
|
||||||
static_cast<float>(dest.mY), static_cast<float>(dest.mZ));
|
static_cast<float>(dest.mY), static_cast<float>(dest.mZ));
|
||||||
|
|
|
@ -118,6 +118,9 @@ namespace MWMechanics
|
||||||
GroupIndex_MaxIdle = 9
|
GroupIndex_MaxIdle = 9
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// convert point from local (i.e. cell) to world co-ordinates
|
||||||
|
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
|
||||||
|
|
||||||
/// lookup table for converting idleSelect value to groupName
|
/// lookup table for converting idleSelect value to groupName
|
||||||
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
|
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue