From d5341b2fc7a43d63c38e72d671053d28de42e156 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 3 Apr 2012 10:32:32 -0400 Subject: PEGASUS: Implement saving/restoring the in-game AI data AI data should now be restored properly after the space chase --- engines/pegasus/ai/ai_area.cpp | 16 ++++++++++++++-- engines/pegasus/pegasus.cpp | 2 ++ engines/pegasus/pegasus.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/engines/pegasus/ai/ai_area.cpp b/engines/pegasus/ai/ai_area.cpp index 9eacb038bd..b9b5ce9a51 100755 --- a/engines/pegasus/ai/ai_area.cpp +++ b/engines/pegasus/ai/ai_area.cpp @@ -23,6 +23,8 @@ * */ +#include "common/memstream.h" + #include "pegasus/cursor.h" #include "pegasus/pegasus.h" #include "pegasus/ai/ai_area.h" @@ -72,11 +74,21 @@ AIArea::~AIArea() { // Save last state of AI rules... void AIArea::saveAIState() { - // TODO + PegasusEngine *vm = (PegasusEngine *)g_engine; + + delete vm->_aiSaveStream; + + Common::MemoryWriteStreamDynamic out; + writeAIRules(&out); + + vm->_aiSaveStream = new Common::MemoryReadStream(out.getData(), out.size(), DisposeAfterUse::YES); } void AIArea::restoreAIState() { - // TODO + PegasusEngine *vm = (PegasusEngine *)g_engine; + + if (vm->_aiSaveStream) + readAIRules(vm->_aiSaveStream); } void AIArea::writeAIRules(Common::WriteStream *stream) { diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp index a346af581a..46aea7328b 100644 --- a/engines/pegasus/pegasus.cpp +++ b/engines/pegasus/pegasus.cpp @@ -90,6 +90,7 @@ PegasusEngine::PegasusEngine(OSystem *syst, const PegasusGameDescription *gamede _idlerHead = 0; _currentCD = 1; _introTimer = 0; + _aiSaveStream = 0; } PegasusEngine::~PegasusEngine() { @@ -101,6 +102,7 @@ PegasusEngine::~PegasusEngine() { delete _neighborhood; delete _rnd; delete _introTimer; + delete _aiSaveStream; // NOTE: This must be deleted last! delete _gfx; diff --git a/engines/pegasus/pegasus.h b/engines/pegasus/pegasus.h index c6d4c80b76..349856d27b 100644 --- a/engines/pegasus/pegasus.h +++ b/engines/pegasus/pegasus.h @@ -162,6 +162,7 @@ public: bool canSolve(); void prepareForAIHint(const Common::String &); void cleanUpAfterAIHint(const Common::String &); + Common::SeekableReadStream *_aiSaveStream; // Neighborhood void jumpToNewEnvironment(const NeighborhoodID, const RoomID, const DirectionConstant); -- cgit v1.2.3