|
|
|
@ -26,6 +26,27 @@
|
|
|
|
|
#include "../mwrender/actors.hpp"
|
|
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
struct LightCustomData : public MWWorld::CustomData
|
|
|
|
|
{
|
|
|
|
|
float mTime;
|
|
|
|
|
///< Time remaining
|
|
|
|
|
|
|
|
|
|
LightCustomData(MWWorld::Ptr ptr)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
|
|
|
|
|
mTime = ref->mBase->mData.mTime;
|
|
|
|
|
}
|
|
|
|
|
///< Constructs this CustomData from the base values for Ptr.
|
|
|
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const
|
|
|
|
|
{
|
|
|
|
|
return new LightCustomData (*this);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace MWClass
|
|
|
|
|
{
|
|
|
|
|
std::string Light::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
@ -198,16 +219,17 @@ namespace MWClass
|
|
|
|
|
|
|
|
|
|
void Light::setRemainingUsageTime (const MWWorld::Ptr& ptr, float duration) const
|
|
|
|
|
{
|
|
|
|
|
ptr.getCellRef().setChargeFloat(duration);
|
|
|
|
|
ensureCustomData(ptr);
|
|
|
|
|
|
|
|
|
|
float &timeRemaining = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
|
|
|
|
timeRemaining = duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
|
|
|
|
|
if (ptr.getCellRef().getCharge() == -1)
|
|
|
|
|
return ref->mBase->mData.mTime;
|
|
|
|
|
else
|
|
|
|
|
return ptr.getCellRef().getChargeFloat();
|
|
|
|
|
ensureCustomData(ptr);
|
|
|
|
|
|
|
|
|
|
return dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MWWorld::Ptr
|
|
|
|
@ -219,6 +241,12 @@ namespace MWClass
|
|
|
|
|
return MWWorld::Ptr(&cell.get<ESM::Light>().insert(*ref), &cell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Light::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
|
{
|
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
|
ptr.getRefData().setCustomData(new LightCustomData(ptr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Light::canSell (const MWWorld::Ptr& item, int npcServices) const
|
|
|
|
|
{
|
|
|
|
|
return npcServices & ESM::NPC::Lights;
|
|
|
|
@ -254,6 +282,22 @@ namespace MWClass
|
|
|
|
|
return std::make_pair(1,"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Light::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
|
|
|
|
const
|
|
|
|
|
{
|
|
|
|
|
ensureCustomData (ptr);
|
|
|
|
|
|
|
|
|
|
dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime = state.mTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Light::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
|
|
|
|
const
|
|
|
|
|
{
|
|
|
|
|
ensureCustomData (ptr);
|
|
|
|
|
|
|
|
|
|
state.mTime = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Light::getSound(const MWWorld::Ptr& ptr) const
|
|
|
|
|
{
|
|
|
|
|
return ptr.get<ESM::Light>()->mBase->mSound;
|
|
|
|
|