1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 12:53:51 +00:00

NPC/creature persistence flag

This commit is contained in:
scrawl 2013-05-16 18:50:26 +02:00
parent 9fee99d56c
commit 8a3d3f954b
13 changed files with 45 additions and 7 deletions

View file

@ -235,6 +235,12 @@ namespace MWClass
return 0; return 0;
} }
bool Creature::isPersistent(const MWWorld::Ptr &actor) const
{
MWWorld::LiveCellRef<ESM::Creature>* ref = actor.get<ESM::Creature>();
return ref->mBase->mPersistent;
}
MWWorld::Ptr MWWorld::Ptr
Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{ {

View file

@ -64,6 +64,8 @@ namespace MWClass
virtual int getServices (const MWWorld::Ptr& actor) const; virtual int getServices (const MWWorld::Ptr& actor) const;
virtual bool isPersistent (const MWWorld::Ptr& ptr) const;
static void registerSelf(); static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const; virtual std::string getModel(const MWWorld::Ptr &ptr) const;

View file

@ -235,6 +235,12 @@ namespace MWClass
MWBase::Environment::get().getMechanicsManager()->add(ptr); MWBase::Environment::get().getMechanicsManager()->add(ptr);
} }
bool Npc::isPersistent(const MWWorld::Ptr &actor) const
{
MWWorld::LiveCellRef<ESM::NPC>* ref = actor.get<ESM::NPC>();
return ref->mBase->mPersistent;
}
std::string Npc::getModel(const MWWorld::Ptr &ptr) const std::string Npc::getModel(const MWWorld::Ptr &ptr) const
{ {
MWWorld::LiveCellRef<ESM::NPC> *ref = MWWorld::LiveCellRef<ESM::NPC> *ref =

View file

@ -130,6 +130,8 @@ namespace MWClass
virtual int getServices (const MWWorld::Ptr& actor) const; virtual int getServices (const MWWorld::Ptr& actor) const;
virtual bool isPersistent (const MWWorld::Ptr& ptr) const;
static void registerSelf(); static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const; virtual std::string getModel(const MWWorld::Ptr &ptr) const;

View file

@ -201,7 +201,7 @@ namespace MWGui
{ {
mPtr = container; mPtr = container;
if (container.getTypeName() == typeid(ESM::NPC).name() && !loot) if (!loot)
{ {
// we are stealing stuff // we are stealing stuff
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
@ -258,9 +258,9 @@ namespace MWGui
onTakeAllButtonClicked(mTakeButton); onTakeAllButtonClicked(mTakeButton);
/// \todo if corpse is non-disposable: messagebox #{sDisposeCorpseFail} /// \todo if corpse is non-disposable: messagebox #{sDisposeCorpseFail}
//if () if (MWWorld::Class::get(mPtr).isPersistent(mPtr))
// MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}");
//else else
MWBase::Environment::get().getWorld()->deleteObject(mPtr); MWBase::Environment::get().getWorld()->deleteObject(mPtr);
mPtr = MWWorld::Ptr(); mPtr = MWWorld::Ptr();

View file

@ -220,6 +220,11 @@ namespace MWWorld
return get (ptr.getTypeName()); 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<Class> instance) void Class::registerClass (const std::string& key, boost::shared_ptr<Class> instance)
{ {
sClasses.insert (std::make_pair (key, instance)); sClasses.insert (std::make_pair (key, instance));

View file

@ -253,6 +253,8 @@ namespace MWWorld
virtual float getWeight (const MWWorld::Ptr& ptr) const; virtual float getWeight (const MWWorld::Ptr& ptr) const;
virtual bool isPersistent (const MWWorld::Ptr& ptr) const;
virtual Ptr virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell) const; copyToCell(const Ptr &ptr, CellStore &cell) const;

View file

@ -15,8 +15,9 @@ ESM_Context ESMReader::getContext()
return mCtx; return mCtx;
} }
ESMReader::ESMReader(): ESMReader::ESMReader()
mBuffer(50*1024) : mBuffer(50*1024)
, mRecordFlags(0)
{ {
} }

View file

@ -216,7 +216,7 @@ public:
follows the header, ie beyond the entire record. You should use follows the header, ie beyond the entire record. You should use
leftRec to orient yourself inside the record itself. leftRec to orient yourself inside the record itself.
*/ */
void getRecHeader() { uint32_t u; getRecHeader(u); } void getRecHeader() { getRecHeader(mRecordFlags); }
void getRecHeader(uint32_t &flags); void getRecHeader(uint32_t &flags);
bool hasMoreRecs() const { return mCtx.leftFile > 0; } bool hasMoreRecs() const { return mCtx.leftFile > 0; }
@ -249,11 +249,16 @@ public:
/// Sets font encoder for ESM strings /// Sets font encoder for ESM strings
void setEncoder(ToUTF8::Utf8Encoder* encoder); void setEncoder(ToUTF8::Utf8Encoder* encoder);
/// Get record flags of last record
unsigned int getRecordFlags() { return mRecordFlags; }
private: private:
Ogre::DataStreamPtr mEsm; Ogre::DataStreamPtr mEsm;
ESM_Context mCtx; ESM_Context mCtx;
unsigned int mRecordFlags;
// Special file signifier (see SpecialFile enum above) // Special file signifier (see SpecialFile enum above)
// Buffer for ESM strings // Buffer for ESM strings

View file

@ -7,6 +7,8 @@ namespace ESM {
void Creature::load(ESMReader &esm) void Creature::load(ESMReader &esm)
{ {
mPersistent = esm.getRecordFlags() & 0x0400;
mModel = esm.getHNString("MODL"); mModel = esm.getHNString("MODL");
mOriginal = esm.getHNOString("CNAM"); mOriginal = esm.getHNOString("CNAM");
mName = esm.getHNOString("FNAM"); mName = esm.getHNOString("FNAM");

View file

@ -69,6 +69,9 @@ struct Creature
NPDTstruct mData; NPDTstruct mData;
int mFlags; int mFlags;
bool mPersistent;
float mScale; float mScale;
std::string mId, mModel, mName, mScript; std::string mId, mModel, mName, mScript;

View file

@ -10,6 +10,8 @@ void NPC::load(ESMReader &esm)
{ {
mNpdt52.mGold = -10; mNpdt52.mGold = -10;
mPersistent = esm.getRecordFlags() & 0x0400;
mModel = esm.getHNOString("MODL"); mModel = esm.getHNOString("MODL");
mName = esm.getHNOString("FNAM"); mName = esm.getHNOString("FNAM");

View file

@ -100,6 +100,8 @@ struct NPC
int mFlags; int mFlags;
bool mPersistent;
InventoryList mInventory; InventoryList mInventory;
SpellList mSpells; SpellList mSpells;