forked from teamnwah/openmw-tes3coop
ESSImport: container state
This commit is contained in:
parent
a7b82e5107
commit
8e1eeccbe1
12 changed files with 196 additions and 127 deletions
|
@ -8,12 +8,14 @@ set(ESSIMPORTER_FILES
|
||||||
importacdt.cpp
|
importacdt.cpp
|
||||||
importinventory.cpp
|
importinventory.cpp
|
||||||
importklst.cpp
|
importklst.cpp
|
||||||
|
importcntc.cpp
|
||||||
importercontext.cpp
|
importercontext.cpp
|
||||||
converter.cpp
|
converter.cpp
|
||||||
convertacdt.cpp
|
convertacdt.cpp
|
||||||
convertnpcc.cpp
|
convertnpcc.cpp
|
||||||
convertinventory.cpp
|
convertinventory.cpp
|
||||||
convertcrec.cpp
|
convertcrec.cpp
|
||||||
|
convertcntc.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(openmw-essimporter
|
add_executable(openmw-essimporter
|
||||||
|
|
13
apps/essimporter/convertcntc.cpp
Normal file
13
apps/essimporter/convertcntc.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#include "convertcntc.hpp"
|
||||||
|
|
||||||
|
#include "convertinventory.hpp"
|
||||||
|
|
||||||
|
namespace ESSImport
|
||||||
|
{
|
||||||
|
|
||||||
|
void convertCNTC(const CNTC &cntc, ESM::ContainerState &state)
|
||||||
|
{
|
||||||
|
convertInventory(cntc.mInventory, state.mInventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
apps/essimporter/convertcntc.hpp
Normal file
15
apps/essimporter/convertcntc.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef OPENMW_ESSIMPORT_CONVERTCNTC_H
|
||||||
|
#define OPENMW_ESSIMPORT_CONVERTCNTC_H
|
||||||
|
|
||||||
|
#include "importcntc.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/containerstate.hpp>
|
||||||
|
|
||||||
|
namespace ESSImport
|
||||||
|
{
|
||||||
|
|
||||||
|
void convertCNTC(const CNTC& cntc, ESM::ContainerState& state);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,8 +3,10 @@
|
||||||
#include <OgreImage.h>
|
#include <OgreImage.h>
|
||||||
|
|
||||||
#include <components/esm/creaturestate.hpp>
|
#include <components/esm/creaturestate.hpp>
|
||||||
|
#include <components/esm/containerstate.hpp>
|
||||||
|
|
||||||
#include "convertcrec.hpp"
|
#include "convertcrec.hpp"
|
||||||
|
#include "convertcntc.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -17,6 +19,13 @@ namespace
|
||||||
screenshot.save(out);
|
screenshot.save(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void convertCellRef(const ESSImport::CellRef& cellref, ESM::ObjectState& objstate)
|
||||||
|
{
|
||||||
|
objstate.mEnabled = cellref.mEnabled;
|
||||||
|
objstate.mPosition = cellref.mPos;
|
||||||
|
objstate.mRef.mRefNum = cellref.mRefNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ESSImport
|
namespace ESSImport
|
||||||
|
@ -116,8 +125,9 @@ namespace ESSImport
|
||||||
ref.load (esm);
|
ref.load (esm);
|
||||||
if (esm.isNextSub("DELE"))
|
if (esm.isNextSub("DELE"))
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
// strangely this can be e.g. 52 instead of just 1,
|
// strangely this can be e.g. 52 instead of just 1,
|
||||||
std::cout << "deleted ref " << ref.mIndexedRefId << std::endl;
|
//std::cout << "deleted ref " << ref.mIndexedRefId << std::endl;
|
||||||
esm.skipHSub();
|
esm.skipHSub();
|
||||||
}
|
}
|
||||||
cellrefs.push_back(ref);
|
cellrefs.push_back(ref);
|
||||||
|
@ -155,26 +165,27 @@ namespace ESSImport
|
||||||
|
|
||||||
newcell.mRefs = cellrefs;
|
newcell.mRefs = cellrefs;
|
||||||
|
|
||||||
// FIXME: map by ID for exterior cells
|
|
||||||
mCells[id] = newcell;
|
if (cell.isExterior())
|
||||||
|
mExtCells[std::make_pair(cell.mData.mX, cell.mData.mY)] = newcell;
|
||||||
|
else
|
||||||
|
mIntCells[id] = newcell;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertCell::write(ESM::ESMWriter &esm)
|
void ConvertCell::writeCell(const Cell &cell, ESM::ESMWriter& esm)
|
||||||
{
|
{
|
||||||
for (std::map<std::string, Cell>::const_iterator it = mCells.begin(); it != mCells.end(); ++it)
|
ESM::Cell esmcell = cell.mCell;
|
||||||
{
|
|
||||||
const ESM::Cell& cell = it->second.mCell;
|
|
||||||
esm.startRecord(ESM::REC_CSTA);
|
esm.startRecord(ESM::REC_CSTA);
|
||||||
ESM::CellState csta;
|
ESM::CellState csta;
|
||||||
csta.mHasFogOfWar = 0;
|
csta.mHasFogOfWar = 0;
|
||||||
csta.mId = cell.getCellId();
|
csta.mId = esmcell.getCellId();
|
||||||
csta.mId.save(esm);
|
csta.mId.save(esm);
|
||||||
// TODO csta.mLastRespawn;
|
// TODO csta.mLastRespawn;
|
||||||
// shouldn't be needed if we respawn on global schedule like in original MW
|
// shouldn't be needed if we respawn on global schedule like in original MW
|
||||||
csta.mWaterLevel = cell.mWater;
|
csta.mWaterLevel = esmcell.mWater;
|
||||||
csta.save(esm);
|
csta.save(esm);
|
||||||
|
|
||||||
for (std::vector<CellRef>::const_iterator refIt = it->second.mRefs.begin(); refIt != it->second.mRefs.end(); ++refIt)
|
for (std::vector<CellRef>::const_iterator refIt = cell.mRefs.begin(); refIt != cell.mRefs.end(); ++refIt)
|
||||||
{
|
{
|
||||||
const CellRef& cellref = *refIt;
|
const CellRef& cellref = *refIt;
|
||||||
ESM::CellRef out;
|
ESM::CellRef out;
|
||||||
|
@ -198,12 +209,10 @@ namespace ESSImport
|
||||||
{
|
{
|
||||||
ESM::CreatureState objstate;
|
ESM::CreatureState objstate;
|
||||||
objstate.blank();
|
objstate.blank();
|
||||||
|
objstate.mRef = out;
|
||||||
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
||||||
convertCREC(crecIt->second, objstate);
|
convertCREC(crecIt->second, objstate);
|
||||||
objstate.mEnabled = cellref.mEnabled;
|
convertCellRef(cellref, objstate);
|
||||||
objstate.mPosition = cellref.mPos;
|
|
||||||
objstate.mRef = out;
|
|
||||||
objstate.mRef.mRefNum = cellref.mRefNum;
|
|
||||||
// FIXME: change save format to not require object type, instead look up it up using the RefId
|
// FIXME: change save format to not require object type, instead look up it up using the RefId
|
||||||
esm.writeHNT ("OBJE", ESM::REC_CREA);
|
esm.writeHNT ("OBJE", ESM::REC_CREA);
|
||||||
objstate.save(esm);
|
objstate.save(esm);
|
||||||
|
@ -216,24 +225,44 @@ namespace ESSImport
|
||||||
{
|
{
|
||||||
ESM::NpcState objstate;
|
ESM::NpcState objstate;
|
||||||
objstate.blank();
|
objstate.blank();
|
||||||
|
objstate.mRef = out;
|
||||||
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
convertACDT(cellref.mActorData.mACDT, objstate.mCreatureStats);
|
||||||
convertNpcData(cellref.mActorData, objstate.mNpcStats);
|
convertNpcData(cellref.mActorData, objstate.mNpcStats);
|
||||||
convertNPCC(npccIt->second, objstate);
|
convertNPCC(npccIt->second, objstate);
|
||||||
objstate.mEnabled = cellref.mEnabled;
|
convertCellRef(cellref, objstate);
|
||||||
objstate.mPosition = cellref.mPos;
|
|
||||||
objstate.mRef = out;
|
|
||||||
objstate.mRef.mRefNum = cellref.mRefNum;
|
|
||||||
esm.writeHNT ("OBJE", ESM::REC_NPC_);
|
esm.writeHNT ("OBJE", ESM::REC_NPC_);
|
||||||
objstate.save(esm);
|
objstate.save(esm);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::pair<int, std::string>, CNTC>::const_iterator cntcIt = mContext->mContainerChanges.find(
|
||||||
|
std::make_pair(refIndex, out.mRefID));
|
||||||
|
if (cntcIt != mContext->mContainerChanges.end())
|
||||||
|
{
|
||||||
|
ESM::ContainerState objstate;
|
||||||
|
objstate.blank();
|
||||||
|
objstate.mRef = out;
|
||||||
|
convertCNTC(cntcIt->second, objstate);
|
||||||
|
convertCellRef(cellref, objstate);
|
||||||
|
esm.writeHNT ("OBJE", ESM::REC_CONT);
|
||||||
|
objstate.save(esm);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
std::cerr << "Can't find type for " << refIndex << " " << out.mRefID << std::endl;
|
std::cerr << "Can't find type for " << refIndex << " " << out.mRefID << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
esm.endRecord(ESM::REC_CSTA);
|
esm.endRecord(ESM::REC_CSTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConvertCell::write(ESM::ESMWriter &esm)
|
||||||
|
{
|
||||||
|
for (std::map<std::string, Cell>::const_iterator it = mIntCells.begin(); it != mIntCells.end(); ++it)
|
||||||
|
writeCell(it->second, esm);
|
||||||
|
|
||||||
|
for (std::map<std::pair<int, int>, Cell>::const_iterator it = mExtCells.begin(); it != mExtCells.end(); ++it)
|
||||||
|
writeCell(it->second, esm);
|
||||||
|
|
||||||
for (std::vector<ESM::CustomMarker>::const_iterator it = mMarkers.begin(); it != mMarkers.end(); ++it)
|
for (std::vector<ESM::CustomMarker>::const_iterator it = mMarkers.begin(); it != mMarkers.end(); ++it)
|
||||||
{
|
{
|
||||||
esm.startRecord(ESM::REC_MARK);
|
esm.startRecord(ESM::REC_MARK);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <components/esm/custommarkerstate.hpp>
|
#include <components/esm/custommarkerstate.hpp>
|
||||||
|
|
||||||
#include "importcrec.hpp"
|
#include "importcrec.hpp"
|
||||||
|
#include "importcntc.hpp"
|
||||||
|
|
||||||
#include "importercontext.hpp"
|
#include "importercontext.hpp"
|
||||||
#include "importcellref.hpp"
|
#include "importcellref.hpp"
|
||||||
|
@ -94,7 +95,8 @@ public:
|
||||||
mContext->mPlayer.mObject.mCreatureStats.mLevel = npc.mNpdt52.mLevel;
|
mContext->mPlayer.mObject.mCreatureStats.mLevel = npc.mNpdt52.mLevel;
|
||||||
mContext->mPlayerBase = npc;
|
mContext->mPlayerBase = npc;
|
||||||
std::map<const int, float> empty;
|
std::map<const int, float> empty;
|
||||||
// FIXME: not working?
|
// FIXME: player start spells, racial spells and birthsign spells aren't listed here,
|
||||||
|
// need to fix openmw to account for this
|
||||||
for (std::vector<std::string>::const_iterator it = npc.mSpells.mList.begin(); it != npc.mSpells.mList.end(); ++it)
|
for (std::vector<std::string>::const_iterator it = npc.mSpells.mList.begin(); it != npc.mSpells.mList.end(); ++it)
|
||||||
mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[*it] = empty;
|
mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[*it] = empty;
|
||||||
}
|
}
|
||||||
|
@ -209,6 +211,17 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ConvertCNTC : public Converter
|
||||||
|
{
|
||||||
|
virtual void read(ESM::ESMReader &esm)
|
||||||
|
{
|
||||||
|
std::string id = esm.getHNString("NAME");
|
||||||
|
CNTC cntc;
|
||||||
|
cntc.load(esm);
|
||||||
|
mContext->mContainerChanges.insert(std::make_pair(std::make_pair(cntc.mIndex,id), cntc));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ConvertCREC : public Converter
|
class ConvertCREC : public Converter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -242,9 +255,12 @@ private:
|
||||||
std::vector<unsigned int> mFogOfWar;
|
std::vector<unsigned int> mFogOfWar;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, Cell> mCells;
|
std::map<std::string, Cell> mIntCells;
|
||||||
|
std::map<std::pair<int, int>, Cell> mExtCells;
|
||||||
|
|
||||||
std::vector<ESM::CustomMarker> mMarkers;
|
std::vector<ESM::CustomMarker> mMarkers;
|
||||||
|
|
||||||
|
void writeCell(const Cell& cell, ESM::ESMWriter &esm);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConvertKLST : public Converter
|
class ConvertKLST : public Converter
|
||||||
|
|
16
apps/essimporter/importcntc.cpp
Normal file
16
apps/essimporter/importcntc.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "importcntc.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/esmreader.hpp>
|
||||||
|
|
||||||
|
namespace ESSImport
|
||||||
|
{
|
||||||
|
|
||||||
|
void CNTC::load(ESM::ESMReader &esm)
|
||||||
|
{
|
||||||
|
mIndex = 0;
|
||||||
|
esm.getHNT(mIndex, "INDX");
|
||||||
|
|
||||||
|
mInventory.load(esm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
apps/essimporter/importcntc.hpp
Normal file
25
apps/essimporter/importcntc.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef OPENMW_ESSIMPORT_IMPORTCNTC_H
|
||||||
|
#define OPENMW_ESSIMPORT_IMPORTCNTC_H
|
||||||
|
|
||||||
|
#include "importinventory.hpp"
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class ESMReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ESSImport
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Changed container contents
|
||||||
|
struct CNTC
|
||||||
|
{
|
||||||
|
int mIndex;
|
||||||
|
|
||||||
|
Inventory mInventory;
|
||||||
|
|
||||||
|
void load(ESM::ESMReader& esm);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -215,6 +215,7 @@ namespace ESSImport
|
||||||
converters[ESM::REC_WEAP] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::Weapon>());
|
converters[ESM::REC_WEAP] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::Weapon>());
|
||||||
converters[ESM::REC_LEVC] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::CreatureLevList>());
|
converters[ESM::REC_LEVC] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::CreatureLevList>());
|
||||||
converters[ESM::REC_LEVI] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::ItemLevList>());
|
converters[ESM::REC_LEVI] = boost::shared_ptr<Converter>(new DefaultConverter<ESM::ItemLevList>());
|
||||||
|
converters[ESM::REC_CNTC] = boost::shared_ptr<Converter>(new ConvertCNTC());
|
||||||
|
|
||||||
std::set<unsigned int> unknownRecords;
|
std::set<unsigned int> unknownRecords;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "importnpcc.hpp"
|
#include "importnpcc.hpp"
|
||||||
#include "importcrec.hpp"
|
#include "importcrec.hpp"
|
||||||
|
#include "importcntc.hpp"
|
||||||
#include "importplayer.hpp"
|
#include "importplayer.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ namespace ESSImport
|
||||||
// key <refIndex, refId>
|
// key <refIndex, refId>
|
||||||
std::map<std::pair<int, std::string>, CREC> mCreatureChanges;
|
std::map<std::pair<int, std::string>, CREC> mCreatureChanges;
|
||||||
std::map<std::pair<int, std::string>, NPCC> mNpcChanges;
|
std::map<std::pair<int, std::string>, NPCC> mNpcChanges;
|
||||||
|
std::map<std::pair<int, std::string>, CNTC> mContainerChanges;
|
||||||
|
|
||||||
Context()
|
Context()
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,7 @@ add_component_dir (to_utf8
|
||||||
|
|
||||||
add_component_dir (esm
|
add_component_dir (esm
|
||||||
attr defs esmcommon esmreader esmwriter loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell
|
attr defs esmcommon esmreader esmwriter loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell
|
||||||
loadclas loadclot loadcont loadcrea loadcrec loaddial loaddoor loadench loadfact loadglob loadgmst
|
loadclas loadclot loadcont loadcrea loaddial loaddoor loadench loadfact loadglob loadgmst
|
||||||
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
|
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
|
||||||
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
||||||
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#ifndef OPENMW_ESM_CREC_H
|
|
||||||
#define OPENMW_ESM_CREC_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// TODO create implementation files and remove this one
|
|
||||||
#include "esmreader.hpp"
|
|
||||||
|
|
||||||
namespace ESM {
|
|
||||||
|
|
||||||
class ESMReader;
|
|
||||||
class ESMWriter;
|
|
||||||
|
|
||||||
/* These two are only used in save games. They are not decoded yet.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// Changes a creature
|
|
||||||
struct LoadCREC
|
|
||||||
{
|
|
||||||
static unsigned int sRecordId;
|
|
||||||
|
|
||||||
std::string mId;
|
|
||||||
|
|
||||||
void load(ESMReader &esm)
|
|
||||||
{
|
|
||||||
esm.skipRecord();
|
|
||||||
}
|
|
||||||
|
|
||||||
void save(ESMWriter &esm) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Changes an item list / container
|
|
||||||
struct LoadCNTC
|
|
||||||
{
|
|
||||||
std::string mId;
|
|
||||||
|
|
||||||
void load(ESMReader &esm)
|
|
||||||
{
|
|
||||||
esm.skipRecord();
|
|
||||||
}
|
|
||||||
|
|
||||||
void save(ESMWriter &esm) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "loadclot.hpp"
|
#include "loadclot.hpp"
|
||||||
#include "loadcont.hpp"
|
#include "loadcont.hpp"
|
||||||
#include "loadcrea.hpp"
|
#include "loadcrea.hpp"
|
||||||
#include "loadcrec.hpp"
|
|
||||||
#include "loadinfo.hpp"
|
#include "loadinfo.hpp"
|
||||||
#include "loaddial.hpp"
|
#include "loaddial.hpp"
|
||||||
#include "loaddoor.hpp"
|
#include "loaddoor.hpp"
|
||||||
|
|
Loading…
Reference in a new issue