forked from mirror/openmw-tes3mp
Changed getNearbyDoor to use MWWorld::Ptr
This commit is contained in:
parent
58bf7624be
commit
7cd4c93fa4
4 changed files with 14 additions and 13 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
MWMechanics::AiPackage::~AiPackage() {}
|
||||
|
||||
MWMechanics::AiPackage::AiPackage() : mLastDoorChecked(NULL), mTimer(0), mStuckTimer(0) {
|
||||
MWMechanics::AiPackage::AiPackage() : mLastDoorChecked(MWWorld::Ptr()), mTimer(0), mStuckTimer(0) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -92,11 +92,11 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
|
|||
//if(mObstacleCheck.check(actor, duration)) {
|
||||
if(distance(start, mStuckPos.pos[0], mStuckPos.pos[1], mStuckPos.pos[2]) < 10 && distance(dest, start) > 20) { //Actually stuck, and far enough away from destination to care
|
||||
// first check if we're walking into a door
|
||||
MWWorld::LiveCellRef<ESM::Door>* door = getNearbyDoor(actor);
|
||||
if(door != NULL) // NOTE: checks interior cells only
|
||||
MWWorld::Ptr door = getNearbyDoor(actor);
|
||||
if(door != MWWorld::Ptr()) // NOTE: checks interior cells only
|
||||
{
|
||||
if(door->mRef.mTrap.empty() && mLastDoorChecked != door) { //Open the door if untrapped
|
||||
door->mClass->activate(MWWorld::Ptr(door, actor.getCell()), actor).get()->execute(actor);
|
||||
if(door.getCellRef().mTrap.empty() && mLastDoorChecked != door) { //Open the door if untrapped
|
||||
door.getClass().activate(door, actor).get()->execute(actor);
|
||||
mLastDoorChecked = door;
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
|
|||
else { //Not stuck, so reset things
|
||||
mStuckTimer = 0;
|
||||
mStuckPos = pos;
|
||||
mLastDoorChecked = NULL; //Resets it, in case he gets stuck behind the door again
|
||||
mLastDoorChecked = MWWorld::Ptr(); //Resets it, in case he gets stuck behind the door again
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "pathfinding.hpp"
|
||||
#include <components/esm/defs.hpp>
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "obstacle.hpp"
|
||||
|
||||
|
@ -63,7 +64,7 @@ namespace MWMechanics
|
|||
float mStuckTimer;
|
||||
float mTotalTime;
|
||||
|
||||
MWWorld::LiveCellRef<ESM::Door>* mLastDoorChecked; //Used to ensure we don't try to CONSTANTLY open a door
|
||||
MWWorld::Ptr mLastDoorChecked; //Used to ensure we don't try to CONSTANTLY open a door
|
||||
|
||||
ESM::Position mStuckPos;
|
||||
};
|
||||
|
|
|
@ -20,18 +20,18 @@ namespace MWMechanics
|
|||
// actor is facing the door.
|
||||
bool proximityToDoor(const MWWorld::Ptr& actor, float minSqr, bool closed)
|
||||
{
|
||||
if(getNearbyDoor(actor, minSqr, closed)!=NULL)
|
||||
if(getNearbyDoor(actor, minSqr, closed)!=MWWorld::Ptr())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
MWWorld::LiveCellRef<ESM::Door>* getNearbyDoor(const MWWorld::Ptr& actor, float minSqr, bool closed)
|
||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minSqr, bool closed)
|
||||
{
|
||||
MWWorld::CellStore *cell = actor.getCell();
|
||||
|
||||
if(cell->getCell()->isExterior())
|
||||
return NULL; // check interior cells only
|
||||
return MWWorld::Ptr(); // check interior cells only
|
||||
|
||||
// Check all the doors in this cell
|
||||
MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>();
|
||||
|
@ -54,10 +54,10 @@ namespace MWMechanics
|
|||
if((closed && ref.mData.getLocalRotation().rot[2] == 0) ||
|
||||
(!closed && ref.mData.getLocalRotation().rot[2] >= 1))
|
||||
{
|
||||
return &ref; // found, stop searching
|
||||
return MWWorld::Ptr(&ref, actor.getCell()); // found, stop searching
|
||||
}
|
||||
}
|
||||
return NULL; // none found
|
||||
return MWWorld::Ptr(); // none found
|
||||
}
|
||||
|
||||
ObstacleCheck::ObstacleCheck():
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace MWMechanics
|
|||
|
||||
/// Returns door pointer within range. No guarentee is given as too which one
|
||||
/** \return Pointer to the door, or NULL if none exists **/
|
||||
MWWorld::LiveCellRef<ESM::Door>* getNearbyDoor(const MWWorld::Ptr& actor,
|
||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor,
|
||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED,
|
||||
bool closed = true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue