[Scummvm-git-logs] scummvm master -> 9f87526f937f934ebc16345536d8fad1b2193392
neuromancer
noreply at scummvm.org
Thu Mar 10 19:59:32 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9f87526f93 HYPNO: implemented basic saving and loading in wet
Commit: 9f87526f937f934ebc16345536d8fad1b2193392
https://github.com/scummvm/scummvm/commit/9f87526f937f934ebc16345536d8fad1b2193392
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-03-10T20:58:56+01:00
Commit Message:
HYPNO: implemented basic saving and loading in wet
Changed paths:
engines/hypno/hypno.h
engines/hypno/wet/arcade.cpp
engines/hypno/wet/hard.cpp
engines/hypno/wet/wet.cpp
diff --git a/engines/hypno/hypno.h b/engines/hypno/hypno.h
index 4945a40bc4d..40c9a95753a 100644
--- a/engines/hypno/hypno.h
+++ b/engines/hypno/hypno.h
@@ -319,6 +319,8 @@ public:
WetEngine(OSystem *syst, const ADGameDescription *gd);
Common::HashMap<int, const struct chapterEntry*> _chapterTable;
Common::Array<int> _ids;
+ int _lastLevel;
+ Common::String _name;
void loadAssets() override;
void loadAssetsDemoDisc();
@@ -339,6 +341,12 @@ public:
Common::String findNextLevel(const Common::String &level) override;
Common::String findNextLevel(const Transition *trans) override;
+ // Saves
+ Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
+ Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
+ bool loadGame(const Common::String &name);
+ void saveGame(int levelId);
+
// Arcade
void runBeforeArcade(ArcadeShooting *arc) override;
void runAfterArcade(ArcadeShooting *arc) override;
diff --git a/engines/hypno/wet/arcade.cpp b/engines/hypno/wet/arcade.cpp
index de48bd7e5ae..c8c94087bab 100644
--- a/engines/hypno/wet/arcade.cpp
+++ b/engines/hypno/wet/arcade.cpp
@@ -292,6 +292,7 @@ void WetEngine::runBeforeArcade(ArcadeShooting *arc) {
MVideo *video;
if (!isDemo()) {
+ saveGame(int(arc->id));
byte *palette;
Graphics::Surface *frame = decodeFrame("c_misc/zones.smk", (arc->id / 10 - 1) * 2, &palette);
loadPalette(palette, 0, 256);
diff --git a/engines/hypno/wet/hard.cpp b/engines/hypno/wet/hard.cpp
index c5d8baa02c4..34295e20d1e 100644
--- a/engines/hypno/wet/hard.cpp
+++ b/engines/hypno/wet/hard.cpp
@@ -22,6 +22,7 @@
#include "common/bitarray.h"
#include "common/events.h"
#include "common/config-manager.h"
+#include "common/savefile.h"
#include "hypno/hypno.h"
@@ -54,6 +55,11 @@ void WetEngine::runCheckLives(Code *code) {
}
void WetEngine::runLevelMenu(Code *code) {
+ if (_lastLevel == 0) {
+ _nextLevel = Common::String::format("c%d", _ids[0]);
+ return;
+ }
+
Common::Event event;
byte *palette;
Graphics::Surface *menu = decodeFrame("c_misc/menus.smk", 20, &palette);
@@ -61,11 +67,10 @@ void WetEngine::runLevelMenu(Code *code) {
byte black[3] = {0x00, 0x00, 0x00}; // Always red?
byte lime[3] = {0x00, 0xFF, 0x00}; // Always red?
byte green[3] = {0x2C, 0x82, 0x28}; // Always red?
- int lastLevel = 20;
int maxLevel = 20;
int currentLevel = 0;
for (int i = 0; i < maxLevel; i++)
- if (i < lastLevel)
+ if (i <= _lastLevel)
loadPalette((byte *) &green, 192+i, 1);
else
loadPalette((byte *) &black, 192+i, 1);
@@ -83,7 +88,7 @@ void WetEngine::runLevelMenu(Code *code) {
break;
case Common::EVENT_KEYDOWN:
- if (event.kbd.keycode == Common::KEYCODE_DOWN && currentLevel < lastLevel-1) {
+ if (event.kbd.keycode == Common::KEYCODE_DOWN && currentLevel < _lastLevel) {
playSound("sound/extra.raw", 1, 11025);
currentLevel++;
} else if (event.kbd.keycode == Common::KEYCODE_UP && currentLevel > 0) {
@@ -95,7 +100,7 @@ void WetEngine::runLevelMenu(Code *code) {
}
for (int i = 0; i < maxLevel; i++)
- if (i < lastLevel)
+ if (i <= _lastLevel)
loadPalette((byte *) &green, 192+i, 1);
else
loadPalette((byte *) &black, 192+i, 1);
@@ -123,8 +128,6 @@ void WetEngine::runMainMenu(Code *code) {
Graphics::Surface *menu = decodeFrame("c_misc/menus.smk", 16, &palette);
Graphics::Surface *overlay = decodeFrame("c_misc/menus.smk", 18, nullptr);
loadPalette(palette, 0, 256);
- Common::String _name = "";
-
Common::Rect subName(21, 10, 159, 24);
drawImage(*menu, 0, 0, false);
@@ -168,6 +171,20 @@ void WetEngine::runMainMenu(Code *code) {
g_system->delayMillis(10);
}
+ if (_name == "COOLCOLE") {
+ _lastLevel = 19;
+ playSound("sound/extra.raw", 1);
+ } else
+ _lastLevel = 0;
+
+ _name.toLowercase();
+ bool found = loadGame(_name);
+
+ if (found)
+ return;
+
+ saveGame(_ids[_lastLevel]);
+
Common::Rect subDifficulty(20, 104, 233, 119);
Graphics::Surface surDifficulty = overlay->getSubArea(subDifficulty);
drawImage(*menu, 0, 0, false);
diff --git a/engines/hypno/wet/wet.cpp b/engines/hypno/wet/wet.cpp
index ac834a910ab..30de5b229fa 100644
--- a/engines/hypno/wet/wet.cpp
+++ b/engines/hypno/wet/wet.cpp
@@ -22,6 +22,7 @@
#include "common/bitarray.h"
#include "common/events.h"
#include "common/config-manager.h"
+#include "common/savefile.h"
#include "hypno/hypno.h"
@@ -55,6 +56,7 @@ WetEngine::WetEngine(OSystem *syst, const ADGameDescription *gd) : HypnoEngine(s
_screenW = 320;
_screenH = 200;
_lives = 2;
+ _lastLevel = 0;
_c40SegmentIdx = -1;
_c40lastTurn = -1;
@@ -448,6 +450,82 @@ void WetEngine::drawString(const Common::String &font, const Common::String &str
error("Invalid font: '%s'", font.c_str());
}
+void WetEngine::saveGame(int levelId) {
+ Common::SaveFileManager *saveManager = getSaveFileManager();
+ Common::String namedPattern = Common::String::format("%s-wet.*", _name.c_str());
+ Common::String allPattern = "*-wet.*";
+ Common::StringArray namedSaves = saveManager->listSavefiles(namedPattern);
+ Common::StringArray allSaves = saveManager->listSavefiles(allPattern);
+
+ if (namedSaves.size() == 0) {
+ namedSaves.push_back(Common::String::format("%s-wet.%03d", _name.c_str(), allSaves.size()));
+ } else if (namedSaves.size() > 1)
+ error("Found %d saves to write!", namedSaves.size());
+ // Find the correct level index to before saving
+ for (uint32 i = 0; i < _ids.size(); i++) {
+ if (levelId == _ids[i]) {
+ _lastLevel = i;
+ break;
+ }
+ }
+ debugC(1, kHypnoDebugMedia, "Saving in %s", namedSaves[0].c_str());
+ Common::OutSaveFile *outf = saveManager->openForSaving(namedSaves[0]);
+ saveGameStream(outf, false);
+ outf->finalize();
+ delete outf;
+}
+
+bool WetEngine::loadGame(const Common::String &name) {
+ Common::SaveFileManager *saveManager = getSaveFileManager();
+ Common::StringArray saves = saveManager->listSavefiles("*-wet.*");
+
+ for (uint32 i = 0; i < saves.size(); i++) {
+ Common::String filename = Common::String::format("%s-wet.%03d", name.c_str(), i);
+ if (saves[i] == filename) {
+ debugC(1, kHypnoDebugMedia, "Loading %s", filename.c_str());
+ Common::InSaveFile *inf = saveManager->openForLoading(filename);
+ loadGameStream(inf);
+
+ if (_lastLevel == 0)
+ _nextLevel = Common::String::format("c%d", _ids[0]);
+ else
+ _nextLevel = "<level_menu>";
+ return true;
+ }
+ }
+ debugC(1, kHypnoDebugMedia, "Failed to load %s", name.c_str());
+ return false;
+}
+
+Common::Error WetEngine::saveGameStream(Common::WriteStream *stream, bool isAutosave) {
+ if (isAutosave)
+ return Common::kNoError;
+
+ if (_lastLevel < 0 || _lastLevel >= 20)
+ error("Invalid last level!");
+
+ stream->writeString(_name);
+ stream->writeByte(0);
+
+ stream->writeString(_difficulty);
+ stream->writeByte(0);
+
+ stream->writeUint32LE(_lives);
+ stream->writeUint32LE(_score);
+
+ stream->writeUint32LE(_lastLevel);
+ return Common::kNoError;
+}
+
+Common::Error WetEngine::loadGameStream(Common::SeekableReadStream *stream) {
+ _name = stream->readString();
+ _difficulty = stream->readString();
+ _lives = stream->readUint32LE();
+ _score = stream->readUint32LE();
+ _lastLevel = stream->readUint32LE();
+ return Common::kNoError;
+}
+
Common::String WetEngine::findNextLevel(const Transition *trans) {
if (trans->nextLevel.empty())
error("Invalid transition!");
More information about the Scummvm-git-logs
mailing list