Remove NAME and DELE handling from IdCollection

openmw-38
Stanislav Bas 10 years ago
parent 42f9136141
commit 74a055f3cc

@ -5,16 +5,13 @@
void CSMWorld::Cell::load (ESM::ESMReader &esm)
{
mName = mId;
ESM::Cell::load (esm, false);
mId = mName;
if (!(mData.mFlags & Interior))
{
std::ostringstream stream;
stream << "#" << mData.mX << " " << mData.mY;
mId = stream.str();
}
}

@ -988,41 +988,41 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
case ESM::REC_DIAL:
{
std::string id = mReader->getHNOString ("NAME");
ESM::Dialogue record;
record.mId = id;
record.load (*mReader);
if (record.mType==ESM::Dialogue::Journal)
{
mJournals.load (record, mBase);
mDialogue = &mJournals.getRecord (id).get();
}
else if (record.mType==ESM::Dialogue::Deleted)
if (record.mIsDeleted)
{
mDialogue = 0; // record vector can be shuffled around which would make pointer
// to record invalid
// record vector can be shuffled around which would make pointer to record invalid
mDialogue = 0;
if (mJournals.tryDelete (id))
if (mJournals.tryDelete (record.mId))
{
/// \todo handle info records
}
else if (mTopics.tryDelete (id))
else if (mTopics.tryDelete (record.mId))
{
/// \todo handle info records
}
else
{
messages.add (UniversalId::Type_None,
"Trying to delete dialogue record " + id + " which does not exist",
"Trying to delete dialogue record " + record.mId + " which does not exist",
"", CSMDoc::Message::Severity_Warning);
}
}
else
{
mTopics.load (record, mBase);
mDialogue = &mTopics.getRecord (id).get();
if (record.mType == ESM::Dialogue::Journal)
{
mJournals.load (record, mBase);
mDialogue = &mJournals.getRecord (record.mId).get();
}
else
{
mTopics.load (record, mBase);
mDialogue = &mTopics.getRecord (record.mId).get();
}
}
break;

@ -2,6 +2,7 @@
#define CSM_WOLRD_IDCOLLECTION_H
#include <components/esm/esmreader.hpp>
#include <components/esm/util.hpp>
#include "collection.hpp"
@ -41,69 +42,43 @@ namespace CSMWorld
template<typename ESXRecordT, typename IdAccessorT>
int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base)
{
std::string id = reader.getHNOString ("NAME");
ESXRecordT record;
loadRecord (record, reader);
if (reader.isNextSub ("DELE"))
{
int index = Collection<ESXRecordT, IdAccessorT>::searchId (id);
reader.skipRecord();
std::string id = IdAccessorT().getId (record);
int index = searchId (id);
if (ESM::isRecordDeleted (record))
{
if (index==-1)
{
// deleting a record that does not exist
// ignore it for now
/// \todo report the problem to the user
return -1;
}
else if (base)
if (base)
{
Collection<ESXRecordT, IdAccessorT>::removeRows (index, 1);
removeRows (index, 1);
}
else
{
Record<ESXRecordT> record = Collection<ESXRecordT, IdAccessorT>::getRecord (index);
record.mState = RecordBase::State_Deleted;
this->setRecord (index, record);
Record<ESXRecordT> baseRecord = getRecord (index);
baseRecord.mState = RecordBase::State_Deleted;
this->setRecord (index, baseRecord);
}
return -1;
}
else
{
ESXRecordT record;
// Sometimes id (i.e. NAME of the cell) may be different to the id we stored
// earlier. e.g. NAME == "Vivec, Arena" but id == "#-4 11". Sometime NAME is
// missing altogether for scripts or cells.
//
// In such cases the returned index will be -1. We then try updating the
// IdAccessor's id manually (e.g. set mId of the record to "Vivec, Arena")
// and try getting the index once more after loading the record. The mId of the
// record would have changed to "#-4 11" after the load, and searchId() should find
// it (if this is a modify)
int index = this->searchId (id);
if (index==-1)
IdAccessorT().getId (record) = id;
else
{
record = this->getRecord (index).get();
}
loadRecord (record, reader);
if (index==-1)
{
std::string newId = IdAccessorT().getId(record);
int newIndex = this->searchId(newId);
if (newIndex != -1 && id != newId)
index = newIndex;
}
return load (record, base, index);
}
//
//if (index != -1)
//{
// ESXRecordT existedRecord = getRecord(index).get();
// IdAccessorT().getId(record) = IdAccessorT().getId(existedRecord);
//}
return load (record, base, index);
}
template<typename ESXRecordT, typename IdAccessorT>

@ -4,6 +4,7 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include <components/esm/loadland.hpp>
#include <components/esm/util.hpp>
namespace CSMWorld
{
@ -26,4 +27,13 @@ namespace CSMWorld
};
}
namespace ESM
{
template <>
bool isRecordDeleted<CSMWorld::Land>(const CSMWorld::Land &land)
{
return false;
}
}
#endif

@ -5,6 +5,7 @@
#include <string>
#include <components/esm/loadpgrd.hpp>
#include <components/esm/util.hpp>
namespace CSMWorld
{
@ -26,4 +27,13 @@ namespace CSMWorld
};
}
namespace ESM
{
template <>
bool isRecordDeleted<CSMWorld::Pathgrid>(const CSMWorld::Pathgrid &pgrd)
{
return false;
}
}
#endif

@ -36,4 +36,40 @@ namespace ESM
{
return false;
}
template <>
bool isRecordDeleted<Skill>(const Skill &skill)
{
return false;
}
template <>
bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef)
{
return false;
}
template <>
bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd)
{
return false;
}
template <>
bool isRecordDeleted<Land>(const Land &land)
{
return false;
}
template <>
bool isRecordDeleted<DebugProfile>(const DebugProfile &profile)
{
return false;
}
template <>
bool isRecordDeleted<Filter>(const Filter &filter)
{
return false;
}
}

@ -12,6 +12,12 @@
#include "loadglob.hpp"
#include "loadrace.hpp"
#include "loadgmst.hpp"
#include "loadskil.hpp"
#include "loadmgef.hpp"
#include "loadland.hpp"
#include "loadpgrd.hpp"
#include "debugprofile.hpp"
#include "filter.hpp"
namespace ESM
{
@ -76,6 +82,24 @@ bool isRecordDeleted<Race>(const Race &race);
template <>
bool isRecordDeleted<GameSetting>(const GameSetting &gmst);
template <>
bool isRecordDeleted<Skill>(const Skill &skill);
template <>
bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef);
template <>
bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd);
template <>
bool isRecordDeleted<Land>(const Land &land);
template <>
bool isRecordDeleted<DebugProfile>(const DebugProfile &profile);
template <>
bool isRecordDeleted<Filter>(const Filter &filter);
}
#endif

Loading…
Cancel
Save