[Scummvm-git-logs] scummvm master -> 067035a80dcf8cf8d6426c8a6215cbb8194ac914

dreammaster paulfgilbert at gmail.com
Sun Apr 19 22:29:58 UTC 2020


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

Summary:
9e7495e738 ULTIMA4: Removing intermediate U4FILE class
95492d56f9 ULTIMA4: Removal of unneed zip stuff
3e6d971a11 ULTIMA4: Fix reading settings
2148dee1c7 ULTIMA4: Further file cleanup
9be8f03725 ULTIMA4: Fix opening of .ega files
993ec0aacc ULTIMA4: Have a separate original vs enhanced detection entry
067035a80d ULTIMA4: Cleanup and fixes for Initiate question sequence


Commit: 9e7495e7382eec6e6bcf668c0da6ac87fb9bfc44
    https://github.com/scummvm/scummvm/commit/9e7495e7382eec6e6bcf668c0da6ac87fb9bfc44
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Removing intermediate U4FILE class

Changed paths:
    engines/ultima/ultima4/controllers/intro_controller.cpp
    engines/ultima/ultima4/conversation/dialogueloader_hw.cpp
    engines/ultima/ultima4/conversation/dialogueloader_lb.cpp
    engines/ultima/ultima4/conversation/dialogueloader_tlk.cpp
    engines/ultima/ultima4/filesys/u4file.cpp
    engines/ultima/ultima4/filesys/u4file.h
    engines/ultima/ultima4/game/codex.cpp
    engines/ultima/ultima4/gfx/imageloader.h
    engines/ultima/ultima4/gfx/imageloader_fmtowns.cpp
    engines/ultima/ultima4/gfx/imageloader_fmtowns.h
    engines/ultima/ultima4/gfx/imageloader_png.cpp
    engines/ultima/ultima4/gfx/imageloader_png.h
    engines/ultima/ultima4/gfx/imageloader_u4.cpp
    engines/ultima/ultima4/gfx/imageloader_u4.h
    engines/ultima/ultima4/gfx/imagemgr.cpp
    engines/ultima/ultima4/gfx/imagemgr.h
    engines/ultima/ultima4/map/maploader.cpp
    engines/ultima/ultima4/map/maploader.h
    engines/ultima/ultima4/map/shrine.cpp


diff --git a/engines/ultima/ultima4/controllers/intro_controller.cpp b/engines/ultima/ultima4/controllers/intro_controller.cpp
index 395e309e15..ccf0b67887 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.cpp
+++ b/engines/ultima/ultima4/controllers/intro_controller.cpp
@@ -127,7 +127,7 @@ IntroBinData::~IntroBinData() {
 bool IntroBinData::load() {
 	int i;
 
-	U4FILE *title = u4fopen("title.exe");
+	Common::File *title = u4fopen("title.exe");
 	if (!title)
 		return false;
 
diff --git a/engines/ultima/ultima4/conversation/dialogueloader_hw.cpp b/engines/ultima/ultima4/conversation/dialogueloader_hw.cpp
index f858a37fc3..56ec4d6aa0 100644
--- a/engines/ultima/ultima4/conversation/dialogueloader_hw.cpp
+++ b/engines/ultima/ultima4/conversation/dialogueloader_hw.cpp
@@ -57,7 +57,7 @@ vector<Common::String> hawkwindText;
  * A special case dialogue loader for Hawkwind.
  */
 Dialogue *U4HWDialogueLoader::load(void *source) {
-	U4FILE *avatar = u4fopen("avatar.exe");
+	Common::File *avatar = u4fopen("avatar.exe");
 	if (!avatar)
 		return nullptr;
 
diff --git a/engines/ultima/ultima4/conversation/dialogueloader_lb.cpp b/engines/ultima/ultima4/conversation/dialogueloader_lb.cpp
index d2c93f88cf..f57bfa7d44 100644
--- a/engines/ultima/ultima4/conversation/dialogueloader_lb.cpp
+++ b/engines/ultima/ultima4/conversation/dialogueloader_lb.cpp
@@ -43,7 +43,7 @@ Response *lordBritishGetIntro(const DynamicResponse *resp);
  * current party status.
  */
 Dialogue *U4LBDialogueLoader::load(void *source) {
-	U4FILE *avatar = u4fopen("avatar.exe");
+	Common::File *avatar = u4fopen("avatar.exe");
 	if (!avatar)
 		return nullptr;
 
diff --git a/engines/ultima/ultima4/conversation/dialogueloader_tlk.cpp b/engines/ultima/ultima4/conversation/dialogueloader_tlk.cpp
index a1b4a61817..a4d08498da 100644
--- a/engines/ultima/ultima4/conversation/dialogueloader_tlk.cpp
+++ b/engines/ultima/ultima4/conversation/dialogueloader_tlk.cpp
@@ -34,7 +34,7 @@ using Common::String;
  * A dialogue loader for standard u4dos .tlk files.
  */
 Dialogue *U4TlkDialogueLoader::load(void *source) {
-	U4FILE *file = static_cast<U4FILE *>(source);
+	Common::File *file = static_cast<Common::File *>(source);
 
 	enum QTrigger {
 		NONE = 0,
diff --git a/engines/ultima/ultima4/filesys/u4file.cpp b/engines/ultima/ultima4/filesys/u4file.cpp
index f1325dc374..b0490309aa 100644
--- a/engines/ultima/ultima4/filesys/u4file.cpp
+++ b/engines/ultima/ultima4/filesys/u4file.cpp
@@ -34,82 +34,24 @@ using Std::map;
 using Common::String;
 using Std::vector;
 
-/**
- * A specialization of U4FILE that uses C stdio internally.
- */
-class U4FILE_stdio : public U4FILE {
-private:
-	Common::SeekableReadStream *_in;
-	Common::WriteStream *_out;
-public:
-	static U4FILE *openForReading(const Common::String &fname);
-	static U4FILE *openForWriting(const Common::String &fname);
-
-	U4FILE_stdio(Common::SeekableReadStream *rs) : _in(rs), _out(nullptr) {}
-	U4FILE_stdio(Common::WriteStream *ws) : _in(nullptr), _out(ws) {}
-	virtual ~U4FILE_stdio() {
-		close();
-	}
-
-	void close() override;
-	int seek(long offset, int whence) override;
-	long tell() override;
-	size_t read(void *ptr, size_t size, size_t nmemb) override;
-	int getc() override;
-	int putc(int c) override;
-	long length() override;
-};
-
-/**
- * A specialization of U4FILE that reads files out of zip archives
- * automatically.
- */
-class U4FILE_zip : public U4FILE {
-public:
-	static U4FILE *open(const Common::String &fname, const U4ZipPackage *package);
-
-	virtual void close();
-	virtual int seek(long offset, int whence);
-	virtual long tell();
-	virtual size_t read(void *ptr, size_t size, size_t nmemb);
-	virtual int getc();
-	virtual int putc(int c);
-	virtual long length();
-
-private:
-	Common::SeekableReadStream *_file;
-};
-
-/**
- * Returns true if the upgrade is present.
- */
 bool u4isUpgradeAvailable() {
-	bool avail = false;
-	U4FILE *pal;
-	if ((pal = u4fopen("u4vga.pal")) != nullptr) {
-		avail = true;
-		u4fclose(pal);
-	}
+	Common::File *pal = u4fopen("u4vga.pal");
+	bool avail = pal != nullptr;
+	delete pal;
+
 	return avail;
 }
 
-/**
- * Returns true if the upgrade is not only present, but is installed
- * (switch.bat or setup.bat has been run)
- */
 bool u4isUpgradeInstalled() {
-	U4FILE *u4f = nullptr;
-	long int filelength;
+	int filelength;
 	bool result = false;
 
-	/* FIXME: Is there a better way to determine this? */
-	u4f = u4fopen("ega.drv");
+	Common::File *u4f = u4fopen("ega.drv");
 	if (u4f) {
-
-		filelength = u4f->length();
+		filelength = u4f->size();
 		u4fclose(u4f);
 
-		/* see if (ega.drv > 5k).  If so, the upgrade is installed */
+		// See if (ega.drv > 5k).  If so, the upgrade is installed
 		if (filelength > (5 * 1024))
 			result = true;
 	}
@@ -315,71 +257,13 @@ U4ZipPackageMgr::~U4ZipPackageMgr() {
 		delete *i;
 }
 
-int U4FILE::getshort() {
-	int byteLow = getc();
-	return byteLow | (getc() << 8);
-}
-
-U4FILE *U4FILE_stdio::openForReading(const Common::String &fname) {
-	Common::File *f = new Common::File();
-
-	if (!f->open(fname)) {
-		delete f;
-		return nullptr;
-	}
-
-	return new U4FILE_stdio(f);
-}
-
-U4FILE *U4FILE_stdio::openForWriting(const Common::String &fname) {
-	Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(fname);
-
-	if (!saveFile)
-		return nullptr;
-
-	return new U4FILE_stdio(saveFile);
-}
-
-void U4FILE_stdio::close() {
-	delete _in;
-	delete _out;
-	_in = nullptr;
-	_out = nullptr;
-}
-
-int U4FILE_stdio::seek(long offset, int whence) {
-	assert(_in);
-	return _in->seek(offset, whence);
-}
-
-long U4FILE_stdio::tell() {
-	return _in->pos();
-}
-
-size_t U4FILE_stdio::read(void *ptr, size_t size, size_t nmemb) {
-	uint bytesRead = _in->read(ptr, size * nmemb);
-	return bytesRead / size;
-}
-
-int U4FILE_stdio::getc() {
-	return _in->eos() ? EOF : _in->readByte();
-}
-
-int U4FILE_stdio::putc(int c) {
-	_out->writeByte(c);
-	return 1;
-}
-
-long U4FILE_stdio::length() {
-	return _in->size();
-}
-
 /*------------------------------------------------------------------------*/
+#ifdef TODO
 
 /**
  * Opens a file from within a zip archive.
  */
-U4FILE *U4FILE_zip::open(const Common::String &fname, const U4ZipPackage *package) {
+Common::File *U4FILE_zip::open(const Common::String &fname, const U4ZipPackage *package) {
 #ifdef TODO
 	U4FILE_zip *u4f;
 	unzFile f;
@@ -492,11 +376,13 @@ long U4FILE_zip::length() {
 #endif
 }
 
+#endif
+
 /**
- * Open a data file from the Ultima 4 for DOS installation
+ * Open a data file
  */
-U4FILE *u4fopen(const Common::String &fname) {
-	U4FILE *u4f = nullptr;
+Common::File *u4fopen(const Common::String &fname) {
+	Common::File *u4f = nullptr;
 
 	debug(1, "looking for %s\n", fname.c_str());
 #ifdef TODO
@@ -517,66 +403,65 @@ U4FILE *u4fopen(const Common::String &fname) {
 #endif
 
 	if (!fname.empty()) {
-		u4f = U4FILE_stdio::openForReading(fname);
-		if (u4f != nullptr)
+		u4f = new Common::File();
+		if (u4f->open(fname)) {
 			debug(1, "%s successfully opened\n", fname.c_str());
+		} else {
+			delete u4f;
+			u4f = nullptr;
+		}
 	}
 
 	return u4f;
 }
 
-/**
- * Opens a file with the standard C stdio facilities and wrap it in a
- * U4FILE.
- */
-U4FILE *u4fopen_stdio(const Common::String &fname) {
-	return U4FILE_stdio::openForReading(fname);
-}
-
 /**
  * Opens a file from a zipfile and wraps it in a U4FILE.
  */
-U4FILE *u4fopen_zip(const Common::String &fname, U4ZipPackage *package) {
-	return U4FILE_zip::open(fname, package);
+Common::File *u4fopen_zip(const Common::String &fname, Common::Archive *archive) {
+	Common::File *f = new Common::File();
+
+	if (f->open(fname, *archive))
+		return f;
+
+	delete f;
+	return nullptr;
 }
 
 /**
  * Closes a data file from the Ultima 4 for DOS installation.
  */
-void u4fclose(U4FILE *f) {
+void u4fclose(Common::File *f) {
 	f->close();
 	delete f;
 }
 
-int u4fseek(U4FILE *f, long offset, int whence) {
+int u4fseek(Common::File *f, long offset, int whence) {
 	return f->seek(offset, whence);
 }
 
-long u4ftell(U4FILE *f) {
-	return f->tell();
-}
-
-size_t u4fread(void *ptr, size_t size, size_t nmemb, U4FILE *f) {
-	return f->read(ptr, size, nmemb);
+long u4ftell(Common::File *f) {
+	return f->pos();
 }
 
-int u4fgetc(U4FILE *f) {
-	return f->getc();
+size_t u4fread(void *ptr, size_t size, size_t nmemb, Common::File *f) {
+	int count = f->read(ptr, size * nmemb);
+	return count / size;
 }
 
-int u4fgetshort(U4FILE *f) {
-	return f->getshort();
+int u4fgetc(Common::File *f) {
+	return f->readByte();
 }
 
-int u4fputc(int c, U4FILE *f) {
-	return f->putc(c);
+int u4fgetshort(Common::File *f) {
+	return f->readUint16LE();
 }
 
 /**
  * Returns the length in bytes of a file.
  */
-long u4flength(U4FILE *f) {
-	return f->length();
+long u4flength(Common::File *f) {
+	return f->size();
 }
 
 /**
@@ -584,7 +469,7 @@ long u4flength(U4FILE *f) {
  * are read from the given offset, or the current file position if
  * offset is -1.
  */
-vector<Common::String> u4read_stringtable(U4FILE *f, long offset, int nstrings) {
+vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings) {
 	Common::String buffer;
 	int i;
 	vector<Common::String> strs;
@@ -597,7 +482,7 @@ vector<Common::String> u4read_stringtable(U4FILE *f, long offset, int nstrings)
 		char c;
 		buffer.clear();
 
-		while ((c = f->getc()) != '\0')
+		while ((c = f->readByte()) != '\0')
 			buffer += c;
 
 		strs.push_back(buffer);
diff --git a/engines/ultima/ultima4/filesys/u4file.h b/engines/ultima/ultima4/filesys/u4file.h
index 9cc61e10c9..4696ef0695 100644
--- a/engines/ultima/ultima4/filesys/u4file.h
+++ b/engines/ultima/ultima4/filesys/u4file.h
@@ -23,6 +23,7 @@
 #ifndef ULTIMA4_FILE_H
 #define ULTIMA4_FILE_H
 
+#include "common/file.h"
 #include "common/hash-str.h"
 #include "ultima/shared/std/containers.h"
 
@@ -84,43 +85,32 @@ private:
 #endif
 
 /**
- * An abstract interface for file access.
+ * Returns true if the upgrade is present.
  */
-class U4FILE {
-public:
-	virtual ~U4FILE() {}
-
-	virtual void close() = 0;
-	virtual int seek(long offset, int whence) = 0;
-	virtual long tell() = 0;
-	virtual size_t read(void *ptr, size_t size, size_t nmemb) = 0;
-	virtual int getc() = 0;
-	virtual int putc(int c) = 0;
-	virtual long length() = 0;
-
-	int getshort();
-};
+extern bool u4isUpgradeAvailable();
 
-bool u4isUpgradeAvailable();
-bool u4isUpgradeInstalled();
-U4FILE *u4fopen(const Common::String &fname);
-U4FILE *u4fopen_stdio(const Common::String &fname);
-U4FILE *u4fopen_zip(const Common::String &fname, U4ZipPackage *package);
-void u4fclose(U4FILE *f);
-int u4fseek(U4FILE *f, long offset, int whence);
-long u4ftell(U4FILE *f);
-size_t u4fread(void *ptr, size_t size, size_t nmemb, U4FILE *f);
-int u4fgetc(U4FILE *f);
-int u4fgetshort(U4FILE *f);
-int u4fputc(int c, U4FILE *f);
-long u4flength(U4FILE *f);
-Std::vector<Common::String> u4read_stringtable(U4FILE *f, long offset, int nstrings);
-
-Common::String u4find_path(const Common::String &fname, Common::List<Common::String> specificSubPaths);
-Common::String u4find_music(const Common::String &fname);
-Common::String u4find_sound(const Common::String &fname);
-Common::String u4find_conf(const Common::String &fname);
-Common::String u4find_graphics(const Common::String &fname);
+/**
+ * Returns true if the upgrade is not only present, but is installed
+ * (switch.bat or setup.bat has been run)
+ */
+extern bool u4isUpgradeInstalled();
+
+extern Common::File *u4fopen(const Common::String &fname);
+extern Common::File *u4fopen_zip(const Common::String &fname, Common::Archive *archive);
+extern void u4fclose(Common::File *f);
+extern int u4fseek(Common::File *f, long offset, int whence);
+extern long u4ftell(Common::File *f);
+extern size_t u4fread(void *ptr, size_t size, size_t nmemb, Common::File *f);
+extern int u4fgetc(Common::File *f);
+extern int u4fgetshort(Common::File *f);
+extern long u4flength(Common::File *f);
+extern Std::vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings);
+
+extern Common::String u4find_path(const Common::String &fname, Common::List<Common::String> specificSubPaths);
+extern Common::String u4find_music(const Common::String &fname);
+extern Common::String u4find_sound(const Common::String &fname);
+extern Common::String u4find_conf(const Common::String &fname);
+extern Common::String u4find_graphics(const Common::String &fname);
 
 } // End of namespace Ultima4
 } // End of namespace Ultima
diff --git a/engines/ultima/ultima4/game/codex.cpp b/engines/ultima/ultima4/game/codex.cpp
index b36a4b9f4b..f3b3ec16fe 100644
--- a/engines/ultima/ultima4/game/codex.cpp
+++ b/engines/ultima/ultima4/game/codex.cpp
@@ -61,7 +61,7 @@ Std::vector<Common::String> codexEndgameText2;
  * Initializes the Chamber of the Codex sequence (runs from codexStart())
  */
 int codexInit() {
-	U4FILE *avatar;
+	Common::File *avatar;
 
 	avatar = u4fopen("avatar.exe");
 	if (!avatar)
diff --git a/engines/ultima/ultima4/gfx/imageloader.h b/engines/ultima/ultima4/gfx/imageloader.h
index 382f2629be..1c87510848 100644
--- a/engines/ultima/ultima4/gfx/imageloader.h
+++ b/engines/ultima/ultima4/gfx/imageloader.h
@@ -69,7 +69,7 @@ protected:
 public:
 	ImageLoader() {}
 	virtual ~ImageLoader() {}
-	virtual Image *load(U4FILE *file, int width, int height, int bpp) = 0;
+	virtual Image *load(Common::File *file, int width, int height, int bpp) = 0;
 };
 
 } // End of namespace Ultima4
diff --git a/engines/ultima/ultima4/gfx/imageloader_fmtowns.cpp b/engines/ultima/ultima4/gfx/imageloader_fmtowns.cpp
index 14d21ead80..81c81cbc3a 100644
--- a/engines/ultima/ultima4/gfx/imageloader_fmtowns.cpp
+++ b/engines/ultima/ultima4/gfx/imageloader_fmtowns.cpp
@@ -32,17 +32,17 @@ namespace Ultima4 {
 
 using Std::vector;
 
-Image *FMTOWNSImageLoader::load(U4FILE *file, int width, int height, int bpp) {
+Image *FMTOWNSImageLoader::load(Common::File *file, int width, int height, int bpp) {
 	if (width == -1 || height == -1 || bpp == -1) {
 		error("dimensions not set for fmtowns image");
 	}
 
 	ASSERT((bpp == 16) | (bpp == 4), "invalid bpp: %d", bpp);
 
-	long rawLen = file->length() - _offset;
+	long rawLen = file->size() - _offset;
 	file->seek(_offset, 0);
 	byte *raw = (byte *) malloc(rawLen);
-	file->read(raw, 1, rawLen);
+	file->read(raw, rawLen);
 
 	long requiredLength = (width * height * bpp / 8);
 	if (rawLen < requiredLength) {
diff --git a/engines/ultima/ultima4/gfx/imageloader_fmtowns.h b/engines/ultima/ultima4/gfx/imageloader_fmtowns.h
index d30339eadc..d1aea8a53a 100644
--- a/engines/ultima/ultima4/gfx/imageloader_fmtowns.h
+++ b/engines/ultima/ultima4/gfx/imageloader_fmtowns.h
@@ -38,7 +38,7 @@ public:
 	/**
 	 * Loads in an FM TOWNS files, which we assume is 16 bits.
 	 */
-	Image *load(U4FILE *file, int width, int height, int bpp) override;
+	Image *load(Common::File *file, int width, int height, int bpp) override;
 };
 
 } // End of namespace Ultima4
diff --git a/engines/ultima/ultima4/gfx/imageloader_png.cpp b/engines/ultima/ultima4/gfx/imageloader_png.cpp
index b021669a67..ec745c5c25 100644
--- a/engines/ultima/ultima4/gfx/imageloader_png.cpp
+++ b/engines/ultima/ultima4/gfx/imageloader_png.cpp
@@ -29,14 +29,14 @@
 namespace Ultima {
 namespace Ultima4 {
 
-Image *PngImageLoader::load(U4FILE *file, int width, int height, int bpp) {
+Image *PngImageLoader::load(Common::File *file, int width, int height, int bpp) {
 	if (width != -1 || height != -1 || bpp != -1) {
 		warning("dimensions set for PNG image, will be ignored");
 	}
 
-	size_t fileSize = file->length();
+	size_t fileSize = file->size();
 	byte *buffer = (byte *)malloc(fileSize);
-	file->read(buffer, fileSize, 1);
+	file->read(buffer, fileSize);
 	Common::MemoryReadStream src(buffer, fileSize, DisposeAfterUse::YES);
 
 	::Image::PNGDecoder decoder;
diff --git a/engines/ultima/ultima4/gfx/imageloader_png.h b/engines/ultima/ultima4/gfx/imageloader_png.h
index c9fe827dbc..a840f9a150 100644
--- a/engines/ultima/ultima4/gfx/imageloader_png.h
+++ b/engines/ultima/ultima4/gfx/imageloader_png.h
@@ -40,7 +40,7 @@ public:
 	/**
 	 * Loads in the PNG with the libpng library.
 	 */
-	Image *load(U4FILE *file, int width, int height, int bpp) override;
+	Image *load(Common::File *file, int width, int height, int bpp) override;
 };
 
 } // End of namespace Ultima4
diff --git a/engines/ultima/ultima4/gfx/imageloader_u4.cpp b/engines/ultima/ultima4/gfx/imageloader_u4.cpp
index 617edaa6de..716ea65029 100644
--- a/engines/ultima/ultima4/gfx/imageloader_u4.cpp
+++ b/engines/ultima/ultima4/gfx/imageloader_u4.cpp
@@ -37,16 +37,16 @@ RGBA *U4PaletteLoader::_bwPalette = nullptr;
 RGBA *U4PaletteLoader::_egaPalette = nullptr;
 RGBA *U4PaletteLoader::_vgaPalette = nullptr;
 
-Image *U4RawImageLoader::load(U4FILE *file, int width, int height, int bpp) {
+Image *U4RawImageLoader::load(Common::File *file, int width, int height, int bpp) {
 	if (width == -1 || height == -1 || bpp == -1) {
 		error("dimensions not set for u4raw image");
 	}
 
 	ASSERT(bpp == 1 || bpp == 4 || bpp == 8 || bpp == 24 || bpp == 32, "invalid bpp: %d", bpp);
 
-	long rawLen = file->length();
-	byte *raw = (byte *) malloc(rawLen);
-	file->read(raw, 1, rawLen);
+	long rawLen = file->size();
+	byte *raw = (byte *)malloc(rawLen);
+	file->read(raw, rawLen);
 
 	long requiredLength = (width * height * bpp / 8);
 	if (rawLen < requiredLength) {
@@ -82,16 +82,16 @@ Image *U4RawImageLoader::load(U4FILE *file, int width, int height, int bpp) {
  * Loads in the rle-compressed image and apply the standard U4 16 or
  * 256 color palette.
  */
-Image *U4RleImageLoader::load(U4FILE *file, int width, int height, int bpp) {
+Image *U4RleImageLoader::load(Common::File *file, int width, int height, int bpp) {
 	if (width == -1 || height == -1 || bpp == -1) {
 		error("dimensions not set for u4rle image");
 	}
 
 	ASSERT(bpp == 1 || bpp == 4 || bpp == 8 || bpp == 24 || bpp == 32, "invalid bpp: %d", bpp);
 
-	long compressedLen = file->length();
+	long compressedLen = file->size();
 	byte *compressed = (byte *) malloc(compressedLen);
-	file->read(compressed, 1, compressedLen);
+	file->read(compressed, compressedLen);
 
 	byte *raw = nullptr;
 	long rawLen = rleDecompressMemory(compressed, compressedLen, (void **) &raw);
@@ -129,16 +129,16 @@ Image *U4RleImageLoader::load(U4FILE *file, int width, int height, int bpp) {
  * Loads in the lzw-compressed image and apply the standard U4 16 or
  * 256 color palette.
  */
-Image *U4LzwImageLoader::load(U4FILE *file, int width, int height, int bpp) {
+Image *U4LzwImageLoader::load(Common::File *file, int width, int height, int bpp) {
 	if (width == -1 || height == -1 || bpp == -1) {
 		error("dimensions not set for u4lzw image");
 	}
 
 	ASSERT(bpp == 1 || bpp == 4 || bpp == 8 || bpp == 24 || bpp == 32, "invalid bpp: %d", bpp);
 
-	long compressedLen = file->length();
+	long compressedLen = file->size();
 	byte *compressed = (byte *) malloc(compressedLen);
-	file->read(compressed, 1, compressedLen);
+	file->read(compressed, compressedLen);
 
 	byte *raw = nullptr;
 	long rawLen = LZW::decompress_u4_memory(compressed, compressedLen, (void **) &raw);
@@ -222,7 +222,7 @@ RGBA *U4PaletteLoader::loadEgaPalette() {
  */
 RGBA *U4PaletteLoader::loadVgaPalette() {
 	if (_vgaPalette == nullptr) {
-		U4FILE *pal = u4fopen("u4vga.pal");
+		Common::File *pal = u4fopen("u4vga.pal");
 		if (!pal)
 			return nullptr;
 
diff --git a/engines/ultima/ultima4/gfx/imageloader_u4.h b/engines/ultima/ultima4/gfx/imageloader_u4.h
index f53a709e75..7a7044639d 100644
--- a/engines/ultima/ultima4/gfx/imageloader_u4.h
+++ b/engines/ultima/ultima4/gfx/imageloader_u4.h
@@ -41,7 +41,7 @@ public:
 	/**
 	 * Loads in the raw image and apply the standard U4 16 or 256 color palette.
 	 */
-	Image *load(U4FILE *file, int width, int height, int bpp) override;
+	Image *load(Common::File *file, int width, int height, int bpp) override;
 };
 
 /**
@@ -52,7 +52,7 @@ public:
  */
 class U4RleImageLoader : public ImageLoader {
 public:
-	Image *load(U4FILE *file, int width, int height, int bpp) override;
+	Image *load(Common::File *file, int width, int height, int bpp) override;
 };
 
 /**
@@ -63,7 +63,7 @@ public:
  */
 class U4LzwImageLoader : public ImageLoader {
 public:
-	Image *load(U4FILE *file, int width, int height, int bpp) override;
+	Image *load(Common::File *file, int width, int height, int bpp) override;
 };
 
 class U4PaletteLoader {
diff --git a/engines/ultima/ultima4/gfx/imagemgr.cpp b/engines/ultima/ultima4/gfx/imagemgr.cpp
index ee47f7a44d..b5de73fb68 100644
--- a/engines/ultima/ultima4/gfx/imagemgr.cpp
+++ b/engines/ultima/ultima4/gfx/imagemgr.cpp
@@ -510,7 +510,7 @@ Common::String ImageMgr::guessFileType(const Common::String &filename) {
 bool ImageMgr::imageExists(ImageInfo *info) {
 	if (info->_filename == "") //If it is an abstract image like "screen"
 		return true;
-	U4FILE *file = getImageFile(info);
+	Common::File *file = getImageFile(info);
 	if (file) {
 		u4fclose(file);
 		return true;
@@ -519,7 +519,7 @@ bool ImageMgr::imageExists(ImageInfo *info) {
 }
 
 
-U4FILE *ImageMgr::getImageFile(ImageInfo *info) {
+Common::File *ImageMgr::getImageFile(ImageInfo *info) {
 	Common::String filename = info->_filename;
 
 	/*
@@ -539,16 +539,17 @@ U4FILE *ImageMgr::getImageFile(ImageInfo *info) {
 	if (filename == "")
 		return nullptr;
 
-	U4FILE *file = nullptr;
+	Common::File *file = nullptr;
 	if (info->_xu4Graphic) {
 		Common::String pathname(u4find_graphics(filename));
 
 		if (!pathname.empty())
-			file = u4fopen_stdio(pathname);
+			file = u4fopen(pathname);
 	} else {
 		filename = u4find_graphics(filename);
 		file = u4fopen(filename);
 	}
+
 	return file;
 }
 
@@ -561,7 +562,7 @@ ImageInfo *ImageMgr::get(const Common::String &name, bool returnUnscaled) {
 	if (info->_image != nullptr)
 		return info;
 
-	U4FILE *file = getImageFile(info);
+	Common::File *file = getImageFile(info);
 	Image *unscaled = nullptr;
 	if (file) {
 		if (info->_filetype.empty())
diff --git a/engines/ultima/ultima4/gfx/imagemgr.h b/engines/ultima/ultima4/gfx/imagemgr.h
index fde538077a..b91b46f4e5 100644
--- a/engines/ultima/ultima4/gfx/imagemgr.h
+++ b/engines/ultima/ultima4/gfx/imagemgr.h
@@ -137,7 +137,7 @@ public:
 	 */
 	void freeIntroBackgrounds();
 	const Std::vector<Common::String> &getSetNames();
-	U4FILE *getImageFile(ImageInfo *info);
+	Common::File *getImageFile(ImageInfo *info);
 	bool imageExists(ImageInfo *info);
 
 private:
diff --git a/engines/ultima/ultima4/map/maploader.cpp b/engines/ultima/ultima4/map/maploader.cpp
index 5c0e876a0a..23362c4eaa 100644
--- a/engines/ultima/ultima4/map/maploader.cpp
+++ b/engines/ultima/ultima4/map/maploader.cpp
@@ -71,7 +71,7 @@ MapLoader *MapLoader::registerLoader(MapLoader *loader, Map::Type type) {
 	return loader;
 }
 
-bool MapLoader::loadData(Map *map, U4FILE *f) {
+bool MapLoader::loadData(Map *map, Common::File *f) {
 	uint x, xch, y, ych;
 
 	/* allocate the space we need for the map data */
@@ -134,8 +134,8 @@ bool CityMapLoader::load(Map *map) {
 	Dialogue *dialogues[CITY_MAX_PERSONS];
 	DialogueLoader *dlgLoader = DialogueLoaders::getLoader("application/x-u4tlk");
 
-	U4FILE *ult = u4fopen(city->_fname);
-	U4FILE *tlk = u4fopen(city->_tlkFname);
+	Common::File *ult = u4fopen(city->_fname);
+	Common::File *tlk = u4fopen(city->_tlkFname);
 	if (!ult || !tlk)
 		error("unable to load map data");
 
@@ -247,7 +247,7 @@ bool CityMapLoader::load(Map *map) {
 bool ConMapLoader::load(Map *map) {
 	int i;
 
-	U4FILE *con = u4fopen(map->_fname);
+	Common::File *con = u4fopen(map->_fname);
 	if (!con)
 		error("unable to load map data");
 
@@ -284,7 +284,7 @@ bool ConMapLoader::load(Map *map) {
 bool DngMapLoader::load(Map *map) {
 	Dungeon *dungeon = dynamic_cast<Dungeon *>(map);
 
-	U4FILE *dng = u4fopen(dungeon->_fname);
+	Common::File *dng = u4fopen(dungeon->_fname);
 	if (!dng)
 		error("unable to load map data");
 
@@ -436,7 +436,7 @@ void DngMapLoader::initDungeonRoom(Dungeon *dng, int room) {
 }
 
 bool WorldMapLoader::load(Map *map) {
-	U4FILE *world = u4fopen(map->_fname);
+	Common::File *world = u4fopen(map->_fname);
 	if (!world)
 		error("unable to load map data");
 
diff --git a/engines/ultima/ultima4/map/maploader.h b/engines/ultima/ultima4/map/maploader.h
index 7ddc8f2f9e..45988ba876 100644
--- a/engines/ultima/ultima4/map/maploader.h
+++ b/engines/ultima/ultima4/map/maploader.h
@@ -73,7 +73,7 @@ protected:
 	/**
 	 * Loads raw data from the given file.
 	 */
-	static bool loadData(Map *map, U4FILE *f);
+	static bool loadData(Map *map, Common::File *f);
 	static bool isChunkCompressed(Map *map, int chunk);
 
 private:
diff --git a/engines/ultima/ultima4/map/shrine.cpp b/engines/ultima/ultima4/map/shrine.cpp
index b031a37416..c6c5d0ac0b 100644
--- a/engines/ultima/ultima4/map/shrine.cpp
+++ b/engines/ultima/ultima4/map/shrine.cpp
@@ -106,7 +106,7 @@ void Shrine::setMantra(Common::String m)    {
 
 void Shrine::enter() {
 	if (shrineAdvice.empty()) {
-		U4FILE *avatar = u4fopen("avatar.exe");
+		Common::File *avatar = u4fopen("avatar.exe");
 		if (!avatar)
 			return;
 		shrineAdvice = u4read_stringtable(avatar, 93682, 24);


Commit: 95492d56f950245c008facd3f3e3bfd2f0fef6c8
    https://github.com/scummvm/scummvm/commit/95492d56f950245c008facd3f3e3bfd2f0fef6c8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Removal of unneed zip stuff

Changed paths:
    engines/ultima/ultima4/filesys/u4file.cpp
    engines/ultima/ultima4/filesys/u4file.h


diff --git a/engines/ultima/ultima4/filesys/u4file.cpp b/engines/ultima/ultima4/filesys/u4file.cpp
index b0490309aa..d436f52d09 100644
--- a/engines/ultima/ultima4/filesys/u4file.cpp
+++ b/engines/ultima/ultima4/filesys/u4file.cpp
@@ -26,6 +26,7 @@
 #include "common/file.h"
 #include "common/savefile.h"
 #include "common/system.h"
+#include "common/unzip.h"
 
 namespace Ultima {
 namespace Ultima4 {
@@ -61,322 +62,7 @@ bool u4isUpgradeInstalled() {
 	return result;
 }
 
-/**
- * Creates a new zip package.
- */
-U4ZipPackage::U4ZipPackage(const Common::String &name, const Common::String &path, bool extension) {
-	this->_name = name;
-	this->_path = path;
-	this->_extension = extension;
-}
-
-void U4ZipPackage::addTranslation(const Common::String &value, const Common::String &translation) {
-	_translations[value] = translation;
-}
-
-const Common::String &U4ZipPackage::translate(const Common::String &name) const {
-	Std::map<Common::String, Common::String>::const_iterator i = _translations.find(name);
-	if (i != _translations.end())
-		return i->_value;
-	else
-		return name;
-}
-
-U4ZipPackageMgr *U4ZipPackageMgr::_instance = nullptr;
-
-U4ZipPackageMgr *U4ZipPackageMgr::getInstance() {
-	if (_instance == nullptr) {
-		_instance = new U4ZipPackageMgr();
-	}
-	return _instance;
-}
-
-void U4ZipPackageMgr::destroy() {
-	if (_instance != nullptr) {
-		delete _instance;
-		_instance = nullptr;
-	}
-}
-
-void U4ZipPackageMgr::add(U4ZipPackage *package) {
-	_packages.push_back(package);
-}
-
-U4ZipPackageMgr::U4ZipPackageMgr() {
-#ifdef TODO
-	unzFile f;
-
-	Common::String upg_pathname(u4find_path("u4upgrad.zip", u4Path.u4ZipPaths));
-	if (!upg_pathname.empty()) {
-		/* upgrade zip is present */
-		U4ZipPackage *upgrade = new U4ZipPackage(upg_pathname, "", false);
-		upgrade->addTranslation("compassn.ega", "compassn.old");
-		upgrade->addTranslation("courage.ega", "courage.old");
-		upgrade->addTranslation("cove.tlk", "cove.old");
-		upgrade->addTranslation("ega.drv", "ega.old"); // not actually used
-		upgrade->addTranslation("honesty.ega", "honesty.old");
-		upgrade->addTranslation("honor.ega", "honor.old");
-		upgrade->addTranslation("humility.ega", "humility.old");
-		upgrade->addTranslation("key7.ega", "key7.old");
-		upgrade->addTranslation("lcb.tlk", "lcb.old");
-		upgrade->addTranslation("love.ega", "love.old");
-		upgrade->addTranslation("love.ega", "love.old");
-		upgrade->addTranslation("minoc.tlk", "minoc.old");
-		upgrade->addTranslation("rune_0.ega", "rune_0.old");
-		upgrade->addTranslation("rune_1.ega", "rune_1.old");
-		upgrade->addTranslation("rune_2.ega", "rune_2.old");
-		upgrade->addTranslation("rune_3.ega", "rune_3.old");
-		upgrade->addTranslation("rune_4.ega", "rune_4.old");
-		upgrade->addTranslation("rune_5.ega", "rune_5.old");
-		upgrade->addTranslation("sacrific.ega", "sacrific.old");
-		upgrade->addTranslation("skara.tlk", "skara.old");
-		upgrade->addTranslation("spirit.ega", "spirit.old");
-		upgrade->addTranslation("start.ega", "start.old");
-		upgrade->addTranslation("stoncrcl.ega", "stoncrcl.old");
-		upgrade->addTranslation("truth.ega", "truth.old");
-		upgrade->addTranslation("ultima.com", "ultima.old"); // not actually used
-		upgrade->addTranslation("valor.ega", "valor.old");
-		upgrade->addTranslation("yew.tlk", "yew.old");
-		add(upgrade);
-	}
-
-	// Check for the default zip packages
-	int flag = 0;
-	Common::String pathname;
-
-	do {
-		//Check for the upgraded package once. unlikely it'll be renamed.
-		pathname = u4find_path("ultima4-1.01.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		// We check for all manner of generic packages, though.
-		pathname = u4find_path("ultima4.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("Ultima4.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("ULTIMA4.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("u4.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("U4.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		//search for the ultimaforever.com zip and variations
-		pathname = u4find_path("UltimaIV.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("Ultimaiv.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("ULTIMAIV.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("ultimaIV.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		pathname = u4find_path("ultimaiv.zip", u4Path.u4ZipPaths);
-		if (!pathname.empty()) {
-			flag = 1;
-			break;
-		}
-
-		// If it's not found by this point, give up.
-		break;
-
-	} while (flag == 0);
-
-	if (flag) {
-		f = unzOpen(pathname.c_str());
-		if (!f)
-			return;
-
-		//Now we detect the folder structure inside the zipfile.
-		if (unzLocateFile(f, "charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "", false));
-
-		} else if (unzLocateFile(f, "ultima4/charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "ultima4/", false));
-
-		} else if (unzLocateFile(f, "Ultima4/charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "Ultima4/", false));
-
-		} else if (unzLocateFile(f, "ULTIMA4/charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "ULTIMA4/", false));
-
-		} else if (unzLocateFile(f, "u4/charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "u4/", false));
-
-		} else if (unzLocateFile(f, "U4/charset.ega", 2) == UNZ_OK) {
-			add(new U4ZipPackage(pathname, "U4/", false));
-
-		}
-
-		unzClose(f);
-
-	}
-#endif
-	/* scan for extensions */
-}
-
-U4ZipPackageMgr::~U4ZipPackageMgr() {
-	for (Std::vector<U4ZipPackage *>::iterator i = _packages.begin(); i != _packages.end(); i++)
-		delete *i;
-}
-
-/*------------------------------------------------------------------------*/
-#ifdef TODO
-
-/**
- * Opens a file from within a zip archive.
- */
-Common::File *U4FILE_zip::open(const Common::String &fname, const U4ZipPackage *package) {
-#ifdef TODO
-	U4FILE_zip *u4f;
-	unzFile f;
-
-	f = unzOpen(package->getFilename().c_str());
-	if (!f)
-		return nullptr;
-
-	Common::String pathname = package->getInternalPath() + package->translate(fname);
-
-	if (unzLocateFile(f, pathname.c_str(), 2) == UNZ_END_OF_LIST_OF_FILE) {
-		unzClose(f);
-		return nullptr;
-	}
-	unzOpenCurrentFile(f);
-
-	u4f = new U4FILE_zip();
-	u4f->zfile = f;
-
-	return u4f;
-#else
-	return nullptr;
-#endif
-}
-
-void U4FILE_zip::close() {
-#ifdef TODO
-	unzClose(zfile);
-#endif
-}
-
-int U4FILE_zip::seek(long offset, int whence) {
-#ifdef TODO
-	char *buf;
-	long pos;
-
-	ASSERT(whence != SEEK_END, "seeking with whence == SEEK_END not allowed with zipfiles");
-	pos = unztell(zfile);
-	if (whence == SEEK_CUR)
-		offset = pos + offset;
-	if (offset == pos)
-		return 0;
-	if (offset < pos) {
-		unzCloseCurrentFile(zfile);
-		unzOpenCurrentFile(zfile);
-		pos = 0;
-	}
-	ASSERT(offset - pos > 0, "error in U4FILE_zip::seek");
-	buf = new char[offset - pos];
-	unzReadCurrentFile(zfile, buf, offset - pos);
-	delete [] buf;
-	return 0;
-#else
-	return -1;
-#endif
-}
-
-long U4FILE_zip::tell() {
-#ifdef TODO
-	return unztell(zfile);
-#else
-	return 0;
-#endif
-}
-
-size_t U4FILE_zip::read(void *ptr, size_t size, size_t nmemb) {
-#ifdef TODO
-	size_t retval = unzReadCurrentFile(zfile, ptr, size * nmemb);
-	if (retval > 0)
-		retval = retval / size;
-
-	return retval;
-#else
-	return 0;
-#endif
-}
-
-int U4FILE_zip::getc() {
-#ifdef TODO
-	int retval;
-	byte c;
-
-	if (unzReadCurrentFile(zfile, &c, 1) > 0)
-		retval = c;
-	else
-		retval = EOF;
-
-	return retval;
-#else
-	return 0;
-#endif
-}
-
-int U4FILE_zip::putc(int c) {
-	error("zipfiles must be read-only!");
-	return c;
-}
-
-long U4FILE_zip::length() {
-#ifdef TODO
-	unz_file_info fileinfo;
-
-	unzGetCurrentFileInfo(zfile, &fileinfo,
-	                      nullptr, 0,
-	                      nullptr, 0,
-	                      nullptr, 0);
-	return fileinfo.uncompressed_size;
-#else
-	return 0;
-#endif
-}
-
-#endif
+/*-------------------------------------------------------------------*/
 
 /**
  * Open a data file
@@ -384,24 +70,6 @@ long U4FILE_zip::length() {
 Common::File *u4fopen(const Common::String &fname) {
 	Common::File *u4f = nullptr;
 
-	debug(1, "looking for %s\n", fname.c_str());
-#ifdef TODO
-	/**
-	 * search for file within zipfiles (ultima4.zip, u4upgrad.zip, etc.)
-	 */
-	const vector<U4ZipPackage *> &packages = U4ZipPackageMgr::getInstance()->getPackages();
-	for (Std::vector<U4ZipPackage *>::const_reverse_iterator j = packages.rbegin();
-	        j != packages.rend(); ++j) {
-		u4f = U4FILE_zip::open(fname, *j);
-		if (u4f)
-			return u4f; /* file was found, return it! */
-	}
-
-	/*
-	 * file not in a zipfile; check if it has been unzipped
-	 */
-#endif
-
 	if (!fname.empty()) {
 		u4f = new Common::File();
 		if (u4f->open(fname)) {
@@ -415,19 +83,6 @@ Common::File *u4fopen(const Common::String &fname) {
 	return u4f;
 }
 
-/**
- * Opens a file from a zipfile and wraps it in a U4FILE.
- */
-Common::File *u4fopen_zip(const Common::String &fname, Common::Archive *archive) {
-	Common::File *f = new Common::File();
-
-	if (f->open(fname, *archive))
-		return f;
-
-	delete f;
-	return nullptr;
-}
-
 /**
  * Closes a data file from the Ultima 4 for DOS installation.
  */
@@ -492,91 +147,7 @@ vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstr
 }
 
 Common::String u4find_path(const Common::String &fname, Common::List<Common::String> specificSubPaths) {
-#ifdef TODO
-	FILE *f = nullptr;
-
-	// Try absolute first
-	char path[2048]; // Sometimes paths get big.
-
-	f = fopen(fname.c_str(), "rb");
-	if (f)
-		strcpy(path, fname.c_str());
-
-	// Try 'file://' protocol if specified
-	if (f == nullptr) {
-		const Common::String file_url_prefix("file://");
-
-		if (fname.compare(0, file_url_prefix.length(), file_url_prefix) == 0) {
-			strcpy(path, fname.substr(file_url_prefix.length()).c_str());
-			if (verbose) {
-				debug("trying to open %s\n", path);
-			}
-			f = fopen(path, "rb");
-		}
-	}
-
-	// Try paths
-	if (f == nullptr) {
-		for (Common::List<Common::String>::iterator rootItr = u4Path.rootResourcePaths.begin();
-		        rootItr != u4Path.rootResourcePaths.end() && !f;
-		        ++rootItr) {
-			for (Common::List<Common::String>::iterator subItr = specificSubPaths.begin();
-			        subItr != specificSubPaths.end() && !f;
-			        ++subItr) {
-
-				snprintf(path, sizeof(path), "%s/%s/%s", rootItr->c_str(), subItr->c_str(), fname.c_str());
-
-				if (verbose) {
-					debug("trying to open %s\n", path);
-				}
-				if ((f = fopen(path, "rb")) != nullptr)
-					break;
-			}
-		}
-	}
-#if defined(IOS)
-	if (f == nullptr) {
-		Common::String base = fname;
-		Common::String ext = "";
-		Common::String dir = "";
-		// This is VERY dependant on the current layout of the XML files. It will fail in a general case.
-		size_t seppos = fname.rfind('/');
-		if (seppos != Common::String::npos)
-			dir = fname.substr(0, seppos);
-		size_t pos = fname.rfind('.');
-		if (pos != Common::String::npos) {
-			if (seppos != Common::String::npos)
-				base = fname.substr(seppos + 1, pos - seppos - 1);
-			else
-				base = fname.substr(0, pos);
-			ext = fname.substr(pos + 1);
-		}
-
-		Common::String pathFile = U4IOS::getFileLocation(dir, base, ext);
-		strncpy(path, pathFile.c_str(), 2048);
-		if (verbose)
-			debug("trying to open %s\n", path);
-
-		f = fopen(path, "rb");
-	}
-#endif
-
-	if (verbose) {
-		if (f != nullptr)
-			debug("%s successfully found\n", path);
-		else
-			debug("%s not found\n", fname.c_str());
-	}
-
-	if (f) {
-		delete f;
-		return path;
-	} else
-		return "";
-#else
-	warning("findpath");
 	return fname;
-#endif
 }
 
 Common::String u4find_music(const Common::String &fname) {
diff --git a/engines/ultima/ultima4/filesys/u4file.h b/engines/ultima/ultima4/filesys/u4file.h
index 4696ef0695..6be40387bd 100644
--- a/engines/ultima/ultima4/filesys/u4file.h
+++ b/engines/ultima/ultima4/filesys/u4file.h
@@ -30,60 +30,6 @@
 namespace Ultima {
 namespace Ultima4 {
 
-/**
- * Represents zip files that game resources can be loaded from.
- */
-class U4ZipPackage {
-public:
-	U4ZipPackage(const Common::String &name, const Common::String &path, bool extension);
-	void addTranslation(const Common::String &value, const Common::String &translation);
-
-	const Common::String &getFilename() const {
-		return _name;
-	}
-	const Common::String &getInternalPath() const {
-		return _path;
-	}
-	bool isExtension() const {
-		return _extension;
-	}
-	const Common::String &translate(const Common::String &name) const;
-
-private:
-	Common::String _name;                /**< filename */
-	Common::String _path;                /**< the path within the zipfile where resources are located */
-	bool _extension;             /**< whether this zipfile is an extension with config information */
-	Common::HashMap<Common::String, Common::String> _translations; /**< mapping from standard resource names to internal names */
-};
-
-/**
- * Keeps track of available zip packages.
- */
-class U4ZipPackageMgr {
-public:
-	static U4ZipPackageMgr *getInstance();
-	static void destroy();
-
-	void add(U4ZipPackage *package);
-	const Std::vector<U4ZipPackage *> &getPackages() const {
-		return _packages;
-	}
-
-private:
-	U4ZipPackageMgr();
-	~U4ZipPackageMgr();
-
-	static U4ZipPackageMgr *_instance;
-	Std::vector<U4ZipPackage *> _packages;
-};
-
-#ifdef putc
-#undef putc
-#endif
-#ifdef getc
-#undef getc
-#endif
-
 /**
  * Returns true if the upgrade is present.
  */
@@ -96,7 +42,6 @@ extern bool u4isUpgradeAvailable();
 extern bool u4isUpgradeInstalled();
 
 extern Common::File *u4fopen(const Common::String &fname);
-extern Common::File *u4fopen_zip(const Common::String &fname, Common::Archive *archive);
 extern void u4fclose(Common::File *f);
 extern int u4fseek(Common::File *f, long offset, int whence);
 extern long u4ftell(Common::File *f);
@@ -106,7 +51,6 @@ extern int u4fgetshort(Common::File *f);
 extern long u4flength(Common::File *f);
 extern Std::vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings);
 
-extern Common::String u4find_path(const Common::String &fname, Common::List<Common::String> specificSubPaths);
 extern Common::String u4find_music(const Common::String &fname);
 extern Common::String u4find_sound(const Common::String &fname);
 extern Common::String u4find_conf(const Common::String &fname);


Commit: 3e6d971a11aa13ce488a16d1a60d661c762a1681
    https://github.com/scummvm/scummvm/commit/3e6d971a11aa13ce488a16d1a60d661c762a1681
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Fix reading settings

Changed paths:
    engines/ultima/ultima4/core/settings.cpp


diff --git a/engines/ultima/ultima4/core/settings.cpp b/engines/ultima/ultima4/core/settings.cpp
index c83627d0de..76214bf24c 100644
--- a/engines/ultima/ultima4/core/settings.cpp
+++ b/engines/ultima/ultima4/core/settings.cpp
@@ -247,7 +247,7 @@ bool Settings::read() {
 
 	// graphics enhancements options
 	if (ConfMan.hasKey("renderTileTransparency"))
-		_enhancementsOptions._u4TileTransparencyHack = ConfMan.getBool("");
+		_enhancementsOptions._u4TileTransparencyHack = ConfMan.getBool("renderTileTransparency");
 	if (ConfMan.hasKey("transparentTilePixelShadowOpacity"))
 		_enhancementsOptions._u4TileTransparencyHackPixelShadowOpacity =
 			ConfMan.getInt("transparentTilePixelShadowOpacity");


Commit: 2148dee1c7e0e463eef323f52782f7c7def7ec0d
    https://github.com/scummvm/scummvm/commit/2148dee1c7e0e463eef323f52782f7c7def7ec0d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Further file cleanup

Changed paths:
    engines/ultima/ultima4/filesys/u4file.cpp
    engines/ultima/ultima4/filesys/u4file.h
    engines/ultima/ultima4/gfx/imagemgr.cpp
    engines/ultima/ultima4/gfx/screen.cpp


diff --git a/engines/ultima/ultima4/filesys/u4file.cpp b/engines/ultima/ultima4/filesys/u4file.cpp
index d436f52d09..4c281bb466 100644
--- a/engines/ultima/ultima4/filesys/u4file.cpp
+++ b/engines/ultima/ultima4/filesys/u4file.cpp
@@ -31,42 +31,6 @@
 namespace Ultima {
 namespace Ultima4 {
 
-using Std::map;
-using Common::String;
-using Std::vector;
-
-bool u4isUpgradeAvailable() {
-	Common::File *pal = u4fopen("u4vga.pal");
-	bool avail = pal != nullptr;
-	delete pal;
-
-	return avail;
-}
-
-bool u4isUpgradeInstalled() {
-	int filelength;
-	bool result = false;
-
-	Common::File *u4f = u4fopen("ega.drv");
-	if (u4f) {
-		filelength = u4f->size();
-		u4fclose(u4f);
-
-		// See if (ega.drv > 5k).  If so, the upgrade is installed
-		if (filelength > (5 * 1024))
-			result = true;
-	}
-
-	debug(1, "u4isUpgradeInstalled %d\n", (int) result);
-
-	return result;
-}
-
-/*-------------------------------------------------------------------*/
-
-/**
- * Open a data file
- */
 Common::File *u4fopen(const Common::String &fname) {
 	Common::File *u4f = nullptr;
 
@@ -83,12 +47,10 @@ Common::File *u4fopen(const Common::String &fname) {
 	return u4f;
 }
 
-/**
- * Closes a data file from the Ultima 4 for DOS installation.
- */
-void u4fclose(Common::File *f) {
+void u4fclose(Common::File *&f) {
 	f->close();
 	delete f;
+	f = nullptr;
 }
 
 int u4fseek(Common::File *f, long offset, int whence) {
@@ -112,22 +74,14 @@ int u4fgetshort(Common::File *f) {
 	return f->readUint16LE();
 }
 
-/**
- * Returns the length in bytes of a file.
- */
 long u4flength(Common::File *f) {
 	return f->size();
 }
 
-/**
- * Read a series of zero terminated strings from a file.  The strings
- * are read from the given offset, or the current file position if
- * offset is -1.
- */
-vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings) {
+Std::vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings) {
 	Common::String buffer;
 	int i;
-	vector<Common::String> strs;
+	Std::vector<Common::String> strs;
 
 	ASSERT(offset < u4flength(f), "offset begins beyond end of file");
 
diff --git a/engines/ultima/ultima4/filesys/u4file.h b/engines/ultima/ultima4/filesys/u4file.h
index 6be40387bd..8121a61681 100644
--- a/engines/ultima/ultima4/filesys/u4file.h
+++ b/engines/ultima/ultima4/filesys/u4file.h
@@ -31,24 +31,27 @@ namespace Ultima {
 namespace Ultima4 {
 
 /**
- * Returns true if the upgrade is present.
+ * Open a data file
  */
-extern bool u4isUpgradeAvailable();
+extern Common::File *u4fopen(const Common::String &fname);
 
 /**
- * Returns true if the upgrade is not only present, but is installed
- * (switch.bat or setup.bat has been run)
+ * Closes a data file from the Ultima 4 for DOS installation.
  */
-extern bool u4isUpgradeInstalled();
+extern void u4fclose(Common::File *&f);
 
-extern Common::File *u4fopen(const Common::String &fname);
-extern void u4fclose(Common::File *f);
 extern int u4fseek(Common::File *f, long offset, int whence);
 extern long u4ftell(Common::File *f);
 extern size_t u4fread(void *ptr, size_t size, size_t nmemb, Common::File *f);
 extern int u4fgetc(Common::File *f);
 extern int u4fgetshort(Common::File *f);
 extern long u4flength(Common::File *f);
+
+/**
+ * Read a series of zero terminated strings from a file.  The strings
+ * are read from the given offset, or the current file position if
+ * offset is -1.
+ */
 extern Std::vector<Common::String> u4read_stringtable(Common::File *f, long offset, int nstrings);
 
 extern Common::String u4find_music(const Common::String &fname);
diff --git a/engines/ultima/ultima4/gfx/imagemgr.cpp b/engines/ultima/ultima4/gfx/imagemgr.cpp
index b5de73fb68..199d80e2be 100644
--- a/engines/ultima/ultima4/gfx/imagemgr.cpp
+++ b/engines/ultima/ultima4/gfx/imagemgr.cpp
@@ -522,20 +522,6 @@ bool ImageMgr::imageExists(ImageInfo *info) {
 Common::File *ImageMgr::getImageFile(ImageInfo *info) {
 	Common::String filename = info->_filename;
 
-	/*
-	 * If the u4 VGA upgrade is installed (i.e. setup has been run and
-	 * the u4dos files have been renamed), we need to use VGA names
-	 * for EGA and vice versa, but *only* when the upgrade file has a
-	 * .old extention.  The charset and tiles have a .vga extention
-	 * and are not renamed in the upgrade installation process
-	 */
-	if (u4isUpgradeInstalled() && getInfoFromSet(info->_name, getSet("VGA"))->_filename.find(".old") != Common::String::npos) {
-		if (settings._videoType == "EGA")
-			filename = getInfoFromSet(info->_name, getSet("VGA"))->_filename;
-		else
-			filename = getInfoFromSet(info->_name, getSet("EGA"))->_filename;
-	}
-
 	if (filename == "")
 		return nullptr;
 
diff --git a/engines/ultima/ultima4/gfx/screen.cpp b/engines/ultima/ultima4/gfx/screen.cpp
index eb37bf972a..c62a36b570 100644
--- a/engines/ultima/ultima4/gfx/screen.cpp
+++ b/engines/ultima/ultima4/gfx/screen.cpp
@@ -94,11 +94,6 @@ void Screen::init() {
 
 	debug(1, "using %s scaler\n", settings._filter.c_str());
 
-	/* if we can't use vga, reset to default:ega */
-	if (!u4isUpgradeAvailable() && settings._videoType == "VGA")
-		settings._videoType = "EGA";
-
-
 	KeyHandler::setKeyRepeat(settings._keydelay, settings._keyinterval);
 
 	/* find the tile animations for our tileset */


Commit: 9be8f03725f3c3818d1c5b74d71f2e3f6f68b9dd
    https://github.com/scummvm/scummvm/commit/9be8f03725f3c3818d1c5b74d71f2e3f6f68b9dd
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Fix opening of .ega files

Changed paths:
    engines/ultima/ultima4/gfx/imagemgr.cpp


diff --git a/engines/ultima/ultima4/gfx/imagemgr.cpp b/engines/ultima/ultima4/gfx/imagemgr.cpp
index 199d80e2be..26b6acbdf9 100644
--- a/engines/ultima/ultima4/gfx/imagemgr.cpp
+++ b/engines/ultima/ultima4/gfx/imagemgr.cpp
@@ -522,20 +522,20 @@ bool ImageMgr::imageExists(ImageInfo *info) {
 Common::File *ImageMgr::getImageFile(ImageInfo *info) {
 	Common::String filename = info->_filename;
 
-	if (filename == "")
+	if (filename.empty())
 		return nullptr;
 
 	Common::File *file = nullptr;
-	if (info->_xu4Graphic) {
-		Common::String pathname(u4find_graphics(filename));
-
-		if (!pathname.empty())
-			file = u4fopen(pathname);
-	} else {
-		filename = u4find_graphics(filename);
+	if (!info->_xu4Graphic) {
+		// It's a file in the game folder
 		file = u4fopen(filename);
+		if (file)
+			return file;
 	}
 
+	Common::String pathname = u4find_graphics(filename);
+	file = u4fopen(pathname);
+
 	return file;
 }
 
@@ -555,9 +555,9 @@ ImageInfo *ImageMgr::get(const Common::String &name, bool returnUnscaled) {
 			info->_filetype = guessFileType(info->_filename);
 		Common::String filetype = info->_filetype;
 		ImageLoader *loader = g_ultima->_imageLoaders->getLoader(filetype);
-		if (loader == nullptr)
+		if (loader == nullptr) {
 			warning("can't find loader to load image \"%s\" with type \"%s\"", info->_filename.c_str(), filetype.c_str());
-		else {
+		} else {
 			unscaled = loader->load(file, info->_width, info->_height, info->_depth);
 			if (info->_width == -1) {
 				// Write in the values for later use.
@@ -566,6 +566,7 @@ ImageInfo *ImageMgr::get(const Common::String &name, bool returnUnscaled) {
 				// ###            info->depth = ???
 			}
 		}
+
 		u4fclose(file);
 	} else {
 		warning("Failed to open file %s for reading.", info->_filename.c_str());


Commit: 993ec0aaccce4bfddb3eede4280717865816d1f4
    https://github.com/scummvm/scummvm/commit/993ec0aaccce4bfddb3eede4280717865816d1f4
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Have a separate original vs enhanced detection entry

Changed paths:
    engines/ultima/detection.cpp
    engines/ultima/detection_tables.h
    engines/ultima/ultima4/core/settings.cpp
    engines/ultima/ultima4/core/settings.h


diff --git a/engines/ultima/detection.cpp b/engines/ultima/detection.cpp
index deb9c6998d..a886493ebe 100644
--- a/engines/ultima/detection.cpp
+++ b/engines/ultima/detection.cpp
@@ -41,6 +41,7 @@ namespace Ultima {
 static const PlainGameDescriptor ULTIMA_GAMES[] = {
 	{ "ultima1", "Ultima I - The First Age of Darkness" },
 	{ "ultima4", "Ultima IV - Quest of the Avatar" },
+	{ "ultima4_enh", "Ultima IV - Quest of the Avatar - Enhanced" },
 	{ "ultima6", "Ultima VI - The False Prophet" },
 	{ "ultima6_enh", "Ultima VI - The False Prophet - Enhanced" },
 	{ "ultima8", "Ultima VIII - Pagan" },
diff --git a/engines/ultima/detection_tables.h b/engines/ultima/detection_tables.h
index be014532f7..87d8a51ac4 100644
--- a/engines/ultima/detection_tables.h
+++ b/engines/ultima/detection_tables.h
@@ -74,6 +74,21 @@ static const UltimaGameDescription GAME_DESCRIPTIONS[] = {
 		0
 	},
 
+	{
+		// Ultima IV - Quest of the Avatar
+		{
+			"ultima4_enh",
+			0,
+			AD_ENTRY1s("britain.ult", "304fe52ce5f34b9181052363d74d7505", 1280),
+			Common::EN_ANY,
+			Common::kPlatformDOS,
+			ADGF_UNSTABLE,
+			GUIO0()
+		},
+		GAME_ULTIMA4,
+		GF_VGA_ENHANCED
+	},
+
 	// GOG Ultima VI
 	{
 		{
diff --git a/engines/ultima/ultima4/core/settings.cpp b/engines/ultima/ultima4/core/settings.cpp
index 76214bf24c..654e43d5f9 100644
--- a/engines/ultima/ultima4/core/settings.cpp
+++ b/engines/ultima/ultima4/core/settings.cpp
@@ -87,14 +87,6 @@ bool SettingsData::operator!=(const SettingsData &s) const {
 /*-------------------------------------------------------------------*/
 
 Settings::Settings() {
-	init();
-
-	_battleDiffs.push_back("Normal");
-	_battleDiffs.push_back("Hard");
-	_battleDiffs.push_back("Expert");
-}
-
-void Settings::init() {
 	read();
 }
 
@@ -168,6 +160,12 @@ bool Settings::read() {
 	_logging = DEFAULT_LOGGING;
 	_game = "Ultima IV";
 
+	_battleDiffs.push_back("Normal");
+	_battleDiffs.push_back("Hard");
+	_battleDiffs.push_back("Expert");
+
+	if (ConfMan.hasKey("video"))
+		_videoType = ConfMan.get("video");
 	if (ConfMan.hasKey("gemLayout"))
 		_gemLayout = ConfMan.get("gemLayout");
 	if (ConfMan.hasKey("lineOfSight"))
@@ -261,6 +259,7 @@ bool Settings::read() {
 }
 
 bool Settings::write() {
+	ConfMan.set("video", _videoType);
 	ConfMan.set("gemLayout", _gemLayout);
 	ConfMan.set("lineOfSight", _lineOfSight);
 	ConfMan.setBool("screenShakes", _screenShakes);
diff --git a/engines/ultima/ultima4/core/settings.h b/engines/ultima/ultima4/core/settings.h
index a594b98678..efe64986f9 100644
--- a/engines/ultima/ultima4/core/settings.h
+++ b/engines/ultima/ultima4/core/settings.h
@@ -46,7 +46,7 @@ namespace Ultima4 {
 #define DEFAULT_SCALE                   2
 #define DEFAULT_FULLSCREEN              0
 #define DEFAULT_FILTER                  "Scale2x"
-#define DEFAULT_VIDEO_TYPE              "new"
+#define DEFAULT_VIDEO_TYPE              (g_ultima->isEnhanced() ? "new" : "EGA")
 #define DEFAULT_GEM_LAYOUT              "Standard"
 #define DEFAULT_LINEOFSIGHT             "DOS"
 #define DEFAULT_SCREEN_SHAKES           1
@@ -169,11 +169,6 @@ class Settings : public SettingsData, public Observable<Settings *> {
 public:
 	/* Methods */
 
-	/**
-	 * Initialize the settings.
-	 */
-	void init();
-
 	/**
 	 * Return the global instance of settings.
 	 */


Commit: 067035a80dcf8cf8d6426c8a6215cbb8194ac914
    https://github.com/scummvm/scummvm/commit/067035a80dcf8cf8d6426c8a6215cbb8194ac914
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-19T15:28:57-07:00

Commit Message:
ULTIMA4: Cleanup and fixes for Initiate question sequence

Changed paths:
    engines/ultima/ultima4/controllers/controller.cpp
    engines/ultima/ultima4/controllers/controller.h
    engines/ultima/ultima4/controllers/intro_controller.cpp
    engines/ultima/ultima4/core/utils.cpp


diff --git a/engines/ultima/ultima4/controllers/controller.cpp b/engines/ultima/ultima4/controllers/controller.cpp
index 871ed53ba8..5f5c1bee13 100644
--- a/engines/ultima/ultima4/controllers/controller.cpp
+++ b/engines/ultima/ultima4/controllers/controller.cpp
@@ -22,6 +22,7 @@
 
 #include "ultima/ultima4/controllers/controller.h"
 #include "ultima/ultima4/events/event.h"
+#include "engines/engine.h"
 
 namespace Ultima {
 namespace Ultima4 {
@@ -58,6 +59,10 @@ void Controller::timerCallback(void *data) {
 	controller->timerFired();
 }
 
+bool Controller::shouldQuit() const {
+	return g_engine->shouldQuit();
+}
+
 void Controller_startWait() {
 	eventHandler->run();
 	eventHandler->setControllerDone(false);
diff --git a/engines/ultima/ultima4/controllers/controller.h b/engines/ultima/ultima4/controllers/controller.h
index 642c19f1f3..e448ec37f4 100644
--- a/engines/ultima/ultima4/controllers/controller.h
+++ b/engines/ultima/ultima4/controllers/controller.h
@@ -82,6 +82,10 @@ public:
 	 */
 	virtual void timerFired();
 
+	/**
+	 * Returns true if game should quit
+	 */
+	bool shouldQuit() const;
 private:
 	int _timerInterval;
 };
diff --git a/engines/ultima/ultima4/controllers/intro_controller.cpp b/engines/ultima/ultima4/controllers/intro_controller.cpp
index ccf0b67887..06a3fdacba 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.cpp
+++ b/engines/ultima/ultima4/controllers/intro_controller.cpp
@@ -186,19 +186,23 @@ bool IntroBinData::load() {
 	return true;
 }
 
-IntroController::IntroController() :
-	Controller(1),
-	_backgroundArea(),
-	_menuArea(1 * CHAR_WIDTH, 13 * CHAR_HEIGHT, 38, 11),
-	_extendedMenuArea(2 * CHAR_WIDTH, 10 * CHAR_HEIGHT, 36, 13),
-	_questionArea(INTRO_TEXT_X * CHAR_WIDTH, INTRO_TEXT_Y * CHAR_HEIGHT, INTRO_TEXT_WIDTH, INTRO_TEXT_HEIGHT),
-	_mapArea(BORDER_WIDTH, (TILE_HEIGHT * 6) + BORDER_HEIGHT, INTRO_MAP_WIDTH, INTRO_MAP_HEIGHT, "base"),
-	_binData(nullptr),
-	_titles(),                   // element list
-	_title(_titles.begin()),      // element iterator
-	_transparentIndex(13),       // palette index for transparency
-	_transparentColor(),         // palette color for transparency
-	_bSkipTitles(false) {
+IntroController::IntroController() : Controller(1),
+		_backgroundArea(),
+		_menuArea(1 * CHAR_WIDTH, 13 * CHAR_HEIGHT, 38, 11),
+		_extendedMenuArea(2 * CHAR_WIDTH, 10 * CHAR_HEIGHT, 36, 13),
+		_questionArea(INTRO_TEXT_X * CHAR_WIDTH, INTRO_TEXT_Y * CHAR_HEIGHT, INTRO_TEXT_WIDTH, INTRO_TEXT_HEIGHT),
+		_mapArea(BORDER_WIDTH, (TILE_HEIGHT * 6) + BORDER_HEIGHT, INTRO_MAP_WIDTH, INTRO_MAP_HEIGHT, "base"),
+		_binData(nullptr), _mode(INTRO_TITLES), _answerInd(0), _questionRound(0),
+		_beastie1Cycle(0), _beastie2Cycle(0), _beastieOffset(0),
+		_beastiesVisible(false), _sleepCycles(0), _scrPos(0),
+		_objectStateTable(nullptr), _justInitiatedNewGame(false),
+		_titles(),                   // element list
+		_title(_titles.begin()),     // element iterator
+		_transparentIndex(13),       // palette index for transparency
+		_transparentColor(),         // palette color for transparency
+		_bSkipTitles(false) {
+	Common::fill(&_questionTree[0], &_questionTree[15], -1);
+
 	// initialize menus
 	_confMenu.setTitle("XU4 Configuration:", 0, 0);
 	_confMenu.add(MI_CONF_VIDEO,               "\010 Video Options",              2,  2,/*'v'*/  2);
@@ -578,7 +582,7 @@ void IntroController::drawCard(int pos, int card) {
 	};
 
 	ASSERT(pos == 0 || pos == 1, "invalid pos: %d", pos);
-	ASSERT(card < 8, "invalid card: %d", card);
+	ASSERT(card >= 0 && card < 8, "invalid card: %d", card);
 
 	_backgroundArea.draw(cardNames[card], pos ? 218 : 12, 12);
 }
@@ -796,7 +800,7 @@ void IntroController::startQuestions() {
 	_questionRound = 0;
 	initQuestionTree();
 
-	while (1) {
+	while (!shouldQuit()) {
 		// draw the abacus background, if necessary
 		if (_questionRound == 0)
 			_backgroundArea.draw(BKGD_ABACUS);
@@ -1242,25 +1246,20 @@ void IntroController::updateInterfaceMenu(MenuEvent &event) {
 }
 
 void IntroController::initQuestionTree() {
-	int i, tmp, r;
+	int i, r;
 
 	for (i = 0; i < 8; i++)
 		_questionTree[i] = i;
 
 	for (i = 0; i < 8; i++) {
 		r = xu4_random(8);
-		tmp = _questionTree[r];
-		_questionTree[r] = _questionTree[i];
-		_questionTree[i] = tmp;
+		SWAP(_questionTree[r], _questionTree[i]);
 	}
 	_answerInd = 8;
 
 	if (_questionTree[0] > _questionTree[1]) {
-		tmp = _questionTree[0];
-		_questionTree[0] = _questionTree[1];
-		_questionTree[1] = tmp;
+		SWAP(_questionTree[0], _questionTree[1]);
 	}
-
 }
 
 bool IntroController::doQuestion(int answer) {
@@ -1279,9 +1278,8 @@ bool IntroController::doQuestion(int answer) {
 		return true;
 
 	if (_questionTree[_questionRound * 2] > _questionTree[_questionRound * 2 + 1]) {
-		int tmp = _questionTree[_questionRound * 2];
-		_questionTree[_questionRound * 2] = _questionTree[_questionRound * 2 + 1];
-		_questionTree[_questionRound * 2 + 1] = tmp;
+		SWAP(_questionTree[_questionRound * 2],
+			_questionTree[_questionRound * 2 + 1]);
 	}
 
 	return false;
diff --git a/engines/ultima/ultima4/core/utils.cpp b/engines/ultima/ultima4/core/utils.cpp
index 16be7b780f..02b65c035c 100644
--- a/engines/ultima/ultima4/core/utils.cpp
+++ b/engines/ultima/ultima4/core/utils.cpp
@@ -41,7 +41,12 @@ void xu4_srandom() {
 }
 
 int xu4_random(int upperRange) {
-	return g_ultima->getRandomNumber(upperRange);
+	if (upperRange == 0) {
+		warning("No upper range specified");
+		return 0;
+	}
+
+	return g_ultima->getRandomNumber(upperRange - 1);
 }
 
 Common::String &trim(Common::String &val, const Common::String &chars_to_trim) {




More information about the Scummvm-git-logs mailing list