From 8a3d3f954b1acf409dc7cebcdcefb23537cd565a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 16 May 2013 18:50:26 +0200 Subject: [PATCH] NPC/creature persistence flag --- apps/openmw/mwclass/creature.cpp | 6 ++++++ apps/openmw/mwclass/creature.hpp | 2 ++ apps/openmw/mwclass/npc.cpp | 6 ++++++ apps/openmw/mwclass/npc.hpp | 2 ++ apps/openmw/mwgui/container.cpp | 8 ++++---- apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 2 ++ components/esm/esmreader.cpp | 5 +++-- components/esm/esmreader.hpp | 7 ++++++- components/esm/loadcrea.cpp | 2 ++ components/esm/loadcrea.hpp | 3 +++ components/esm/loadnpc.cpp | 2 ++ components/esm/loadnpc.hpp | 2 ++ 13 files changed, 45 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 9eef1896ed..a4eda71267 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -235,6 +235,12 @@ namespace MWClass return 0; } + bool Creature::isPersistent(const MWWorld::Ptr &actor) const + { + MWWorld::LiveCellRef* ref = actor.get(); + return ref->mBase->mPersistent; + } + MWWorld::Ptr Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const { diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 03b8f5d70a..b5657e265a 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -64,6 +64,8 @@ namespace MWClass virtual int getServices (const MWWorld::Ptr& actor) const; + virtual bool isPersistent (const MWWorld::Ptr& ptr) const; + static void registerSelf(); virtual std::string getModel(const MWWorld::Ptr &ptr) const; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 47dae4ec04..4574792ae4 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -235,6 +235,12 @@ namespace MWClass MWBase::Environment::get().getMechanicsManager()->add(ptr); } + bool Npc::isPersistent(const MWWorld::Ptr &actor) const + { + MWWorld::LiveCellRef* ref = actor.get(); + return ref->mBase->mPersistent; + } + std::string Npc::getModel(const MWWorld::Ptr &ptr) const { MWWorld::LiveCellRef *ref = diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 8f440e7ecd..83bfbdcbfe 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -130,6 +130,8 @@ namespace MWClass virtual int getServices (const MWWorld::Ptr& actor) const; + virtual bool isPersistent (const MWWorld::Ptr& ptr) const; + static void registerSelf(); virtual std::string getModel(const MWWorld::Ptr &ptr) const; diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index ddfd945b3a..8820467ffa 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -201,7 +201,7 @@ namespace MWGui { mPtr = container; - if (container.getTypeName() == typeid(ESM::NPC).name() && !loot) + if (!loot) { // we are stealing stuff MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); @@ -258,9 +258,9 @@ namespace MWGui onTakeAllButtonClicked(mTakeButton); /// \todo if corpse is non-disposable: messagebox #{sDisposeCorpseFail} - //if () - // MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}"); - //else + if (MWWorld::Class::get(mPtr).isPersistent(mPtr)) + MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}"); + else MWBase::Environment::get().getWorld()->deleteObject(mPtr); mPtr = MWWorld::Ptr(); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index e9038f4810..5690531e71 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -220,6 +220,11 @@ namespace MWWorld return get (ptr.getTypeName()); } + bool Class::isPersistent(const Ptr &ptr) const + { + throw std::runtime_error ("class does not support persistence"); + } + void Class::registerClass (const std::string& key, boost::shared_ptr instance) { sClasses.insert (std::make_pair (key, instance)); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index ef8838c80a..b4fd84a6b4 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -253,6 +253,8 @@ namespace MWWorld virtual float getWeight (const MWWorld::Ptr& ptr) const; + virtual bool isPersistent (const MWWorld::Ptr& ptr) const; + virtual Ptr copyToCell(const Ptr &ptr, CellStore &cell) const; diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 580e576d05..0a4c1a3fee 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -15,8 +15,9 @@ ESM_Context ESMReader::getContext() return mCtx; } -ESMReader::ESMReader(): - mBuffer(50*1024) +ESMReader::ESMReader() + : mBuffer(50*1024) + , mRecordFlags(0) { } diff --git a/components/esm/esmreader.hpp b/components/esm/esmreader.hpp index f805998e43..ff10a202c9 100644 --- a/components/esm/esmreader.hpp +++ b/components/esm/esmreader.hpp @@ -216,7 +216,7 @@ public: follows the header, ie beyond the entire record. You should use leftRec to orient yourself inside the record itself. */ - void getRecHeader() { uint32_t u; getRecHeader(u); } + void getRecHeader() { getRecHeader(mRecordFlags); } void getRecHeader(uint32_t &flags); bool hasMoreRecs() const { return mCtx.leftFile > 0; } @@ -249,11 +249,16 @@ public: /// Sets font encoder for ESM strings void setEncoder(ToUTF8::Utf8Encoder* encoder); + /// Get record flags of last record + unsigned int getRecordFlags() { return mRecordFlags; } + private: Ogre::DataStreamPtr mEsm; ESM_Context mCtx; + unsigned int mRecordFlags; + // Special file signifier (see SpecialFile enum above) // Buffer for ESM strings diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index b59835bd64..272a1378da 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -7,6 +7,8 @@ namespace ESM { void Creature::load(ESMReader &esm) { + mPersistent = esm.getRecordFlags() & 0x0400; + mModel = esm.getHNString("MODL"); mOriginal = esm.getHNOString("CNAM"); mName = esm.getHNOString("FNAM"); diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 1c93d995a5..d792a9a47d 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -69,6 +69,9 @@ struct Creature NPDTstruct mData; int mFlags; + + bool mPersistent; + float mScale; std::string mId, mModel, mName, mScript; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 72d0b37362..e6c1e58056 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -10,6 +10,8 @@ void NPC::load(ESMReader &esm) { mNpdt52.mGold = -10; + mPersistent = esm.getRecordFlags() & 0x0400; + mModel = esm.getHNOString("MODL"); mName = esm.getHNOString("FNAM"); diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index b30077f23c..27e1ebeee1 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -100,6 +100,8 @@ struct NPC int mFlags; + bool mPersistent; + InventoryList mInventory; SpellList mSpells;