1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hpl1/hpl1.h"
#include "audio/mixer.h"
#include "common/config-manager.h"
#include "common/debug-channels.h"
#include "common/events.h"
#include "common/savefile.h"
#include "common/scummsys.h"
#include "common/system.h"
#include "engine/engine.h"
#include "engines/util.h"
#include "graphics/palette.h"
#include "hpl1/debug.h"
#include "hpl1/detection.h"
#include "hpl1/engine/system/String.h"
#include "hpl1/penumbra-overture/Init.h"
#include "hpl1/penumbra-overture/MainMenu.h"
#include "hpl1/penumbra-overture/SaveHandler.h"
namespace Hpl1 {
Hpl1Engine *g_engine;
Hpl1Engine::Hpl1Engine(OSystem *syst, const ADGameDescription *gameDesc)
: Engine(syst), _gameDescription(gameDesc), _randomSource("Hpl1") {
g_engine = this;
}
Hpl1Engine::~Hpl1Engine() {
delete _screen;
}
uint32 Hpl1Engine::getFeatures() const {
return _gameDescription->flags;
}
Common::String Hpl1Engine::getGameId() const {
return _gameDescription->gameId;
}
static Common::String getStartupSave(MetaEngine *meta, const char *target) {
if (ConfMan.hasKey("save_slot")) {
const int saveSlot = ConfMan.getInt("save_slot");
const SaveStateDescriptor saveInfo = meta->querySaveMetaInfos(target, saveSlot);
return saveInfo.getDescription();
}
return "";
}
Common::Error Hpl1Engine::run() {
_gameInit = new cInit(); // TODO: remove allocation
if (!_gameInit->Init(getStartupSave(getMetaEngine(), _targetName.c_str()).c_str())) {
delete _gameInit;
return Common::kUnknownError; // TODO: better errors
};
_gameInit->Run();
_gameInit->Exit();
delete _gameInit;
return Common::kNoError;
}
void Hpl1Engine::pauseEngineIntern(bool pause) {
_mixer->pauseAll(pause);
g_system->lockMouse(!pause);
// if a save is deleted from the global main menu,
// it would still appear on the game's menu
if (!pause)
_gameInit->mpMainMenu->UpdateWidgets();
}
static Common::String freeSaveSlot(const Engine *engine, const int maxSaves) {
for (int i = 1; i < maxSaves; ++i) {
const Common::String name = engine->getSaveStateName(i);
if (!g_system->getSavefileManager()->exists(name))
return name;
}
return "";
}
Common::String Hpl1Engine::createSaveFile(const Common::String &internalName) {
const Common::String freeSlot = freeSaveSlot(this, getMetaEngine()->getMaximumSaveSlot());
if (freeSlot == "")
warning("game out of save slots");
return freeSlot;
}
static Common::String findSaveFile(const SaveStateList &saves, const Common::String &internalName) {
for (auto &s : saves) {
if (s.getDescription() == internalName)
return g_engine->getSaveStateName(s.getSaveSlot());
}
logWarning(kDebugSaves | kDebugFilePath, "save file for save %s does not exist", internalName.c_str());
return "";
}
void Hpl1Engine::removeSaveFile(const Common::String &internalName) {
Common::String filename = findSaveFile(g_engine->getMetaEngine()->listSaves(_targetName.c_str()), internalName);
if (filename != "")
_saveFileMan->removeSavefile(filename);
}
Common::String Hpl1Engine::mapInternalSaveToFile(const Common::String &internalName) {
return findSaveFile(g_engine->getMetaEngine()->listSaves(_targetName.c_str()), internalName);
}
Common::StringArray Hpl1Engine::listInternalSaves(const Common::String &pattern) {
Common::StringArray internalSaves;
SaveStateList saves = g_engine->getMetaEngine()->listSaves(_targetName.c_str());
for (auto &save : saves) {
const Common::String saveDesc = save.getDescription();
if (saveDesc.matchString(pattern))
internalSaves.push_back(saveDesc);
}
return internalSaves;
}
Common::Error Hpl1Engine::loadGameState(int slot) {
SaveStateDescriptor a = getMetaEngine()->querySaveMetaInfos(_targetName.c_str(), slot);
_gameInit->mpMainMenu->SetActive(false);
_gameInit->mpSaveHandler->LoadGameFromFile(a.getDescription());
return Common::kNoError;
}
Common::Error Hpl1Engine::syncGame(Common::Serializer &s) {
// The Serializer has methods isLoading() and isSaving()
// if you need to specific steps; for example setting
// an array size after reading it's length, whereas
// for saving it would write the existing array's length
int dummy = 0;
s.syncAsUint32LE(dummy);
return Common::kNoError;
}
} // namespace Hpl1
|