Accept a ConstPtr in getDoorState

openmw-38
scrawl 9 years ago
parent 7a2ca5580a
commit 51c77c5045

@ -41,6 +41,10 @@ namespace MWClass
{ {
return *this; return *this;
} }
virtual const DoorCustomData& asDoorCustomData() const
{
return *this;
}
}; };
MWWorld::CustomData *DoorCustomData::clone() const MWWorld::CustomData *DoorCustomData::clone() const
@ -312,9 +316,10 @@ namespace MWClass
} }
} }
int Door::getDoorState (const MWWorld::Ptr &ptr) const int Door::getDoorState (const MWWorld::ConstPtr &ptr) const
{ {
ensureCustomData(ptr); if (!ptr.getRefData().getCustomData())
return 0;
const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData(); const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
return customData.mDoorState; return customData.mDoorState;
} }

@ -53,7 +53,7 @@ namespace MWClass
virtual std::string getModel(const MWWorld::ConstPtr &ptr) const; virtual std::string getModel(const MWWorld::ConstPtr &ptr) const;
/// 0 = nothing, 1 = opening, 2 = closing /// 0 = nothing, 1 = opening, 2 = closing
virtual int getDoorState (const MWWorld::Ptr &ptr) const; virtual int getDoorState (const MWWorld::ConstPtr &ptr) const;
/// This does not actually cause the door to move. Use World::activateDoor instead. /// This does not actually cause the door to move. Use World::activateDoor instead.
virtual void setDoorState (const MWWorld::Ptr &ptr, int state) const; virtual void setDoorState (const MWWorld::Ptr &ptr, int state) const;

@ -11,7 +11,7 @@
#include "steering.hpp" #include "steering.hpp"
MWMechanics::AiAvoidDoor::AiAvoidDoor(const MWWorld::Ptr& doorPtr) MWMechanics::AiAvoidDoor::AiAvoidDoor(const MWWorld::ConstPtr& doorPtr)
: AiPackage(), mDuration(1), mDoorPtr(doorPtr), mAdjAngle(0) : AiPackage(), mDuration(1), mDoorPtr(doorPtr), mAdjAngle(0)
{ {

@ -16,7 +16,7 @@ namespace MWMechanics
{ {
public: public:
/// Avoid door until the door is fully open /// Avoid door until the door is fully open
AiAvoidDoor(const MWWorld::Ptr& doorPtr); AiAvoidDoor(const MWWorld::ConstPtr& doorPtr);
virtual AiAvoidDoor *clone() const; virtual AiAvoidDoor *clone() const;
@ -28,7 +28,7 @@ namespace MWMechanics
private: private:
float mDuration; float mDuration;
MWWorld::Ptr mDoorPtr; MWWorld::ConstPtr mDoorPtr;
ESM::Position mLastPos; ESM::Position mLastPos;
float mAdjAngle; float mAdjAngle;
}; };

@ -404,7 +404,7 @@ namespace MWWorld
return false; return false;
} }
int Class::getDoorState (const MWWorld::Ptr &ptr) const int Class::getDoorState (const MWWorld::ConstPtr &ptr) const
{ {
throw std::runtime_error("this is not a door"); throw std::runtime_error("this is not a door");
} }

@ -319,7 +319,7 @@ namespace MWWorld
virtual bool isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const; virtual bool isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const;
/// 0 = nothing, 1 = opening, 2 = closing /// 0 = nothing, 1 = opening, 2 = closing
virtual int getDoorState (const MWWorld::Ptr &ptr) const; virtual int getDoorState (const MWWorld::ConstPtr &ptr) const;
/// This does not actually cause the door to move. Use World::activateDoor instead. /// This does not actually cause the door to move. Use World::activateDoor instead.
virtual void setDoorState (const MWWorld::Ptr &ptr, int state) const; virtual void setDoorState (const MWWorld::Ptr &ptr, int state) const;

@ -42,6 +42,13 @@ MWClass::DoorCustomData &CustomData::asDoorCustomData()
throw std::logic_error(error.str()); throw std::logic_error(error.str());
} }
const MWClass::DoorCustomData &CustomData::asDoorCustomData() const
{
std::stringstream error;
error << "bad cast " << typeid(this).name() << " to DoorCustomData";
throw std::logic_error(error.str());
}
MWClass::CreatureLevListCustomData &CustomData::asCreatureLevListCustomData() MWClass::CreatureLevListCustomData &CustomData::asCreatureLevListCustomData()
{ {
std::stringstream error; std::stringstream error;

@ -31,6 +31,7 @@ namespace MWWorld
virtual MWClass::ContainerCustomData& asContainerCustomData(); virtual MWClass::ContainerCustomData& asContainerCustomData();
virtual MWClass::DoorCustomData& asDoorCustomData(); virtual MWClass::DoorCustomData& asDoorCustomData();
virtual const MWClass::DoorCustomData& asDoorCustomData() const;
virtual MWClass::CreatureLevListCustomData& asCreatureLevListCustomData(); virtual MWClass::CreatureLevListCustomData& asCreatureLevListCustomData();
}; };

Loading…
Cancel
Save