mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 07:56:40 +00:00 
			
		
		
		
	Rework ESS importer code. Remove explicit NAME handling for ESM records
(cherry picked from commit 6b21da7f8e)
			
			
This commit is contained in:
		
							parent
							
								
									459fe3da52
								
							
						
					
					
						commit
						a3d48fd482
					
				
					 3 changed files with 17 additions and 27 deletions
				
			
		| 
						 | 
					@ -134,8 +134,6 @@ namespace ESSImport
 | 
				
			||||||
    void ConvertCell::read(ESM::ESMReader &esm)
 | 
					    void ConvertCell::read(ESM::ESMReader &esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ESM::Cell cell;
 | 
					        ESM::Cell cell;
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        cell.mName = id;
 | 
					 | 
				
			||||||
        cell.load(esm, false);
 | 
					        cell.load(esm, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // I wonder what 0x40 does?
 | 
					        // I wonder what 0x40 does?
 | 
				
			||||||
| 
						 | 
					@ -145,7 +143,7 @@ namespace ESSImport
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // note if the player is in a nameless exterior cell, we will assign the cellId later based on player position
 | 
					        // note if the player is in a nameless exterior cell, we will assign the cellId later based on player position
 | 
				
			||||||
        if (id == mContext->mPlayerCellName)
 | 
					        if (cell.mName == mContext->mPlayerCellName)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            mContext->mPlayer.mCellId = cell.getCellId();
 | 
					            mContext->mPlayer.mCellId = cell.getCellId();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -253,7 +251,7 @@ namespace ESSImport
 | 
				
			||||||
        if (cell.isExterior())
 | 
					        if (cell.isExterior())
 | 
				
			||||||
            mExtCells[std::make_pair(cell.mData.mX, cell.mData.mY)] = newcell;
 | 
					            mExtCells[std::make_pair(cell.mData.mX, cell.mData.mY)] = newcell;
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            mIntCells[id] = newcell;
 | 
					            mIntCells[cell.mName] = newcell;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertCell::writeCell(const Cell &cell, ESM::ESMWriter& esm)
 | 
					    void ConvertCell::writeCell(const Cell &cell, ESM::ESMWriter& esm)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,10 +75,9 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void read(ESM::ESMReader& esm)
 | 
					    virtual void read(ESM::ESMReader& esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        T record;
 | 
					        T record;
 | 
				
			||||||
        record.load(esm);
 | 
					        record.load(esm);
 | 
				
			||||||
        mRecords[id] = record;
 | 
					        mRecords[record.mId] = record;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void write(ESM::ESMWriter& esm)
 | 
					    virtual void write(ESM::ESMWriter& esm)
 | 
				
			||||||
| 
						 | 
					@ -86,7 +85,6 @@ public:
 | 
				
			||||||
        for (typename std::map<std::string, T>::const_iterator it = mRecords.begin(); it != mRecords.end(); ++it)
 | 
					        for (typename std::map<std::string, T>::const_iterator it = mRecords.begin(); it != mRecords.end(); ++it)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            esm.startRecord(T::sRecordId);
 | 
					            esm.startRecord(T::sRecordId);
 | 
				
			||||||
            esm.writeHNString("NAME", it->first);
 | 
					 | 
				
			||||||
            it->second.save(esm);
 | 
					            it->second.save(esm);
 | 
				
			||||||
            esm.endRecord(T::sRecordId);
 | 
					            esm.endRecord(T::sRecordId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -102,14 +100,13 @@ public:
 | 
				
			||||||
    virtual void read(ESM::ESMReader &esm)
 | 
					    virtual void read(ESM::ESMReader &esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ESM::NPC npc;
 | 
					        ESM::NPC npc;
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        npc.load(esm);
 | 
					        npc.load(esm);
 | 
				
			||||||
        if (id != "player")
 | 
					        if (npc.mId != "player")
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Handles changes to the NPC struct, but since there is no index here
 | 
					            // Handles changes to the NPC struct, but since there is no index here
 | 
				
			||||||
            // it will apply to ALL instances of the class. seems to be the reason for the
 | 
					            // it will apply to ALL instances of the class. seems to be the reason for the
 | 
				
			||||||
            // "feature" in MW where changing AI settings of one guard will change it for all guards of that refID.
 | 
					            // "feature" in MW where changing AI settings of one guard will change it for all guards of that refID.
 | 
				
			||||||
            mContext->mNpcs[Misc::StringUtils::lowerCase(id)] = npc;
 | 
					            mContext->mNpcs[Misc::StringUtils::lowerCase(npc.mId)] = npc;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					@ -139,9 +136,8 @@ public:
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // See comment in ConvertNPC
 | 
					        // See comment in ConvertNPC
 | 
				
			||||||
        ESM::Creature creature;
 | 
					        ESM::Creature creature;
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        creature.load(esm);
 | 
					        creature.load(esm);
 | 
				
			||||||
        mContext->mCreatures[Misc::StringUtils::lowerCase(id)] = creature;
 | 
					        mContext->mCreatures[Misc::StringUtils::lowerCase(creature.mId)] = creature;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -154,18 +150,17 @@ class ConvertGlobal : public DefaultConverter<ESM::Global>
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    virtual void read(ESM::ESMReader &esm)
 | 
					    virtual void read(ESM::ESMReader &esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        ESM::Global global;
 | 
					        ESM::Global global;
 | 
				
			||||||
        global.load(esm);
 | 
					        global.load(esm);
 | 
				
			||||||
        if (Misc::StringUtils::ciEqual(id, "gamehour"))
 | 
					        if (Misc::StringUtils::ciEqual(global.mId, "gamehour"))
 | 
				
			||||||
            mContext->mHour = global.mValue.getFloat();
 | 
					            mContext->mHour = global.mValue.getFloat();
 | 
				
			||||||
        if (Misc::StringUtils::ciEqual(id, "day"))
 | 
					        if (Misc::StringUtils::ciEqual(global.mId, "day"))
 | 
				
			||||||
            mContext->mDay = global.mValue.getInteger();
 | 
					            mContext->mDay = global.mValue.getInteger();
 | 
				
			||||||
        if (Misc::StringUtils::ciEqual(id, "month"))
 | 
					        if (Misc::StringUtils::ciEqual(global.mId, "month"))
 | 
				
			||||||
            mContext->mMonth = global.mValue.getInteger();
 | 
					            mContext->mMonth = global.mValue.getInteger();
 | 
				
			||||||
        if (Misc::StringUtils::ciEqual(id, "year"))
 | 
					        if (Misc::StringUtils::ciEqual(global.mId, "year"))
 | 
				
			||||||
            mContext->mYear = global.mValue.getInteger();
 | 
					            mContext->mYear = global.mValue.getInteger();
 | 
				
			||||||
        mRecords[id] = global;
 | 
					        mRecords[global.mId] = global;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,14 +169,13 @@ class ConvertClass : public DefaultConverter<ESM::Class>
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    virtual void read(ESM::ESMReader &esm)
 | 
					    virtual void read(ESM::ESMReader &esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        ESM::Class class_;
 | 
					        ESM::Class class_;
 | 
				
			||||||
        class_.load(esm);
 | 
					        class_.load(esm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (id == "NEWCLASSID_CHARGEN")
 | 
					        if (class_.mId == "NEWCLASSID_CHARGEN")
 | 
				
			||||||
            mContext->mCustomPlayerClassName = class_.mName;
 | 
					            mContext->mCustomPlayerClassName = class_.mName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mRecords[id] = class_;
 | 
					        mRecords[class_.mId] = class_;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -190,13 +184,12 @@ class ConvertBook : public DefaultConverter<ESM::Book>
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    virtual void read(ESM::ESMReader &esm)
 | 
					    virtual void read(ESM::ESMReader &esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        ESM::Book book;
 | 
					        ESM::Book book;
 | 
				
			||||||
        book.load(esm);
 | 
					        book.load(esm);
 | 
				
			||||||
        if (book.mData.mSkillID == -1)
 | 
					        if (book.mData.mSkillID == -1)
 | 
				
			||||||
            mContext->mPlayer.mObject.mNpcStats.mUsedIds.push_back(Misc::StringUtils::lowerCase(id));
 | 
					            mContext->mPlayer.mObject.mNpcStats.mUsedIds.push_back(Misc::StringUtils::lowerCase(book.mId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mRecords[id] = book;
 | 
					        mRecords[book.mId] = book;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -368,11 +361,10 @@ class ConvertFACT : public Converter
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    virtual void read(ESM::ESMReader& esm)
 | 
					    virtual void read(ESM::ESMReader& esm)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string id = esm.getHNString("NAME");
 | 
					 | 
				
			||||||
        ESM::Faction faction;
 | 
					        ESM::Faction faction;
 | 
				
			||||||
        faction.load(esm);
 | 
					        faction.load(esm);
 | 
				
			||||||
 | 
					        std::string id = Misc::StringUtils::toLower(faction.mId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Misc::StringUtils::toLower(id);
 | 
					 | 
				
			||||||
        for (std::map<std::string, int>::const_iterator it = faction.mReactions.begin(); it != faction.mReactions.end(); ++it)
 | 
					        for (std::map<std::string, int>::const_iterator it = faction.mReactions.begin(); it != faction.mReactions.end(); ++it)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            std::string faction2 = Misc::StringUtils::lowerCase(it->first);
 | 
					            std::string faction2 = Misc::StringUtils::lowerCase(it->first);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -348,7 +348,7 @@ namespace ESSImport
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        writer.startRecord(ESM::REC_NPC_);
 | 
					        writer.startRecord(ESM::REC_NPC_);
 | 
				
			||||||
        writer.writeHNString("NAME", "player");
 | 
					        context.mPlayerBase.mId = "player";
 | 
				
			||||||
        context.mPlayerBase.save(writer);
 | 
					        context.mPlayerBase.save(writer);
 | 
				
			||||||
        writer.endRecord(ESM::REC_NPC_);
 | 
					        writer.endRecord(ESM::REC_NPC_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue