forked from mirror/openmw-tes3mp
store content of containers in saved game files
parent
900532a6ca
commit
dd674566a2
@ -0,0 +1,16 @@
|
||||
|
||||
#include "containerstate.hpp"
|
||||
|
||||
void ESM::ContainerState::load (ESMReader &esm)
|
||||
{
|
||||
ObjectState::load (esm);
|
||||
|
||||
mInventory.load (esm);
|
||||
}
|
||||
|
||||
void ESM::ContainerState::save (ESMWriter &esm, bool inInventory) const
|
||||
{
|
||||
ObjectState::save (esm, inInventory);
|
||||
|
||||
mInventory.save (esm);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef OPENMW_ESM_CONTAINERSTATE_H
|
||||
#define OPENMW_ESM_CONTAINERSTATE_H
|
||||
|
||||
#include "objectstate.hpp"
|
||||
#include "inventorystate.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
// format 0, saved games only
|
||||
|
||||
struct ContainerState : public ObjectState
|
||||
{
|
||||
InventoryState mInventory;
|
||||
|
||||
virtual void load (ESMReader &esm);
|
||||
virtual void save (ESMWriter &esm, bool inInventory = false) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,60 @@
|
||||
|
||||
#include "inventorystate.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
void read (ESM::ESMReader &esm, ESM::ObjectState& state, int& slot)
|
||||
{
|
||||
slot = -1;
|
||||
esm.getHNOT (slot, "SLOT");
|
||||
|
||||
state.load (esm);
|
||||
}
|
||||
|
||||
void write (ESM::ESMWriter &esm, const ESM::ObjectState& state, unsigned int type, int slot)
|
||||
{
|
||||
esm.writeHNT ("IOBJ", type);
|
||||
|
||||
if (slot!=-1)
|
||||
esm.writeHNT ("SLOT", slot);
|
||||
|
||||
state.save (esm, true);
|
||||
}
|
||||
}
|
||||
|
||||
void ESM::InventoryState::load (ESMReader &esm)
|
||||
{
|
||||
while (esm.isNextSub ("IOBJ"))
|
||||
{
|
||||
unsigned int id = 0;
|
||||
esm.getHT (id);
|
||||
|
||||
if (id==ESM::REC_LIGH)
|
||||
{
|
||||
LightState state;
|
||||
int slot;
|
||||
read (esm, state, slot);
|
||||
mLights.push_back (std::make_pair (state, slot));
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectState state;
|
||||
int slot;
|
||||
read (esm, state, slot);
|
||||
mItems.push_back (std::make_pair (state, std::make_pair (id, slot)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ESM::InventoryState::save (ESMWriter &esm) const
|
||||
{
|
||||
for (std::vector<std::pair<ObjectState, std::pair<unsigned int, int> > >::const_iterator iter (mItems.begin()); iter!=mItems.end(); ++iter)
|
||||
write (esm, iter->first, iter->second.first, iter->second.second);
|
||||
|
||||
for (std::vector<std::pair<LightState, int> >::const_iterator iter (mLights.begin());
|
||||
iter!=mLights.end(); ++iter)
|
||||
write (esm, iter->first, ESM::REC_LIGH, iter->second);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#ifndef OPENMW_ESM_INVENTORYSTATE_H
|
||||
#define OPENMW_ESM_INVENTORYSTATE_H
|
||||
|
||||
#include "objectstate.hpp"
|
||||
#include "lightstate.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
// format 0, saved games only
|
||||
|
||||
/// \brief State for inventories and containers
|
||||
struct InventoryState
|
||||
{
|
||||
// anything but lights (type, slot)
|
||||
std::vector<std::pair<ObjectState, std::pair<unsigned int, int> > > mItems;
|
||||
|
||||
// lights (slot)
|
||||
std::vector<std::pair<LightState, int> > mLights;
|
||||
|
||||
virtual void load (ESMReader &esm);
|
||||
virtual void save (ESMWriter &esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue