Commit 5b04c10e authored by Marc Zinnschlag's avatar Marc Zinnschlag

added creature/NPC state to saved games (only container/inventory for now)

parent d2ec3ffd
......@@ -2,6 +2,7 @@
#include "creature.hpp"
#include <components/esm/loadcrea.hpp>
#include <components/esm/creaturestate.hpp>
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/magiceffects.hpp"
......@@ -613,6 +614,28 @@ namespace MWClass
return 0;
}
void Creature::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const
{
const ESM::CreatureState& state2 = dynamic_cast<const ESM::CreatureState&> (state);
ensureCustomData (ptr);
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore.
readState (state2.mInventory);
}
void Creature::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
const
{
ESM::CreatureState& state2 = dynamic_cast<ESM::CreatureState&> (state);
ensureCustomData (ptr);
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore.
writeState (state2.mInventory);
}
const ESM::GameSetting* Creature::fMinWalkSpeedCreature;
const ESM::GameSetting* Creature::fMaxWalkSpeedCreature;
const ESM::GameSetting *Creature::fEncumberedMoveEffect;
......
......@@ -84,7 +84,7 @@ namespace MWClass
virtual bool isEssential (const MWWorld::Ptr& ptr) const;
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
virtual int getServices (const MWWorld::Ptr& actor) const;
virtual bool isPersistent (const MWWorld::Ptr& ptr) const;
......@@ -118,6 +118,14 @@ namespace MWClass
/// Get a blood texture suitable for \a ptr (see Blood Texture 0-2 in Morrowind.ini)
virtual int getBloodTexture (const MWWorld::Ptr& ptr) const;
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const;
///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
const;
///< Write additional state from \a ptr into \a state.
};
}
......
......@@ -7,6 +7,7 @@
#include <components/esm/loadmgef.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/esm/npcstate.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
......@@ -514,7 +515,7 @@ namespace MWClass
weapon.getCellRef().mCharge = weapmaxhealth;
damage *= float(weapon.getCellRef().mCharge) / weapmaxhealth;
}
if (!MWBase::Environment::get().getWorld()->getGodModeState())
weapon.getCellRef().mCharge -= std::min(std::max(1,
(int)(damage * gmst.find("fWeaponDamageMult")->getFloat())), weapon.getCellRef().mCharge);
......@@ -964,7 +965,7 @@ namespace MWClass
return ref->mBase->mFlags & ESM::NPC::Essential;
}
void Npc::registerSelf()
{
boost::shared_ptr<Class> instance (new Npc);
......@@ -1233,6 +1234,28 @@ namespace MWClass
return 0;
}
void Npc::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const
{
const ESM::NpcState& state2 = dynamic_cast<const ESM::NpcState&> (state);
ensureCustomData (ptr);
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore.
readState (state2.mInventory);
}
void Npc::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
const
{
ESM::NpcState& state2 = dynamic_cast<ESM::NpcState&> (state);
ensureCustomData (ptr);
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore.
writeState (state2.mInventory);
}
const ESM::GameSetting *Npc::fMinWalkSpeed;
const ESM::GameSetting *Npc::fMaxWalkSpeed;
const ESM::GameSetting *Npc::fEncumberedMoveEffect;
......
......@@ -131,7 +131,7 @@ namespace MWClass
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
virtual int getServices (const MWWorld::Ptr& actor) const;
virtual bool isPersistent (const MWWorld::Ptr& ptr) const;
virtual std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const;
......@@ -152,6 +152,14 @@ namespace MWClass
virtual bool isNpc() const {
return true;
}
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const;
///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
const;
///< Write additional state from \a ptr into \a state.
};
}
......
......@@ -8,6 +8,8 @@
#include <components/esm/objectstate.hpp>
#include <components/esm/lightstate.hpp>
#include <components/esm/containerstate.hpp>
#include <components/esm/npcstate.hpp>
#include <components/esm/creaturestate.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
......@@ -328,7 +330,7 @@ namespace MWWorld
writeReferenceCollection<ESM::ObjectState> (writer, mBooks);
writeReferenceCollection<ESM::ObjectState> (writer, mClothes);
writeReferenceCollection<ESM::ContainerState> (writer, mContainers);
writeReferenceCollection<ESM::ObjectState> (writer, mCreatures);
writeReferenceCollection<ESM::CreatureState> (writer, mCreatures);
writeReferenceCollection<ESM::ObjectState> (writer, mDoors);
writeReferenceCollection<ESM::ObjectState> (writer, mIngreds);
writeReferenceCollection<ESM::ObjectState> (writer, mCreatureLists);
......@@ -336,7 +338,7 @@ namespace MWWorld
writeReferenceCollection<ESM::LightState> (writer, mLights);
writeReferenceCollection<ESM::ObjectState> (writer, mLockpicks);
writeReferenceCollection<ESM::ObjectState> (writer, mMiscItems);
writeReferenceCollection<ESM::ObjectState> (writer, mNpcs);
writeReferenceCollection<ESM::NpcState> (writer, mNpcs);
writeReferenceCollection<ESM::ObjectState> (writer, mProbes);
writeReferenceCollection<ESM::ObjectState> (writer, mRepairs);
writeReferenceCollection<ESM::ObjectState> (writer, mStatics);
......@@ -390,7 +392,7 @@ namespace MWWorld
case ESM::REC_CREA:
readReferenceCollection<ESM::ObjectState> (reader, mCreatures, contentFileMap);
readReferenceCollection<ESM::CreatureState> (reader, mCreatures, contentFileMap);
break;
case ESM::REC_DOOR:
......@@ -430,7 +432,7 @@ namespace MWWorld
case ESM::REC_NPC_:
readReferenceCollection<ESM::ObjectState> (reader, mNpcs, contentFileMap);
readReferenceCollection<ESM::NpcState> (reader, mNpcs, contentFileMap);
break;
case ESM::REC_PROB:
......
......@@ -130,7 +130,7 @@ namespace MWWorld
void fill (const ESM::InventoryList& items, const std::string& owner, const std::string& faction, const MWWorld::ESMStore& store);
///< Insert items into *this.
void clear();
virtual void clear();
///< Empty container.
float getWeight() const;
......
......@@ -40,7 +40,7 @@ add_component_dir (esm
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate npcstate creaturestate
)
add_component_dir (misc
......
#include "creaturestate.hpp"
void ESM::CreatureState::load (ESMReader &esm)
{
ObjectState::load (esm);
mInventory.load (esm);
}
void ESM::CreatureState::save (ESMWriter &esm, bool inInventory) const
{
ObjectState::save (esm, inInventory);
mInventory.save (esm);
}
\ No newline at end of file
#ifndef OPENMW_ESM_CREATURESTATE_H
#define OPENMW_ESM_CREATURESTATE_H
#include "objectstate.hpp"
#include "inventorystate.hpp"
namespace ESM
{
// format 0, saved games only
struct CreatureState : public ObjectState
{
InventoryState mInventory;
virtual void load (ESMReader &esm);
virtual void save (ESMWriter &esm, bool inInventory = false) const;
};
}
#endif
#include "npcstate.hpp"
void ESM::NpcState::load (ESMReader &esm)
{
ObjectState::load (esm);
mInventory.load (esm);
}
void ESM::NpcState::save (ESMWriter &esm, bool inInventory) const
{
ObjectState::save (esm, inInventory);
mInventory.save (esm);
}
\ No newline at end of file
#ifndef OPENMW_ESM_NPCSTATE_H
#define OPENMW_ESM_NPCSTATE_H
#include "objectstate.hpp"
#include "inventorystate.hpp"
namespace ESM
{
// format 0, saved games only
struct NpcState : public ObjectState
{
InventoryState mInventory;
virtual void load (ESMReader &esm);
virtual void save (ESMWriter &esm, bool inInventory = false) const;
};
}
#endif
......@@ -3,7 +3,7 @@
#include <string>
#include "objectstate.hpp"
#include "npcstate.hpp"
#include "cellid.hpp"
#include "defs.hpp"
......@@ -16,7 +16,7 @@ namespace ESM
struct Player
{
ObjectState mObject;
NpcState mObject;
CellId mCellId;
float mLastKnownExteriorPosition[3];
unsigned char mHasMark;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment