Correction to teleportation changes.

OMW Bug #2400
Related to OMW Bug #1533

Don't crash when finding the closest marker to an exterior position.
celladd
Jordan Ayers 10 years ago
parent da9bd09a8c
commit 691ebd2372

@ -2832,6 +2832,10 @@ namespace MWWorld
MWWorld::Ptr World::getClosestMarker( const MWWorld::Ptr &ptr, const std::string &id ) 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 // 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 // cell and the exterior as a distance of 1. If an exterior is found, jump
// to the nearest exterior marker, without further interior searching. // to the nearest exterior marker, without further interior searching.
@ -2868,9 +2872,25 @@ namespace MWWorld
if (ref.mRef.getDestCell().empty()) if (ref.mRef.getDestCell().empty())
{ {
Ogre::Vector3 worldPos = Ogre::Vector3(ref.mRef.getDoorDest().pos); Ogre::Vector3 worldPos = Ogre::Vector3(ref.mRef.getDoorDest().pos);
float closestDistance = FLT_MAX; return getClosestMarkerFromExteriorPosition(worldPos, id);
}
else
{
std::string dest = ref.mRef.getDestCell();
if ( !checkedCells.count(dest) && !currentCells.count(dest) )
nextCells.insert(dest);
}
}
}
}
return MWWorld::Ptr();
}
MWWorld::Ptr World::getClosestMarkerFromExteriorPosition( const Ogre::Vector3 worldPos, const std::string &id ) {
MWWorld::Ptr closestMarker; MWWorld::Ptr closestMarker;
float closestDistance = FLT_MAX;
std::vector<MWWorld::Ptr> markers; std::vector<MWWorld::Ptr> markers;
mCells.getExteriorPtrs(id, markers); mCells.getExteriorPtrs(id, markers);
for (std::vector<MWWorld::Ptr>::iterator it2 = markers.begin(); it2 != markers.end(); ++it2) for (std::vector<MWWorld::Ptr>::iterator it2 = markers.begin(); it2 != markers.end(); ++it2)
@ -2888,18 +2908,7 @@ namespace MWWorld
return closestMarker; return closestMarker;
} }
else
{
std::string dest = ref.mRef.getDestCell();
if ( !checkedCells.count(dest) && !currentCells.count(dest) )
nextCells.insert(dest);
}
}
}
}
return MWWorld::Ptr();
}
void World::teleportToClosestMarker (const MWWorld::Ptr& ptr, void World::teleportToClosestMarker (const MWWorld::Ptr& ptr,
const std::string& id) const std::string& id)

@ -151,6 +151,7 @@ namespace MWWorld
float feetToGameUnits(float feet); float feetToGameUnits(float feet);
MWWorld::Ptr getClosestMarker( const MWWorld::Ptr &ptr, const std::string &id ); MWWorld::Ptr getClosestMarker( const MWWorld::Ptr &ptr, const std::string &id );
MWWorld::Ptr getClosestMarkerFromExteriorPosition( const Ogre::Vector3 worldPos, const std::string &id );
public: public:

Loading…
Cancel
Save