OpenMW
components/esm/loadlevlist.hpp
Go to the documentation of this file.
00001 #ifndef OPENMW_ESM_LEVLISTS_H
00002 #define OPENMW_ESM_LEVLISTS_H
00003 
00004 #include <string>
00005 #include <vector>
00006 
00007 namespace ESM
00008 {
00009 
00010 class ESMReader;
00011 class ESMWriter;
00012 
00013 /*
00014  * Leveled lists. Since these have identical layout, I only bothered
00015  * to implement it once.
00016  *
00017  * We should later implement the ability to merge leveled lists from
00018  * several files.
00019  */
00020 
00021 struct LeveledListBase
00022 {
00023     enum Flags
00024     {
00025 
00026         Each = 0x01,      // Select a new item each time this
00027                           // list is instantiated, instead of
00028                           // giving several identical items
00029                           // (used when a container has more
00030                           // than one instance of one leveled
00031                           // list.)
00032         AllLevels = 0x02  // Calculate from all levels <= player
00033                           // level, not just the closest below
00034                           // player.
00035     };
00036 
00037     int mFlags;
00038     unsigned char mChanceNone; // Chance that none are selected (0-100)
00039     std::string mId;
00040 
00041     // Record name used to read references. Must be set before load() is
00042     // called.
00043     const char *mRecName;
00044 
00045     struct LevelItem
00046     {
00047         std::string mId;
00048         short mLevel;
00049     };
00050 
00051     std::vector<LevelItem> mList;
00052 
00053     void load(ESMReader &esm);
00054     void save(ESMWriter &esm) const;
00055 
00056     void blank();
00058 };
00059 
00060 struct CreatureLevList: LeveledListBase
00061 {
00062     static unsigned int sRecordId;
00063 
00064     CreatureLevList()
00065     {
00066         mRecName = "CNAM";
00067     }
00068 };
00069 
00070 struct ItemLevList: LeveledListBase
00071 {
00072     static unsigned int sRecordId;
00073 
00074     ItemLevList()
00075     {
00076         mRecName = "INAM";
00077     }
00078 };
00079 
00080 }
00081 #endif