From 1fe7ca1d3868a701a2e53c08fbbeaac69df74dd0 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 29 Sep 2011 19:45:17 -0400 Subject: PEGASUS: Update save/load code a bit --- engines/pegasus/detection.cpp | 2 +- engines/pegasus/pegasus.cpp | 74 +++++++++++++++++++++++++++++++++++++------ engines/pegasus/pegasus.h | 4 +-- 3 files changed, 67 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/pegasus/detection.cpp b/engines/pegasus/detection.cpp index af651c8f22..fe797b4eee 100644 --- a/engines/pegasus/detection.cpp +++ b/engines/pegasus/detection.cpp @@ -77,7 +77,7 @@ static const PegasusGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformMacintosh, ADGF_MACRESFORK|ADGF_DEMO, - Common::GUIO_NONE + Common::GUIO_NOLAUNCHLOAD }, }, diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp index 9cb1bd250c..ac6946db67 100644 --- a/engines/pegasus/pegasus.cpp +++ b/engines/pegasus/pegasus.cpp @@ -326,7 +326,13 @@ void PegasusEngine::removeTimeBase(TimeBase *timeBase) { } bool PegasusEngine::loadFromStream(Common::ReadStream *stream) { - // TODO: Dispose currently running stuff (neighborhood, etc.) + // Dispose currently running stuff + useMenu(0); + useNeighborhood(0); + removeAllItemsFromInventory(); + removeAllItemsFromBiochips(); + _currentItemID = kNoItemID; + _currentBiochipID = kNoItemID; // Signature uint32 creator = stream->readUint32BE(); @@ -370,18 +376,48 @@ bool PegasusEngine::loadFromStream(Common::ReadStream *stream) { // Death reason setEnergyDeathReason(stream->readByte()); - // TODO: This is as far as we can go right now + // TODO: This is as far as we can go right now (until I implement the mapping biochip and AI rules loading) return true; // Items g_allItems.readFromStream(stream); - // TODO: Player Inventory - // TODO: Player BioChips + // Inventory + uint32 itemCount = stream->readUint32BE(); + + if (itemCount > 0) { + for (uint32 i = 0; i < itemCount; i++) { + InventoryItem *inv = (InventoryItem *)g_allItems.findItemByID((tItemID)stream->readUint16BE()); + addItemToInventory(inv); + } + + g_interface->setCurrentInventoryItemID((tItemID)stream->readUint16BE()); + } + + // Biochips + uint32 biochipCount = stream->readUint32BE(); + + if (biochipCount > 0) { + for (uint32 i = 0; i < biochipCount; i++) { + BiochipItem *biochip = (BiochipItem *)g_allItems.findItemByID((tItemID)stream->readUint16BE()); + addItemToBiochips(biochip); + } + + g_interface->setCurrentBiochipID((tItemID)stream->readUint16BE()); + } + + // TODO: Disc check - // TODO: Jump to environment + + // Jump to environment + jumpToNewEnvironment(GameState.getCurrentNeighborhood(), GameState.getCurrentRoom(), GameState.getCurrentDirection()); + _shellNotification.setNotificationFlags(0, kNeedNewJumpFlag); + performJump(GameState.getCurrentNeighborhood()); + // TODO: AI rules + startNeighborhood(); + // Make a new continue point if this isn't already one if (saveType == kNormalSave) makeContinuePoint(); @@ -417,10 +453,30 @@ bool PegasusEngine::writeToStream(Common::WriteStream *stream, int saveType) { // Items g_allItems.writeToStream(stream); - // TODO: Player Inventory - // TODO: Player BioChips - // TODO: Jump to environment + // Inventory + uint32 itemCount = _items.getNumItems(); + stream->writeUint32BE(itemCount); + + if (itemCount > 0) { + for (uint32 i = 0; i < itemCount; i++) + stream->writeUint16BE(_items.getItemIDAt(i)); + + stream->writeUint16BE(g_interface->getCurrentInventoryItem()->getObjectID()); + } + + // Biochips + uint32 biochipCount = _biochips.getNumItems(); + stream->writeUint32BE(biochipCount); + + if (itemCount > 0) { + for (uint32 i = 0; i < biochipCount; i++) + stream->writeUint16BE(_biochips.getItemIDAt(i)); + + stream->writeUint16BE(g_interface->getCurrentBiochip()->getObjectID()); + } + // TODO: AI rules + return true; } @@ -440,8 +496,6 @@ void PegasusEngine::loadFromContinuePoint() { if (!loadFromStream(_continuePoint)) error("Failed loading continue point"); - - error("STUB: loadFromContinuePoint()"); } Common::Error PegasusEngine::loadGameState(int slot) { diff --git a/engines/pegasus/pegasus.h b/engines/pegasus/pegasus.h index 277f3bd687..6f2309a437 100644 --- a/engines/pegasus/pegasus.h +++ b/engines/pegasus/pegasus.h @@ -73,8 +73,8 @@ public: const PegasusGameDescription *_gameDescription; bool hasFeature(EngineFeature f) const; GUI::Debugger *getDebugger(); - bool canLoadGameStateCurrently() { return _loadAllowed; } - bool canSaveGameStateCurrently() { return _saveAllowed; } + bool canLoadGameStateCurrently() { return _loadAllowed && !isDemo(); } + bool canSaveGameStateCurrently() { return _saveAllowed && !isDemo(); } Common::Error loadGameState(int slot); Common::Error saveGameState(int slot, const Common::String &desc); -- cgit v1.2.3