1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-31 19:20:26 +00:00

Changed getNearbyDoor to use MWWorld::Ptr

This commit is contained in:
Thomas 2014-05-13 23:46:00 -04:00
parent 58bf7624be
commit 7cd4c93fa4
4 changed files with 14 additions and 13 deletions

View File

@ -16,7 +16,7 @@
MWMechanics::AiPackage::~AiPackage() {} 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(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 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 // first check if we're walking into a door
MWWorld::LiveCellRef<ESM::Door>* door = getNearbyDoor(actor); MWWorld::Ptr door = getNearbyDoor(actor);
if(door != NULL) // NOTE: checks interior cells only if(door != MWWorld::Ptr()) // NOTE: checks interior cells only
{ {
if(door->mRef.mTrap.empty() && mLastDoorChecked != door) { //Open the door if untrapped if(door.getCellRef().mTrap.empty() && mLastDoorChecked != door) { //Open the door if untrapped
door->mClass->activate(MWWorld::Ptr(door, actor.getCell()), actor).get()->execute(actor); door.getClass().activate(door, actor).get()->execute(actor);
mLastDoorChecked = door; mLastDoorChecked = door;
} }
} }
@ -113,7 +113,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
else { //Not stuck, so reset things else { //Not stuck, so reset things
mStuckTimer = 0; mStuckTimer = 0;
mStuckPos = pos; 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 { else {

View File

@ -3,6 +3,7 @@
#include "pathfinding.hpp" #include "pathfinding.hpp"
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
#include "../mwbase/world.hpp"
#include "obstacle.hpp" #include "obstacle.hpp"
@ -63,7 +64,7 @@ namespace MWMechanics
float mStuckTimer; float mStuckTimer;
float mTotalTime; 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; ESM::Position mStuckPos;
}; };

View File

@ -20,18 +20,18 @@ namespace MWMechanics
// actor is facing the door. // actor is facing the door.
bool proximityToDoor(const MWWorld::Ptr& actor, float minSqr, bool closed) 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; return true;
else else
return false; 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(); MWWorld::CellStore *cell = actor.getCell();
if(cell->getCell()->isExterior()) if(cell->getCell()->isExterior())
return NULL; // check interior cells only return MWWorld::Ptr(); // check interior cells only
// Check all the doors in this cell // Check all the doors in this cell
MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>(); MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>();
@ -54,10 +54,10 @@ namespace MWMechanics
if((closed && ref.mData.getLocalRotation().rot[2] == 0) || if((closed && ref.mData.getLocalRotation().rot[2] == 0) ||
(!closed && ref.mData.getLocalRotation().rot[2] >= 1)) (!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(): ObstacleCheck::ObstacleCheck():

View File

@ -22,7 +22,7 @@ namespace MWMechanics
/// Returns door pointer within range. No guarentee is given as too which one /// Returns door pointer within range. No guarentee is given as too which one
/** \return Pointer to the door, or NULL if none exists **/ /** \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, float minSqr = MIN_DIST_TO_DOOR_SQUARED,
bool closed = true); bool closed = true);