mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 21:56:41 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			113 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "loaddial.hpp"
 | |
| 
 | |
| #include <iostream>
 | |
| 
 | |
| #include "esmreader.hpp"
 | |
| #include "esmwriter.hpp"
 | |
| #include "defs.hpp"
 | |
| 
 | |
| namespace ESM
 | |
| {
 | |
|     unsigned int Dialogue::sRecordId = REC_DIAL;
 | |
| 
 | |
| void Dialogue::load(ESMReader &esm)
 | |
| {
 | |
|     esm.getSubNameIs("DATA");
 | |
|     esm.getSubHeader();
 | |
|     int si = esm.getSubSize();
 | |
|     if (si == 1)
 | |
|         esm.getT(mType);
 | |
|     else if (si == 4)
 | |
|     {
 | |
|         // These are just markers, their values are not used.
 | |
|         int i;
 | |
|         esm.getT(i);
 | |
|         esm.getHNT(i, "DELE");
 | |
|         mType = Deleted;
 | |
|     }
 | |
|     else
 | |
|         esm.fail("Unknown sub record size");
 | |
| }
 | |
| 
 | |
| void Dialogue::save(ESMWriter &esm) const
 | |
| {
 | |
|     if (mType != Deleted)
 | |
|         esm.writeHNT("DATA", mType);
 | |
|     else
 | |
|     {
 | |
|         esm.writeHNT("DATA", (int)1);
 | |
|         esm.writeHNT("DELE", (int)1);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void Dialogue::blank()
 | |
| {
 | |
|     mInfo.clear();
 | |
| }
 | |
| 
 | |
| void Dialogue::readInfo(ESMReader &esm, bool merge)
 | |
| {
 | |
|     const std::string& id = esm.getHNOString("INAM");
 | |
| 
 | |
|     if (!merge || mInfo.empty())
 | |
|     {
 | |
|         ESM::DialInfo info;
 | |
|         info.mId = id;
 | |
|         info.load(esm);
 | |
|         mLookup[id] = mInfo.insert(mInfo.end(), info);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
 | |
| 
 | |
|     std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
 | |
| 
 | |
|     lookup = mLookup.find(id);
 | |
|     if (lookup != mLookup.end())
 | |
|     {
 | |
|         it = lookup->second;
 | |
| 
 | |
|         // Merge with existing record. Only the subrecords that are present in
 | |
|         // the new record will be overwritten.
 | |
|         it->load(esm);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     // New record
 | |
|     ESM::DialInfo info;
 | |
|     info.mId = id;
 | |
|     info.load(esm);
 | |
| 
 | |
|     if (info.mNext.empty())
 | |
|     {
 | |
|         mLookup[id] = mInfo.insert(mInfo.end(), info);
 | |
|         return;
 | |
|     }
 | |
|     if (info.mPrev.empty())
 | |
|     {
 | |
|         mLookup[id] = mInfo.insert(mInfo.begin(), info);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     lookup = mLookup.find(info.mPrev);
 | |
|     if (lookup != mLookup.end())
 | |
|     {
 | |
|         it = lookup->second;
 | |
| 
 | |
|         mLookup[id] = mInfo.insert(++it, info);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     lookup = mLookup.find(info.mNext);
 | |
|     if (lookup != mLookup.end())
 | |
|     {
 | |
|         it = lookup->second;
 | |
| 
 | |
|         mLookup[id] = mInfo.insert(it, info);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     std::cerr << "Failed to insert info " << id << std::endl;
 | |
| }
 | |
| 
 | |
| }
 |