1 #ifndef OPENMW_ESM_CELLREF_H 2 #define OPENMW_ESM_CELLREF_H 3 4 #include <limits> 5 #include <string> 6 7 #include "defs.hpp" 8 9 namespace ESM 10 { 11 class ESMWriter; 12 class ESMReader; 13 14 const int UnbreakableLock = std::numeric_limits<int>::max(); 15 extern int GroundcoverIndex; 16 17 struct RefNum 18 { 19 unsigned int mIndex; 20 int mContentFile; 21 22 void load (ESMReader& esm, bool wide = false, const std::string& tag = "FRMR"); 23 24 void save (ESMWriter &esm, bool wide = false, const std::string& tag = "FRMR") const; 25 26 enum { RefNum_NoContentFile = -1 }; hasContentFileESM::RefNum27 inline bool hasContentFile() const { return mContentFile != RefNum_NoContentFile; } unsetESM::RefNum28 inline void unset() { mIndex = 0; mContentFile = RefNum_NoContentFile; } 29 30 // Note: this method should not be used for objects with invalid RefNum 31 // (for example, for objects from disabled plugins in savegames). fromGroundcoverFileESM::RefNum32 inline bool fromGroundcoverFile() const { return mContentFile >= GroundcoverIndex; } 33 }; 34 35 /* Cell reference. This represents ONE object (of many) inside the 36 cell. The cell references are not loaded as part of the normal 37 loading process, but are rather loaded later on demand when we are 38 setting up a specific cell. 39 */ 40 41 class CellRef 42 { 43 public: 44 // Reference number 45 // Note: Currently unused for items in containers 46 RefNum mRefNum; 47 48 std::string mRefID; // ID of object being referenced 49 50 float mScale; // Scale applied to mesh 51 52 // The NPC that owns this object (and will get angry if you steal it) 53 std::string mOwner; 54 55 // Name of a global variable. If the global variable is set to '1', using the object is temporarily allowed 56 // even if it has an Owner field. 57 // Used by bed rent scripts to allow the player to use the bed for the duration of the rent. 58 std::string mGlobalVariable; 59 60 // ID of creature trapped in this soul gem 61 std::string mSoul; 62 63 // The faction that owns this object (and will get angry if 64 // you take it and are not a faction member) 65 std::string mFaction; 66 67 // PC faction rank required to use the item. Sometimes is -1, which means "any rank". 68 int mFactionRank; 69 70 // For weapon or armor, this is the remaining item health. 71 // For tools (lockpicks, probes, repair hammer) it is the remaining uses. 72 // For lights it is remaining time. 73 // This could be -1 if the charge was not touched yet (i.e. full). 74 union 75 { 76 int mChargeInt; // Used by everything except lights 77 float mChargeFloat; // Used only by lights 78 }; 79 float mChargeIntRemainder; // Stores amount of charge not subtracted from mChargeInt 80 81 // Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full). 82 float mEnchantmentCharge; 83 84 // This is 5 for Gold_005 references, 100 for Gold_100 and so on. 85 int mGoldValue; 86 87 // For doors - true if this door teleports to somewhere else, false 88 // if it should open through animation. 89 bool mTeleport; 90 91 // Teleport location for the door, if this is a teleporting door. 92 Position mDoorDest; 93 94 // Destination cell for doors (optional) 95 std::string mDestCell; 96 97 // Lock level for doors and containers 98 int mLockLevel; 99 std::string mKey, mTrap; // Key and trap ID names, if any 100 101 // This corresponds to the "Reference Blocked" checkbox in the construction set, 102 // which prevents editing that reference. 103 // -1 is not blocked, otherwise it is blocked. 104 signed char mReferenceBlocked; 105 106 // Position and rotation of this object within the cell 107 Position mPos; 108 109 /// Calls loadId and loadData 110 void load (ESMReader& esm, bool &isDeleted, bool wideRefNum = false); 111 112 void loadId (ESMReader& esm, bool wideRefNum = false); 113 114 /// Implicitly called by load 115 void loadData (ESMReader& esm, bool &isDeleted); 116 117 void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false, bool isDeleted = false) const; 118 119 void blank(); 120 }; 121 operator ==(const RefNum & left,const RefNum & right)122 inline bool operator== (const RefNum& left, const RefNum& right) 123 { 124 return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile; 125 } 126 operator <(const RefNum & left,const RefNum & right)127 inline bool operator< (const RefNum& left, const RefNum& right) 128 { 129 if (left.mIndex<right.mIndex) 130 return true; 131 if (left.mIndex>right.mIndex) 132 return false; 133 return left.mContentFile<right.mContentFile; 134 } 135 136 } 137 138 #endif 139