1 #ifndef GAME_MWWORLD_REFDATA_H 2 #define GAME_MWWORLD_REFDATA_H 3 4 #include <components/esm/defs.hpp> 5 #include <components/esm/animationstate.hpp> 6 7 #include "../mwscript/locals.hpp" 8 #include "../mwworld/customdata.hpp" 9 10 #include <string> 11 #include <memory> 12 13 namespace SceneUtil 14 { 15 class PositionAttitudeTransform; 16 } 17 18 namespace ESM 19 { 20 class Script; 21 class CellRef; 22 struct ObjectState; 23 } 24 25 namespace MWWorld 26 { 27 28 class CustomData; 29 30 class RefData 31 { 32 SceneUtil::PositionAttitudeTransform* mBaseNode; 33 34 MWScript::Locals mLocals; 35 36 /// separate delete flag used for deletion by a content file 37 /// @note not stored in the save game file. 38 bool mDeletedByContentFile; 39 40 bool mEnabled; 41 42 /// 0: deleted 43 int mCount; 44 45 ESM::Position mPosition; 46 47 ESM::AnimationState mAnimationState; 48 49 std::unique_ptr<CustomData> mCustomData; 50 51 void copy (const RefData& refData); 52 53 void cleanup(); 54 55 bool mChanged; 56 57 unsigned int mFlags; 58 59 public: 60 61 RefData(); 62 63 /// @param cellRef Used to copy constant data such as position into this class where it can 64 /// be altered without affecting the original data. This makes it possible 65 /// to reset the position as the original data is still held in the CellRef 66 RefData (const ESM::CellRef& cellRef); 67 68 RefData (const ESM::ObjectState& objectState, bool deletedByContentFile); 69 ///< Ignores local variables and custom data (not enough context available here to 70 /// perform these operations). 71 72 RefData (const RefData& refData); 73 RefData (RefData&& other) noexcept = default; 74 75 ~RefData(); 76 77 void write (ESM::ObjectState& objectState, const std::string& scriptId = "") const; 78 ///< Ignores custom data (not enough context available here to 79 /// perform this operations). 80 81 RefData& operator= (const RefData& refData); 82 RefData& operator= (RefData&& other) noexcept = default; 83 84 /// Return base node (can be a null pointer). 85 SceneUtil::PositionAttitudeTransform* getBaseNode(); 86 87 /// Return base node (can be a null pointer). 88 const SceneUtil::PositionAttitudeTransform* getBaseNode() const; 89 90 /// Set base node (can be a null pointer). 91 void setBaseNode (SceneUtil::PositionAttitudeTransform* base); 92 93 int getCount(bool absolute = true) const; 94 95 void setLocals (const ESM::Script& script); 96 97 void setCount (int count); 98 ///< Set object count (an object pile is a simple object with a count >1). 99 /// 100 /// \warning Do not call setCount() to add or remove objects from a 101 /// container or an actor's inventory. Call ContainerStore::add() or 102 /// ContainerStore::remove() instead. 103 104 /// This flag is only used for content stack loading and will not be stored in the savegame. 105 /// If the object was deleted by gameplay, then use setCount(0) instead. 106 void setDeletedByContentFile(bool deleted); 107 108 /// Returns true if the object was either deleted by the content file or by gameplay. 109 bool isDeleted() const; 110 /// Returns true if the object was deleted by a content file. 111 bool isDeletedByContentFile() const; 112 113 MWScript::Locals& getLocals(); 114 115 bool isEnabled() const; 116 117 void enable(); 118 119 void disable(); 120 121 void setPosition (const ESM::Position& pos); 122 const ESM::Position& getPosition() const; 123 124 void setCustomData(std::unique_ptr<CustomData>&& value) noexcept; 125 ///< Set custom data (potentially replacing old custom data). The ownership of \a data is 126 /// transferred to this. 127 128 CustomData *getCustomData(); 129 ///< May return a 0-pointer. The ownership of the return data object is not transferred. 130 131 const CustomData *getCustomData() const; 132 133 bool activate(); 134 135 bool onActivate(); 136 137 bool activateByScript(); 138 139 bool hasChanged() const; 140 ///< Has this RefData changed since it was originally loaded? 141 142 const ESM::AnimationState& getAnimationState() const; 143 ESM::AnimationState& getAnimationState(); 144 }; 145 } 146 147 #endif 148