[Scummvm-git-logs] scummvm master -> 72a4186417b152c09cfb5cd029fadfcba35de540

athrxx noreply at scummvm.org
Mon May 20 15:48:13 UTC 2024


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

Summary:
72a4186417 SCUMM: (INDY3) - iq points fix


Commit: 72a4186417b152c09cfb5cd029fadfcba35de540
    https://github.com/scummvm/scummvm/commit/72a4186417b152c09cfb5cd029fadfcba35de540
Author: athrxx (athrxx at scummvm.org)
Date: 2024-05-20T17:47:43+02:00

Commit Message:
SCUMM: (INDY3) - iq points fix

(the engine would write the episode iq data into the series iq file)

Changed paths:
    engines/scumm/script_v4.cpp
    engines/scumm/scumm_v4.h


diff --git a/engines/scumm/script_v4.cpp b/engines/scumm/script_v4.cpp
index 3386193b6ac..47e35f2278c 100644
--- a/engines/scumm/script_v4.cpp
+++ b/engines/scumm/script_v4.cpp
@@ -178,7 +178,9 @@ void ScummEngine_v4::saveVars() {
 
 			if (a == STRINGID_IQ_EPISODE && b == STRINGID_IQ_EPISODE) {
 				if (_game.id == GID_INDY3) {
-					saveIQPoints();
+					// TODO: check what's supposed to happen here. Writing the episode IQ points
+					// into the series iq file is probably not correct.
+					saveIQPoints(0, 0);
 				}
 				break;
 			}
@@ -290,7 +292,6 @@ void ScummEngine_v4::loadVars() {
  * directly is not possible. The other scripts depend on script-9.
  */
 void ScummEngine_v4::updateIQPoints() {
-	int seriesIQ;
 	// IQString[0..72] corresponds to each puzzle's IQ.
 	// IQString[73] indicates that the IQ-file was loaded successfully and is always 0 when
 	// the IQ is calculated, hence it will be ignored here.
@@ -314,20 +315,23 @@ void ScummEngine_v4::updateIQPoints() {
 		return;
 
 	// merge episode and series IQ strings and calculate series IQ
-	seriesIQ = 0;
+	int seriesIQ = 0;
+	int episodeIQ = 0;
 	// iterate over puzzles
 	for (int i = 0; i < NUM_PUZZLES; ++i) {
-		byte puzzleIQ = seriesIQString[i];
-		// if puzzle is solved copy points to episode string
-		if (puzzleIQ > 0)
-			episodeIQString[i] = puzzleIQ;
-		// add puzzle's IQ-points to series IQ
-		seriesIQ += episodeIQString[i];
+		if (episodeIQString[i] != 0 && episodeIQString[i] != 0x40) {
+			seriesIQString[i] = episodeIQString[i];
+			episodeIQ += episodeIQString[i];
+		}
+		if (seriesIQString[i] != 0 && seriesIQString[i] != 0x40)
+			seriesIQ += seriesIQString[i];
 	}
+
+	_scummVars[244] = episodeIQ;
 	_scummVars[245] = seriesIQ;
 
 	// save series IQ string
-	saveIQPoints();
+	saveIQPoints(seriesIQString, sizeof(seriesIQString));
 }
 
 void ScummEngine_v4::clearSeriesIQPoints() {
@@ -347,18 +351,21 @@ void ScummEngine_v4::clearSeriesIQPoints() {
 	}
 }
 
-void ScummEngine_v4::saveIQPoints() {
+void ScummEngine_v4::saveIQPoints(const byte *ptr, int size) {
 	// save Indy3 IQ-points
 	Common::OutSaveFile *file;
 	Common::String filename = _targetName + ".iq";
 
 	file = _saveFileMan->openForSaving(filename);
 	if (file != nullptr) {
-		byte *ptr = getResourceAddress(rtString, STRINGID_IQ_EPISODE);
-		if (ptr) {
-			int size = getResourceSize(rtString, STRINGID_IQ_EPISODE);
-			file->write(ptr, size);
+		if (!ptr || !size) {
+			// I don't see how this could ever be correct, but I leave it as  I found it for now...
+			ptr = getResourceAddress(rtString, STRINGID_IQ_EPISODE);
+			if (ptr)
+				size = getResourceSize(rtString, STRINGID_IQ_EPISODE);
 		}
+		if (ptr && size)
+			file->write(ptr, size);
 		delete file;
 	}
 }
diff --git a/engines/scumm/scumm_v4.h b/engines/scumm/scumm_v4.h
index 9c77b029ca0..c9bdd313e35 100644
--- a/engines/scumm/scumm_v4.h
+++ b/engines/scumm/scumm_v4.h
@@ -58,7 +58,7 @@ protected:
 
 	void saveVars();
 	void loadVars();
-	void saveIQPoints();
+	void saveIQPoints(const byte *ptr, int size);
 	void loadIQPoints(byte *ptr, int size);
 
 	int getBannerColor(int bannerId) override;




More information about the Scummvm-git-logs mailing list