[Scummvm-git-logs] scummvm master -> 2c34901c746d884fbbb9137252bdff828db35b29

dreammaster noreply at scummvm.org
Sat Jun 7 01:20:16 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
2c34901c74 ULTIMA: Split up the UltimaEngine class


Commit: 2c34901c746d884fbbb9137252bdff828db35b29
    https://github.com/scummvm/scummvm/commit/2c34901c746d884fbbb9137252bdff828db35b29
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-06-06T18:20:11-07:00

Commit Message:
ULTIMA: Split up the UltimaEngine class

Changed paths:
  R engines/ultima/shared/engine/ultima.cpp
  R engines/ultima/shared/engine/ultima.h
    engines/ultima/module.mk
    engines/ultima/nuvie/files/nuvie_io_file.cpp
    engines/ultima/nuvie/nuvie.cpp
    engines/ultima/nuvie/nuvie.h
    engines/ultima/nuvie/save/save_game.cpp
    engines/ultima/shared/early/game_base.h
    engines/ultima/shared/early/ultima_early.cpp
    engines/ultima/shared/early/ultima_early.h
    engines/ultima/shared/engine/events.cpp
    engines/ultima/shared/engine/input_handler.cpp
    engines/ultima/ultima1/game.cpp
    engines/ultima/ultima1/game.h
    engines/ultima/ultima4/ultima4.cpp
    engines/ultima/ultima4/ultima4.h


diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 8af5db7605d..0b89e1de875 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -4,7 +4,6 @@ MODULE_OBJS := \
 	metaengine.o \
 	shared/conf/xml_node.o \
 	shared/conf/xml_tree.o \
-	shared/engine/ultima.o \
 	shared/engine/data_archive.o \
 	shared/engine/events.o \
 	shared/std/string.o
diff --git a/engines/ultima/nuvie/files/nuvie_io_file.cpp b/engines/ultima/nuvie/files/nuvie_io_file.cpp
index b66b55596b6..14c18731c76 100644
--- a/engines/ultima/nuvie/files/nuvie_io_file.cpp
+++ b/engines/ultima/nuvie/files/nuvie_io_file.cpp
@@ -21,10 +21,10 @@
 
 #include "ultima/nuvie/core/nuvie_defs.h"
 #include "ultima/nuvie/files/nuvie_io_file.h"
-#include "ultima/shared/engine/ultima.h"
 #include "engines/metaengine.h"
 #include "common/system.h"
 #include "common/config-manager.h"
+#include "engines/engine.h"
 
 namespace Ultima {
 namespace Nuvie {
@@ -186,7 +186,7 @@ void NuvieIOFileWrite::close() {
 	} else if (_saveFile) {
 		// Writing using savefile interface, so flush out data
 		_saveFile->write(_saveFileData.getData(), _saveFileData.size());
-		g_engine->getMetaEngine()->appendExtendedSave(_saveFile, Shared::g_ultima->getTotalPlayTime(), _description, _isAutosave);
+		g_engine->getMetaEngine()->appendExtendedSave(_saveFile, g_engine->getTotalPlayTime(), _description, _isAutosave);
 
 		_saveFile->finalize();
 		delete _saveFile;
diff --git a/engines/ultima/nuvie/nuvie.cpp b/engines/ultima/nuvie/nuvie.cpp
index e7a71276e5c..68f4760a8a0 100644
--- a/engines/ultima/nuvie/nuvie.cpp
+++ b/engines/ultima/nuvie/nuvie.cpp
@@ -36,6 +36,7 @@
 #include "ultima/nuvie/gui/widgets/map_window.h"
 #include "ultima/nuvie/save/save_game.h"
 #include "ultima/nuvie/gui/widgets/msg_scroll.h"
+#include "ultima/shared/engine/data_archive.h"
 #include "common/config-manager.h"
 #include "common/translation.h"
 #include "common/compression/unzip.h"
@@ -46,9 +47,9 @@ namespace Nuvie {
 NuvieEngine *g_engine;
 
 NuvieEngine::NuvieEngine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
-		Ultima::Shared::UltimaEngine(syst, gameDesc),  _config(nullptr), _savegame(nullptr),
+		Engine(syst), _gameDescription(gameDesc),  _config(nullptr), _savegame(nullptr),
 		_screen(nullptr), _script(nullptr), _game(nullptr), _soundManager(nullptr),
-		_events(nullptr) {
+		_events(nullptr), _randomSource("Nuvie") {
 	g_engine = this;
 }
 
@@ -70,14 +71,35 @@ bool NuvieEngine::isDataRequired(Common::Path &folder, int &majorVersion, int &m
 	return true;
 }
 
+GameId NuvieEngine::getGameId() const {
+	return _gameDescription->gameId;
+}
+
+bool NuvieEngine::isEnhanced() const {
+	return _gameDescription->features & GF_VGA_ENHANCED;
+}
 
 bool NuvieEngine::initialize() {
 	uint8 gameType;
 	bool playEnding = false;
 	bool showVirtueMsg = false;
 
-	if (!Ultima::Shared::UltimaEngine::initialize())
+	Common::Path folder;
+	int reqMajorVersion, reqMinorVersion;
+
+	// Call syncSoundSettings to get default volumes set
+	syncSoundSettings();
+
+	// Check if the game uses data from te ultima.dat archive
+	if (!isDataRequired(folder, reqMajorVersion, reqMinorVersion))
+		return true;
+
+	// Try and set up the data archive
+	Common::U32String errorMsg;
+	if (!Shared::UltimaDataArchive::load(folder, reqMajorVersion, reqMinorVersion, errorMsg)) {
+		GUIErrorMessage(errorMsg);
 		return false;
+	}
 
 	// Get which game to play
 	switch (getGameId()) {
@@ -177,6 +199,14 @@ Common::Error NuvieEngine::run() {
 	return Common::kNoError;
 }
 
+bool NuvieEngine::hasFeature(EngineFeature f) const {
+	return
+		(f == kSupportsReturnToLauncher) ||
+		(f == kSupportsLoadingDuringRuntime) ||
+		(f == kSupportsChangingOptionsDuringRuntime) ||
+		(f == kSupportsSavingDuringRuntime);
+}
+
 void NuvieEngine::initConfig() {
 	_config = new Configuration();
 	_config->load(_gameDescription->gameId, isEnhanced());
@@ -226,14 +256,14 @@ bool NuvieEngine::checkDataDir() {
 }
 
 void NuvieEngine::syncSoundSettings() {
-	Ultima::Shared::UltimaEngine::syncSoundSettings();
+	Engine::syncSoundSettings();
 	if (!_soundManager)
 		return;
 
 	_soundManager->syncSoundSettings();
 }
 
-bool NuvieEngine::canLoadGameStateCurrently(bool isAutosave) {
+bool NuvieEngine::canLoadGameStateCurrently(Common::U32String *msg) {
 	if (_game == nullptr || !_game->isLoaded())
 		return false;
 
@@ -242,6 +272,7 @@ bool NuvieEngine::canLoadGameStateCurrently(bool isAutosave) {
 	Events *events = static_cast<Events *>(_events);
 	MapWindow *mapWindow = _game->get_map_window();
 
+	const bool isAutosave = false;
 	if (isAutosave) {
 		return events->get_mode() == MOVE_MODE;
 
@@ -263,14 +294,15 @@ bool NuvieEngine::canLoadGameStateCurrently(bool isAutosave) {
 	}
 }
 
-bool NuvieEngine::canSaveGameStateCurrently(bool isAutosave) {
-	if (!canLoadGameStateCurrently(isAutosave))
+bool NuvieEngine::canSaveGameStateCurrently(Common::U32String *msg) {
+	if (!canLoadGameStateCurrently(msg))
 		return false;
 
 	// Further checks against saving
 	Events *events = static_cast<Events *>(_events);
 	MsgScroll *scroll = _game->get_scroll();
 
+	const bool isAutosave = false;
 	if (_game->is_armageddon()) {
 		if (!isAutosave)
 			scroll->message("Can't save. You killed everyone!\n\n");
@@ -365,12 +397,12 @@ bool NuvieEngine::quickSave(int saveSlot, bool isLoad) {
 	MsgScroll *scroll = _game->get_scroll();
 
 	if (isLoad) {
-		if (!canLoadGameStateCurrently(false))
+		if (!canLoadGameStateCurrently())
 			return false;
 
 		text = Common::convertFromU32String(_("loading quick save %d"));
 	} else {
-		if (!canSaveGameStateCurrently(false))
+		if (!canSaveGameStateCurrently())
 			return false;
 
 		text = Common::convertFromU32String(_("saving quick save %d"));
diff --git a/engines/ultima/nuvie/nuvie.h b/engines/ultima/nuvie/nuvie.h
index ea074619d00..390eca9aae4 100644
--- a/engines/ultima/nuvie/nuvie.h
+++ b/engines/ultima/nuvie/nuvie.h
@@ -23,7 +23,6 @@
 #define NUVIE_NUVIE_H
 
 #include "ultima/shared/engine/events.h"
-#include "ultima/shared/engine/ultima.h"
 #include "ultima/shared/std/string.h"
 #include "ultima/nuvie/conf/configuration.h"
 #include "common/archive.h"
@@ -40,8 +39,9 @@ class Screen;
 class Script;
 class SoundManager;
 
-class NuvieEngine : public Ultima::Shared::UltimaEngine, public Ultima::Shared::EventsCallback {
+class NuvieEngine : public Engine, public Ultima::Shared::EventsCallback {
 private:
+	Common::RandomSource _randomSource;
 	Configuration *_config;
 	Screen *_screen;
 	Script *_script;
@@ -50,6 +50,8 @@ private:
 
 	SoundManager *_soundManager;
 	Ultima::Shared::EventsManager *_events;
+protected:
+	const UltimaGameDescription *_gameDescription;
 private:
 	void initConfig();
 	void assignGameConfigValues(uint8 game_type);
@@ -58,23 +60,44 @@ private:
 
 	bool playIntro();
 protected:
-	bool initialize() override;
+	bool initialize();
 
 	/**
 	 * Returns the data archive folder and version that's required
 	 */
-	bool isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion) override;
+	bool isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion);
 public:
 	const Std::string c_empty_string;
 public:
 	NuvieEngine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc);
 	~NuvieEngine() override;
 
+	/**
+	 * Returns the game type being played
+	 */
+	GameId getGameId() const;
+
+	/**
+	 * Returns true if the game is running an enhanced version
+	 * as compared to the original game
+	 */
+	bool isEnhanced() const;
+
 	/**
 	 * Play the game
 	 */
 	Common::Error run() override;
 
+	/**
+	 * Returns supported engine features
+	 */
+	bool hasFeature(EngineFeature f) const override;
+
+	/**
+	 * Get a random number
+	 */
+	uint getRandomNumber(uint maxVal) { return _randomSource.getRandomNumber(maxVal); }
+
 	/**
 	 * Synchronize sound settings
 	 */
@@ -82,15 +105,13 @@ public:
 
 	/**
 	 * Indicates whether a game state can be loaded.
-	 * @param isAutosave	Flags whether it's an autosave check
 	 */
-	bool canLoadGameStateCurrently(bool isAutosave) override;
+	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Indicates whether a game state can be saved.
-	 * @param isAutosave	Flags whether it's an autosave check
 	 */
-	bool canSaveGameStateCurrently(bool isAutosave) override;
+	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Load a game state.
diff --git a/engines/ultima/nuvie/save/save_game.cpp b/engines/ultima/nuvie/save/save_game.cpp
index 73c896473a7..a4fc57647a7 100644
--- a/engines/ultima/nuvie/save/save_game.cpp
+++ b/engines/ultima/nuvie/save/save_game.cpp
@@ -211,7 +211,7 @@ bool SaveGame::transfer_character() {
 	Common::FSNode folder = dialog.getResult();
 
 	// TODO: Load in character data from given folder and start new game
-	g_engine->GUIError(Common::String::format("Load party file from folder - %s", folder.getPath().toString(Common::Path::kNativeSeparator).c_str()));
+	GUIErrorMessage(Common::String::format("Load party file from folder - %s", folder.getPath().toString(Common::Path::kNativeSeparator).c_str()));
 
 	return false;
 }
diff --git a/engines/ultima/shared/early/game_base.h b/engines/ultima/shared/early/game_base.h
index f464b51596f..49f9e04a214 100644
--- a/engines/ultima/shared/early/game_base.h
+++ b/engines/ultima/shared/early/game_base.h
@@ -184,12 +184,12 @@ public:
 	/**
 	 * Returns true if a savegame can currently be loaded
 	 */
-	virtual bool canLoadGameStateCurrently() { return true; }
+	virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) { return true; }
 
 	/**
 	 * Returns true if the game can currently be saved
 	 */
-	virtual bool canSaveGameStateCurrently() { return false; }
+	virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) { return false; }
 
 	/**
 	 * Handles loading and saving games
diff --git a/engines/ultima/shared/early/ultima_early.cpp b/engines/ultima/shared/early/ultima_early.cpp
index fdc80542500..7c927387105 100644
--- a/engines/ultima/shared/early/ultima_early.cpp
+++ b/engines/ultima/shared/early/ultima_early.cpp
@@ -29,7 +29,6 @@
 #include "gui/saveload.h"
 #include "ultima/shared/early/ultima_early.h"
 #include "ultima/shared/early/game.h"
-#include "ultima/shared/engine/ultima.h"
 #include "ultima/shared/engine/events.h"
 #include "ultima/shared/engine/resources.h"
 #include "ultima/shared/core/mouse_cursor.h"
@@ -46,7 +45,7 @@ Shared::UltimaEarlyEngine *g_vm;
 namespace Shared {
 
 UltimaEarlyEngine::UltimaEarlyEngine(OSystem *syst, const UltimaGameDescription *gameDesc) :
-		UltimaEngine(syst, gameDesc), _game(nullptr) {
+		Engine(syst), _gameDescription(gameDesc), _game(nullptr), _randomSource("Ultima") {
 	g_vm = this;
 	_mouseCursor = nullptr;
 	_screen = nullptr;
@@ -60,8 +59,8 @@ UltimaEarlyEngine::~UltimaEarlyEngine() {
 }
 
 bool UltimaEarlyEngine::initialize() {
-	if (!UltimaEngine::initialize())
-		return false;
+	// Call syncSoundSettings to get default volumes set
+	syncSoundSettings();
 
 	// Set up the resources datafile
 	Resources *res = new Resources();
@@ -92,10 +91,6 @@ bool UltimaEarlyEngine::initialize() {
 	return true;
 }
 
-void UltimaEarlyEngine::deinitialize() {
-	UltimaEngine::deinitialize();
-}
-
 Common::Error UltimaEarlyEngine::run() {
 	// Initialize the engine and play the game
 	if (initialize())
@@ -106,6 +101,14 @@ Common::Error UltimaEarlyEngine::run() {
 	return Common::kNoError;
 }
 
+bool UltimaEarlyEngine::hasFeature(EngineFeature f) const {
+	return
+		(f == kSupportsReturnToLauncher) ||
+		(f == kSupportsLoadingDuringRuntime) ||
+		(f == kSupportsChangingOptionsDuringRuntime) ||
+		(f == kSupportsSavingDuringRuntime);
+}
+
 void UltimaEarlyEngine::playGame() {
 	while (!shouldQuit()) {
 		_events->pollEventsAndWait();
@@ -116,6 +119,14 @@ Graphics::Screen *UltimaEarlyEngine::getScreen() const {
 	return _screen;
 }
 
+GameId UltimaEarlyEngine::getGameId() const {
+	return _gameDescription->gameId;
+}
+
+bool UltimaEarlyEngine::isEnhanced() const {
+	return _gameDescription->features & GF_VGA_ENHANCED;
+}
+
 Game *UltimaEarlyEngine::createGame() const {
 	switch (getGameId()) {
 #ifndef RELEASE_BUILD
@@ -141,12 +152,12 @@ Common::Error UltimaEarlyEngine::saveGameStream(Common::WriteStream *stream, boo
 	return Common::kNoError;
 }
 
-bool UltimaEarlyEngine::canLoadGameStateCurrently(bool isAutosave) {
-	return _game->canLoadGameStateCurrently();
+bool UltimaEarlyEngine::canLoadGameStateCurrently(Common::U32String *msg) {
+	return _game->canLoadGameStateCurrently(msg);
 }
 
-bool UltimaEarlyEngine::canSaveGameStateCurrently(bool isAutosave) {
-	return _game->canSaveGameStateCurrently();
+bool UltimaEarlyEngine::canSaveGameStateCurrently(Common::U32String *msg) {
+	return _game->canSaveGameStateCurrently(msg);
 }
 
 } // End of namespace Shared
diff --git a/engines/ultima/shared/early/ultima_early.h b/engines/ultima/shared/early/ultima_early.h
index 316b7259882..62d5c9dcc0f 100644
--- a/engines/ultima/shared/early/ultima_early.h
+++ b/engines/ultima/shared/early/ultima_early.h
@@ -35,7 +35,6 @@
 #include "ultima/detection.h"
 
 #include "ultima/shared/engine/events.h"
-#include "ultima/shared/engine/ultima.h"
 
 namespace Ultima {
 
@@ -65,18 +64,22 @@ namespace Gfx {
 class Screen;
 }
 
-class UltimaEarlyEngine : public UltimaEngine, public EventsCallback {
+class UltimaEarlyEngine : public Engine, public EventsCallback {
 private:
 	/**
 	 * Initialize the engine
 	 */
-	bool initialize() override;
+	virtual bool initialize();
 
 	/**
 	 * Deinitialize the engine
 	 */
+	virtual void deinitialize() {}
 
-	void deinitialize() override;
+private:
+	Common::RandomSource _randomSource;
+protected:
+	const UltimaGameDescription *_gameDescription;
 public:
 	GameBase *_game;
 	MouseCursor *_mouseCursor;
@@ -91,26 +94,44 @@ public:
 	 */
 	Common::Error run() override;
 
+	/**
+	 * Returns supported engine features
+	 */
+	bool hasFeature(EngineFeature f) const override;
+
 	/**
 	 * Play the game
 	 */
 	void playGame();
 
+	/**
+	 * Get a random number
+	 */
+	uint getRandomNumber(uint maxVal) { return _randomSource.getRandomNumber(maxVal); }
+
+	/**
+	 * Gets a random number
+	 */
+	uint getRandomNumber(uint min, uint max) {
+		return min + _randomSource.getRandomNumber(max - min);
+	}
+
 	/**
 	 * Get the screen
 	 */
 	Graphics::Screen *getScreen() const override;
+
 	/**
 	 * Indicates whether a game state can be loaded.
 	 * @param isAutosave	Flags whether it's an autosave check
 	 */
-	bool canLoadGameStateCurrently(bool isAutosave) override;
+	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Indicates whether a game state can be saved.
 	 * @param isAutosave	Flags whether it's an autosave check
 	 */
-	bool canSaveGameStateCurrently(bool isAutosave) override;
+	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Load a savegame
@@ -122,6 +143,17 @@ public:
 	 */
 	Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
 
+	/**
+	 * Returns the game type being played
+	 */
+	GameId getGameId() const;
+
+	/**
+	 * Returns true if the game is running an enhanced version
+	 * as compared to the original game
+	 */
+	bool isEnhanced() const;
+
 	/*
 	 * Creates a new hierarchy for the game, that contains all the logic for playing that particular game.
 	 */
diff --git a/engines/ultima/shared/engine/events.cpp b/engines/ultima/shared/engine/events.cpp
index 2832218b96b..80bcc256d83 100644
--- a/engines/ultima/shared/engine/events.cpp
+++ b/engines/ultima/shared/engine/events.cpp
@@ -25,7 +25,6 @@
 #include "common/endian.h"
 #include "common/system.h"
 #include "engines/util.h"
-#include "ultima/shared/engine/ultima.h"
 #include "ultima/shared/engine/events.h"
 
 namespace Ultima {
diff --git a/engines/ultima/shared/engine/input_handler.cpp b/engines/ultima/shared/engine/input_handler.cpp
index f6ec3b56e8e..55d510af039 100644
--- a/engines/ultima/shared/engine/input_handler.cpp
+++ b/engines/ultima/shared/engine/input_handler.cpp
@@ -20,7 +20,6 @@
  */
 
 #include "ultima/shared/engine/input_handler.h"
-#include "ultima/shared/engine/ultima.h"
 #include "ultima/shared/engine/events.h"
 #include "ultima/shared/early/game_base.h"
 #include "ultima/shared/engine/messages.h"
diff --git a/engines/ultima/shared/engine/ultima.cpp b/engines/ultima/shared/engine/ultima.cpp
deleted file mode 100644
index 37f66002fc5..00000000000
--- a/engines/ultima/shared/engine/ultima.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/* 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 "ultima/ultima.h"
-#include "ultima/shared/engine/ultima.h"
-#include "ultima/shared/engine/data_archive.h"
-#include "ultima/shared/engine/events.h"
-#include "audio/mixer.h"
-#include "common/config-manager.h"
-#include "common/debug-channels.h"
-#include "common/file.h"
-#include "common/translation.h"
-
-namespace Ultima {
-namespace Shared {
-
-UltimaEngine * g_ultima;
-
-UltimaEngine::UltimaEngine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
-		Engine(syst), _gameDescription(gameDesc), _randomSource("Ultima"),
-		_dataArchive(nullptr) {
-	g_ultima = this;
-}
-
-UltimaEngine::~UltimaEngine() {
-	g_ultima = nullptr;
-}
-
-bool UltimaEngine::initialize() {
-	Common::Path folder;
-	int reqMajorVersion, reqMinorVersion;
-
-	// Call syncSoundSettings to get default volumes set
-	syncSoundSettings();
-
-	// Check if the game uses data from te ultima.dat archive
-	if (!isDataRequired(folder, reqMajorVersion, reqMinorVersion))
-		return true;
-
-	// Try and set up the data archive
-	Common::U32String errorMsg;
-	if (!UltimaDataArchive::load(folder, reqMajorVersion, reqMinorVersion, errorMsg)) {
-		GUIError(errorMsg);
-		return false;
-	}
-
-	return true;
-}
-
-void UltimaEngine::GUIError(const Common::U32String &msg) {
-	GUIErrorMessage(msg);
-}
-
-bool UltimaEngine::hasFeature(EngineFeature f) const {
-	return
-		(f == kSupportsReturnToLauncher) ||
-		(f == kSupportsLoadingDuringRuntime) ||
-		(f == kSupportsChangingOptionsDuringRuntime) ||
-		(f == kSupportsSavingDuringRuntime);
-}
-
-uint32 UltimaEngine::getFeatures() const {
-	return _gameDescription->features;
-}
-
-Common::Language UltimaEngine::getLanguage() const {
-	return _gameDescription->desc.language;
-}
-
-GameId UltimaEngine::getGameId() const {
-	return _gameDescription->gameId;
-}
-
-Common::FSNode UltimaEngine::getGameDirectory() const {
-	return Common::FSNode(ConfMan.getPath("path"));
-}
-
-} // End of namespace Shared
-} // End of namespace Ultima
diff --git a/engines/ultima/shared/engine/ultima.h b/engines/ultima/shared/engine/ultima.h
deleted file mode 100644
index 0287ebf11a5..00000000000
--- a/engines/ultima/shared/engine/ultima.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/* 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/>.
- *
- */
-
-#ifndef ULTIMA_SHARED_ENGINE_ULTIMA_H
-#define ULTIMA_SHARED_ENGINE_ULTIMA_H
-
-#include "ultima/detection.h"
-#include "common/archive.h"
-#include "common/random.h"
-#include "engines/engine.h"
-
-namespace Ultima {
-namespace Shared {
-
-class UltimaEngine : public Engine {
-private:
-	Common::RandomSource _randomSource;
-protected:
-	const UltimaGameDescription *_gameDescription;
-	Common::Archive *_dataArchive;
-protected:
-	/**
-	 * Initializes needed data for the engine
-	 */
-	virtual bool initialize();
-
-	/**
-	 * Deinitialize the engine
-	 */
-	virtual void deinitialize() {}
-
-	/**
-	 * Returns the data archive folder and version that's required
-	 */
-	virtual bool isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion) {
-		return false;
-	}
-
-public:
-	UltimaEngine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc);
-	~UltimaEngine() override;
-
-	/**
-	 * Returns supported engine features
-	 */
-	bool hasFeature(EngineFeature f) const override;
-
-	/**
-	 * Returns game features
-	 */
-	uint32 getFeatures() const;
-
-	/**
-	 * Return the game's language
-	 */
-	Common::Language getLanguage() const;
-
-	/**
-	 * Returns the game type being played
-	 */
-	GameId getGameId() const;
-
-	/**
-	 * Returns true if the game is running an enhanced version
-	 * as compared to the original game
-	 */
-	bool isEnhanced() const {
-		return getFeatures() & GF_VGA_ENHANCED;
-	}
-
-	/**
-	 * Show a message in a GUI dialog
-	 */
-	void GUIError(const Common::U32String &msg);
-
-	/**
-	 * Get a random number
-	 */
-	uint getRandomNumber(uint maxVal) { return _randomSource.getRandomNumber(maxVal); }
-
-	/**
-	 * Gets a random number
-	 */
-	uint getRandomNumber(uint min, uint max) {
-		return min + _randomSource.getRandomNumber(max - min);
-	}
-
-	/**
-	 * Returns a file system node for the game directory
-	 */
-	Common::FSNode getGameDirectory() const;
-
-	/**
-	 * Indicates whether a game state can be loaded.
-	 * @param isAutosave	Flags whether it's an autosave check
-	 */
-	virtual bool canLoadGameStateCurrently(bool isAutosave) = 0;
-
-	/**
-	 * Indicates whether a game state can be loaded.
-	 */
-	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
-		return canLoadGameStateCurrently(false);
-	}
-
-	/**
-	 * Indicates whether a game state can be saved.
-	 * @param isAutosave	Flags whether it's an autosave check
-	 */
-	virtual bool canSaveGameStateCurrently(bool isAutosave) = 0;
-
-	/**
-	 * Indicates whether a game state can be saved.
-	 */
-	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
-		return canSaveGameStateCurrently(false);
-	}
-};
-
-extern UltimaEngine *g_ultima;
-
-} // End of namespace Shared
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/ultima1/game.cpp b/engines/ultima/ultima1/game.cpp
index 49b260cbdef..15c329f0e90 100644
--- a/engines/ultima/ultima1/game.cpp
+++ b/engines/ultima/ultima1/game.cpp
@@ -89,7 +89,7 @@ void Ultima1Game::starting(bool isLoading) {
 	_gameView->setView(isLoading ? "Game" : "Title");
 }
 
-bool Ultima1Game::canSaveGameStateCurrently() {
+bool Ultima1Game::canSaveGameStateCurrently(Common::U32String *msg) {
 	return _currentView->getName() == "Game";
 }
 
diff --git a/engines/ultima/ultima1/game.h b/engines/ultima/ultima1/game.h
index e5be2e59bdd..886a23a328a 100644
--- a/engines/ultima/ultima1/game.h
+++ b/engines/ultima/ultima1/game.h
@@ -71,7 +71,7 @@ public:
 	/**
 	 * Returns true if the game can currently be saved
 	 */
-	bool canSaveGameStateCurrently() override;
+	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Give some treasure
diff --git a/engines/ultima/ultima4/ultima4.cpp b/engines/ultima/ultima4/ultima4.cpp
index 0145a4c4947..1ce65e421ab 100644
--- a/engines/ultima/ultima4/ultima4.cpp
+++ b/engines/ultima/ultima4/ultima4.cpp
@@ -46,6 +46,7 @@
 #include "ultima/ultima4/map/tileset.h"
 #include "ultima/ultima4/sound/music.h"
 #include "ultima/ultima4/sound/sound.h"
+#include "ultima/shared/engine/data_archive.h"
 #include "common/debug.h"
 #include "common/system.h"
 
@@ -55,7 +56,7 @@ namespace Ultima4 {
 Ultima4Engine *g_ultima;
 
 Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
-		Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _armors(nullptr),
+		Engine(syst), _gameDescription(gameDesc), _randomSource("Ultima4"), _saveSlotToLoad(-1), _armors(nullptr),
 		_codex(nullptr), _config(nullptr), _context(nullptr), _death(nullptr),
 		_dialogueLoaders(nullptr), _game(nullptr), _items(nullptr), _music(nullptr),
 		_mapLoaders(nullptr), _moongates(nullptr),
@@ -112,8 +113,22 @@ Ultima4Engine::~Ultima4Engine() {
 }
 
 bool Ultima4Engine::initialize() {
-	if (!Shared::UltimaEngine::initialize())
+	Common::Path folder;
+	int reqMajorVersion, reqMinorVersion;
+
+	// Call syncSoundSettings to get default volumes set
+	syncSoundSettings();
+
+	// Check if the game uses data from te ultima.dat archive
+	if (!isDataRequired(folder, reqMajorVersion, reqMinorVersion))
+		return true;
+
+	// Try and set up the data archive
+	Common::U32String errorMsg;
+	if (!Shared::UltimaDataArchive::load(folder, reqMajorVersion, reqMinorVersion, errorMsg)) {
+		GUIErrorMessage(errorMsg);
 		return false;
+	}
 
 	// Initialize the sub-systems
 	_config = new Config();
@@ -198,17 +213,17 @@ void Ultima4Engine::setToJourneyOnwards() {
 	assert(_saveSlotToLoad);
 }
 
-bool Ultima4Engine::canLoadGameStateCurrently(bool isAutosave) {
+bool Ultima4Engine::canLoadGameStateCurrently(Common::U32String *msg) {
 	return g_game != nullptr && g_context != nullptr && eventHandler->getController() == g_game;
 }
 
-bool Ultima4Engine::canSaveGameStateCurrently(bool isAutosave) {
+bool Ultima4Engine::canSaveGameStateCurrently(Common::U32String *msg) {
 	return g_game != nullptr && g_context != nullptr && eventHandler->getController() == g_game
 		&& (g_context->_location->_context & CTX_CAN_SAVE_GAME);
 }
 
 Common::Error Ultima4Engine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
-	Common::Error result = Shared::UltimaEngine::saveGameState(slot, desc, isAutosave);
+	Common::Error result = Engine::saveGameState(slot, desc, isAutosave);
 	if (!isAutosave && result.getCode() == Common::kNoError) {
 		ConfMan.setInt("last_save", slot);
 		ConfMan.flushToDisk();
@@ -217,6 +232,17 @@ Common::Error Ultima4Engine::saveGameState(int slot, const Common::String &desc,
 	return result;
 }
 
+bool Ultima4Engine::hasFeature(EngineFeature f) const {
+	return
+		(f == kSupportsReturnToLauncher) ||
+		(f == kSupportsLoadingDuringRuntime) ||
+		(f == kSupportsChangingOptionsDuringRuntime) ||
+		(f == kSupportsSavingDuringRuntime);
+}
+
+bool Ultima4Engine::isEnhanced() const {
+	return _gameDescription->features & GF_VGA_ENHANCED;
+}
 
 Common::Error Ultima4Engine::loadGameStream(Common::SeekableReadStream *stream) {
 	g_ultima->_saveGame->load(stream);
@@ -230,7 +256,7 @@ Common::Error Ultima4Engine::saveGameStream(Common::WriteStream *stream, bool is
 }
 
 void Ultima4Engine::quitGame() {
-	UltimaEngine::quitGame();
+	Engine::quitGame();
 
 	// Do an event poll to all the quit message to be processed
 	Common::Event e;
diff --git a/engines/ultima/ultima4/ultima4.h b/engines/ultima/ultima4/ultima4.h
index 9f0db6ca9d4..6a5b149663f 100644
--- a/engines/ultima/ultima4/ultima4.h
+++ b/engines/ultima/ultima4/ultima4.h
@@ -22,7 +22,9 @@
 #ifndef ULTIMA4_H
 #define ULTIMA4_H
 
-#include "ultima/shared/engine/ultima.h"
+#include "common/random.h"
+#include "engines/engine.h"
+#include "ultima/detection.h"
 #include "ultima/shared/std/containers.h"
 
 namespace Ultima {
@@ -50,8 +52,12 @@ class TileRules;
 class TileSets;
 class Weapons;
 
-class Ultima4Engine : public Shared::UltimaEngine {
+class Ultima4Engine : public Engine {
 private:
+	Common::RandomSource _randomSource;
+
+	const UltimaGameDescription *_gameDescription;
+
 	int _saveSlotToLoad;
 private:
 	void startup();
@@ -59,12 +65,12 @@ protected:
 	// Engine APIs
 	Common::Error run() override;
 
-	bool initialize() override;
+	bool initialize();
 
 	/**
 	 * Returns the data archive folder and version that's required
 	 */
-	bool isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion) override;
+	bool isDataRequired(Common::Path &folder, int &majorVersion, int &minorVersion);
 public:
 	Armors *_armors;
 	Codex *_codex;
@@ -92,15 +98,31 @@ public:
 	Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc);
 	~Ultima4Engine() override;
 
+	/**
+	 * Returns supported engine features
+	 */
+	bool hasFeature(EngineFeature f) const override;
+
+	/**
+	 * Returns true if the game is running an enhanced version
+	 * as compared to the original game
+	 */
+	bool isEnhanced() const;
+
+	/**
+	 * Get a random number
+	 */
+	uint getRandomNumber(uint maxVal) { return _randomSource.getRandomNumber(maxVal); }
+
 	/**
 	 * Returns true if a savegame can be loaded
 	 */
-	bool canLoadGameStateCurrently(bool isAutosave = false) override;
+	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Returns true if the game can be saved
 	 */
-	bool canSaveGameStateCurrently(bool isAutosave = false) override;
+	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
 
 	/**
 	 * Save a game state.




More information about the Scummvm-git-logs mailing list