forked from mirror/openmw-tes3mp
Correction to teleportation changes.
OMW Bug #2400 Related to OMW Bug #1533 Don't crash when finding the closest marker to an exterior position.
This commit is contained in:
parent
da9bd09a8c
commit
691ebd2372
2 changed files with 29 additions and 19 deletions
|
@ -2832,6 +2832,10 @@ namespace MWWorld
|
|||
|
||||
MWWorld::Ptr World::getClosestMarker( const MWWorld::Ptr &ptr, const std::string &id )
|
||||
{
|
||||
if ( ptr.getCell()->isExterior() ) {
|
||||
return getClosestMarkerFromExteriorPosition(mPlayer->getLastKnownExteriorPosition(), id);
|
||||
}
|
||||
|
||||
// Search for a 'nearest' marker, counting each cell between the starting
|
||||
// cell and the exterior as a distance of 1. If an exterior is found, jump
|
||||
// to the nearest exterior marker, without further interior searching.
|
||||
|
@ -2868,25 +2872,7 @@ namespace MWWorld
|
|||
if (ref.mRef.getDestCell().empty())
|
||||
{
|
||||
Ogre::Vector3 worldPos = Ogre::Vector3(ref.mRef.getDoorDest().pos);
|
||||
float closestDistance = FLT_MAX;
|
||||
|
||||
MWWorld::Ptr closestMarker;
|
||||
std::vector<MWWorld::Ptr> markers;
|
||||
mCells.getExteriorPtrs(id, markers);
|
||||
for (std::vector<MWWorld::Ptr>::iterator it2 = markers.begin(); it2 != markers.end(); ++it2)
|
||||
{
|
||||
ESM::Position pos = it2->getRefData().getPosition();
|
||||
Ogre::Vector3 markerPos = Ogre::Vector3(pos.pos);
|
||||
float distance = worldPos.squaredDistance(markerPos);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestMarker = *it2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return closestMarker;
|
||||
return getClosestMarkerFromExteriorPosition(worldPos, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2901,6 +2887,29 @@ namespace MWWorld
|
|||
return MWWorld::Ptr();
|
||||
}
|
||||
|
||||
MWWorld::Ptr World::getClosestMarkerFromExteriorPosition( const Ogre::Vector3 worldPos, const std::string &id ) {
|
||||
MWWorld::Ptr closestMarker;
|
||||
float closestDistance = FLT_MAX;
|
||||
|
||||
std::vector<MWWorld::Ptr> markers;
|
||||
mCells.getExteriorPtrs(id, markers);
|
||||
for (std::vector<MWWorld::Ptr>::iterator it2 = markers.begin(); it2 != markers.end(); ++it2)
|
||||
{
|
||||
ESM::Position pos = it2->getRefData().getPosition();
|
||||
Ogre::Vector3 markerPos = Ogre::Vector3(pos.pos);
|
||||
float distance = worldPos.squaredDistance(markerPos);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestMarker = *it2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return closestMarker;
|
||||
}
|
||||
|
||||
|
||||
void World::teleportToClosestMarker (const MWWorld::Ptr& ptr,
|
||||
const std::string& id)
|
||||
{
|
||||
|
|
|
@ -151,6 +151,7 @@ namespace MWWorld
|
|||
float feetToGameUnits(float feet);
|
||||
|
||||
MWWorld::Ptr getClosestMarker( const MWWorld::Ptr &ptr, const std::string &id );
|
||||
MWWorld::Ptr getClosestMarkerFromExteriorPosition( const Ogre::Vector3 worldPos, const std::string &id );
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue