diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index 9d88dd73ef2..fc09e8ab097 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -25,7 +25,6 @@ #include "common/md5.h" -#include "common/events.h" #include "common/file.h" #include "common/savefile.h" #include "common/config-manager.h" @@ -61,9 +60,6 @@ void AgiEngine::processEvents() { while (_eventMan->pollEvent(event)) { switch (event.type) { - case Common::EVENT_QUIT: - _game.quitProgNow = true; - break; case Common::EVENT_PREDICTIVE_DIALOG: if (_predictiveDialogRunning) break; @@ -738,6 +734,8 @@ void AgiEngine::initialize() { _gfx->initVideo(); _sound->initSound(); + _lastSaveTime = 0; + _timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, NULL); _game.ver = -1; /* Don't display the conf file warning */ @@ -809,7 +807,17 @@ int AgiEngine::go() { runGame(); - return 0; + return _eventMan->shouldRTL(); +} + +void AgiEngine::syncSoundSettings() { + int soundVolumeMusic = ConfMan.getInt("music_volume"); + int soundVolumeSFX = ConfMan.getInt("music_volume"); + int soundVolumeSpeech = ConfMan.getInt("music_volume"); + + _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSFX); + _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech); } } // End of namespace Agi diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 9240d562af2..ff2b05ace1d 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -530,7 +530,6 @@ struct AgiGame { /* internal flags */ int playerControl; /**< player is in control */ - int quitProgNow; /**< quit now */ int statusLine; /**< status line on/off */ int clockEnabled; /**< clock is on/off */ int exitAllLogics; /**< break cycle after new.room */ @@ -747,6 +746,8 @@ protected: int go(); void initialize(); + uint32 _lastSaveTime; + public: AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc); virtual ~AgiEngine(); @@ -754,6 +755,8 @@ public: return _gameId; } + virtual void syncSoundSettings(); + private: int _keyQueue[KEY_QUEUE_SIZE]; diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp index e0babdf9262..52c2ed8a784 100644 --- a/engines/agi/cycle.cpp +++ b/engines/agi/cycle.cpp @@ -24,7 +24,6 @@ */ - #include "agi/agi.h" #include "agi/sprite.h" #include "agi/graphics.h" @@ -116,7 +115,7 @@ void AgiEngine::interpretCycle() { oldSound = getflag(fSoundOn); _game.exitAllLogics = false; - while (runLogic(0) == 0 && !_game.quitProgNow) { + while (runLogic(0) == 0 && !quit()) { _game.vars[vWordNotFound] = 0; _game.vars[vBorderTouchObj] = 0; _game.vars[vBorderCode] = 0; @@ -314,7 +313,6 @@ int AgiEngine::playGame() { setvar(vTimeDelay, 2); /* "normal" speed */ _game.gfxMode = true; - _game.quitProgNow = false; _game.clockEnabled = true; _game.lineUserInput = 22; @@ -354,10 +352,14 @@ int AgiEngine::playGame() { _game.vars[vKey] = 0; } - if (_game.quitProgNow == 0xff) + if (quit() == 0xff) ec = errRestartGame; - } while (_game.quitProgNow == 0); + if (shouldPerformAutoSave(_lastSaveTime)) { + saveGame(getSavegameFilename(0), "Autosave"); + } + + } while (quit() == 0); _sound->stopSound(); diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index cd6942f9c0b..6b655262263 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -2122,11 +2122,22 @@ public: return "Sierra AGI Engine (C) Sierra On-Line Software"; } + virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const; - + virtual SaveStateList listSaves(const char *target) const; + const Common::ADGameDescription *fallbackDetect(const FSList *fslist) const; }; +bool AgiMetaEngine::hasFeature(MetaEngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsListSaves) || + (f == kSupportsDirectLoad) || + (f == kSupportsDeleteSave); +} + + bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const { const Agi::AGIGameDescription *gd = (const Agi::AGIGameDescription *)desc; bool res = true; @@ -2147,6 +2158,37 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common: return res; } +SaveStateList AgiMetaEngine::listSaves(const char *target) const { + const uint32 AGIflag = MKID_BE('AGI:'); + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringList filenames; + char saveDesc[31]; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + uint32 type = in->readUint32BE(); + if (type == AGIflag) + in->read(saveDesc, 31); + saveList.push_back(SaveStateDescriptor(slotNum, Common::String(saveDesc), *file)); + delete in; + } + } + } + + return saveList; +} + const Common::ADGameDescription *AgiMetaEngine::fallbackDetect(const FSList *fslist) const { typedef Common::HashMap IntMap; IntMap allFiles; diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp index dcf7d838099..9f1255a43a8 100644 --- a/engines/agi/loader_v3.cpp +++ b/engines/agi/loader_v3.cpp @@ -230,8 +230,8 @@ uint8 *AgiLoader_v3::loadVolRes(AgiDir *agid) { debugC(3, kDebugLevelResources, "offset = %d", agid->offset); debugC(3, kDebugLevelResources, "x = %x %x", x[0], x[1]); error("ACK! BAD RESOURCE"); - - g_system->quit(); + + _vm->quitGame(); } agid->len = READ_LE_UINT16((uint8 *) x + 3); /* uncompressed size */ diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp index 7ecedfbc8c7..758bff0cb66 100644 --- a/engines/agi/op_cmd.cpp +++ b/engines/agi/op_cmd.cpp @@ -1213,11 +1213,11 @@ cmd(quit) { g_sound->stopSound(); if (p0) { - game.quitProgNow = true; + g_agi->quitGame(); } else { if (g_agi->selectionBox (" Quit the game, or continue? \n\n\n", buttons) == 0) { - game.quitProgNow = true; + g_agi->quitGame(); } } } @@ -1231,7 +1231,7 @@ cmd(restart_game) { g_agi->selectionBox(" Restart game, or continue? \n\n\n", buttons); if (sel == 0) { - game.quitProgNow = 0xff; + g_agi->quitGame(); g_agi->setflag(fRestartGame, true); g_agi->_menu->enableAll(); } @@ -1739,7 +1739,7 @@ int AgiEngine::runLogic(int n) { curLogic->cIP = curLogic->sIP; timerHack = 0; - while (ip < _game.logics[n].size && !_game.quitProgNow) { + while (ip < _game.logics[n].size && !quit()) { if (_debug.enabled) { if (_debug.steps > 0) { if (_debug.logic0 || n) { diff --git a/engines/agi/op_test.cpp b/engines/agi/op_test.cpp index 7ba3e625bf2..393057ed9c1 100644 --- a/engines/agi/op_test.cpp +++ b/engines/agi/op_test.cpp @@ -24,7 +24,6 @@ */ - #include "agi/agi.h" #include "agi/keyboard.h" #include "agi/opcodes.h" @@ -232,7 +231,7 @@ int AgiEngine::testIfCode(int lognum) { uint8 p[16] = { 0 }; bool end_test = false; - while (retval && !game.quitProgNow && !end_test) { + while (retval && !quit() && !end_test) { if (_debug.enabled && (_debug.logic0 || lognum)) debugConsole(lognum, lTEST_MODE, NULL); diff --git a/engines/agi/preagi.cpp b/engines/agi/preagi.cpp index f2301e012a0..f391cd974a5 100644 --- a/engines/agi/preagi.cpp +++ b/engines/agi/preagi.cpp @@ -23,7 +23,6 @@ * */ -#include "common/events.h" #include "common/file.h" #include "common/savefile.h" #include "common/config-manager.h" @@ -228,7 +227,7 @@ FIXME (Fingolfin asks): Why are Mickey, Winnie and Troll standalone classes error("Unknown preagi engine"); break; } - return 0; + return _eventMan->shouldRTL(); } } // End of namespace Agi diff --git a/engines/agi/preagi_common.cpp b/engines/agi/preagi_common.cpp index 5d99dfa7f91..3cd04351f78 100644 --- a/engines/agi/preagi_common.cpp +++ b/engines/agi/preagi_common.cpp @@ -23,8 +23,6 @@ * */ -#include "common/events.h" - #include "agi/preagi.h" #include "agi/font.h" #include "agi/graphics.h" @@ -122,11 +120,12 @@ void PreAgiEngine::printStrXOR(char *szMsg) { int PreAgiEngine::getSelection(SelectionTypes type) { Common::Event event; - for (;;) { + while (!quit()) { while (_eventMan->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _system->quit(); + return 0; case Common::EVENT_RBUTTONUP: return 0; case Common::EVENT_LBUTTONUP: diff --git a/engines/agi/preagi_mickey.cpp b/engines/agi/preagi_mickey.cpp index b9591d1f2d7..f643ab9cfce 100644 --- a/engines/agi/preagi_mickey.cpp +++ b/engines/agi/preagi_mickey.cpp @@ -23,7 +23,6 @@ * */ -#include "common/events.h" #include "common/savefile.h" #include "common/stream.h" @@ -343,11 +342,12 @@ bool Mickey::getMenuSelRow(MSA_MENU menu, int *sel0, int *sel1, int iRow) { drawMenu(menu, *sel0, *sel1); - for (;;) { + for(;;) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - exit(0); + return 0; case Common::EVENT_MOUSEMOVE: if (iRow < 2) { x = event.mouse.x / 8; @@ -640,8 +640,8 @@ void Mickey::playSound(ENUM_MSA_SOUND iSound) { if (iSound == IDI_MSA_SND_THEME) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->_system->quit(); case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: case Common::EVENT_KEYDOWN: @@ -1221,7 +1221,7 @@ void Mickey::gameOver() { } waitAnyKey(); - exit(0); + _vm->quitGame(); } void Mickey::flipSwitch() { @@ -2060,8 +2060,8 @@ void Mickey::waitAnyKey(bool anim) { for (;;) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->_system->quit(); case Common::EVENT_KEYDOWN: case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: @@ -2160,7 +2160,7 @@ void Mickey::run() { intro(); // Game loop - for (;;) { + while (!_vm->quit()) { drawRoom(); if (_game.fIntro) { diff --git a/engines/agi/preagi_troll.cpp b/engines/agi/preagi_troll.cpp index 7502c63c6cb..beff721fda6 100644 --- a/engines/agi/preagi_troll.cpp +++ b/engines/agi/preagi_troll.cpp @@ -30,8 +30,6 @@ #include "graphics/cursorman.h" -#include "common/events.h" - namespace Agi { Troll::Troll(PreAgiEngine* vm) : _vm(vm) { @@ -58,11 +56,12 @@ bool Troll::getMenuSel(const char *szMenu, int *iSel, int nSel) { drawMenu(szMenu, *iSel); - for (;;) { + while (!_vm->quit()) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->_system->quit(); + return 0; case Common::EVENT_MOUSEMOVE: y = event.mouse.y / 8; @@ -205,8 +204,8 @@ void Troll::waitAnyKeyIntro() { for (;;) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->_system->quit(); case Common::EVENT_LBUTTONUP: case Common::EVENT_KEYDOWN: return; @@ -269,7 +268,7 @@ void Troll::tutorial() { int iSel = 0; //char szTreasure[16] = {0}; - for (;;) { + while (!_vm->quit()) { _vm->clearScreen(0xFF); _vm->printStr(IDS_TRO_TUTORIAL_0); diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index 87d13bff3d5..de8839b7bc1 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -29,7 +29,6 @@ #include "graphics/cursorman.h" -#include "common/events.h" #include "common/savefile.h" #include "common/stream.h" @@ -797,12 +796,12 @@ void Winnie::getMenuSel(char *szMenu, int *iSel, int fCanSel[]) { // Show the mouse cursor for the menu CursorMan.showMouse(true); - for (;;) { + while (!_vm->quit()) { while (_vm->_system->getEventManager()->pollEvent(event)) { switch(event.type) { + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->_system->quit(); - break; + return; case Common::EVENT_MOUSEMOVE: x = event.mouse.x / 8; y = event.mouse.y / 8; @@ -1014,7 +1013,7 @@ phase2: if (parser(hdr.ofsDesc[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) goto phase1; } - for (;;) { + while (!_vm->quit()) { for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { switch(parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata)) { case IDI_WTP_PAR_GOTO: diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index db7bba13e49..0b308bb37b6 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -91,7 +91,7 @@ int AgiEngine::saveGame(const char *fileName, const char *description) { out->writeSint16BE((int16)_game.lognum); out->writeSint16BE((int16)_game.playerControl); - out->writeSint16BE((int16)_game.quitProgNow); + out->writeSint16BE((int16)quit()); out->writeSint16BE((int16)_game.statusLine); out->writeSint16BE((int16)_game.clockEnabled); out->writeSint16BE((int16)_game.exitAllLogics); @@ -214,6 +214,9 @@ int AgiEngine::saveGame(const char *fileName, const char *description) { delete out; debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Closed %s", fileName); + + _lastSaveTime = _system->getMillis(); + return result; } @@ -281,7 +284,8 @@ int AgiEngine::loadGame(const char *fileName, bool checkId) { _game.lognum = in->readSint16BE(); _game.playerControl = in->readSint16BE(); - _game.quitProgNow = in->readSint16BE(); + if (in->readSint16BE()) + quitGame(); _game.statusLine = in->readSint16BE(); _game.clockEnabled = in->readSint16BE(); _game.exitAllLogics = in->readSint16BE(); @@ -698,13 +702,18 @@ int AgiEngine::saveGameDialog() { sprintf(fileName, "%s", getSavegameFilename(slot)); - drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); - printText("Select a slot in which you wish to\nsave the game:", - 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); - slot = selectSlot(); - if (slot < 0) - return errOK; + do { + drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); + printText("Select a slot in which you wish to\nsave the game:", + 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); + slot = selectSlot(); + if (slot == 0) + messageBox("That slot is for Autosave only."); + else if (slot < 0) + return errOK; + } + while (slot == 0); drawWindow(hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp, GFX_HEIGHT - vp - 9 * CHAR_LINES);