Savegame: Store death counter (Fixes #1477)

pull/160/head
scrawl 11 years ago
parent 797134aa51
commit e458cf1df2

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <list>
#include <stdint.h>
namespace Ogre
{
@ -13,6 +14,9 @@ namespace Ogre
namespace ESM
{
struct Class;
class ESMReader;
class ESMWriter;
}
namespace MWWorld
@ -21,6 +25,11 @@ namespace MWWorld
class CellStore;
}
namespace Loading
{
class Listener;
}
namespace MWBase
{
/// \brief Interface for game mechanics manager (implemented in MWMechanics)
@ -174,6 +183,14 @@ namespace MWBase
virtual std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor) = 0;
virtual void playerLoaded() = 0;
virtual int countSavedGameRecords() const = 0;
virtual void write (ESM::ESMWriter& writer, Loading::Listener& listener) const = 0;
virtual void readRecord (ESM::ESMReader& reader, int32_t type) = 0;
virtual void clear() = 0;
};
}

@ -1181,4 +1181,36 @@ namespace MWMechanics
}
return list;
}
void Actors::write (ESM::ESMWriter& writer, Loading::Listener& listener) const
{
writer.startRecord(ESM::REC_DCOU);
for (std::map<std::string, int>::const_iterator it = mDeathCount.begin(); it != mDeathCount.end(); ++it)
{
writer.writeHNString("ID__", it->first);
writer.writeHNT ("COUN", it->second);
}
writer.endRecord(ESM::REC_DCOU);
listener.increaseProgress(1);
}
void Actors::readRecord (ESM::ESMReader& reader, int32_t type)
{
if (type == ESM::REC_DCOU)
{
while (reader.isNextSub("ID__"))
{
std::string id = reader.getHString();
int count;
reader.getHNT (count, "COUN");
mDeathCount[id] = count;
}
}
}
void Actors::clear()
{
mDeathCount.clear();
}
}

@ -112,6 +112,12 @@ namespace MWMechanics
/**ie AiCombat is active and the target is the actor **/
std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor);
void write (ESM::ESMWriter& writer, Loading::Listener& listener) const;
void readRecord (ESM::ESMReader& reader, int32_t type);
void clear(); // Clear death counter
private:
PtrControllerMap mActors;

@ -1050,4 +1050,24 @@ namespace MWMechanics
std::list<MWWorld::Ptr> MechanicsManager::getActorsFighting(const MWWorld::Ptr& actor) {
return mActors.getActorsFighting(actor);
}
int MechanicsManager::countSavedGameRecords() const
{
return 1; // Death counter
}
void MechanicsManager::write(ESM::ESMWriter &writer, Loading::Listener &listener) const
{
mActors.write(writer, listener);
}
void MechanicsManager::readRecord(ESM::ESMReader &reader, int32_t type)
{
mActors.readRecord(reader, type);
}
void MechanicsManager::clear()
{
mActors.clear();
}
}

@ -147,6 +147,14 @@ namespace MWMechanics
virtual bool isAIActive();
virtual void playerLoaded();
virtual int countSavedGameRecords() const;
virtual void write (ESM::ESMWriter& writer, Loading::Listener& listener) const;
virtual void readRecord (ESM::ESMReader& reader, int32_t type);
virtual void clear();
};
}

@ -45,6 +45,7 @@ void MWState::StateManager::cleanup (bool force)
MWBase::Environment::get().getWorld()->clear();
MWBase::Environment::get().getWindowManager()->clear();
MWBase::Environment::get().getInputManager()->clear();
MWBase::Environment::get().getMechanicsManager()->clear();
mState = State_NoGame;
mCharacterManager.clearCurrentCharacter();
@ -205,7 +206,8 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
+MWBase::Environment::get().getWorld()->countSavedGameRecords()
+MWBase::Environment::get().getScriptManager()->getGlobalScripts().countSavedGameRecords()
+MWBase::Environment::get().getDialogueManager()->countSavedGameRecords()
+MWBase::Environment::get().getWindowManager()->countSavedGameRecords();
+MWBase::Environment::get().getWindowManager()->countSavedGameRecords()
+MWBase::Environment::get().getMechanicsManager()->countSavedGameRecords();
writer.setRecordCount (recordCount);
writer.save (stream);
@ -226,6 +228,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
MWBase::Environment::get().getWorld()->write (writer, listener);
MWBase::Environment::get().getScriptManager()->getGlobalScripts().write (writer, listener);
MWBase::Environment::get().getWindowManager()->write(writer, listener);
MWBase::Environment::get().getMechanicsManager()->write(writer, listener);
// Ensure we have written the number of records that was estimated
if (writer.getRecordCount() != recordCount+1) // 1 extra for TES3 record
@ -357,6 +360,11 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val);
break;
case ESM::REC_DCOU:
MWBase::Environment::get().getMechanicsManager()->readRecord(reader, n.val);
break;
default:
// ignore invalid records

@ -111,6 +111,7 @@ enum RecNameInts
REC_ACTC = FourCC<'A','C','T','C'>::value,
REC_MPRJ = FourCC<'M','P','R','J'>::value,
REC_PROJ = FourCC<'P','R','O','J'>::value,
REC_DCOU = FourCC<'D','C','O','U'>::value,
// format 1
REC_FILT = 0x544C4946

Loading…
Cancel
Save