mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:49:56 +00:00
Light charge handling fix
This commit is contained in:
parent
db64ff6645
commit
5e0428243b
14 changed files with 47 additions and 87 deletions
|
@ -261,7 +261,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info)
|
||||||
std::cout << " Faction: '" << ref.mFaction << "'" << std::endl;
|
std::cout << " Faction: '" << ref.mFaction << "'" << std::endl;
|
||||||
std::cout << " Faction rank: '" << ref.mFactionRank << "'" << std::endl;
|
std::cout << " Faction rank: '" << ref.mFactionRank << "'" << std::endl;
|
||||||
std::cout << " Enchantment charge: '" << ref.mEnchantmentCharge << "'\n";
|
std::cout << " Enchantment charge: '" << ref.mEnchantmentCharge << "'\n";
|
||||||
std::cout << " Uses/health: '" << ref.mCharge << "'\n";
|
std::cout << " Uses/health: '" << ref.mChargeInt << "'\n";
|
||||||
std::cout << " Gold value: '" << ref.mGoldValue << "'\n";
|
std::cout << " Gold value: '" << ref.mGoldValue << "'\n";
|
||||||
std::cout << " Blocked: '" << static_cast<int>(ref.mReferenceBlocked) << "'" << std::endl;
|
std::cout << " Blocked: '" << static_cast<int>(ref.mReferenceBlocked) << "'" << std::endl;
|
||||||
std::cout << " Deleted: " << deleted << std::endl;
|
std::cout << " Deleted: " << deleted << std::endl;
|
||||||
|
|
|
@ -12,10 +12,10 @@ namespace ESSImport
|
||||||
{
|
{
|
||||||
ESM::ObjectState objstate;
|
ESM::ObjectState objstate;
|
||||||
objstate.blank();
|
objstate.blank();
|
||||||
|
objstate.mRef = *it;
|
||||||
objstate.mRef.mRefID = Misc::StringUtils::lowerCase(it->mId);
|
objstate.mRef.mRefID = Misc::StringUtils::lowerCase(it->mId);
|
||||||
objstate.mCount = std::abs(it->mCount); // restocking items have negative count in the savefile
|
objstate.mCount = std::abs(it->mCount); // restocking items have negative count in the savefile
|
||||||
// openmw handles them differently, so no need to set any flags
|
// openmw handles them differently, so no need to set any flags
|
||||||
objstate.mRef.mCharge = it->mCondition;
|
|
||||||
state.mItems.push_back(std::make_pair(objstate, it->mRelativeEquipmentSlot));
|
state.mItems.push_back(std::make_pair(objstate, it->mRelativeEquipmentSlot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@ namespace ESSImport
|
||||||
// for XSOL and XCHG seen so far, but probably others too
|
// for XSOL and XCHG seen so far, but probably others too
|
||||||
item.ESM::CellRef::loadData(esm);
|
item.ESM::CellRef::loadData(esm);
|
||||||
|
|
||||||
item.mCondition = -1;
|
int charge=-1;
|
||||||
// FIXME: for Lights, this is actually a float
|
esm.getHNOT(charge, "XHLT");
|
||||||
esm.getHNOT(item.mCondition, "XHLT");
|
item.mChargeInt = charge;
|
||||||
}
|
}
|
||||||
|
|
||||||
mItems.push_back(item);
|
mItems.push_back(item);
|
||||||
|
|
|
@ -20,7 +20,6 @@ namespace ESSImport
|
||||||
{
|
{
|
||||||
std::string mId;
|
std::string mId;
|
||||||
int mCount;
|
int mCount;
|
||||||
int mCondition;
|
|
||||||
int mRelativeEquipmentSlot;
|
int mRelativeEquipmentSlot;
|
||||||
};
|
};
|
||||||
std::vector<InventoryItem> mItems;
|
std::vector<InventoryItem> mItems;
|
||||||
|
|
|
@ -1053,13 +1053,13 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||||
{
|
{
|
||||||
return record.get().mCharge;
|
return record.get().mChargeInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
||||||
{
|
{
|
||||||
ESXRecordT record2 = record.get();
|
ESXRecordT record2 = record.get();
|
||||||
record2.mCharge = data.toInt();
|
record2.mChargeInt = data.toInt();
|
||||||
record.setModified (record2);
|
record.setModified (record2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,27 +26,6 @@
|
||||||
#include "../mwrender/actors.hpp"
|
#include "../mwrender/actors.hpp"
|
||||||
#include "../mwrender/renderinginterface.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
|
namespace MWClass
|
||||||
{
|
{
|
||||||
std::string Light::getId (const MWWorld::Ptr& ptr) const
|
std::string Light::getId (const MWWorld::Ptr& ptr) const
|
||||||
|
@ -219,17 +198,16 @@ namespace MWClass
|
||||||
|
|
||||||
void Light::setRemainingUsageTime (const MWWorld::Ptr& ptr, float duration) const
|
void Light::setRemainingUsageTime (const MWWorld::Ptr& ptr, float duration) const
|
||||||
{
|
{
|
||||||
ensureCustomData(ptr);
|
ptr.getCellRef().setChargeFloat(duration);
|
||||||
|
|
||||||
float &timeRemaining = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
|
||||||
timeRemaining = duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const
|
float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
ensureCustomData(ptr);
|
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
|
||||||
|
if (ptr.getCellRef().getCharge() == -1)
|
||||||
return dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
return ref->mBase->mData.mTime;
|
||||||
|
else
|
||||||
|
return ptr.getCellRef().getChargeFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Ptr
|
MWWorld::Ptr
|
||||||
|
@ -241,12 +219,6 @@ namespace MWClass
|
||||||
return MWWorld::Ptr(&cell.get<ESM::Light>().insert(*ref), &cell);
|
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
|
bool Light::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||||
{
|
{
|
||||||
return npcServices & ESM::NPC::Lights;
|
return npcServices & ESM::NPC::Lights;
|
||||||
|
@ -282,22 +254,6 @@ namespace MWClass
|
||||||
return std::make_pair(1,"");
|
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
|
std::string Light::getSound(const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
return ptr.get<ESM::Light>()->mBase->mSound;
|
return ptr.get<ESM::Light>()->mBase->mSound;
|
||||||
|
|
|
@ -10,8 +10,6 @@ namespace MWClass
|
||||||
virtual MWWorld::Ptr
|
virtual MWWorld::Ptr
|
||||||
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
|
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
|
||||||
|
|
||||||
void ensureCustomData (const MWWorld::Ptr& ptr) const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Return ID of \a ptr
|
/// Return ID of \a ptr
|
||||||
|
@ -75,14 +73,6 @@ namespace MWClass
|
||||||
|
|
||||||
std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
|
||||||
|
|
||||||
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
|
||||||
const;
|
|
||||||
///< Read additional state from \a state into \a ptr.
|
|
||||||
|
|
||||||
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
|
||||||
const;
|
|
||||||
///< Write additional state from \a ptr into \a state.
|
|
||||||
|
|
||||||
virtual std::string getSound(const MWWorld::Ptr& ptr) const;
|
virtual std::string getSound(const MWWorld::Ptr& ptr) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,15 +81,29 @@ namespace MWWorld
|
||||||
|
|
||||||
int CellRef::getCharge() const
|
int CellRef::getCharge() const
|
||||||
{
|
{
|
||||||
return mCellRef.mCharge;
|
return mCellRef.mChargeInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellRef::setCharge(int charge)
|
void CellRef::setCharge(int charge)
|
||||||
{
|
{
|
||||||
if (charge != mCellRef.mCharge)
|
if (charge != mCellRef.mChargeInt)
|
||||||
{
|
{
|
||||||
mChanged = true;
|
mChanged = true;
|
||||||
mCellRef.mCharge = charge;
|
mCellRef.mChargeInt = charge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float CellRef::getChargeFloat() const
|
||||||
|
{
|
||||||
|
return mCellRef.mChargeFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CellRef::setChargeFloat(float charge)
|
||||||
|
{
|
||||||
|
if (charge != mCellRef.mChargeFloat)
|
||||||
|
{
|
||||||
|
mChanged = true;
|
||||||
|
mCellRef.mChargeFloat = charge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,11 @@ namespace MWWorld
|
||||||
|
|
||||||
// For weapon or armor, this is the remaining item health.
|
// For weapon or armor, this is the remaining item health.
|
||||||
// For tools (lockpicks, probes, repair hammer) it is the remaining uses.
|
// For tools (lockpicks, probes, repair hammer) it is the remaining uses.
|
||||||
|
// If this returns int(-1) it means full health.
|
||||||
int getCharge() const;
|
int getCharge() const;
|
||||||
|
float getChargeFloat() const; // Implemented as union with int charge
|
||||||
void setCharge(int charge);
|
void setCharge(int charge);
|
||||||
|
void setChargeFloat(float charge);
|
||||||
|
|
||||||
// The NPC that owns this object (and will get angry if you steal it)
|
// The NPC that owns this object (and will get angry if you steal it)
|
||||||
std::string getOwner() const;
|
std::string getOwner() const;
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace MWWorld
|
||||||
cellRef.mRefID = name;
|
cellRef.mRefID = name;
|
||||||
cellRef.mScale = 1;
|
cellRef.mScale = 1;
|
||||||
cellRef.mFactionRank = 0;
|
cellRef.mFactionRank = 0;
|
||||||
cellRef.mCharge = -1;
|
cellRef.mChargeInt = -1;
|
||||||
cellRef.mGoldValue = 1;
|
cellRef.mGoldValue = 1;
|
||||||
cellRef.mEnchantmentCharge = -1;
|
cellRef.mEnchantmentCharge = -1;
|
||||||
cellRef.mTeleport = false;
|
cellRef.mTeleport = false;
|
||||||
|
|
|
@ -46,12 +46,12 @@ void ESM::CellRef::loadData(ESMReader &esm)
|
||||||
esm.getHNOT (mFactionRank, "INDX");
|
esm.getHNOT (mFactionRank, "INDX");
|
||||||
|
|
||||||
mGoldValue = 1;
|
mGoldValue = 1;
|
||||||
mCharge = -1;
|
mChargeInt = -1;
|
||||||
mEnchantmentCharge = -1;
|
mEnchantmentCharge = -1;
|
||||||
|
|
||||||
esm.getHNOT (mEnchantmentCharge, "XCHG");
|
esm.getHNOT (mEnchantmentCharge, "XCHG");
|
||||||
|
|
||||||
esm.getHNOT (mCharge, "INTV");
|
esm.getHNOT (mChargeInt, "INTV");
|
||||||
|
|
||||||
esm.getHNOT (mGoldValue, "NAM9");
|
esm.getHNOT (mGoldValue, "NAM9");
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons
|
||||||
if (mEnchantmentCharge != -1)
|
if (mEnchantmentCharge != -1)
|
||||||
esm.writeHNT("XCHG", mEnchantmentCharge);
|
esm.writeHNT("XCHG", mEnchantmentCharge);
|
||||||
|
|
||||||
if (mCharge != -1)
|
if (mChargeInt != -1)
|
||||||
esm.writeHNT("INTV", mCharge);
|
esm.writeHNT("INTV", mChargeInt);
|
||||||
|
|
||||||
if (mGoldValue != 1) {
|
if (mGoldValue != 1) {
|
||||||
esm.writeHNT("NAM9", mGoldValue);
|
esm.writeHNT("NAM9", mGoldValue);
|
||||||
|
@ -146,7 +146,7 @@ void ESM::CellRef::blank()
|
||||||
mSoul.clear();
|
mSoul.clear();
|
||||||
mFaction.clear();
|
mFaction.clear();
|
||||||
mFactionRank = -2;
|
mFactionRank = -2;
|
||||||
mCharge = -1;
|
mChargeInt = -1;
|
||||||
mEnchantmentCharge = -1;
|
mEnchantmentCharge = -1;
|
||||||
mGoldValue = 0;
|
mGoldValue = 0;
|
||||||
mDestCell.clear();
|
mDestCell.clear();
|
||||||
|
|
|
@ -59,7 +59,11 @@ namespace ESM
|
||||||
|
|
||||||
// For weapon or armor, this is the remaining item health.
|
// For weapon or armor, this is the remaining item health.
|
||||||
// For tools (lockpicks, probes, repair hammer) it is the remaining uses.
|
// For tools (lockpicks, probes, repair hammer) it is the remaining uses.
|
||||||
int mCharge;
|
union
|
||||||
|
{
|
||||||
|
int mChargeInt;
|
||||||
|
float mChargeFloat;
|
||||||
|
};
|
||||||
|
|
||||||
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
||||||
float mEnchantmentCharge;
|
float mEnchantmentCharge;
|
||||||
|
|
|
@ -24,9 +24,9 @@ void ESM::ObjectState::load (ESMReader &esm)
|
||||||
|
|
||||||
esm.getHNOT (mLocalRotation, "LROT", 12);
|
esm.getHNOT (mLocalRotation, "LROT", 12);
|
||||||
|
|
||||||
// used for lights only
|
// obsolete
|
||||||
mTime = 0;
|
int unused;
|
||||||
esm.getHNOT (mTime, "LTIM");
|
esm.getHNOT(unused, "LTIM");
|
||||||
|
|
||||||
// FIXME: assuming "false" as default would make more sense, but also break compatibility with older save files
|
// FIXME: assuming "false" as default would make more sense, but also break compatibility with older save files
|
||||||
mHasCustomState = true;
|
mHasCustomState = true;
|
||||||
|
@ -55,9 +55,6 @@ void ESM::ObjectState::save (ESMWriter &esm, bool inInventory) const
|
||||||
esm.writeHNT ("LROT", mLocalRotation, 12);
|
esm.writeHNT ("LROT", mLocalRotation, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTime)
|
|
||||||
esm.writeHNT ("LTIM", mTime);
|
|
||||||
|
|
||||||
if (!mHasCustomState)
|
if (!mHasCustomState)
|
||||||
esm.writeHNT ("HCUS", false);
|
esm.writeHNT ("HCUS", false);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +71,6 @@ void ESM::ObjectState::blank()
|
||||||
mPosition.rot[i] = 0;
|
mPosition.rot[i] = 0;
|
||||||
mLocalRotation[i] = 0;
|
mLocalRotation[i] = 0;
|
||||||
}
|
}
|
||||||
mTime = 0;
|
|
||||||
mHasCustomState = true;
|
mHasCustomState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,6 @@ namespace ESM
|
||||||
ESM::Position mPosition;
|
ESM::Position mPosition;
|
||||||
float mLocalRotation[3];
|
float mLocalRotation[3];
|
||||||
|
|
||||||
float mTime; // Used for lights only. Overhead should not be so awful, besides CellRef isn't OO either
|
|
||||||
|
|
||||||
// Is there any class-specific state following the ObjectState
|
// Is there any class-specific state following the ObjectState
|
||||||
bool mHasCustomState;
|
bool mHasCustomState;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue