[Scummvm-git-logs] scummvm master -> 809a6c88859d5bfcdb40559a6b629e3fabc9042c

sev- sev at scummvm.org
Mon Oct 25 20:51:47 UTC 2021


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:
2d12c0aea6 GROOVIE: Added stubs for all Mouse Trap functions
29f47ad4e5 GROOVIE: Implemented few Mouse Trap methods
19becb5e25 GROOVIE: Unstubbed more Mouse Trap subs
6fb96e71b8 GROOVIE: Furhter work on Mouse Trap puzzle
809a6c8885 GROOVIE: Implement rest of the Mouse Trap functions


Commit: 2d12c0aea68bf0fea9979a9ee787151fbda2836a
    https://github.com/scummvm/scummvm/commit/2d12c0aea68bf0fea9979a9ee787151fbda2836a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-25T23:50:11+03:00

Commit Message:
GROOVIE: Added stubs for all Mouse Trap functions

Changed paths:
    engines/groovie/logic/mousetrap.cpp
    engines/groovie/logic/mousetrap.h


diff --git a/engines/groovie/logic/mousetrap.cpp b/engines/groovie/logic/mousetrap.cpp
index b5c09fd7e9..66913a518b 100644
--- a/engines/groovie/logic/mousetrap.cpp
+++ b/engines/groovie/logic/mousetrap.cpp
@@ -117,6 +117,9 @@ void MouseTrapGame::sub08(byte *scriptVariables) {
 void MouseTrapGame::sub09(byte *scriptVariables) {
 }
 
+void MouseTrapGame::sub11(int8 x, int8 y) {
+}
+
 int8 MouseTrapGame::xyToPos(int8 x, int8 y) {
 	return 5 * y + x + 1;
 }
@@ -157,5 +160,41 @@ bool MouseTrapGame::calcSolution() {
 		|| ((val & 2) != 0 && _mouseTrapPos.x && (_mouseTrapCells[pos + 4] & 8) != 0);
 }
 
+bool MouseTrapGame::havePosInRoute(int8 y, int8 x) {
+	return false;
+}
+
+void MouseTrapGame::addToRoute(int8 y, int8 x, int8 num) {
+}
+
+void MouseTrapGame::updateRoute() {
+}
+
+void MouseTrapGame::popLastStep(int8 *x, int8 *y) {
+}
+
+void MouseTrapGame::goFarthest(int8 *x, int8 *y) {
+}
+
+void MouseTrapGame::findMinPointInRoute(int8 *y, int8 *x) {
+}
+
+int8 MouseTrapGame::calcDistanceToExit() {
+	return 0;
+}
+
+int8 MouseTrapGame::getBestDirection(int8 *x, int8 *y) {
+	return 0;
+}
+
+int8 MouseTrapGame::findMaxPointInRoute(int8 *y, int8 *x) {
+	return 0;
+}
+
+int8 MouseTrapGame::findMaxInRoute() {
+	return 0;
+}
+
+
 
 } // End of Groovie namespace
diff --git a/engines/groovie/logic/mousetrap.h b/engines/groovie/logic/mousetrap.h
index 672e281f8d..ca70558fb4 100644
--- a/engines/groovie/logic/mousetrap.h
+++ b/engines/groovie/logic/mousetrap.h
@@ -65,12 +65,24 @@ private:
 	void sub07(byte *scriptVariables);
 	void sub08(byte *scriptVariables);
 	void sub09(byte *scriptVariables);
+	void sub11(int8 x, int8 y);
 	int8 xyToPos(int8 x, int8 y);
 	void posToXY(int8 pos, int8 *x, int8 *y);
 	void copyStateToVars(byte *scriptVariables);
 	int8 findState(int8 val);
 	void flipField(int8 x, int8 y);
 	bool calcSolution();
+	bool havePosInRoute(int8 y, int8 x);
+	void addToRoute(int8 y, int8 x, int8 num);
+	void updateRoute();
+	void popLastStep(int8 *x, int8 *y);
+	void goFarthest(int8 *x, int8 *y);
+	void findMinPointInRoute(int8 *y, int8 *x);
+	int8 calcDistanceToExit();
+	int8 getBestDirection(int8 *x, int8 *y);
+	int8 findMaxPointInRoute(int8 *y, int8 *x);
+	int8 findMaxInRoute();
+
 
 private:
 	Common::RandomSource _random;


Commit: 29f47ad4e5f0080feb75bf302a8ae6b3828c47a6
    https://github.com/scummvm/scummvm/commit/29f47ad4e5f0080feb75bf302a8ae6b3828c47a6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-25T23:50:11+03:00

Commit Message:
GROOVIE: Implemented few Mouse Trap methods

Changed paths:
    engines/groovie/logic/mousetrap.cpp
    engines/groovie/logic/mousetrap.h


diff --git a/engines/groovie/logic/mousetrap.cpp b/engines/groovie/logic/mousetrap.cpp
index 66913a518b..4dae5e5b0f 100644
--- a/engines/groovie/logic/mousetrap.cpp
+++ b/engines/groovie/logic/mousetrap.cpp
@@ -26,11 +26,13 @@
 namespace Groovie {
 
 MouseTrapGame::MouseTrapGame() : _random("MouseTrapGame") {
-	_mouseTrapCounter = 0;
+	_mouseTrapCounter = _mouseTrapCounter1 = 0;
 	_mouseTrapX = _mouseTrapY = 0;
 	memset(_mouseTrapRoute, 0, 75);
+	memset(_mouseTrapRouteCopy, 0, 76);
 	_mouseTrapPos.x = _mouseTrapPos.y = 0;
 	memset(_mouseTrapCells, 0, 31);
+	_mouseTrapNumSteps = 0;
 }
 
 void MouseTrapGame::run(byte *scriptVariables) {
@@ -93,6 +95,10 @@ static const int8 mouseTrapStates[] = {
 	6, 12,  9,  3
 };
 
+static const int8 mouseTrapLookup[] = {
+	1, 0, 3, 0, 0, 1, 0, 3, 1, 4, 3, 4, 4, 1, 4, 3
+};
+
 void MouseTrapGame::init() {
 }
 
@@ -117,7 +123,25 @@ void MouseTrapGame::sub08(byte *scriptVariables) {
 void MouseTrapGame::sub09(byte *scriptVariables) {
 }
 
-void MouseTrapGame::sub11(int8 x, int8 y) {
+void MouseTrapGame::copyRoute(int8 x, int8 y) {
+	int i;
+
+	for (i = 0; i < _mouseTrapCounter > i; i++) {
+		if (_mouseTrapRoute[3 * i] == x && _mouseTrapRoute[3 * i + 1] == y )
+			break;
+	}
+
+	_mouseTrapCounter1 = 0;
+
+	do {
+		_mouseTrapRouteCopy[3 * _mouseTrapCounter1 + 0] = _mouseTrapRoute[3 * i + 0];
+		_mouseTrapRouteCopy[3 * _mouseTrapCounter1 + 1] = _mouseTrapRoute[3 * i + 1];
+		_mouseTrapRouteCopy[3 * _mouseTrapCounter1 + 2] = _mouseTrapRoute[3 * i + 2];
+
+		_mouseTrapCounter1++;
+
+		i = _mouseTrapRoute[3 * i + 2];
+	} while (i);
 }
 
 int8 MouseTrapGame::xyToPos(int8 x, int8 y) {
@@ -171,30 +195,138 @@ void MouseTrapGame::updateRoute() {
 }
 
 void MouseTrapGame::popLastStep(int8 *x, int8 *y) {
+	_mouseTrapCounter1--;
+
+	*x = _mouseTrapRouteCopy[3 * _mouseTrapCounter1];
+	*y = _mouseTrapRouteCopy[3 * _mouseTrapCounter1 + 1];
 }
 
 void MouseTrapGame::goFarthest(int8 *x, int8 *y) {
+	int8 origX = _mouseTrapX;
+	int8 origY = _mouseTrapY;
+	int8 maxVal = 0;
+	int8 maxX = 0, maxY = 0;
+
+	if (_mouseTrapNumSteps)
+		--_mouseTrapNumSteps;
+
+	for (int8 i = 0; i < 8; i++) {
+		int8 x1 = mouseTrapLookup[2 * i];
+		int8 y1 = mouseTrapLookup[2 * i + 1];
+		if (x1 != origX || y1 != origY) {
+			flipField(x1, y1);
+
+			int8 dist = calcDistanceToExit();
+
+			if (_mouseTrapNumSteps && _random.getRandomNumber(1) != 0 )
+				dist += 3;
+
+			if (dist >= maxVal) {
+				maxVal = dist;
+				maxX = x1;
+				maxY = y1;
+			}
+
+			flipField(mouseTrapLookup[2 * ((i + 4) & 7)], mouseTrapLookup[2 * ((i + 4) & 7) + 1]);
+		}
+	}
+
+	*x = maxX;
+	*y = maxY;
 }
 
 void MouseTrapGame::findMinPointInRoute(int8 *y, int8 *x) {
+	int8 maxVal = 0;
+	int8 x1 = _mouseTrapPos.x;
+	int8 y1 = _mouseTrapPos.y;
+	for (int i = 0; i < _mouseTrapCounter > i; i++) {
+		if (8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i] > maxVal) {
+			maxVal = 8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i];
+			y1 = _mouseTrapRoute[3 * i];
+			x1 = _mouseTrapRoute[3 * i + 1];
+		}
+	}
+	*y = y1;
+	*x = x1;
 }
 
 int8 MouseTrapGame::calcDistanceToExit() {
-	return 0;
+	int8 maxDist = 0;
+
+	updateRoute();
+	if (havePosInRoute(4, 4))
+		return 0;
+
+	for (int i = 0; i < _mouseTrapCounter > i; i++) {
+		if (8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i] > maxDist)
+			maxDist = 8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i];
+	}
+
+	return maxDist;
 }
 
-int8 MouseTrapGame::getBestDirection(int8 *x, int8 *y) {
-	return 0;
+void MouseTrapGame::getBestDirection(int8 *x, int8 *y) {
+	int8 maxVal = 0;
+	int8 origX = _mouseTrapX;
+	int8 origY = _mouseTrapY;
+	_mouseTrapNumSteps = 8;
+	int8 maxX = 0, maxY = 0;
+
+	for (int i = 0; i < 8; i++) {
+		int x1 = mouseTrapLookup[2 * i];
+		int y1 = mouseTrapLookup[2 * i + 1];
+
+		if (origX != x1 || origY != y1) {
+			flipField(x1, y1);
+
+			int8 maxInRoute = findMaxInRoute();
+			if (maxInRoute >= maxVal) {
+				maxVal = maxInRoute;
+				maxX = x1;
+				maxY = y1;
+			}
+
+			flipField(mouseTrapLookup[2 * ((i + 4) & 7)], mouseTrapLookup[2 * ((i + 4) & 7) + 1]);
+		}
+	}
+
+	*x = maxX;
+	*y = maxY;
 }
 
-int8 MouseTrapGame::findMaxPointInRoute(int8 *y, int8 *x) {
-	return 0;
+void MouseTrapGame::findMaxPointInRoute(int8 *y, int8 *x) {
+	int8 maxVal = 0;
+	int8 y1 = _mouseTrapPos.y;
+	int8 x1 = _mouseTrapPos.x;
+
+	updateRoute();
+
+	for (int i = 0; i < _mouseTrapCounter; i++) {
+		if (_mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1] > maxVal) {
+			maxVal = _mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1];
+			y1 = _mouseTrapRoute[3 * i];
+			x1 = _mouseTrapRoute[3 * i + 1];
+		}
+	}
+
+	*y = y1;
+	*x = x1;
 }
 
 int8 MouseTrapGame::findMaxInRoute() {
-	return 0;
-}
+	updateRoute();
+
+	if (havePosInRoute(0, 0))
+		return 0;
 
+	int8 maxCoords = 0;
 
+	for (int i = 0; i < _mouseTrapCounter; i++) {
+		if (_mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1] > maxCoords )
+			maxCoords = _mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1];
+		}
+
+	return maxCoords;
+}
 
 } // End of Groovie namespace
diff --git a/engines/groovie/logic/mousetrap.h b/engines/groovie/logic/mousetrap.h
index ca70558fb4..fcb7716284 100644
--- a/engines/groovie/logic/mousetrap.h
+++ b/engines/groovie/logic/mousetrap.h
@@ -65,7 +65,7 @@ private:
 	void sub07(byte *scriptVariables);
 	void sub08(byte *scriptVariables);
 	void sub09(byte *scriptVariables);
-	void sub11(int8 x, int8 y);
+	void copyRoute(int8 x, int8 y);
 	int8 xyToPos(int8 x, int8 y);
 	void posToXY(int8 pos, int8 *x, int8 *y);
 	void copyStateToVars(byte *scriptVariables);
@@ -79,18 +79,20 @@ private:
 	void goFarthest(int8 *x, int8 *y);
 	void findMinPointInRoute(int8 *y, int8 *x);
 	int8 calcDistanceToExit();
-	int8 getBestDirection(int8 *x, int8 *y);
-	int8 findMaxPointInRoute(int8 *y, int8 *x);
+	void getBestDirection(int8 *x, int8 *y);
+	void findMaxPointInRoute(int8 *y, int8 *x);
 	int8 findMaxInRoute();
 
 
 private:
 	Common::RandomSource _random;
 	int8 _mouseTrapX, _mouseTrapY;
-	int8 _mouseTrapCounter;
+	int8 _mouseTrapCounter, _mouseTrapCounter1;
 	int8 _mouseTrapRoute[75];
+	int8 _mouseTrapRouteCopy[76];
 	int8 _mouseTrapCells[31];
 	Point8 _mouseTrapPos;
+	int8 _mouseTrapNumSteps;
 };
 
 } // End of Groovie namespace


Commit: 19becb5e25822798f2d89a0d3076cbc6e9834667
    https://github.com/scummvm/scummvm/commit/19becb5e25822798f2d89a0d3076cbc6e9834667
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-25T23:50:11+03:00

Commit Message:
GROOVIE: Unstubbed more Mouse Trap subs

Changed paths:
    engines/groovie/logic/mousetrap.cpp
    engines/groovie/logic/mousetrap.h


diff --git a/engines/groovie/logic/mousetrap.cpp b/engines/groovie/logic/mousetrap.cpp
index 4dae5e5b0f..43ebc2ab6f 100644
--- a/engines/groovie/logic/mousetrap.cpp
+++ b/engines/groovie/logic/mousetrap.cpp
@@ -30,7 +30,7 @@ MouseTrapGame::MouseTrapGame() : _random("MouseTrapGame") {
 	_mouseTrapX = _mouseTrapY = 0;
 	memset(_mouseTrapRoute, 0, 75);
 	memset(_mouseTrapRouteCopy, 0, 76);
-	_mouseTrapPos.x = _mouseTrapPos.y = 0;
+	_mouseTrapPosX = _mouseTrapPosY = 0;
 	memset(_mouseTrapCells, 0, 31);
 	_mouseTrapNumSteps = 0;
 }
@@ -175,23 +175,60 @@ void MouseTrapGame::flipField(int8 x, int8 y) {
 }
 
 bool MouseTrapGame::calcSolution() {
-	int8 pos = _mouseTrapPos.x + 5 * _mouseTrapPos.y;
+	int8 pos = _mouseTrapPosY + 5 * _mouseTrapPosX;	// coordinates swapped?
 	int8 val = _mouseTrapCells[pos + 5];
 
-	return ((val & 1) != 0 && _mouseTrapPos.y && (_mouseTrapCells[pos] & 4) != 0)
-		|| ((val & 4) != 0 && _mouseTrapPos.y < 4 && (_mouseTrapCells[pos + 10] & 1) != 0)
-		|| ((val & 8) != 0 && _mouseTrapPos.x < 4 && (_mouseTrapCells[pos + 6] & 2) != 0)
-		|| ((val & 2) != 0 && _mouseTrapPos.x && (_mouseTrapCells[pos + 4] & 8) != 0);
+	return ((val & 1) != 0 && _mouseTrapPosX && (_mouseTrapCells[pos] & 4) != 0)
+		|| ((val & 4) != 0 && _mouseTrapPosX < 4 && (_mouseTrapCells[pos + 10] & 1) != 0)
+		|| ((val & 8) != 0 && _mouseTrapPosY < 4 && (_mouseTrapCells[pos + 6] & 2) != 0)
+		|| ((val & 2) != 0 && _mouseTrapPosY && (_mouseTrapCells[pos + 4] & 8) != 0);
 }
 
-bool MouseTrapGame::havePosInRoute(int8 y, int8 x) {
+bool MouseTrapGame::havePosInRoute(int8 x, int8 y) {
+	for (int i = 0; i < _mouseTrapCounter; i++) {
+		if (_mouseTrapRoute[3 * i] == x && _mouseTrapRoute[3 * i + 1] == y)
+			return true;
+	}
+
 	return false;
 }
 
-void MouseTrapGame::addToRoute(int8 y, int8 x, int8 num) {
+void MouseTrapGame::addToRoute(int8 x, int8 y, int8 num) {
+	if (!havePosInRoute(x, y)) {
+		_mouseTrapRoute[3 * _mouseTrapCounter] = x;
+		_mouseTrapRoute[3 * _mouseTrapCounter + 1] = y;
+		_mouseTrapRoute[3 * _mouseTrapCounter + 2] = num;
+
+		_mouseTrapCounter++;
+	}
 }
 
 void MouseTrapGame::updateRoute() {
+	_mouseTrapCounter = 0;
+
+	addToRoute(_mouseTrapPosX, _mouseTrapPosY, 0);
+
+	int prevCounter = 0;
+
+	do {
+		prevCounter = _mouseTrapCounter;
+
+		for (int i = prevCounter; i < _mouseTrapCounter; i++) {
+			int8 y1 = _mouseTrapRoute[3 * i + 1];
+			int8 x1 = _mouseTrapRoute[3 * i];
+			int8 pos = 5 * x1 + y1;
+			int8 mask = _mouseTrapCells[pos + 5];
+
+			if ((mask & 1) != 0 && x1 && (_mouseTrapCells[pos] & 4) != 0)
+				addToRoute(x1 - 1, y1, i);
+			if ((mask & 4) != 0 && x1 < 4 && (_mouseTrapCells[pos + 10] & 1) != 0)
+				addToRoute(x1 + 1, y1, i);
+			if ((mask & 8) != 0 && y1 < 4 && (_mouseTrapCells[pos + 6] & 2) != 0)
+				addToRoute(x1, y1 + 1, i);
+			if ((mask & 2) != 0 && y1 && (_mouseTrapCells[pos + 4] & 8) != 0)
+				addToRoute(x1, y1 - 1, i);
+		}
+	} while (_mouseTrapCounter != prevCounter);
 }
 
 void MouseTrapGame::popLastStep(int8 *x, int8 *y) {
@@ -235,19 +272,19 @@ void MouseTrapGame::goFarthest(int8 *x, int8 *y) {
 	*y = maxY;
 }
 
-void MouseTrapGame::findMinPointInRoute(int8 *y, int8 *x) {
+void MouseTrapGame::findMinPointInRoute(int8 *x, int8 *y) {
 	int8 maxVal = 0;
-	int8 x1 = _mouseTrapPos.x;
-	int8 y1 = _mouseTrapPos.y;
+	int8 x1 = _mouseTrapPosX;
+	int8 y1 = _mouseTrapPosY;
 	for (int i = 0; i < _mouseTrapCounter > i; i++) {
 		if (8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i] > maxVal) {
 			maxVal = 8 - _mouseTrapRoute[3 * i + 1] - _mouseTrapRoute[3 * i];
-			y1 = _mouseTrapRoute[3 * i];
-			x1 = _mouseTrapRoute[3 * i + 1];
+			x1 = _mouseTrapRoute[3 * i];
+			y1 = _mouseTrapRoute[3 * i + 1];
 		}
 	}
-	*y = y1;
 	*x = x1;
+	*y = y1;
 }
 
 int8 MouseTrapGame::calcDistanceToExit() {
@@ -294,23 +331,23 @@ void MouseTrapGame::getBestDirection(int8 *x, int8 *y) {
 	*y = maxY;
 }
 
-void MouseTrapGame::findMaxPointInRoute(int8 *y, int8 *x) {
+void MouseTrapGame::findMaxPointInRoute(int8 *x, int8 *y) {
 	int8 maxVal = 0;
-	int8 y1 = _mouseTrapPos.y;
-	int8 x1 = _mouseTrapPos.x;
+	int8 x1 = _mouseTrapPosX;
+	int8 y1 = _mouseTrapPosY;
 
 	updateRoute();
 
 	for (int i = 0; i < _mouseTrapCounter; i++) {
 		if (_mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1] > maxVal) {
 			maxVal = _mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1];
-			y1 = _mouseTrapRoute[3 * i];
-			x1 = _mouseTrapRoute[3 * i + 1];
+			x1 = _mouseTrapRoute[3 * i];
+			y1 = _mouseTrapRoute[3 * i + 1];
 		}
 	}
 
-	*y = y1;
 	*x = x1;
+	*y = y1;
 }
 
 int8 MouseTrapGame::findMaxInRoute() {
diff --git a/engines/groovie/logic/mousetrap.h b/engines/groovie/logic/mousetrap.h
index fcb7716284..c570197dfe 100644
--- a/engines/groovie/logic/mousetrap.h
+++ b/engines/groovie/logic/mousetrap.h
@@ -28,11 +28,6 @@
 
 namespace Groovie {
 
-struct Point8 {
-	int8 x;
-	int8 y;
-};
-
 /*
  * Mouse Trap puzzle in the Lab.
  *
@@ -80,7 +75,7 @@ private:
 	void findMinPointInRoute(int8 *y, int8 *x);
 	int8 calcDistanceToExit();
 	void getBestDirection(int8 *x, int8 *y);
-	void findMaxPointInRoute(int8 *y, int8 *x);
+	void findMaxPointInRoute(int8 *x, int8 *y);
 	int8 findMaxInRoute();
 
 
@@ -91,7 +86,7 @@ private:
 	int8 _mouseTrapRoute[75];
 	int8 _mouseTrapRouteCopy[76];
 	int8 _mouseTrapCells[31];
-	Point8 _mouseTrapPos;
+	int8 _mouseTrapPosX, _mouseTrapPosY;
 	int8 _mouseTrapNumSteps;
 };
 


Commit: 6fb96e71b84a50248ea9f83f29cc45f41d5490e7
    https://github.com/scummvm/scummvm/commit/6fb96e71b84a50248ea9f83f29cc45f41d5490e7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-25T23:50:11+03:00

Commit Message:
GROOVIE: Furhter work on Mouse Trap puzzle

Changed paths:
    engines/groovie/logic/mousetrap.cpp


diff --git a/engines/groovie/logic/mousetrap.cpp b/engines/groovie/logic/mousetrap.cpp
index 43ebc2ab6f..80f1e28828 100644
--- a/engines/groovie/logic/mousetrap.cpp
+++ b/engines/groovie/logic/mousetrap.cpp
@@ -92,7 +92,7 @@ void MouseTrapGame::run(byte *scriptVariables) {
 }
 
 static const int8 mouseTrapStates[] = {
-	6, 12,  9,  3
+	6, 12, 9, 3
 };
 
 static const int8 mouseTrapLookup[] = {
@@ -103,9 +103,32 @@ void MouseTrapGame::init() {
 }
 
 void MouseTrapGame::sub01(byte *scriptVariables) {
+	int8 x, y;
+
+	findMaxPointInRoute(&x, &y);
+	scriptVariables[5] = (_mouseTrapPosX == x && _mouseTrapPosY == y) ? 1 : 0;
+	if (havePosInRoute(4, 4)) {
+		copyRoute(4, 4);
+		scriptVariables[22] = 1;
+	} else if (havePosInRoute(0, 0)) {
+		copyRoute(0, 0);
+		scriptVariables[22] = 2;
+	} else {
+		scriptVariables[22] = 0;
+		if (!scriptVariables[5])
+			copyRoute(x, y);
+	}
 }
 
 void MouseTrapGame::sub03(byte *scriptVariables) {
+	int cnt = 1;
+	for (int i = 0; i < 5; i++) {
+		for (int j = 0; j < 5; j++) {
+			scriptVariables[cnt + 25] = findState(_mouseTrapCells[5 * j + 5 + i]);
+			cnt++;
+		}
+	}
+	scriptVariables[23] = findState(_mouseTrapCells[30]);
 }
 
 void MouseTrapGame::sub05(byte *scriptVariables) {
@@ -118,16 +141,77 @@ void MouseTrapGame::sub07(byte *scriptVariables) {
 }
 
 void MouseTrapGame::sub08(byte *scriptVariables) {
+	int8 x1, y1, x, y;
+
+	popLastStep(&x1, &y1);
+	int8 pos = xyToPos(x1, y1);
+
+	_mouseTrapPosX = x1;
+	_mouseTrapPosY = y1;
+
+	scriptVariables[0] = scriptVariables[11];
+	scriptVariables[1] = scriptVariables[12];
+	scriptVariables[11] = pos / 10;
+	scriptVariables[12] = pos % 10;
+	posToXY(scriptVariables[1] + 10 * scriptVariables[0], &x, &y);
+
+	if (y <= y1) {
+		if (y >= y1) {
+			if (x <= x1) {
+				if (x < x1)
+					scriptVariables[15] = 1;
+			} else {
+				scriptVariables[15] = 3;
+			}
+		} else {
+			scriptVariables[15] = 2;
+		}
+	} else {
+		scriptVariables[15] = 0;
+	}
+
+	if (!_mouseTrapCounter1)
+		scriptVariables[2] = 0;
 }
 
 void MouseTrapGame::sub09(byte *scriptVariables) {
+	int8 x1, y1, x2, y2;
+
+	getBestDirection(&x1, &y1);
+	flipField(x1, y1);
+
+	if (!calcSolution()) {
+		scriptVariables[5] = 1;
+		scriptVariables[22] = 0;
+	} else {
+		scriptVariables[5] = 0;
+		updateRoute();
+
+		if (!havePosInRoute(4, 4)) {
+			if (havePosInRoute(0, 0)) {
+				copyRoute(0, 0);
+				scriptVariables[22] = 2;
+			} else {
+				findMaxPointInRoute(&x2, &y2);
+				copyRoute(x2, y2);
+				scriptVariables[22] = 0;
+			}
+		} else {
+			copyRoute(4, 4);
+			scriptVariables[22] = 1;
+		}
+	}
+
+	int8 pos = xyToPos(x1, y1);
+	scriptVariables[0] = pos / 10;
+	scriptVariables[1] = pos % 10;
 }
 
 void MouseTrapGame::copyRoute(int8 x, int8 y) {
 	int i;
 
 	for (i = 0; i < _mouseTrapCounter > i; i++) {
-		if (_mouseTrapRoute[3 * i] == x && _mouseTrapRoute[3 * i + 1] == y )
+		if (_mouseTrapRoute[3 * i] == x && _mouseTrapRoute[3 * i + 1] == y)
 			break;
 	}
 
@@ -162,16 +246,107 @@ void MouseTrapGame::copyStateToVars(byte *scriptVariables) {
 }
 
 int8 MouseTrapGame::findState(int8 val) {
-  int8 result = 0;
+	int8 result = 0;
 
-  while (mouseTrapStates[result] != val) {
-    if (++result >= 4)
-      return -1;
-  }
-  return result;
+	while (mouseTrapStates[result] != val) {
+		if (++result >= 4)
+			return -1;
+	}
+	return result;
 }
 
 void MouseTrapGame::flipField(int8 x, int8 y) {
+	int8 tmp;
+
+	if (y) {
+		if (y == 4) {
+			if (x == 1) {
+				tmp = _mouseTrapCells[10];
+				_mouseTrapCells[10] = _mouseTrapCells[11];
+				_mouseTrapCells[11] = _mouseTrapCells[12];
+				_mouseTrapCells[12] = _mouseTrapCells[13];
+				_mouseTrapCells[13] = _mouseTrapCells[14];
+				_mouseTrapCells[14] = _mouseTrapCells[30];
+				_mouseTrapCells[30] = tmp;
+				_mouseTrapX = 1;
+				_mouseTrapY = 0;
+			} else if (x == 3) {
+				tmp = _mouseTrapCells[20];
+				_mouseTrapCells[20] = _mouseTrapCells[21];
+				_mouseTrapCells[21] = _mouseTrapCells[22];
+				_mouseTrapCells[22] = _mouseTrapCells[23];
+				_mouseTrapCells[23] = _mouseTrapCells[24];
+				_mouseTrapCells[24] = _mouseTrapCells[30];
+				_mouseTrapCells[30] = tmp;
+				_mouseTrapX = 3;
+				_mouseTrapY = 0;
+			}
+		} else if (x) {
+			if (x == 4) {
+				if (y == 1) {
+					tmp = _mouseTrapCells[6];
+					_mouseTrapCells[6] = _mouseTrapCells[11];
+					_mouseTrapCells[11] = _mouseTrapCells[16];
+					_mouseTrapCells[16] = _mouseTrapCells[21];
+					_mouseTrapCells[21] = _mouseTrapCells[26];
+					_mouseTrapCells[26] = _mouseTrapCells[30];
+					_mouseTrapCells[30] = tmp;
+					_mouseTrapX = 0;
+					_mouseTrapY = 1;
+				} else if (y == 3) {
+					tmp = _mouseTrapCells[8];
+					_mouseTrapCells[8] = _mouseTrapCells[13];
+					_mouseTrapCells[13] = _mouseTrapCells[18];
+					_mouseTrapCells[18] = _mouseTrapCells[23];
+					_mouseTrapCells[23] = _mouseTrapCells[28];
+					_mouseTrapCells[28] = _mouseTrapCells[30];
+					_mouseTrapCells[30] = tmp;
+					_mouseTrapX = 0;
+					_mouseTrapY = 3;
+				}
+			}
+		} else if (y == 1) {
+			tmp = _mouseTrapCells[26];
+			_mouseTrapCells[26] = _mouseTrapCells[21];
+			_mouseTrapCells[21] = _mouseTrapCells[16];
+			_mouseTrapCells[16] = _mouseTrapCells[11];
+			_mouseTrapCells[11] = _mouseTrapCells[6];
+			_mouseTrapCells[6] = _mouseTrapCells[30];
+			_mouseTrapCells[30] = tmp;
+			_mouseTrapX = 4;
+			_mouseTrapY = 1;
+		} else if (y == 3) {
+			tmp = _mouseTrapCells[28];
+			_mouseTrapCells[28] = _mouseTrapCells[23];
+			_mouseTrapCells[23] = _mouseTrapCells[18];
+			_mouseTrapCells[18] = _mouseTrapCells[13];
+			_mouseTrapCells[13] = _mouseTrapCells[8];
+			_mouseTrapCells[8] = _mouseTrapCells[30];
+			_mouseTrapCells[30] = tmp;
+			_mouseTrapX = 4;
+			_mouseTrapY = 3;
+		}
+	} else if (x == 1) {
+		tmp = _mouseTrapCells[14];
+		_mouseTrapCells[14] = _mouseTrapCells[13];
+		_mouseTrapCells[13] = _mouseTrapCells[12];
+		_mouseTrapCells[12] = _mouseTrapCells[11];
+		_mouseTrapCells[11] = _mouseTrapCells[10];
+		_mouseTrapCells[10] = _mouseTrapCells[30];
+		_mouseTrapCells[30] = tmp;
+		_mouseTrapX = 1;
+		_mouseTrapY = 4;
+	} else if (x == 3) {
+		tmp = _mouseTrapCells[24];
+		_mouseTrapCells[24] = _mouseTrapCells[23];
+		_mouseTrapCells[23] = _mouseTrapCells[22];
+		_mouseTrapCells[22] = _mouseTrapCells[21];
+		_mouseTrapCells[21] = _mouseTrapCells[20];
+		_mouseTrapCells[20] = _mouseTrapCells[30];
+		_mouseTrapCells[30] = tmp;
+		_mouseTrapX = 3;
+		_mouseTrapY = 4;
+	}
 }
 
 bool MouseTrapGame::calcSolution() {
@@ -255,7 +430,7 @@ void MouseTrapGame::goFarthest(int8 *x, int8 *y) {
 
 			int8 dist = calcDistanceToExit();
 
-			if (_mouseTrapNumSteps && _random.getRandomNumber(1) != 0 )
+			if (_mouseTrapNumSteps && _random.getRandomNumber(1) != 0)
 				dist += 3;
 
 			if (dist >= maxVal) {
@@ -359,7 +534,7 @@ int8 MouseTrapGame::findMaxInRoute() {
 	int8 maxCoords = 0;
 
 	for (int i = 0; i < _mouseTrapCounter; i++) {
-		if (_mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1] > maxCoords )
+		if (_mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1] > maxCoords)
 			maxCoords = _mouseTrapRoute[3 * i] + _mouseTrapRoute[3 * i + 1];
 		}
 


Commit: 809a6c88859d5bfcdb40559a6b629e3fabc9042c
    https://github.com/scummvm/scummvm/commit/809a6c88859d5bfcdb40559a6b629e3fabc9042c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-25T23:50:11+03:00

Commit Message:
GROOVIE: Implement rest of the Mouse Trap functions

Changed paths:
    engines/groovie/logic/mousetrap.cpp


diff --git a/engines/groovie/logic/mousetrap.cpp b/engines/groovie/logic/mousetrap.cpp
index 80f1e28828..4ae7bc4775 100644
--- a/engines/groovie/logic/mousetrap.cpp
+++ b/engines/groovie/logic/mousetrap.cpp
@@ -100,6 +100,68 @@ static const int8 mouseTrapLookup[] = {
 };
 
 void MouseTrapGame::init() {
+	int8 initState[8], initX[8], initY[8];
+
+	initState[0] = 0;
+	initState[1] = 1;
+	initState[3] = 3;
+	initState[2] = 2;
+	initState[4] = 4;
+	initState[5] = 5;
+	initState[6] = 6;
+	initState[7] = 7;
+	initY[0] = 1;
+	initY[1] = 3;
+	initY[2] = 0;
+	initY[3] = 4;
+	initY[4] = 0;
+	initY[5] = 4;
+	initY[6] = 1;
+	initY[7] = 3;
+	initX[0] = 0;
+	initX[1] = 0;
+	initX[2] = 1;
+	initX[3] = 1;
+	initX[4] = 3;
+	initX[5] = 3;
+	initX[6] = 4;
+	initX[7] = 4;
+
+	for (int i = 7; i >= 0; i--) {
+		int8 j = _random.getRandomNumber(i);
+
+		_mouseTrapCells[5 * initY[i] + 5 + initX[i]] = mouseTrapStates[initState[j] >> 1];
+
+		for (; j < i; j++) {
+			initState[j] = initState[j + 1];
+		}
+	}
+
+	_mouseTrapCells[11] = mouseTrapStates[3];
+	_mouseTrapCells[16] = mouseTrapStates[0];
+	_mouseTrapCells[5] = 12;
+	_mouseTrapCells[21] = mouseTrapStates[0];
+	_mouseTrapCells[12] = mouseTrapStates[3];
+	_mouseTrapCells[15] = 13;
+	_mouseTrapCells[25] = 9;
+	_mouseTrapCells[22] = mouseTrapStates[1];
+	_mouseTrapCells[13] = mouseTrapStates[2];
+	_mouseTrapCells[18] = mouseTrapStates[2];
+	_mouseTrapCells[23] = mouseTrapStates[1];
+	_mouseTrapCells[7] = 14;
+	_mouseTrapCells[17] = 15;
+	_mouseTrapCells[27] = 11;
+	_mouseTrapCells[9] = 6;
+	_mouseTrapCells[19] = 7;
+	_mouseTrapCells[29] = 3;
+	_mouseTrapCells[30] = mouseTrapStates[_random.getRandomNumber(3)];
+
+	_mouseTrapPosY = 2;
+	_mouseTrapPosX = 2;
+	_mouseTrapY = 0;
+	_mouseTrapX = 0;
+	_mouseTrapNumSteps = 0;
+	_mouseTrapCounter = 0;
 }
 
 void MouseTrapGame::sub01(byte *scriptVariables) {
@@ -132,12 +194,75 @@ void MouseTrapGame::sub03(byte *scriptVariables) {
 }
 
 void MouseTrapGame::sub05(byte *scriptVariables) {
+	int8 x, y;
+
+	posToXY(scriptVariables[1] + 10 * scriptVariables[0], &x, &y);
+	flipField(x, y);
+
+	if (calcSolution()) {
+		scriptVariables[5] = 0;
+		updateRoute();
+
+		if (havePosInRoute(4, 4)) {
+			copyRoute(4, 4);
+			scriptVariables[22] = 1;
+		} else if (havePosInRoute(0, 0)) {
+			copyRoute(0, 0);
+			scriptVariables[22] = 2;
+		} else {
+			copyStateToVars(scriptVariables);
+			scriptVariables[22] = 0;
+		}
+	} else {
+		scriptVariables[5] = 1;
+		scriptVariables[22] = 0;
+	}
 }
 
 void MouseTrapGame::sub06(byte *scriptVariables) {
+	int8 x, y;
+
+	posToXY(10 * scriptVariables[0] + scriptVariables[1], &x, &y);
+	copyRoute(x, y);
 }
 
 void MouseTrapGame::sub07(byte *scriptVariables) {
+	int8 x1, y1, x2, y2;
+
+	goFarthest(&x1, &y1);
+	flipField(x1, y1);
+
+	if (!calcSolution()) {
+		scriptVariables[5] = 1;
+		scriptVariables[22] = 0;
+	} else {
+		scriptVariables[5] = 0;
+		updateRoute();
+
+		if (!havePosInRoute(0, 0)) {
+			if (havePosInRoute(4, 4)) {
+				copyRoute(4, 4);
+				scriptVariables[22] = 1;
+			} else {
+				findMinPointInRoute(&x2, &y2);
+
+				if (_mouseTrapPosX != x2 || _mouseTrapPosY != y2) {
+					copyRoute(x2, y2);
+					scriptVariables[22] = 0;
+				} else {
+					scriptVariables[5] = 1;
+					scriptVariables[22] = 0;
+				}
+			}
+		} else {
+			copyRoute(0, 0);
+			scriptVariables[22] = 2;
+		}
+	}
+
+	int8 pos = xyToPos(x1, y1);
+	scriptVariables[0] = pos / 10;
+	scriptVariables[1] = pos % 10;
 }
 
 void MouseTrapGame::sub08(byte *scriptVariables) {




More information about the Scummvm-git-logs mailing list