From 6f1575d42a046bff854f0a79cb834e6aaf38f4fe Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 27 Mar 2013 17:27:43 +0100 Subject: [PATCH] CELL record corrections --- apps/esmtool/esmtool.cpp | 5 ++++- apps/openmw/mwclass/misc.cpp | 13 +++++++++---- apps/openmw/mwworld/containerstore.cpp | 3 ++- apps/openmw/mwworld/manualref.hpp | 5 +++-- components/esm/loadcell.cpp | 24 ++++++++++++++++-------- components/esm/loadcell.hpp | 12 +++++++++--- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 521383f3ff..d682cf88b9 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -227,7 +227,10 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) std::cout << " Refnum: " << ref.mRefnum << std::endl; std::cout << " ID: '" << ref.mRefID << "'\n"; std::cout << " Owner: '" << ref.mOwner << "'\n"; - std::cout << " Uses/health: " << ref.mCharge << " NAM9: " << ref.mNam9 << std::endl; + std::cout << " Enchantment charge: '" << ref.mEnchantmentCharge << "'\n"; + std::cout << " Uses/health: '" << ref.mCharge << "'\n"; + std::cout << " Gold value: '" << ref.mGoldValue << "'\n"; + std::cout << " Blocked: '" << static_cast(ref.mReferenceBlocked) << "'" << std::endl; } } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 07e41bcfa6..31ae1cfb05 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -89,7 +89,9 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return ref->mBase->mData.mValue; + int value = (ptr.getCellRef().mGoldValue == 1) ? ref->mBase->mData.mValue : ptr.getCellRef().mGoldValue; + + return value; } void Miscellaneous::registerSelf() @@ -151,8 +153,10 @@ namespace MWClass int count = ptr.getRefData().getCount(); bool isGold = (ref->mBase->mName == store.get().find("sGold")->getString()); - if (isGold && count == 1) - count = ref->mBase->mData.mValue; + if (isGold && ptr.getCellRef().mGoldValue != 1) + count = ptr.getCellRef().mGoldValue; + else if (isGold) + count *= ref->mBase->mData.mValue; std::string countString; if (!isGold) @@ -214,7 +218,8 @@ namespace MWClass MWWorld::LiveCellRef *ref = newRef.getPtr().get(); newPtr = MWWorld::Ptr(&cell.mMiscItems.insert(*ref), &cell); - newPtr.getRefData ().setCount(goldAmount); + newPtr.getRefData ().setCount(1); + newPtr.getCellRef().mGoldValue = goldAmount; } else { MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index ac27beb44a..e5b68841b8 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -124,7 +124,8 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr) { MWWorld::ManualRef ref(esmStore, "Gold_001"); - int count = (ptr.getRefData().getCount() == 1) ? gold->mBase->mData.mValue : ptr.getRefData().getCount(); + int count = MWWorld::Class::get(ptr).getValue(ptr) * ptr.getRefData().getCount(); + ref.getPtr().getRefData().setCount(count); for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index 58395d8798..6616165fae 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -69,10 +69,11 @@ namespace MWWorld cellRef.mScale = 1; cellRef.mFactIndex = 0; cellRef.mCharge = -1; - cellRef.mNam9 = 0; + cellRef.mGoldValue = 1; + cellRef.mEnchantmentCharge = -1; cellRef.mTeleport = false; cellRef.mLockLevel = 0; - cellRef.mUnam = 0; + cellRef.mReferenceBlocked = 0; } const Ptr& getPtr() const diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 0731a8ff80..5cbf1de2b7 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -43,11 +43,14 @@ void CellRef::save(ESMWriter &esm) esm.writeHNT("INDX", mFactIndex); } + if (mEnchantmentCharge != -1) + esm.writeHNT("XCHG", mEnchantmentCharge); + if (mCharge != -1) esm.writeHNT("INTV", mCharge); - if (mNam9 != 0) { - esm.writeHNT("NAM9", mNam9); + if (mGoldValue != 1) { + esm.writeHNT("NAM9", mGoldValue); } if (mTeleport) @@ -62,8 +65,8 @@ void CellRef::save(ESMWriter &esm) esm.writeHNOCString("KNAM", mKey); esm.writeHNOCString("TNAM", mTrap); - if (mUnam != -1) { - esm.writeHNT("UNAM", mUnam); + if (mReferenceBlocked != -1) { + esm.writeHNT("UNAM", mReferenceBlocked); } if (mFltv != 0) { esm.writeHNT("FLTV", mFltv); @@ -281,10 +284,15 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) ref.mFactIndex = -2; esm.getHNOT(ref.mFactIndex, "INDX"); - ref.mNam9 = 0; + ref.mGoldValue = 1; ref.mCharge = -1; + ref.mEnchantmentCharge = -1; + + esm.getHNOT(ref.mEnchantmentCharge, "XCHG"); + esm.getHNOT(ref.mCharge, "INTV"); - esm.getHNOT(ref.mNam9, "NAM9"); + + esm.getHNOT(ref.mGoldValue, "NAM9"); // Present for doors that teleport you to another cell. if (esm.isNextSub("DODT")) @@ -302,9 +310,9 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) ref.mKey = esm.getHNOString("KNAM"); ref.mTrap = esm.getHNOString("TNAM"); - ref.mUnam = -1; + ref.mReferenceBlocked = -1; ref.mFltv = 0; - esm.getHNOT(ref.mUnam, "UNAM"); + esm.getHNOT(ref.mReferenceBlocked, "UNAM"); esm.getHNOT(ref.mFltv, "FLTV"); esm.getHNOT(ref.mPos, "DATA", 24); diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 97aa86ba0f..afc953f54c 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -56,7 +56,11 @@ public: // For tools (lockpicks, probes, repair hammer) it is the remaining uses. int mCharge; - int mNam9; + // Remaining enchantment charge + float mEnchantmentCharge; + + // This is 5 for Gold_005 references, 100 for Gold_100 and so on. + int mGoldValue; // For doors - true if this door teleports to somewhere else, false // if it should open through animation. @@ -72,8 +76,10 @@ public: int mLockLevel; std::string mKey, mTrap; // Key and trap ID names, if any - // No idea - occurs ONCE in Morrowind.esm, for an activator - signed char mUnam; + // This corresponds to the "Reference Blocked" checkbox in the construction set, + // which prevents editing that reference. + // -1 is not blocked, otherwise it is blocked. + signed char mReferenceBlocked; // Track deleted references. 0 - not deleted, 1 - deleted, but respawns, 2 - deleted and does not respawn. int mDeleted;