Skip to content

Commit

Permalink
PEGASUS: Implement saving/restoring the in-game AI data
Browse files Browse the repository at this point in the history
AI data should now be restored properly after the space chase
  • Loading branch information
Matthew Hoops committed Apr 3, 2012
1 parent e72f2c3 commit d5341b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions engines/pegasus/ai/ai_area.cpp
Expand Up @@ -23,6 +23,8 @@
*
*/

#include "common/memstream.h"

#include "pegasus/cursor.h"
#include "pegasus/pegasus.h"
#include "pegasus/ai/ai_area.h"
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions engines/pegasus/pegasus.cpp
Expand Up @@ -90,6 +90,7 @@ PegasusEngine::PegasusEngine(OSystem *syst, const PegasusGameDescription *gamede
_idlerHead = 0;
_currentCD = 1;
_introTimer = 0;
_aiSaveStream = 0;
}

PegasusEngine::~PegasusEngine() {
Expand All @@ -101,6 +102,7 @@ PegasusEngine::~PegasusEngine() {
delete _neighborhood;
delete _rnd;
delete _introTimer;
delete _aiSaveStream;

// NOTE: This must be deleted last!
delete _gfx;
Expand Down
1 change: 1 addition & 0 deletions engines/pegasus/pegasus.h
Expand Up @@ -162,6 +162,7 @@ friend class InputHandler;
bool canSolve();
void prepareForAIHint(const Common::String &);
void cleanUpAfterAIHint(const Common::String &);
Common::SeekableReadStream *_aiSaveStream;

// Neighborhood
void jumpToNewEnvironment(const NeighborhoodID, const RoomID, const DirectionConstant);
Expand Down

0 comments on commit d5341b2

Please sign in to comment.