[Scummvm-git-logs] scummvm master -> 942303bbc6a002e0557f7939521d8f57d29ac76f

sluicebox noreply at scummvm.org
Sat Mar 9 16:09:30 UTC 2024


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

Summary:
c3325f25bd AGI: Console cleanup
aabb7b4c30 AGI: Bool usage
065d049008 AGI: op_cmd cleanup
d6c220896e AGI: Misc cleaup
942303bbc6 AGI: Fix KQ3 infinite falling


Commit: c3325f25bd59907f6c22c6c15ddae461e4f0b5ee
    https://github.com/scummvm/scummvm/commit/c3325f25bd59907f6c22c6c15ddae461e4f0b5ee
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-03-09T09:07:59-07:00

Commit Message:
AGI: Console cleanup

Changed paths:
    engines/agi/console.cpp


diff --git a/engines/agi/console.cpp b/engines/agi/console.cpp
index 7d4619759ce..b924f20b6e3 100644
--- a/engines/agi/console.cpp
+++ b/engines/agi/console.cpp
@@ -58,7 +58,7 @@ Console::Console(AgiEngine *vm) : GUI::Debugger() {
 
 bool Console::Cmd_SetVar(int argc, const char **argv) {
 	if (argc != 3) {
-		debugPrintf("Usage: setvar <varnum> <value>\n");
+		debugPrintf("Usage: %s <varnum> <value>\n", argv[0]);
 		return true;
 	}
 	int p1 = (int)atoi(argv[1]);
@@ -70,19 +70,19 @@ bool Console::Cmd_SetVar(int argc, const char **argv) {
 
 bool Console::Cmd_SetFlag(int argc, const char **argv) {
 	if (argc != 3) {
-		debugPrintf("Usage: setvar <varnum> <value>\n");
+		debugPrintf("Usage: %s <flagnum> <value>\n", argv[0]);
 		return true;
 	}
 	int p1 = (int)atoi(argv[1]);
 	int p2 = (int)atoi(argv[2]);
-	_vm->setFlag(p1, !!p2);
+	_vm->setFlag(p1, (p2 != 0));
 
 	return true;
 }
 
 bool Console::Cmd_SetObj(int argc, const char **argv) {
 	if (argc != 3) {
-		debugPrintf("Usage: setvar <varnum> <value>\n");
+		debugPrintf("Usage: %s <objnum> <location>\n", argv[0]);
 		return true;
 	}
 	int p1 = (int)atoi(argv[1]);
@@ -96,7 +96,7 @@ bool Console::Cmd_RunOpcode(int argc, const char **argv) {
 	const AgiOpCodeEntry *opCodes = _vm->getOpCodesTable();
 
 	if (argc < 2) {
-		debugPrintf("Usage: runopcode <name> <parameter0> ....\n");
+		debugPrintf("Usage: %s <name> <parameter0> ...\n", argv[0]);
 		return true;
 	}
 
@@ -104,7 +104,7 @@ bool Console::Cmd_RunOpcode(int argc, const char **argv) {
 		if (!strcmp(argv[1], opCodes[i].name)) {
 			uint8 p[16];
 			if ((argc - 2) != opCodes[i].parameterSize) {
-				debugPrintf("AGI command wants %d arguments\n", opCodes[i].parameterSize);
+				debugPrintf("AGI opcode wants %d parameters\n", opCodes[i].parameterSize);
 				return 0;
 			}
 			p[0] = argv[2] ? (char)strtoul(argv[2], nullptr, 0) : 0;
@@ -127,11 +127,9 @@ bool Console::Cmd_RunOpcode(int argc, const char **argv) {
 }
 
 bool Console::Cmd_Agiver(int argc, const char **argv) {
-	int ver, maj, min;
-
-	ver = _vm->getVersion();
-	maj = (ver >> 12) & 0xf;
-	min = ver & 0xfff;
+	int ver = _vm->getVersion();
+	int maj = (ver >> 12) & 0xf;
+	int min = ver & 0xfff;
 
 	debugPrintf("AGI version: ");
 	debugPrintf(maj <= 2 ? "%x.%03x\n" : "%x.002.%03x\n", maj, min);
@@ -143,20 +141,6 @@ bool Console::Cmd_Agiver(int argc, const char **argv) {
 
 bool Console::Cmd_Version(int argc, const char **argv) {
 	AgiGame *game = &_vm->_game;
-	int scriptNr = 0;
-	int scriptTextCount = 0;
-	int scriptTextNr = 0;
-	const char *scriptTextPtr = nullptr;
-	const char *wordScanPtr = nullptr;
-	const char *wordStartPtr = nullptr;
-	const char *versionStartPtr = nullptr;
-	int wordLen = 0;
-	char curChar = 0;
-	int versionLen = 0;
-	bool wordFound = false;
-	bool versionFound = false;
-	char versionString[CONSOLE_VERSION_MAXLEN];
-	bool scriptLoadedByUs = false;
 
 	// Show AGI version
 	Cmd_Agiver(argc, argv);
@@ -164,114 +148,119 @@ bool Console::Cmd_Version(int argc, const char **argv) {
 	// And now try to figure out the version of the game
 	// We do this by scanning through all script texts
 	// This is the best we can do about it. There is no special location for the game version number.
-	// There are multiple variations, like "ver. X.XX", "ver X.XX" and even "verion X.XX".
-	for (scriptNr = 0; scriptNr < MAX_DIRECTORY_ENTRIES; scriptNr++) {
-		if (game->dirLogic[scriptNr].offset != _EMPTY) {
-			// Script is supposed to exist?
-			scriptLoadedByUs = false;
-			if (!(game->dirLogic[scriptNr].flags & RES_LOADED)) {
-				// But not currently loaded? -> load it now
-				if (_vm->agiLoadResource(RESOURCETYPE_LOGIC, scriptNr) != errOK) {
-					// In case we can't load the source, skip it
-					continue;
-				}
-				scriptLoadedByUs = true;
+	// There are multiple variations, like "ver. X.XX", "ver X.XX" and even "version X.XX".
+	bool versionFound = false;
+	for (int scriptNr = 0; scriptNr < MAX_DIRECTORY_ENTRIES; scriptNr++) {
+		if (game->dirLogic[scriptNr].offset == _EMPTY) {
+			continue;
+		}
+			
+		// Script is supposed to exist?
+		bool scriptLoadedByUs = false;
+		if (!(game->dirLogic[scriptNr].flags & RES_LOADED)) {
+			// But not currently loaded? -> load it now
+			if (_vm->agiLoadResource(RESOURCETYPE_LOGIC, scriptNr) != errOK) {
+				// In case we can't load the source, skip it
+				continue;
 			}
-			// Script currently loaded
-			// Now scan all texts
-			scriptTextCount = game->logics[scriptNr].numTexts;
-			for (scriptTextNr = 0; scriptTextNr < scriptTextCount; scriptTextNr++) {
-				scriptTextPtr = game->logics[scriptNr].texts[scriptTextNr];
-
-				// Now scan this text for version information
-				wordScanPtr = scriptTextPtr;
-
-				do {
-					curChar = *wordScanPtr;
+			scriptLoadedByUs = true;
+		}
+		// Script currently loaded
+		// Now scan all texts
+		int scriptTextCount = game->logics[scriptNr].numTexts;
+		for (int scriptTextNr = 0; scriptTextNr < scriptTextCount; scriptTextNr++) {
+			const char *scriptTextPtr = game->logics[scriptNr].texts[scriptTextNr];
+
+			// Now scan this text for version information
+			const char *wordScanPtr = scriptTextPtr;
+
+			char curChar;
+			do {
+				curChar = *wordScanPtr;
+
+				if ((curChar == 'V') || (curChar == 'v')) {
+					// "V" gefunden, ggf. beginning of version?
+					const char *wordStartPtr = wordScanPtr;
+					bool wordFound = false;
+
+					do {
+						curChar = *wordScanPtr;
+						if (curChar == ' ') {
+							break;
+						}
+						wordScanPtr++;
+					} while (curChar);
+
+					if (curChar) {
+						// end of "version" found
+						int wordLen = wordScanPtr - wordStartPtr;
+
+						if (wordLen >= 3) {
+							if (strncmp(wordStartPtr, "ver", wordLen) == 0)
+								wordFound = true;
+							if (strncmp(wordStartPtr, "Ver", wordLen) == 0)
+								wordFound = true;
+						}
+						if ((!wordFound) && (wordLen >= 4)) {
+							if (strncmp(wordStartPtr, "ver.", wordLen) == 0)
+								wordFound = true;
+							if (strncmp(wordStartPtr, "Ver.", wordLen) == 0)
+								wordFound = true;
+						}
+						if ((!versionFound) && (wordLen >= 7)) {
+							if (strncmp(wordStartPtr, "version", wordLen) == 0)
+								wordFound = true;
+							if (strncmp(wordStartPtr, "Version", wordLen) == 0)
+								wordFound = true;
+							if (strncmp(wordStartPtr, "VERSION", wordLen) == 0)
+								wordFound = true;
+						}
 
-					if ((curChar == 'V') || (curChar == 'v')) {
-						// "V" gefunden, ggf. beginning of version?
-						wordStartPtr = wordScanPtr;
-						wordFound = false;
+						if (wordFound) {
+							// We found something interesting
+							//debugPrintf("%d: %s\n", scriptNr, scriptTextPtr);
 
-						do {
+							wordScanPtr++; // skip space
+							const char*versionStartPtr = wordScanPtr;
 							curChar = *wordScanPtr;
-							if (curChar == ' ') {
-								break;
-							}
-							wordScanPtr++;
-						} while (curChar);
-
-						if (curChar) {
-							// end of "version" found
-							wordLen = wordScanPtr - wordStartPtr;
-
-							if (wordLen >= 3) {
-								if (strncmp(wordStartPtr, "ver", wordLen) == 0)
-									wordFound = true;
-								if (strncmp(wordStartPtr, "Ver", wordLen) == 0)
-									wordFound = true;
-							}
-							if ((!wordFound) && (wordLen >= 4)) {
-								if (strncmp(wordStartPtr, "ver.", wordLen) == 0)
-									wordFound = true;
-								if (strncmp(wordStartPtr, "Ver.", wordLen) == 0)
-									wordFound = true;
-							}
-							if ((!versionFound) && (wordLen >= 7)) {
-								if (strncmp(wordStartPtr, "version", wordLen) == 0)
-									wordFound = true;
-								if (strncmp(wordStartPtr, "Version", wordLen) == 0)
-									wordFound = true;
-								if (strncmp(wordStartPtr, "VERSION", wordLen) == 0)
-									wordFound = true;
-							}
-
-							if (wordFound) {
-								// We found something interesting
-								//debugPrintf("%d: %s\n", scriptNr, scriptTextPtr);
-
-								wordScanPtr++; // skip space
-								versionStartPtr = wordScanPtr;
+							if ((curChar >= '0') && (curChar <= '9')) {
+								// Next word starts with a number
+								wordScanPtr++;
 								curChar = *wordScanPtr;
-								if ((curChar >= '0') && (curChar <= '9')) {
-									// Next word starts with a number
+								if (curChar == '.') {
+									// Followed by a point? then we assume that we found a version number
+									// Now we try to find the end of it
 									wordScanPtr++;
-									curChar = *wordScanPtr;
-									if (curChar == '.') {
-										// Followed by a point? then we assume that we found a version number
-										// Now we try to find the end of it
+									do {
+										curChar = *wordScanPtr;
+										if ((curChar == ' ') || (curChar == '\\') || (!curChar))
+											break; // space or potential new line or NUL? -> found the end
 										wordScanPtr++;
-										do {
-											curChar = *wordScanPtr;
-											if ((curChar == ' ') || (curChar == '\\') || (!curChar))
-												break; // space or potential new line or NUL? -> found the end
-											wordScanPtr++;
-										} while (1);
-
-										versionLen = wordScanPtr - versionStartPtr;
-										if (versionLen < CONSOLE_VERSION_MAXLEN) {
-											// Looks fine, now extract and show it
-											memcpy(versionString, versionStartPtr, versionLen);
-											versionString[versionLen] = 0;
-											debugPrintf("Scanned game version: %s\n", versionString);
-											versionFound = true;
-										}
+									} while (1);
+
+									int versionLen = wordScanPtr - versionStartPtr;
+									if (versionLen < CONSOLE_VERSION_MAXLEN) {
+										// Looks fine, now extract and show it
+										char versionString[CONSOLE_VERSION_MAXLEN];
+										memcpy(versionString, versionStartPtr, versionLen);
+										versionString[versionLen] = 0;
+										debugPrintf("Scanned game version: %s\n", versionString);
+										versionFound = true;
 									}
 								}
 							}
 						}
-
-						// Seek back
-						wordScanPtr = wordStartPtr;
 					}
-					wordScanPtr++;
-				} while (curChar);
-			}
 
-			if (scriptLoadedByUs) {
-				_vm->agiUnloadResource(RESOURCETYPE_LOGIC, scriptNr);
-			}
+					// Seek back
+					wordScanPtr = wordStartPtr;
+				}
+				wordScanPtr++;
+			} while (curChar);
+		}
+
+		if (scriptLoadedByUs) {
+			_vm->agiUnloadResource(RESOURCETYPE_LOGIC, scriptNr);
 		}
 	}
 
@@ -282,16 +271,14 @@ bool Console::Cmd_Version(int argc, const char **argv) {
 }
 
 bool Console::Cmd_Flags(int argc, const char **argv) {
-	int i, j;
-
 	debugPrintf("    ");
-	for (j = 0; j < 10; j++)
-		debugPrintf("%d ", j);
+	for (int i = 0; i < 10; i++)
+		debugPrintf("%d ", i);
 	debugPrintf("\n");
 
-	for (i = 0; i < 255;) {
+	for (int i = 0; i < 255;) {
 		debugPrintf("%3d ", i);
-		for (j = 0; j < 10; j++, i++) {
+		for (int j = 0; j < 10; j++, i++) {
 			debugPrintf("%c ", _vm->getFlag(i) ? 'T' : 'F');
 		}
 		debugPrintf("\n");
@@ -301,10 +288,8 @@ bool Console::Cmd_Flags(int argc, const char **argv) {
 }
 
 bool Console::Cmd_Vars(int argc, const char **argv) {
-	int i, j;
-
-	for (i = 0; i < 255;) {
-		for (j = 0; j < 5; j++, i++) {
+	for (int i = 0; i < 255;) {
+		for (int j = 0; j < 5; j++, i++) {
 			debugPrintf("%03d:%3d ", i, _vm->getVar(i));
 		}
 		debugPrintf("\n");
@@ -314,9 +299,7 @@ bool Console::Cmd_Vars(int argc, const char **argv) {
 }
 
 bool Console::Cmd_Objs(int argc, const char **argv) {
-	unsigned int i;
-
-	for (i = 0; i < _vm->_game.numObjects; i++) {
+	for (unsigned int i = 0; i < _vm->_game.numObjects; i++) {
 		debugPrintf("%3d]%-24s(%3d)\n", i, _vm->objectName(i), _vm->objectGetLocation(i));
 	}
 
@@ -325,7 +308,7 @@ bool Console::Cmd_Objs(int argc, const char **argv) {
 
 bool Console::Cmd_Opcode(int argc, const char **argv) {
 	if (argc != 2 || (strcmp(argv[1], "on") && strcmp(argv[1], "off"))) {
-		debugPrintf("Usage: opcode on|off\n");
+		debugPrintf("Usage: %s on|off\n", argv[0]);
 		return true;
 	}
 
@@ -336,7 +319,7 @@ bool Console::Cmd_Opcode(int argc, const char **argv) {
 
 bool Console::Cmd_Logic0(int argc, const char **argv) {
 	if (argc != 2 || (strcmp(argv[1], "on") && strcmp(argv[1], "off"))) {
-		debugPrintf("Usage: logic0 on|off\n");
+		debugPrintf("Usage: %s on|off\n", argv[0]);
 		return true;
 	}
 
@@ -347,7 +330,7 @@ bool Console::Cmd_Logic0(int argc, const char **argv) {
 
 bool Console::Cmd_Trigger(int argc, const char **argv) {
 	if (argc != 2 || (strcmp(argv[1], "on") && strcmp(argv[1], "off"))) {
-		debugPrintf("Usage: trigger on|off\n");
+		debugPrintf("Usage: %s on|off\n", argv[0]);
 		return true;
 	}
 	_vm->_debug.ignoretriggers = strcmp(argv[1], "on");
@@ -397,16 +380,13 @@ bool Console::Cmd_BT(int argc, const char **argv) {
 
 	debugPrintf("Current script: %d\nStack depth: %d\n", _vm->_game.curLogicNr, _vm->_game.execStack.size());
 
-	uint8 *code = nullptr;
-	uint8 op = 0;
 	uint8 p[CMD_BSIZE] = { 0 };
-	int parameterSize;
 	Common::Array<ScriptPos>::iterator it;
 
 	for (it = _vm->_game.execStack.begin(); it != _vm->_game.execStack.end(); ++it) {
-		code = _vm->_game.logics[it->script].data;
-		op = code[it->curIP];
-		parameterSize = opCodes[op].parameterSize;
+		uint8 *code = _vm->_game.logics[it->script].data;
+		uint8 op = code[it->curIP];
+		int parameterSize = opCodes[op].parameterSize;
 		memmove(p, &code[it->curIP], parameterSize);
 		memset(p + parameterSize, 0, CMD_BSIZE - parameterSize);
 
@@ -459,7 +439,7 @@ bool Console::Cmd_ScreenObj(int argc, const char **argv) {
 		ScreenObjEntry *screenObj = &_vm->_game.screenObjTable[screenObjNr];
 
 		debugPrintf("Screen Object ID %d\n", screenObj->objectNr);
-		debugPrintf("current view: %d, loop: %d, cel: %d\n", screenObj->currentViewNr, screenObj->currentLoopNr, screenObj->currentCelNr);
+		debugPrintf("view: %d, loop: %d, cel: %d\n", screenObj->currentViewNr, screenObj->currentLoopNr, screenObj->currentCelNr);
 
 		// Figure out flags
 		Common::String flagsString;
@@ -507,32 +487,32 @@ bool Console::Cmd_ScreenObj(int argc, const char **argv) {
 		debugPrintf("xPos: %d, yPos: %d, xSize: %d, ySize: %d\n", screenObj->xPos, screenObj->yPos, screenObj->xSize, screenObj->ySize);
 		debugPrintf("previous: xPos: %d, yPos: %d, xSize: %d, ySize: %d\n", screenObj->xPos_prev, screenObj->yPos_prev, screenObj->xSize_prev, screenObj->ySize_prev);
 		debugPrintf("direction: %d, priority: %d\n", screenObj->direction, screenObj->priority);
-		debugPrintf("stepTime: %d, timeCount: %d, size: %d\n", screenObj->stepTime, screenObj->stepTimeCount, screenObj->stepSize);
-		debugPrintf("cycleTime: %d, timeCount: %d\n", screenObj->cycleTime, screenObj->cycleTimeCount);
+		debugPrintf("stepTime: %d, stepTimeCount: %d, stepSize: %d\n", screenObj->stepTime, screenObj->stepTimeCount, screenObj->stepSize);
+		debugPrintf("cycleTime: %d, cycleTimeCount: %d\n", screenObj->cycleTime, screenObj->cycleTimeCount);
 
 		switch (screenObj->motionType) {
 		case kMotionNormal:
-			debugPrintf("motion: normal\n");
+			debugPrintf("\nmotion: normal\n");
 			break;
 		case kMotionWander:
-			debugPrintf("motion: wander\n");
+			debugPrintf("\nmotion: wander\n");
 			debugPrintf("wanderCount: %d\n", screenObj->wander_count);
 			break;
 		case kMotionFollowEgo:
-			debugPrintf("motion: follow ego\n");
-			debugPrintf("stepSize: %d, flag: %x, count: %d", screenObj->follow_stepSize, screenObj->follow_flag, screenObj->follow_count);
+			debugPrintf("\nmotion: follow ego\n");
+			debugPrintf("stepSize: %d, flag: %d, count: %d", screenObj->follow_stepSize, screenObj->follow_flag, screenObj->follow_count);
 			break;
 		case kMotionMoveObj:
 		case kMotionEgo:
 			if (screenObj->motionType == kMotionMoveObj) {
-				debugPrintf("motion: move obj\n");
+				debugPrintf("\nmotion: move obj\n");
 			} else {
-				debugPrintf("motion: ego\n");
+				debugPrintf("\nmotion: ego\n");
 			}
 			debugPrintf("x: %d, y: %d, stepSize: %d, flag: %x\n", screenObj->move_x, screenObj->move_y, screenObj->move_stepSize, screenObj->move_flag);
 			break;
 		default:
-			debugPrintf("motion: UNKNOWN (%d)\n", screenObj->motionType);
+			debugPrintf("\nmotion: UNKNOWN (%d)\n", screenObj->motionType);
 			break;
 		}
 	}
@@ -601,7 +581,7 @@ bool Console::Cmd_VmFlags(int argc, const char **argv) {
 			return true;
 
 		if ((newFlagState != 0) && (newFlagState != 1)) {
-			debugPrintf("new state must bei either 0 or 1\n");
+			debugPrintf("new state must be either 0 or 1\n");
 			return true;
 		}
 


Commit: aabb7b4c30810b1963b0f55ff6a281e2dd168d41
    https://github.com/scummvm/scummvm/commit/aabb7b4c30810b1963b0f55ff6a281e2dd168d41
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-03-09T09:07:59-07:00

Commit Message:
AGI: Bool usage

Changed paths:
    engines/agi/agi.h
    engines/agi/checks.cpp
    engines/agi/op_test.cpp


diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 7f97fdf5197..5caad387247 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -454,7 +454,7 @@ struct AgiGame {
 	bool mouseHidden;               /**< if mouse is currently hidden */
 
 	// IF condition handling
-	int testResult;
+	bool testResult;
 
 	int max_logics;
 	int logic_list[256];
@@ -555,7 +555,7 @@ struct AgiGame {
 		mouseEnabled = false;
 		mouseHidden = false;
 
-		testResult = 0;
+		testResult = false;
 
 		max_logics = 0;
 		for (uint16 i = 0; i < ARRAYSIZE(logic_list); i++) {
@@ -947,13 +947,13 @@ public:
 	// Some submethods of testIfCode
 	void skipInstruction(byte op);
 	void skipInstructionsUntil(byte v);
-	uint8 testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
-	uint8 testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
-	uint8 testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
-	uint8 testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
-	uint8 testSaid(uint8 nwords, uint8 *cc);
-	uint8 testController(uint8 cont);
-	uint8 testCompareStrings(uint8 s1, uint8 s2);
+	bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
+	bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
+	bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
+	bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
+	bool testSaid(uint8 nwords, uint8 *cc);
+	bool testController(uint8 cont);
+	bool testCompareStrings(uint8 s1, uint8 s2);
 
 	// View
 private:
diff --git a/engines/agi/checks.cpp b/engines/agi/checks.cpp
index 4a4060a898b..4c9c0affa69 100644
--- a/engines/agi/checks.cpp
+++ b/engines/agi/checks.cpp
@@ -162,8 +162,8 @@ bool AgiEngine::checkPriority(ScreenObjEntry *screenObj) {
 
 	// Check ego
 	if (screenObj->objectNr == 0) {
-		setFlag(VM_FLAG_EGO_TOUCHED_P2, touchedTrigger ? true : false);
-		setFlag(VM_FLAG_EGO_WATER, touchedWater ? true : false);
+		setFlag(VM_FLAG_EGO_TOUCHED_P2, touchedTrigger);
+		setFlag(VM_FLAG_EGO_WATER, touchedWater);
 	}
 
 	return touchedControl;
diff --git a/engines/agi/op_test.cpp b/engines/agi/op_test.cpp
index 61df9e51833..e9765c70e8a 100644
--- a/engines/agi/op_test.cpp
+++ b/engines/agi/op_test.cpp
@@ -90,7 +90,7 @@ void condIsSetV(AgiGame *state, AgiEngine *vm, uint8 *p) {
 void condIsSetV1(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	uint16 varNr = p[0];
 	uint16 varVal = vm->getVar(varNr);
-	state->testResult = varVal > 0;
+	state->testResult = (varVal > 0);
 }
 
 void condHas(AgiGame *state, AgiEngine *vm, uint8 *p) {
@@ -121,7 +121,7 @@ void condController(AgiGame *state, AgiEngine *vm, uint8 *p) {
 void condHaveKey(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	// Only check for key when there is not already one set by scripts
 	if (vm->getVar(VM_VAR_KEY)) {
-		state->testResult = 1;
+		state->testResult = true;
 		return;
 	}
 	// we are not really an inner loop, but we stop processAGIEvents() from doing regular cycle work by setting it up
@@ -131,15 +131,14 @@ void condHaveKey(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	if (key) {
 		debugC(5, kDebugLevelInput, "keypress = %02x", key);
 		vm->setVar(VM_VAR_KEY, key);
-		state->testResult = 1;
+		state->testResult = true;
 		return;
 	}
-	state->testResult = 0;
+	state->testResult = false;
 }
 
 void condSaid(AgiGame *state, AgiEngine *vm, uint8 *p) {
-	int ec = vm->testSaid(p[0], p + 1);
-	state->testResult = ec;
+	state->testResult = vm->testSaid(p[0], p + 1);
 }
 
 void condSaid1(AgiGame *state, AgiEngine *vm, uint8 *p) {
@@ -188,7 +187,7 @@ void condBit(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	uint16 value1 = p[0];
 	uint16 varNr2 = p[1];
 	uint16 varVal2 = vm->getVar(varNr2);
-	state->testResult = (varVal2 >> value1) & 1;
+	state->testResult = (((varVal2 >> value1) & 1) == 1);
 }
 
 void condCompareStrings(AgiGame *state, AgiEngine *vm, uint8 *p) {
@@ -215,9 +214,9 @@ void condUnknown13(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	// This command is used at least in the Amiga version of Gold Rush! v2.05 1989-03-09
 	// (AGI 2.316) in logics 1, 3, 5, 6, 137 and 192 (Logic.192 revealed this command's nature).
 	// TODO: Check this command's implementation using disassembly just to be sure.
-	int ec = state->screenObjTable[SCREENOBJECTS_EGO_ENTRY].flags & fAdjEgoXY;
-	debugC(7, kDebugLevelScripts, "op_test: in.motion.using.mouse = %s (Amiga-specific testcase 19)", ec ? "true" : "false");
-	state->testResult = ec;
+	bool r = ((state->screenObjTable[SCREENOBJECTS_EGO_ENTRY].flags & fAdjEgoXY) == fAdjEgoXY);
+	debugC(7, kDebugLevelScripts, "op_test: in.motion.using.mouse = %s (Amiga-specific testcase 19)", r ? "true" : "false");
+	state->testResult = r;
 }
 
 void condUnknown(AgiGame *state, AgiEngine *vm, uint8 *p) {
@@ -225,7 +224,7 @@ void condUnknown(AgiGame *state, AgiEngine *vm, uint8 *p) {
 	state->testResult = false;
 }
 
-uint8 AgiEngine::testCompareStrings(uint8 s1, uint8 s2) {
+bool AgiEngine::testCompareStrings(uint8 s1, uint8 s2) {
 	char ms1[MAX_STRINGLEN];
 	char ms2[MAX_STRINGLEN];
 	int j, k, l;
@@ -278,22 +277,21 @@ uint8 AgiEngine::testCompareStrings(uint8 s1, uint8 s2) {
 	return !strcmp(ms1, ms2);
 }
 
-uint8 AgiEngine::testController(uint8 cont) {
-	return (_game.controllerOccurred[cont] ? true : false);
+bool AgiEngine::testController(uint8 cont) {
+	return _game.controllerOccurred[cont];
 }
 
-uint8 AgiEngine::testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
+bool AgiEngine::testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 	ScreenObjEntry *v = &_game.screenObjTable[n];
-	uint8 r;
 
-	r = v->xPos >= x1 && v->yPos >= y1 && v->xPos <= x2 && v->yPos <= y2;
+	bool r = v->xPos >= x1 && v->yPos >= y1 && v->xPos <= x2 && v->yPos <= y2;
 
 	debugC(7, kDebugLevelScripts, "(%d,%d) in (%d,%d,%d,%d): %s", v->xPos, v->yPos, x1, y1, x2, y2, r ? "true" : "false");
 
 	return r;
 }
 
-uint8 AgiEngine::testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
+bool AgiEngine::testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 	ScreenObjEntry *v = &_game.screenObjTable[n];
 
 	return v->xPos >= x1 &&
@@ -301,7 +299,7 @@ uint8 AgiEngine::testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 }
 
 // if n is in center of box
-uint8 AgiEngine::testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
+bool AgiEngine::testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 	ScreenObjEntry *v = &_game.screenObjTable[n];
 
 	return v->xPos + v->xSize / 2 >= x1 &&
@@ -309,7 +307,7 @@ uint8 AgiEngine::testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2)
 }
 
 // if nect N is in right corner
-uint8 AgiEngine::testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
+bool AgiEngine::testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 	ScreenObjEntry *v = &_game.screenObjTable[n];
 
 	return v->xPos + v->xSize - 1 >= x1 &&
@@ -317,11 +315,11 @@ uint8 AgiEngine::testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) {
 }
 
 // When player has entered something, it is parsed elsewhere
-uint8 AgiEngine::testSaid(uint8 nwords, uint8 *cc) {
+bool AgiEngine::testSaid(uint8 nwords, uint8 *cc) {
 	AgiGame *state = &_game;
 	AgiEngine *vm = state->_vm;
 	Words *words = vm->_words;
-	int c, n = words->getEgoWordCount();
+	int n = words->getEgoWordCount();
 	int z = 0;
 
 	if (vm->getFlag(VM_FLAG_SAID_ACCEPTED_INPUT) || !vm->getFlag(VM_FLAG_ENTERED_CLI))
@@ -344,7 +342,7 @@ uint8 AgiEngine::testSaid(uint8 nwords, uint8 *cc) {
 	// With the removal of this code, the behavior of the scene was
 	// corrected
 
-	for (c = 0; nwords && n; c++, nwords--, n--) {
+	for (int c = 0; nwords && n; c++, nwords--, n--) {
 		z = READ_LE_UINT16(cc);
 		cc += 2;
 
@@ -377,27 +375,23 @@ uint8 AgiEngine::testSaid(uint8 nwords, uint8 *cc) {
 
 bool AgiEngine::testIfCode(int16 logicNr) {
 	AgiGame *state = &_game;
-	uint8 op;
-	uint8 p[16];
 
-	int notMode = false;
-	int orMode = false;
-	int endTest = false;
-	int result = true;
+	bool notMode = false;
+	bool orMode = false;
+	bool endTest = false;
+	bool result = true;
 
 	while (!(shouldQuit() || _restartGame) && !endTest) {
 		if (_debug.enabled && (_debug.logic0 || logicNr))
 			debugConsole(logicNr, lTEST_MODE, nullptr);
 
-		op = *(code + ip++);
-		memmove(p, (code + ip), 16);
-
+		uint8 op = *(code + ip++);
 		switch (op) {
 		case 0xFC:
 			if (orMode) {
 				// We have reached the end of an OR expression without
 				// a single test command evaluating as true. Thus the OR
-				// expression evalutes as false which means the whole
+				// expression evaluates as false which means the whole
 				// expression evaluates as false. So skip until the
 				// ending 0xFF and return.
 				skipInstructionsUntil(0xFF);
@@ -415,15 +409,17 @@ bool AgiEngine::testIfCode(int16 logicNr) {
 			endTest = true;
 			continue;
 
-		default:
+		default: {
 			// Evaluate the command and skip the rest of the instruction
+			uint8 p[16];
+			memmove(p, (code + ip), 16);
 			_opCodesCond[op].functionPtr(state, this, p);
 			if (state->exitAllLogics) {
 				// required even here, because of at least the timer heuristic
 				// which when triggered waits a bit and processes ScummVM events and user may therefore restore a saved game
 				// fixes bug #9707
 				// TODO: maybe delay restoring the game instead, when GMM is used?
- 				return true;
+				return true;
 			}
 			skipInstruction(op);
 
@@ -443,7 +439,7 @@ bool AgiEngine::testIfCode(int16 logicNr) {
 					continue;
 				}
 			} else {
-				result &= state->testResult;
+				result = (result && state->testResult);
 				if (!result) {
 					// Since we are in AND mode and the last test command
 					// evaluated as false, the whole expression also evaluates
@@ -455,6 +451,7 @@ bool AgiEngine::testIfCode(int16 logicNr) {
 			}
 			break;
 		}
+		}
 	}
 
 	// Skip the following IF block if the condition evaluates as false


Commit: 065d04900828214f545db984a332ac3889fcc796
    https://github.com/scummvm/scummvm/commit/065d04900828214f545db984a332ac3889fcc796
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-03-09T09:07:59-07:00

Commit Message:
AGI: op_cmd cleanup

Changed paths:
    engines/agi/op_cmd.cpp


diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp
index 53da0ace7b8..baaeef7b8e6 100644
--- a/engines/agi/op_cmd.cpp
+++ b/engines/agi/op_cmd.cpp
@@ -257,32 +257,32 @@ void cmdToggleV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdNewRoom(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 newRoomNr = parameter[0];
 
-	state->_vm->newRoom(newRoomNr);
+	vm->newRoom(newRoomNr);
 }
 
 void cmdNewRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr = parameter[0];
 	byte   value = vm->getVar(varNr);
 
-	state->_vm->newRoom(value);
+	vm->newRoom(value);
 }
 
 void cmdLoadView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
-	state->_vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr);
 }
 
 void cmdLoadLogic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
-	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
 }
 
 void cmdLoadSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
-	state->_vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr);
 }
 
 void cmdLoadViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -296,13 +296,13 @@ void cmdLoadLogicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr = parameter[0];
 	byte   value = vm->getVar(varNr);
 
-	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, value);
+	vm->agiLoadResource(RESOURCETYPE_LOGIC, value);
 }
 
 void cmdDiscardView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
-	state->_vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
+	vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
 }
 
 void cmdObjectOnAnything(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -414,14 +414,14 @@ void cmdStartUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 
-	state->_vm->startUpdate(screenObj);
+	vm->startUpdate(screenObj);
 }
 
 void cmdStopUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 
-	state->_vm->stopUpdate(screenObj);
+	vm->stopUpdate(screenObj);
 }
 
 void cmdCurrentView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -483,7 +483,7 @@ void cmdSetView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 viewNr = parameter[1];
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 
-	state->_vm->setView(screenObj, viewNr);
+	vm->setView(screenObj, viewNr);
 }
 
 void cmdSetViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -492,7 +492,7 @@ void cmdSetViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 	byte   value = vm->getVar(varNr);
 
-	state->_vm->setView(screenObj, value);
+	vm->setView(screenObj, value);
 }
 
 void cmdSetLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -500,7 +500,7 @@ void cmdSetLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 loopNr = parameter[1];
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 
-	state->_vm->setLoop(screenObj, loopNr);
+	vm->setLoop(screenObj, loopNr);
 }
 
 void cmdSetLoopF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -509,7 +509,7 @@ void cmdSetLoopF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 	byte   value = vm->getVar(varNr);
 
-	state->_vm->setLoop(screenObj, value);
+	vm->setLoop(screenObj, value);
 }
 
 void cmdNumberOfLoops(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -609,7 +609,7 @@ void cmdGetRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr2 = parameter[1];
 	byte   varVal1 = vm->getVar(varNr1);
 
-	vm->setVar(varNr2, state->_vm->objectGetLocation(varVal1));
+	vm->setVar(varNr2, vm->objectGetLocation(varVal1));
 }
 
 void cmdPut(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -626,39 +626,39 @@ void cmdPutF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	byte   varVal1 = vm->getVar(varNr1);
 	byte   varVal2 = vm->getVar(varNr2);
 
-	state->_vm->objectSetLocation(varVal1, varVal2);
+	vm->objectSetLocation(varVal1, varVal2);
 }
 
 void cmdDrop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 
-	state->_vm->objectSetLocation(objectNr, 0);
+	vm->objectSetLocation(objectNr, 0);
 }
 
 void cmdGet(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 
-	state->_vm->objectSetLocation(objectNr, EGO_OWNED);
+	vm->objectSetLocation(objectNr, EGO_OWNED);
 }
 
 void cmdGetV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 
-	state->_vm->objectSetLocation(objectNr, EGO_OWNED_V1);
+	vm->objectSetLocation(objectNr, EGO_OWNED_V1);
 }
 
 void cmdGetF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr = parameter[0];
 	byte   varVal = vm->getVar(varNr);
 
-	state->_vm->objectSetLocation(varVal, EGO_OWNED);
+	vm->objectSetLocation(varVal, EGO_OWNED);
 }
 
 void cmdWordToString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 stringNr = parameter[0];
 	uint16 wordNr = parameter[1];
 
-	Common::strlcpy(state->strings[stringNr], state->_vm->_words->getEgoWord(wordNr), MAX_STRINGLEN);
+	Common::strlcpy(state->strings[stringNr], vm->_words->getEgoWord(wordNr), MAX_STRINGLEN);
 }
 
 void cmdOpenDialogue(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -674,41 +674,41 @@ void cmdCloseWindow(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdStatusLineOn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *text = state->_vm->_text;
+	TextMgr *text = vm->_text;
 
 	text->statusEnable();
 	text->statusDraw();
 }
 
 void cmdStatusLineOff(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *text = state->_vm->_text;
+	TextMgr *text = vm->_text;
 
 	text->statusDisable();
-	state->_vm->_text->statusClear();
+	text->statusClear();
 }
 
 void cmdShowObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 objectNr = parameter[0];
 
-	state->_vm->_sprites->showObject(objectNr);
+	vm->_sprites->showObject(objectNr);
 }
 
 void cmdShowObjV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr = parameter[0];
 	byte   varVal = vm->getVar(varNr);
 
-	state->_vm->_sprites->showObject(varVal);
+	vm->_sprites->showObject(varVal);
 }
 
 void cmdSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 	uint16 flagNr = parameter[1];
 
-	state->_vm->_sound->startSound(resourceNr, flagNr);
+	vm->_sound->startSound(resourceNr, flagNr);
 }
 
 void cmdStopSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	state->_vm->_sound->stopSound();
+	vm->_sound->stopSound();
 }
 
 void cmdMenuInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -720,17 +720,17 @@ void cmdMenuInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdEnableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 controlCode = parameter[0];
 
-	state->_vm->_menu->itemEnable(controlCode);
+	vm->_menu->itemEnable(controlCode);
 }
 
 void cmdDisableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 controlCode = parameter[0];
 
-	state->_vm->_menu->itemDisable(controlCode);
+	vm->_menu->itemDisable(controlCode);
 }
 
 void cmdSubmitMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	state->_vm->_menu->submit();
+	vm->_menu->submit();
 }
 
 void cmdSetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -744,7 +744,7 @@ void cmdResetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdSaveGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (vm->getVersion() >= 0x2272) {
 		// this was only donce since 2.272
-		state->_vm->_sound->stopSound();
+		vm->_sound->stopSound();
 	}
 
 	PauseToken pt = vm->pauseEngine();
@@ -763,7 +763,7 @@ void cmdSaveGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdLoadGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (vm->getVersion() >= 0x2272) {
 		// this was only done since 2.272
-		state->_vm->_sound->stopSound();
+		vm->_sound->stopSound();
 	}
 
 	PauseToken pt = vm->pauseEngine();
@@ -841,7 +841,7 @@ void cmdTraceInfo(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdShowMem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	state->_vm->_text->messageBox("Enough memory");
+	vm->_text->messageBox("Enough memory");
 }
 
 void cmdInitJoy(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // do nothing
@@ -925,7 +925,7 @@ void cmdObjStatusF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	        screenObj->stepSize,
 	        cycleDesc,
 	        motionDesc);
-	state->_vm->_text->messageBox(msg);
+	vm->_text->messageBox(msg);
 }
 
 // unknown commands:
@@ -937,7 +937,7 @@ void cmdObjStatusF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 // unk_177: Disable menus completely -- j5
 // unk_181: Deactivate keypressed control (default control of ego)
 void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	if (!(state->_vm->getFeatures() & GF_AGI256)) {
+	if (!(vm->getFeatures() & GF_AGI256)) {
 		// set.simple is called by Larry 1 on Apple IIgs at the store, after answering the 555-6969 phone.
 		// load.sound(16) is called right before it. Interpreter is 2.440-like.
 		// it's called with parameter 16.
@@ -952,12 +952,10 @@ void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 		}
 
 		int16 stringNr = parameter[0];
-		const char *textPtr = nullptr;
-
 		state->automaticSave = false;
 
 		// Try to get description for automatic saves
-		textPtr = state->strings[stringNr];
+		const char *textPtr = state->strings[stringNr];
 
 		strncpy(state->automaticSaveDescription, textPtr, sizeof(state->automaticSaveDescription));
 		state->automaticSaveDescription[sizeof(state->automaticSaveDescription) - 1] = 0;
@@ -966,10 +964,9 @@ void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 			// We got it and it's set, so enable automatic saving
 			state->automaticSave = true;
 		}
-
 	} else { // AGI256 and AGI256-2 use this unknown170 command to load 256 color pictures.
 		// Load the picture. Similar to void cmdLoad_pic(AgiGame *state, AgiEngine *vm, uint8 *p).
-		SpritesMgr *spritesMgr = state->_vm->_sprites;
+		SpritesMgr *spritesMgr = vm->_sprites;
 		uint16 varNr = parameter[0];
 		uint16 resourceNr = vm->getVar(varNr);
 
@@ -1013,7 +1010,7 @@ void cmdShowMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (state->mouseEnabled) {
 		state->mouseHidden = false;
 
-		g_system->showMouse(true);
+		vm->_system->showMouse(true);
 	}
 }
 
@@ -1036,7 +1033,7 @@ void cmdHideMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (state->mouseEnabled) {
 		state->mouseHidden = true;
 
-		g_system->showMouse(false);
+		vm->_system->showMouse(false);
 	}
 }
 
@@ -1050,9 +1047,9 @@ void cmdAllowMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 allowed = parameter[0];
 
 	if (allowed) {
-		state->_vm->_menu->accessAllow();
+		vm->_menu->accessAllow();
 	} else {
-		state->_vm->_menu->accessDeny();
+		vm->_menu->accessDeny();
 	}
 }
 
@@ -1130,27 +1127,24 @@ void cmdAdjEgoMoveToXY(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdParse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *text = state->_vm->_text;
 	uint16 stringNr = parameter[0];
 
 	vm->setVar(VM_VAR_WORD_NOT_FOUND, 0);
 	vm->setFlag(VM_FLAG_ENTERED_CLI, false);
 	vm->setFlag(VM_FLAG_SAID_ACCEPTED_INPUT, false);
 
-	vm->_words->parseUsingDictionary(text->stringPrintf(state->strings[stringNr]));
+	vm->_words->parseUsingDictionary(vm->_text->stringPrintf(state->strings[stringNr]));
 }
 
 void cmdCall(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 logicNr = parameter[0];
-	int oldCIP;
-	int oldLognum;
 
 	// CM: we don't save sIP because set.scan.start can be
 	//     used in a called script (fixes xmas demo)
-	oldCIP = state->_curLogic->cIP;
-	oldLognum = state->curLogicNr;
+	int oldCIP = state->_curLogic->cIP;
+	int oldLognum = state->curLogicNr;
 
-	state->_vm->runLogic(logicNr);
+	vm->runLogic(logicNr);
 
 	state->curLogicNr = oldLognum;
 	state->_curLogic = &state->logics[state->curLogicNr];
@@ -1169,7 +1163,7 @@ void cmdDrawPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = vm->getVar(varNr);
 
 	debugC(6, kDebugLevelScripts, "=== draw pic V1 %d ===", resourceNr);
-	state->_vm->_picture->decodePicture(resourceNr, true);
+	vm->_picture->decodePicture(resourceNr, true);
 
 	// TODO: check, if this was really done
 	vm->_text->promptClear();
@@ -1179,7 +1173,7 @@ void cmdDrawPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdDrawPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	SpritesMgr *spritesMgr = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 	uint16 varNr = parameter[0];
 	uint16 resourceNr = vm->getVar(varNr);
 
@@ -1224,7 +1218,7 @@ void cmdShowPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdLoadPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	SpritesMgr *spritesMgr = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 	uint16 varNr = parameter[0];
 	uint16 resourceNr = vm->getVar(varNr);
 
@@ -1238,7 +1232,7 @@ void cmdLoadPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 varNr = parameter[0];
 	uint16 resourceNr = vm->getVar(varNr);
 
-	state->_vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
 }
 
 void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1247,7 +1241,7 @@ void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdOverlayPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	SpritesMgr *spritesMgr = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 	uint16 varNr = parameter[0];
 	uint16 resourceNr = vm->getVar(varNr);
 
@@ -1265,13 +1259,11 @@ void cmdOverlayPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdShowPriScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	GfxMgr *gfx = state->_vm->_gfx;
-
-	gfx->debugShowMap(1); // switch to priority map
+	vm->_gfx->debugShowMap(1); // switch to priority map
 
 	state->_vm->waitKey();
 
-	gfx->debugShowMap(0); // switch back to visual map
+	vm->_gfx->debugShowMap(0); // switch back to visual map
 }
 
 void cmdAnimateObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1299,11 +1291,9 @@ void cmdAnimateObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdUnanimateAll(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	int i;
+	vm->_sprites->eraseSprites();
 
-	state->_vm->_sprites->eraseSprites();
-
-	for (i = 0; i < SCREENOBJECTS_MAX; i++)
+	for (int i = 0; i < SCREENOBJECTS_MAX; i++)
 		state->screenObjTable[i].flags &= ~(fAnimated | fDrawn);
 }
 
@@ -1321,30 +1311,30 @@ void cmdDraw(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	screenObj->flags |= fUpdate;
 	if (vm->getVersion() >= 0x3000) {
-		state->_vm->setLoop(screenObj, screenObj->currentLoopNr);
-		state->_vm->setCel(screenObj, screenObj->currentCelNr);
+		vm->setLoop(screenObj, screenObj->currentLoopNr);
+		vm->setCel(screenObj, screenObj->currentCelNr);
 	}
 
-	SpritesMgr *sprites = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 
-	state->_vm->fixPosition(objectNr);
+	vm->fixPosition(objectNr);
 	screenObj->xPos_prev = screenObj->xPos;
 	screenObj->yPos_prev = screenObj->yPos;
 	screenObj->xSize_prev = screenObj->xSize;
 	screenObj->ySize_prev = screenObj->ySize;
 	//screenObj->celData2 = screenObj->celData;
-	sprites->eraseRegularSprites();
+	spritesMgr->eraseRegularSprites();
 	screenObj->flags |= fDrawn;
-	sprites->buildRegularSpriteList();
-	sprites->drawRegularSpriteList();
-	sprites->showSprite(screenObj);
+	spritesMgr->buildRegularSpriteList();
+	spritesMgr->drawRegularSpriteList();
+	spritesMgr->showSprite(screenObj);
 	screenObj->flags &= ~fDontUpdate;
 
 	debugC(4, kDebugLevelScripts, "vt entry #%d flags = %02x", objectNr, screenObj->flags);
 }
 
 void cmdErase(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	SpritesMgr *sprites = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 	uint16 objectNr = parameter[0];
 	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
 
@@ -1353,21 +1343,21 @@ void cmdErase(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (!(screenObj->flags & fDrawn))
 		return;
 
-	sprites->eraseRegularSprites();
+	spritesMgr->eraseRegularSprites();
 	if ((screenObj->flags & fUpdate) == 0) {
 		noUpdateFlag = true;
-		sprites->eraseStaticSprites();
+		spritesMgr->eraseStaticSprites();
 	}
 
 	screenObj->flags &= ~fDrawn;
 
 	if (noUpdateFlag) {
-		sprites->buildStaticSpriteList();
-		sprites->drawStaticSpriteList();
+		spritesMgr->buildStaticSpriteList();
+		spritesMgr->drawStaticSpriteList();
 	}
-	sprites->buildRegularSpriteList();
-	sprites->drawRegularSpriteList();
-	sprites->showSprite(screenObj);
+	spritesMgr->buildRegularSpriteList();
+	spritesMgr->drawRegularSpriteList();
+	spritesMgr->showSprite(screenObj);
 }
 
 void cmdPosition(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1452,7 +1442,7 @@ void cmdReposition(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	else
 		screenObj->yPos += dy;
 
-	state->_vm->fixPosition(objectNr);
+	vm->fixPosition(objectNr);
 }
 
 void cmdRepositionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1478,7 +1468,7 @@ void cmdRepositionTo(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	screenObj->xPos = xPos;
 	screenObj->yPos = yPos;
 	screenObj->flags |= fUpdatePos;
-	state->_vm->fixPosition(objectNr);
+	vm->fixPosition(objectNr);
 }
 
 void cmdRepositionToF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1490,7 +1480,7 @@ void cmdRepositionToF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	screenObj->xPos = vm->getVar(varNr1);
 	screenObj->yPos = vm->getVar(varNr2);
 	screenObj->flags |= fUpdatePos;
-	state->_vm->fixPosition(objectNr);
+	vm->fixPosition(objectNr);
 }
 
 void cmdAddToPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1502,7 +1492,7 @@ void cmdAddToPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 priority = parameter[5];
 	uint16 border = parameter[6];
 
-	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
+	vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
 }
 
 void cmdAddToPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1513,7 +1503,7 @@ void cmdAddToPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 yPos = parameter[4];
 	uint16 priority = parameter[5];
 
-	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, -1);
+	vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, -1);
 }
 
 void cmdAddToPicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1525,11 +1515,11 @@ void cmdAddToPicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 priority = vm->getVar(parameter[5]);
 	uint16 border = vm->getVar(parameter[6]);
 
-	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
+	vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
 }
 
 void cmdForceUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	SpritesMgr *spritesMgr = state->_vm->_sprites;
+	SpritesMgr *spritesMgr = vm->_sprites;
 
 	spritesMgr->eraseSprites();
 	spritesMgr->buildAllSpriteLists();
@@ -1546,7 +1536,7 @@ void cmdReverseLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	screenObj->cycle = kCycleRevLoop;
 	screenObj->flags |= (fDontUpdate | fUpdate | fCycling);
 	screenObj->loop_flag = loopFlag;
-	state->_vm->setFlag(screenObj->loop_flag, false);
+	vm->setFlag(screenObj->loop_flag, false);
 
 	vm->cyclerActivated(screenObj);
 }
@@ -1558,7 +1548,7 @@ void cmdReverseLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
 	screenObj->cycle = kCycleRevLoop;
-	state->_vm->setCel(screenObj, 0);
+	vm->setCel(screenObj, 0);
 	screenObj->flags |= (fDontUpdate | fUpdate | fCycling);
 	screenObj->loop_flag = loopFlag;
 	//screenObj->parm3 = 0;
@@ -1585,7 +1575,7 @@ void cmdEndOfLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
 	screenObj->cycle = kCycleEndOfLoop;
-	state->_vm->setCel(screenObj, 0);
+	vm->setCel(screenObj, 0);
 	screenObj->flags |= (fDontUpdate | fUpdate | fCycling);
 	screenObj->loop_flag = loopFlag;
 	//screenObj->parm3 = 0;
@@ -1623,7 +1613,7 @@ void cmdStopMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	screenObj->direction = 0;
 	screenObj->motionType = kMotionNormal;
 	if (objectNr == 0) {        // ego only
-		state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0);
+		vm->setVar(VM_VAR_EGO_DIRECTION, 0);
 		state->playerControl = false;
 	}
 }
@@ -1641,7 +1631,7 @@ void cmdStartMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	screenObj->motionType = kMotionNormal;
 	if (objectNr == 0) {        // ego only
-		state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0);
+		vm->setVar(VM_VAR_EGO_DIRECTION, 0);
 		state->playerControl = true;
 	}
 }
@@ -1789,7 +1779,7 @@ void cmdPause(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	// Show pause message box
 	PauseToken pt = vm->pauseEngine();
 
-	state->_vm->_systemUI->pauseDialog();
+	vm->_systemUI->pauseDialog();
 }
 
 void cmdSetMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -1800,7 +1790,7 @@ void cmdSetMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (state->_curLogic->texts != nullptr && (textNr - 1) <= state->_curLogic->numTexts) {
 		const char *menuText = state->_curLogic->texts[textNr - 1];
 
-		state->_vm->_menu->addMenu(menuText);
+		vm->_menu->addMenu(menuText);
 	}
 }
 
@@ -1813,7 +1803,7 @@ void cmdSetMenuItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	if (state->_curLogic->texts != nullptr && textNr <= state->_curLogic->numTexts) {
 		const char *menuItemText = state->_curLogic->texts[textNr];
 
-		state->_vm->_menu->addMenuItem(menuItemText, controllerSlot);
+		vm->_menu->addMenuItem(menuItemText, controllerSlot);
 	}
 }
 
@@ -1836,11 +1826,11 @@ void cmdVersion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	verMsg += (maj == 2 ? ver2Msg : ver3Msg);
 	verMsg = Common::String::format(verMsg.c_str(), gScummVMVersion, maj, min);
 
-	state->_vm->_text->messageBox(verMsg.c_str());
+	vm->_text->messageBox(verMsg.c_str());
 }
 
 void cmdConfigureScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 	uint16 gameRow = parameter[0];
 	uint16 promptRow = parameter[1];
 	uint16 statusRow = parameter[2];
@@ -1851,8 +1841,8 @@ void cmdConfigureScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdTextScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	GfxMgr  *gfxMgr = state->_vm->_gfx;
-	TextMgr *textMgr = state->_vm->_text;
+	GfxMgr  *gfxMgr = vm->_gfx;
+	TextMgr *textMgr = vm->_text;
 
 	debugC(4, kDebugLevelScripts, "switching to text mode");
 
@@ -1866,18 +1856,17 @@ void cmdTextScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdGraphics(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	debugC(4, kDebugLevelScripts, "switching to graphics mode");
 
-	state->_vm->redrawScreen();
+	vm->redrawScreen();
 }
 
 void cmdSetTextAttribute(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 foreground = parameter[0];
 	int16 background = parameter[1];
-	state->_vm->_text->charAttrib_Set(foreground, background);
+	vm->_text->charAttrib_Set(foreground, background);
 }
 
 void cmdStatus(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
-	InventoryMgr *inventoryMgr = state->_vm->_inventory;
+	TextMgr *textMgr = vm->_text;
 
 	textMgr->inputEditOn();
 	textMgr->charAttrib_Push();
@@ -1885,35 +1874,35 @@ void cmdStatus(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	cmdTextScreen(state, vm, parameter);
 
-	inventoryMgr->show();
+	vm->_inventory->show();
 
 	//invent_state = 0;
 	textMgr->charAttrib_Pop();
-	state->_vm->redrawScreen();
+	vm->redrawScreen();
 }
 
 void cmdQuit(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 withoutPrompt = parameter[0];
 
-	state->_vm->_sound->stopSound();
+	vm->_sound->stopSound();
 	if (withoutPrompt) {
-		state->_vm->quitGame();
+		vm->quitGame();
 	} else {
-		if (state->_vm->_systemUI->quitDialog()) {
-			state->_vm->quitGame();
+		if (vm->_systemUI->quitDialog()) {
+			vm->quitGame();
 		}
 	}
 }
 
 void cmdQuitV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	state->_vm->_sound->stopSound();
-	state->_vm->quitGame();
+	vm->_sound->stopSound();
+	vm->quitGame();
 }
 
 void cmdRestartGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	bool doRestart = false;
 
-	state->_vm->_sound->stopSound();
+	vm->_sound->stopSound();
 
 	if (vm->getFlag(VM_FLAG_AUTO_RESTART)) {
 		doRestart = true;
@@ -1984,7 +1973,7 @@ void cmdDistance(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdAcceptInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 
 	debugC(4, kDebugLevelInput, "input normal");
 
@@ -1993,7 +1982,7 @@ void cmdAcceptInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdPreventInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 
 	debugC(4, kDebugLevelInput, "no input");
 
@@ -2004,11 +1993,11 @@ void cmdPreventInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdCancelLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	state->_vm->_text->promptCancelLine();
+	vm->_text->promptCancelLine();
 }
 
 void cmdEchoLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 
 	if (textMgr->promptIsEnabled()) {
 		textMgr->promptEchoLine();
@@ -2016,7 +2005,7 @@ void cmdEchoLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 	int16 stringDestNr = parameter[0];
 	int16 leadInTextNr = parameter[1] - 1;
 	int16 stringRow = parameter[2];
@@ -2055,14 +2044,14 @@ void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 		textMgr->displayText(leadInTextPtr);
 	}
 
-	state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING);
+	vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING);
 
 	textMgr->stringSet("");
 	textMgr->stringEdit(stringMaxLen);
 
 	// copy string to destination
 	// TODO: not sure if set all the time or only when ENTER is pressed
-	Common::strlcpy(&state->_vm->_game.strings[stringDestNr][0], (char *)textMgr->_inputString, MAX_STRINGLEN);
+	Common::strlcpy(&vm->_game.strings[stringDestNr][0], (char *)textMgr->_inputString, MAX_STRINGLEN);
 
 	textMgr->charPos_Pop();
 
@@ -2072,7 +2061,7 @@ void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 	int16 leadInTextNr = parameter[0] - 1;
 	int16 numberDestVarNr = parameter[1];
 	const char *leadInTextPtr = nullptr;
@@ -2094,7 +2083,7 @@ void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	textMgr->inputEditOff();
 
-	state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETNUMBER);
+	vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETNUMBER);
 
 	textMgr->stringSet("");
 	textMgr->stringEdit(3);
@@ -2108,7 +2097,7 @@ void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 }
 
 void cmdSetCursorChar(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	TextMgr *textMgr = state->_vm->_text;
+	TextMgr *textMgr = vm->_text;
 	uint16 textNr = parameter[0] - 1;
 
 	if (state->_curLogic->texts != nullptr && textNr <= state->_curLogic->numTexts) {
@@ -2159,7 +2148,7 @@ void cmdDisplay(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textRow = parameter[0];
 	int16 textColumn = parameter[1];
 
-	state->_vm->_text->display(textNr, textRow, textColumn);
+	vm->_text->display(textNr, textRow, textColumn);
 }
 
 void cmdDisplayF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2167,7 +2156,7 @@ void cmdDisplayF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textColumn = vm->getVar(parameter[1]);
 	int16 textNr = vm->getVar(parameter[2]);
 
-	state->_vm->_text->display(textNr, textRow, textColumn);
+	vm->_text->display(textNr, textRow, textColumn);
 }
 
 void cmdClearTextRect(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2175,9 +2164,9 @@ void cmdClearTextRect(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textUpperColumn = parameter[1];
 	int16 textLowerRow = parameter[2];
 	int16 textLowerColumn = parameter[3];
-	int16 color = state->_vm->_text->calculateTextBackground(parameter[4]);
+	int16 color = vm->_text->calculateTextBackground(parameter[4]);
 
-	state->_vm->_text->clearBlock(textUpperRow, textUpperColumn, textLowerRow, textLowerColumn, color);
+	vm->_text->clearBlock(textUpperRow, textUpperColumn, textLowerRow, textLowerColumn, color);
 }
 
 void cmdToggleMonitor(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2187,7 +2176,7 @@ void cmdToggleMonitor(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdClearLines(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textRowUpper = parameter[0];
 	int16 textRowLower = parameter[1];
-	int16 color = state->_vm->_text->calculateTextBackground(parameter[2]);
+	int16 color = vm->_text->calculateTextBackground(parameter[2]);
 
 	// Residence 44 calls clear.lines(24,0,0), see Sarien bug #558423
 	// Agent06 incorrectly calls clear.lines(1,150,0), see ScummVM bugs
@@ -2196,19 +2185,19 @@ void cmdClearLines(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 		warning("cmdClearLines: RowUpper higher than RowLower");
 		textRowLower = textRowUpper;
 	}
-	state->_vm->_text->clearLines(textRowUpper, textRowLower, color);
+	vm->_text->clearLines(textRowUpper, textRowLower, color);
 }
 
 void cmdPrint(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textNr = parameter[0];
 
-	state->_vm->_text->print(textNr);
+	vm->_text->print(textNr);
 }
 
 void cmdPrintF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	int16 textNr = vm->getVar(parameter[0]);
 
-	state->_vm->_text->print(textNr);
+	vm->_text->print(textNr);
 }
 
 void cmdPrintAt(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2219,7 +2208,7 @@ void cmdPrintAt(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth);
 
-	state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth);
+	vm->_text->printAt(textNr, textRow, textColumn, textWidth);
 }
 
 void cmdPrintAtV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2230,7 +2219,7 @@ void cmdPrintAtV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth);
 
-	state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth);
+	vm->_text->printAt(textNr, textRow, textColumn, textWidth);
 }
 
 // push.script was not available until 2.425, and also not available in 2.440
@@ -2246,7 +2235,7 @@ void cmdPushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 // The AGIMOUSE interpreter modified push.script to set variables 27-29 to mouse state
 void cmdAgiMousePushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
-	vm->setVar(VM_VAR_MOUSE_BUTTONSTATE, state->_vm->_mouse.button);
+	vm->setVar(VM_VAR_MOUSE_BUTTONSTATE, vm->_mouse.button);
 	vm->setVar(VM_VAR_MOUSE_X, vm->_mouse.pos.x / 2);
 	vm->setVar(VM_VAR_MOUSE_Y, vm->_mouse.pos.y);
 }
@@ -2270,7 +2259,7 @@ void cmdSetPriBase(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 
 	debug(0, "Priority base set to %d", priorityBase);
 
-	state->_vm->_gfx->setPriorityTable(priorityBase);
+	vm->_gfx->setPriorityTable(priorityBase);
 }
 
 void cmdGetMousePosn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2291,11 +2280,11 @@ void cmdShakeScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	// AGIPAL uses shake.screen values between 100 and 109 to set the palette
 	// (Checked the original AGIPAL-hack's shake.screen-routine's disassembly).
 	if (shakeCount >= 100 && shakeCount < 110) {
-		state->_vm->_gfx->setAGIPal(shakeCount);
+		vm->_gfx->setAGIPal(shakeCount);
 		return;
 	}
 
-	state->_vm->_gfx->shakeScreen(shakeCount);
+	vm->_gfx->shakeScreen(shakeCount);
 }
 
 void cmdSetSpeed(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2314,7 +2303,7 @@ void cmdSetItemView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 void cmdCallV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
-	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
 	// FIXME: The following instruction looks incomplete.
 	// Maybe something is meant to be assigned to, or read from,
 	// the logic_list entry?
@@ -2328,7 +2317,7 @@ void cmdNewRoomV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = parameter[0];
 
 	warning("cmdNewRoomV1()");
-	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
 	state->max_logics = 1;
 	state->logic_list[1] = resourceNr;
 	vm->setVar(13, 1);
@@ -2338,7 +2327,7 @@ void cmdNewRoomVV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
 	uint16 resourceNr = vm->getVar(parameter[0]);
 
 	warning("cmdNewRoomVV1()");
-	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+	vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
 	state->max_logics = 1;
 	state->logic_list[1] = resourceNr;
 	vm->setVar(13, 1);
@@ -2362,10 +2351,6 @@ void cmdUnknown(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
  */
 int AgiEngine::runLogic(int16 logicNr) {
 	AgiGame *state = &_game;
-	uint8 op = 0;
-	uint8 p[CMD_BSIZE] = { 0 };
-	int curParameterSize = 0;
-	ScriptPos sp;
 	//int logic_index = 0;
 
 	state->logic_list[0] = 0;
@@ -2374,6 +2359,7 @@ int AgiEngine::runLogic(int16 logicNr) {
 	debugC(2, kDebugLevelScripts, "=================");
 	debugC(2, kDebugLevelScripts, "runLogic(%d)", logicNr);
 
+	ScriptPos sp;
 	sp.script = logicNr;
 	sp.curIP = 0;
 	_game.execStack.push_back(sp);
@@ -2419,7 +2405,8 @@ int AgiEngine::runLogic(int16 logicNr) {
 		memset(st, '.', sz);
 		st[sz] = 0;
 
-		switch (op = *(state->_curLogic->data + state->_curLogic->cIP++)) {
+		uint8 op = *(state->_curLogic->data + state->_curLogic->cIP++);
+		switch (op) {
 		case 0xff:  // if (open/close)
 			testIfCode(logicNr);
 			break;
@@ -2445,12 +2432,13 @@ int AgiEngine::runLogic(int16 logicNr) {
 
 			_game.execStack.pop_back();
 			return 1;
-		default:
+		default: {
 			if (!_opCodes[op].functionPtr) {
 				error("Illegal opcode %2X (%d) in logic %d, ip %d", op, op, state->curLogicNr, state->_curLogic->cIP);
 			}
 
-			curParameterSize = _opCodes[op].parameterSize;
+			uint8 p[CMD_BSIZE];
+			int curParameterSize = _opCodes[op].parameterSize;
 			memmove(p, state->_curLogic->data + state->_curLogic->cIP, curParameterSize);
 			memset(p + curParameterSize, 0, CMD_BSIZE - curParameterSize);
 
@@ -2459,6 +2447,7 @@ int AgiEngine::runLogic(int16 logicNr) {
 			_opCodes[op].functionPtr(&_game, this, p);
 			state->_curLogic->cIP += curParameterSize;
 		}
+		}
 
 //		if ((op == 0x0B || op == 0x3F || op == 0x40) && logic_index < state->max_logics) {
 //			n = state->logic_list[++logic_index];


Commit: d6c220896eba117a011d1a051f56c81af9f25acb
    https://github.com/scummvm/scummvm/commit/d6c220896eba117a011d1a051f56c81af9f25acb
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-03-09T09:07:59-07:00

Commit Message:
AGI: Misc cleaup

Changed paths:
    engines/agi/agi.cpp
    engines/agi/agi.h
    engines/agi/checks.cpp
    engines/agi/font.cpp
    engines/agi/global.cpp
    engines/agi/inv.cpp
    engines/agi/motion.cpp
    engines/agi/text.cpp
    engines/agi/view.cpp


diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 740b9c13080..c594da104d7 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -76,8 +76,6 @@ void AgiEngine::wait(uint32 msec, bool busy) {
 }
 
 int AgiEngine::agiInit() {
-	int ec, i;
-
 	debug(2, "initializing");
 	debug(2, "game version = 0x%x", getVersion());
 
@@ -89,7 +87,7 @@ int AgiEngine::agiInit() {
 	memset(_game.vars, 0, sizeof(_game.vars));
 
 	// clear all resources and events
-	for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
+	for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
 		_game.views[i].reset();
 		_game.pictures[i].reset();
 		_game.logics[i].reset();
@@ -101,7 +99,7 @@ int AgiEngine::agiInit() {
 	}
 
 	// clear view table
-	for (i = 0; i < SCREENOBJECTS_MAX; i++) {
+	for (int i = 0; i < SCREENOBJECTS_MAX; i++) {
 		_game.screenObjTable[i].reset();
 	}
 
@@ -120,7 +118,7 @@ int AgiEngine::agiInit() {
 	// to ask Ego's name again. The name is supposed to be maintained in string 1.
 	// Fixes bug #5673.
 	if (!_restartGame) {
-		for (i = 0; i < MAX_STRINGS; i++)
+		for (int i = 0; i < MAX_STRINGS; i++)
 			_game.strings[i][0] = 0;
 	}
 
@@ -148,7 +146,7 @@ int AgiEngine::agiInit() {
 	if (getFeatures() & GF_AGDS)
 		debug(1, "AGDS mode enabled.");
 
-	ec = _loader->init();   // load vol files, etc
+	int ec = _loader->init();   // load vol files, etc
 
 	if (ec == errOK)
 		ec = _loader->loadObjects(OBJECTS);
@@ -174,10 +172,6 @@ int AgiEngine::agiInit() {
 	return ec;
 }
 
-/*
- * Public functions
- */
-
 void AgiEngine::agiUnloadResources() {
 	// Make sure logic 0 is always loaded
 	for (int i = 1; i < MAX_DIRECTORY_ENTRIES; i++) {
@@ -204,13 +198,11 @@ void AgiEngine::agiDeinit() {
 }
 
 int AgiEngine::agiLoadResource(int16 resourceType, int16 resourceNr) {
-	int i;
-
-	i = _loader->loadResource(resourceType, resourceNr);
+	int ec = _loader->loadResource(resourceType, resourceNr);
 
 	// WORKAROUND: Patches broken picture 147 in a corrupted Amiga version of Gold Rush! (v2.05 1989-03-09).
 	// The picture can be seen in room 147 after dropping through the outhouse's hole in room 146.
-	if (i == errOK && getGameID() == GID_GOLDRUSH && resourceType == RESOURCETYPE_PICTURE && resourceNr == 147 && _game.dirPic[resourceNr].len == 1982) {
+	if (ec == errOK && getGameID() == GID_GOLDRUSH && resourceType == RESOURCETYPE_PICTURE && resourceNr == 147 && _game.dirPic[resourceNr].len == 1982) {
 		uint8 *pic = _game.pictures[resourceNr].rdata;
 		Common::MemoryReadStream picStream(pic, _game.dirPic[resourceNr].len);
 		Common::String md5str = Common::computeStreamMD5AsString(picStream, _game.dirPic[resourceNr].len);
@@ -224,7 +216,7 @@ int AgiEngine::agiLoadResource(int16 resourceType, int16 resourceNr) {
 		}
 	}
 
-	return i;
+	return ec;
 }
 
 void AgiEngine::agiUnloadResource(int16 resourceType, int16 resourceNr) {
@@ -251,7 +243,6 @@ AgiBase::AgiBase(OSystem *syst, const AGIGameDescription *gameDesc) : Engine(sys
 
 AgiBase::~AgiBase() {
 	delete _rnd;
-
 	delete _sound;
 }
 
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 5caad387247..e73c14beec5 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -856,7 +856,7 @@ public:
 	TextMgr *_text;
 	InventoryMgr *_inventory;
 	PictureMgr *_picture;
-	AgiLoader *_loader; // loader
+	AgiLoader *_loader;
 	GfxMenu *_menu;
 	SystemUI *_systemUI;
 	Common::DumpFile *_logFile; // File used for the log() agi command.
diff --git a/engines/agi/checks.cpp b/engines/agi/checks.cpp
index 4c9c0affa69..bd83148cc5f 100644
--- a/engines/agi/checks.cpp
+++ b/engines/agi/checks.cpp
@@ -107,10 +107,6 @@ bool AgiEngine::checkPriority(ScreenObjEntry *screenObj) {
 	bool touchedWater = false;
 	bool touchedTrigger = false;
 	bool touchedControl = true;
-	int16 curX;
-	int16 curY;
-	int16 celX;
-	byte screenPriority = 0;
 
 	if (!(screenObj->flags & fFixedPriority)) {
 		// Priority bands
@@ -118,14 +114,13 @@ bool AgiEngine::checkPriority(ScreenObjEntry *screenObj) {
 	}
 
 	if (screenObj->priority != 0x0f) {
-
 		touchedWater = true;
 
-		curX = screenObj->xPos;
-		curY = screenObj->yPos;
+		int16 curX = screenObj->xPos;
+		int16 curY = screenObj->yPos;
 
-		for (celX = 0; celX < screenObj->xSize; celX++, curX++) {
-			screenPriority = _gfx->getPriority(curX, curY);
+		for (int16 celX = 0; celX < screenObj->xSize; celX++, curX++) {
+			byte screenPriority = _gfx->getPriority(curX, curY);
 
 			if (screenPriority == 0) {  // unconditional black. no go at all!
 				touchedControl = false;
@@ -181,13 +176,11 @@ bool AgiEngine::checkPriority(ScreenObjEntry *screenObj) {
  * rules, otherwise the previous position will be kept.
  */
 void AgiEngine::updatePosition() {
-	ScreenObjEntry *screenObj;
-	int x, y, oldX, oldY, border;
-
 	setVar(VM_VAR_BORDER_CODE, 0);
 	setVar(VM_VAR_BORDER_TOUCH_EGO, 0);
 	setVar(VM_VAR_BORDER_TOUCH_OBJECT, 0);
 
+	ScreenObjEntry *screenObj;
 	for (screenObj = _game.screenObjTable; screenObj < &_game.screenObjTable[SCREENOBJECTS_MAX]; screenObj++) {
 		if ((screenObj->flags & (fAnimated | fUpdate | fDrawn)) != (fAnimated | fUpdate | fDrawn)) {
 			continue;
@@ -200,8 +193,10 @@ void AgiEngine::updatePosition() {
 
 		screenObj->stepTimeCount = screenObj->stepTime;
 
-		x = oldX = screenObj->xPos;
-		y = oldY = screenObj->yPos;
+		int x = screenObj->xPos;
+		int oldX = x;
+		int y = screenObj->yPos;
+		int oldY = y;
 
 		// If object has moved, update its position
 		if (!(screenObj->flags & fUpdatePos)) {
@@ -212,7 +207,7 @@ void AgiEngine::updatePosition() {
 		}
 
 		// Now check if it touched the borders
-		border = 0;
+		int border = 0;
 
 		// Check left/right borders
 		if (getVersion() == 0x3086) {
@@ -299,16 +294,15 @@ void AgiEngine::fixPosition(int16 screenObjNr) {
 }
 
 void AgiEngine::fixPosition(ScreenObjEntry *screenObj) {
-	int count, dir, size;
-
 	debugC(4, kDebugLevelSprites, "adjusting view table entry #%d (%d,%d)", screenObj->objectNr, screenObj->xPos, screenObj->yPos);
 
 	// test horizon
 	if ((!(screenObj->flags & fIgnoreHorizon)) && screenObj->yPos <= _game.horizon)
 		screenObj->yPos = _game.horizon + 1;
 
-	dir = 0;
-	count = size = 1;
+	int dir = 0;
+	int count = 1;
+	int size = 1;
 
 	while (!checkPosition(screenObj) || checkCollision(screenObj) || !checkPriority(screenObj)) {
 		switch (dir) {
diff --git a/engines/agi/font.cpp b/engines/agi/font.cpp
index f3dcbff8f6e..98636c04922 100644
--- a/engines/agi/font.cpp
+++ b/engines/agi/font.cpp
@@ -169,18 +169,15 @@ void GfxFont::overwriteExtendedWithRussianSet() {
 //  DOS      - "agi-font-dos.bin"
 void GfxFont::loadFontScummVMFile(const Common::Path &fontFilename) {
 	Common::File fontFile;
-	int32 fontFileSize = 0;
-
 	if (!fontFile.open(fontFilename)) {
 		// Continue, if file not found
 		// These ScummVM font files are totally optional, so don't show a warning
 		return;
 	}
 
-	fontFileSize = fontFile.size();
+	int32 fontFileSize = fontFile.size();
 	if (fontFileSize != (256 * 8)) {
 		// unexpected file size
-		fontFile.close();
 		warning("Fontfile '%s': unexpected file size", fontFilename.toString(Common::Path::kNativeSeparator).c_str());
 		return;
 	}
@@ -191,7 +188,6 @@ void GfxFont::loadFontScummVMFile(const Common::Path &fontFilename) {
 
 	// read font data, is already in the format that we need (plain bitmap 8x8)
 	fontFile.read(_fontDataAllocated, 256 * 8);
-	fontFile.close();
 
 	overwriteSaveRestoreDialogCharacter();
 
@@ -201,32 +197,27 @@ void GfxFont::loadFontScummVMFile(const Common::Path &fontFilename) {
 // We load the Mickey Mouse font from MICKEY.EXE
 void GfxFont::loadFontMickey() {
 	Common::File interpreterFile;
-	int32 interpreterFileSize = 0;
-	byte *fontData = nullptr;
-
 	if (!interpreterFile.open("mickey.exe")) {
 		// Continue, if file not found
 		warning("Could not open file 'mickey.exe' for Mickey Mouse font");
 		return;
 	}
 
-	interpreterFileSize = interpreterFile.size();
+	int32 interpreterFileSize = interpreterFile.size();
 	if (interpreterFileSize != 55136) {
 		// unexpected file size
-		interpreterFile.close();
 		warning("File 'mickey.exe': unexpected file size");
 		return;
 	}
 	interpreterFile.seek(32476); // offset of font data
 
 	// allocate space for font bitmap data
-	fontData = (uint8 *)calloc(256, 8);
+	byte *fontData = (uint8 *)calloc(256, 8);
 	_fontData = fontData;
 	_fontDataAllocated = fontData;
 
 	// read font data, is already in the format that we need (plain bitmap 8x8)
 	interpreterFile.read(fontData, 256 * 8);
-	interpreterFile.close();
 
 	debug("AGI: Using Mickey Mouse font");
 }
@@ -590,7 +581,6 @@ void GfxFont::loadFontHercules() {
 
 	if (_vm->getLanguage() == Common::RU_RUS) {
 		warning("Hercules font does not contain Russian characters, switching to default");
-
 		return;
 	}
 
@@ -634,7 +624,6 @@ void GfxFont::loadFontHercules() {
 			warning("Fontfile 'hgc_font': unexpected file size");
 		}
 		fontFile.close();
-
 	}
 
 	// It seems hgc_graf.ovl holds a low-res font. It makes no real sense to use it.
@@ -690,8 +679,7 @@ void GfxFont::loadFontHercules() {
 		if (GUI::GuiManager::hasInstance()) {
 			GUI::MessageDialog dialog(_("Could not open/use file 'hgc_font' for Hercules hires font.\nIf you have such file in other AGI (Sierra) game, you can copy it to the game directory"));
 			dialog.runModal();
-		};
-
+		}
 	}
 }
 
diff --git a/engines/agi/global.cpp b/engines/agi/global.cpp
index c678461f763..550d9e85039 100644
--- a/engines/agi/global.cpp
+++ b/engines/agi/global.cpp
@@ -287,13 +287,9 @@ void AgiEngine::inGameTimerUpdate() {
 }
 
 void AgiEngine::decrypt(uint8 *mem, int len) {
-	const uint8 *key;
-	int i;
-
-	key = (getFeatures() & GF_AGDS) ? (const uint8 *)CRYPT_KEY_AGDS
-	                                : (const uint8 *)CRYPT_KEY_SIERRA;
-
-	for (i = 0; i < len; i++)
+	const uint8 *key = (getFeatures() & GF_AGDS) ? (const uint8 *)CRYPT_KEY_AGDS
+	                                             : (const uint8 *)CRYPT_KEY_SIERRA;
+	for (int i = 0; i < len; i++)
 		*(mem + i) ^= *(key + (i % 11));
 }
 
diff --git a/engines/agi/inv.cpp b/engines/agi/inv.cpp
index caaae048862..bc336c0309f 100644
--- a/engines/agi/inv.cpp
+++ b/engines/agi/inv.cpp
@@ -43,14 +43,13 @@ InventoryMgr::~InventoryMgr() {
 void InventoryMgr::getPlayerInventory() {
 	AgiGame game = _vm->_game;
 	int16 selectedInventoryItem = _vm->getVar(VM_VAR_SELECTED_INVENTORY_ITEM);
-	uint16 objectNr = 0;
 	int16 curRow = 2; // starting at position 2,1
 	int16 curColumn = 1;
 
 	_array.clear();
 	_activeItemNr = 0;
 
-	for (objectNr = 0; objectNr < game.numObjects; objectNr++) {
+	for (uint16 objectNr = 0; objectNr < game.numObjects; objectNr++) {
 		if (_vm->objectGetLocation(objectNr) == EGO_OWNED) {
 			// item is in the possession of ego, so add it to our internal list
 			if (objectNr == selectedInventoryItem) {
@@ -107,12 +106,11 @@ void InventoryMgr::getPlayerInventory() {
 
 void InventoryMgr::drawAll() {
 	int16 inventoryCount = _array.size();
-	int16 inventoryNr = 0;
 
 	_text->charPos_Set(0, 11);
 	_text->displayText(_systemUI->getInventoryTextYouAreCarrying());
 
-	for (inventoryNr = 0; inventoryNr < inventoryCount; inventoryNr++) {
+	for (int16 inventoryNr = 0; inventoryNr < inventoryCount; inventoryNr++) {
 		drawItem(inventoryNr);
 	}
 }
diff --git a/engines/agi/motion.cpp b/engines/agi/motion.cpp
index bc0069c03ca..973a17a3eb7 100644
--- a/engines/agi/motion.cpp
+++ b/engines/agi/motion.cpp
@@ -144,18 +144,15 @@ void AgiEngine::motionWander(ScreenObjEntry *screenObj) {
 
 void AgiEngine::motionFollowEgo(ScreenObjEntry *screenObj) {
 	ScreenObjEntry *screenObjEgo = &_game.screenObjTable[SCREENOBJECTS_EGO_ENTRY];
-	int egoX, egoY;
-	int objX, objY;
-	int dir;
 
-	egoX = screenObjEgo->xPos + screenObjEgo->xSize / 2;
-	egoY = screenObjEgo->yPos;
+	int egoX = screenObjEgo->xPos + screenObjEgo->xSize / 2;
+	int egoY = screenObjEgo->yPos;
 
-	objX = screenObj->xPos + screenObj->xSize / 2;
-	objY = screenObj->yPos;
+	int objX = screenObj->xPos + screenObj->xSize / 2;
+	int objY = screenObj->yPos;
 
 	// Get direction to reach ego
-	dir = getDirection(objX, objY, egoX, egoY, screenObj->follow_stepSize);
+	int dir = getDirection(objX, objY, egoX, egoY, screenObj->follow_stepSize);
 
 	// Already at ego coordinates
 	if (dir == 0) {
@@ -186,15 +183,13 @@ void AgiEngine::motionFollowEgo(ScreenObjEntry *screenObj) {
 	}
 
 	if (screenObj->follow_count != 0) {
-		int k;
-
 		// DF: this is ugly and I dont know why this works, but
 		// other line does not! (watcom complained about lvalue)
 		//
 		// if (((int8)v->parm3 -= v->step_size) < 0)
 		//      v->parm3 = 0;
 
-		k = screenObj->follow_count;
+		int k = screenObj->follow_count;
 		k -= screenObj->stepSize;
 		screenObj->follow_count = k;
 
@@ -242,9 +237,6 @@ void AgiEngine::checkMotion(ScreenObjEntry *screenObj) {
  * Public functions
  */
 
-/**
- *
- */
 void AgiEngine::checkAllMotions() {
 	ScreenObjEntry *screenObj;
 
diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp
index 10334a4db39..59c0087de53 100644
--- a/engines/agi/text.cpp
+++ b/engines/agi/text.cpp
@@ -260,15 +260,12 @@ void TextMgr::display(int16 textNr, int16 textRow, int16 textColumn) {
 }
 
 void TextMgr::displayTextInsideWindow(const char *textPtr, int16 windowRow, int16 windowColumn) {
-	int16 textRow = 0;
-	int16 textColumn = 0;
-
 	if (!_messageState.window_Active)
 		return;
 
 	charPos_Push();
-	textRow = _messageState.textPos.row + windowRow;
-	textColumn = _messageState.textPos.column + windowColumn;
+	int16 textRow = _messageState.textPos.row + windowRow;
+	int16 textColumn = _messageState.textPos.column + windowColumn;
 	charPos_Set(textRow, textColumn);
 	displayText(textPtr);
 	charPos_Pop();
diff --git a/engines/agi/view.cpp b/engines/agi/view.cpp
index 45ac24c3854..4cc6eb91506 100644
--- a/engines/agi/view.cpp
+++ b/engines/agi/view.cpp
@@ -26,15 +26,13 @@
 namespace Agi {
 
 void AgiEngine::updateView(ScreenObjEntry *screenObj) {
-	int16 celNr, lastCelNr;
-
 	if (screenObj->flags & fDontUpdate) {
 		screenObj->flags &= ~fDontUpdate;
 		return;
 	}
 
-	celNr = screenObj->currentCelNr;
-	lastCelNr = screenObj->celCount - 1;
+	int16 celNr = screenObj->currentCelNr;
+	int16 lastCelNr = screenObj->celCount - 1;
 
 	switch (screenObj->cycle) {
 	case kCycleNormal:
@@ -347,7 +345,6 @@ void AgiEngine::unpackViewCelDataAGI256(AgiViewCel *celData, byte *compressedDat
 	byte *rawBitmap = new byte[celData->width * celData->height];
 	int16 remainingHeight = celData->height;
 	int16 remainingWidth = celData->width;
-	byte curByte;
 
 	celData->rawBitmap = rawBitmap;
 
@@ -355,7 +352,7 @@ void AgiEngine::unpackViewCelDataAGI256(AgiViewCel *celData, byte *compressedDat
 		if (!compressedSize)
 			error("unexpected end of data, while unpacking AGI256 view");
 
-		curByte = *compressedData++;
+		byte curByte = *compressedData++;
 		compressedSize--;
 
 		if (curByte == 0) {


Commit: 942303bbc6a002e0557f7939521d8f57d29ac76f
    https://github.com/scummvm/scummvm/commit/942303bbc6a002e0557f7939521d8f57d29ac76f
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-03-09T09:07:59-07:00

Commit Message:
AGI: Fix KQ3 infinite falling

Fixes bug #13379

Changed paths:
    engines/agi/checks.cpp


diff --git a/engines/agi/checks.cpp b/engines/agi/checks.cpp
index bd83148cc5f..ab52f683824 100644
--- a/engines/agi/checks.cpp
+++ b/engines/agi/checks.cpp
@@ -159,6 +159,15 @@ bool AgiEngine::checkPriority(ScreenObjEntry *screenObj) {
 	if (screenObj->objectNr == 0) {
 		setFlag(VM_FLAG_EGO_TOUCHED_P2, touchedTrigger);
 		setFlag(VM_FLAG_EGO_WATER, touchedWater);
+
+		// WORKAROUND: KQ3 infinite falling, bug #13379
+		// Falling off of the ladder in room 22 or the stairs in room 64 can
+		// cause ego to fall forever in place. In both rooms, and possibly
+		// others, an unrelated black priority line overlaps with fall paths.
+		// This also occurs in the original. Ignore these lines when falling.
+		if (!touchedControl && getGameID() == GID_KQ3 && screenObj->currentViewNr == 11) {
+			touchedControl = true;
+		}
 	}
 
 	return touchedControl;




More information about the Scummvm-git-logs mailing list