[Scummvm-git-logs] scummvm master -> 0693fa1885328b00bb4ebafb03f6208a36c6fbd5

sev- sev at scummvm.org
Thu Oct 21 20:54:13 UTC 2021


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

Summary:
c66f880858 GROOVIE: Initial complete code for opGallery
0693fa1885 GROOVIE: Fix logic in opGallery


Commit: c66f880858cf929e3aa246cec80a29505a56d57d
    https://github.com/scummvm/scummvm/commit/c66f880858cf929e3aa246cec80a29505a56d57d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-21T23:53:54+03:00

Commit Message:
GROOVIE: Initial complete code for opGallery

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


diff --git a/engines/groovie/logic/t11hgame.cpp b/engines/groovie/logic/t11hgame.cpp
index 0eadafd457..7e18efdc17 100644
--- a/engines/groovie/logic/t11hgame.cpp
+++ b/engines/groovie/logic/t11hgame.cpp
@@ -656,35 +656,38 @@ const byte T11hGame::kGalleryLinks[21][10] = {
 	{12, 14, 15, 18, 20,  0,  0,  0,  0,  0 }	// 21
 };
 
+const int kPieceCount = 21;
+enum kGalleryPieceStatus {
+	kPieceUnselected = 0,
+	kPieceSelected = 1
+};
+
 void T11hGame::opGallery() {
-	const int kPieceCount = 21;
 	byte pieceStatus[kPieceCount];
-	byte var_18[kPieceCount];
-	int selectedPieces;
-	byte curLink = 0;
-
-	enum kGalleryPieceStatus {
-		kPieceUnselected = 0,
-		kPieceSelected = 1
-	};
+	byte status1[kPieceCount];
+	byte status2[kPieceCount];
 
-	memcpy(pieceStatus, _scriptVariables + 26, kPieceCount);
+	memcpy(pieceStatus, _scriptVariables + 25, kPieceCount);
 
-	selectedPieces = 0;
+	int selectedPieces = 0;
 	for (int i = 0; i < kPieceCount; i++) {
-		var_18[i] = 0;
-		if (pieceStatus[i] == kPieceSelected) {
-			curLink = kGalleryLinks[i][0];
+		status1[i] = 0;
+		if (pieceStatus[i + 1] == kPieceSelected) {
+			for (int j = 0; j < kPieceCount; j++)
+				status2[j] = pieceStatus[j];
+
+			byte curLink = kGalleryLinks[i][0];
 			pieceStatus[i] = kPieceUnselected;
+			status2[i] = 0;
 
 			int linkedPiece = 1;
 			while (curLink != 0) {
 				linkedPiece++;
-				pieceStatus[curLink - 1] = kPieceUnselected;
+				status2[curLink - 1] = kPieceUnselected;
 				curLink = kGalleryLinks[linkedPiece - 1][i];
 			}
-			var_18[i] = opGallerySub(pieceStatus, 1);
-			if (var_18[i] == kPieceSelected) {
+			status1[i] = opGalleryAI(status2, 1);
+			if (status1[i] == kPieceSelected) {
 				selectedPieces++;
 			}
 		}
@@ -693,8 +696,8 @@ void T11hGame::opGallery() {
 	if (selectedPieces == 0) {
 		int esi = 0;
 		for (int i = 0; i < kPieceCount; i++) {
-			if (esi < var_18[i]) {
-				esi = var_18[i];
+			if (esi < status1[i]) {
+				esi = status1[i];
 			}
 		}
 
@@ -709,28 +712,78 @@ void T11hGame::opGallery() {
 		}
 
 		for (int i = 0; i < kPieceCount; i++) {
-			if (esi < var_18[i]) {
-				var_18[i] = kPieceSelected;
+			if (esi < status1[i]) {
+				status1[i] = kPieceSelected;
 				selectedPieces++;
 			}
 		}
 	}
 
-	int selectedPiece;
+	int selectedPiece = 0;
+
+	byte v12 = _scriptVariables[49] % selectedPieces;
+	for (int i = 0; i < kPieceCount; i++) {
+		if (status1[selectedPiece] == 1 && !v12--)
+			break;
 
-	// TODO: copy the AI from the game
-	do {
-		selectedPiece = _random.getRandomNumber(20) + 1;
-	} while (_scriptVariables[selectedPiece + 25] != 1);
+		selectedPiece++;
+	}
 
-	setScriptVar(47, selectedPiece / 10);
-	setScriptVar(48, selectedPiece % 10);
+	setScriptVar(47, (selectedPiece + 1) / 10);
+	setScriptVar(48, (selectedPiece + 1) % 10);
 }
 
-byte T11hGame::opGallerySub(byte *field, int start) {
-	// TODO
-	warning("STUB: T11hGame::opGallerySub()");
-	return 0;
+byte T11hGame::opGalleryAI(byte *pieceStatus, int depth) {
+	byte status1[kPieceCount];
+	byte status2[kPieceCount];
+
+	int selectedPieces = 0;
+
+	for (int i = 0; i < kPieceCount; i++) {
+		status1[i] = 0;
+		if (pieceStatus[i] == kPieceSelected) {
+			for (int j = 0; j < kPieceCount; j++)
+				status2[j] = pieceStatus[j];
+
+			byte curLink = kGalleryLinks[i][0];
+			pieceStatus[i] = kPieceUnselected;
+			status2[i] = 0;
+			selectedPieces = 1;
+
+			int linkedPiece = 1;
+			while (curLink != 0) {
+				linkedPiece++;
+				status2[curLink - 1] = kPieceUnselected;
+				curLink = kGalleryLinks[linkedPiece - 1][i];
+			}
+			status1[i] = opGalleryAI(status2, depth == 0 ? 1 : 0);
+			if (!depth && status1[i] == kPieceSelected) {
+				return 1;
+			}
+		}
+	}
+
+	if (selectedPieces) {
+		byte v8 = 0;
+		byte v9 = 0;
+		byte v10 = 0;
+		for (int j = 0; j < 21; ++j) {
+			byte v12 = status2[j];
+			if (v12) {
+				++v10;
+				if (v12 == 1)
+					++v9;
+				else
+					v8 += v12;
+			}
+		}
+		if (v9 == v10)
+			return 1;
+		else
+			return (v8 + 102 * v9) / v10;
+	}
+
+	return depth == 0 ? 2 : 1;
 }
 
 void T11hGame::opTriangle() {
diff --git a/engines/groovie/logic/t11hgame.h b/engines/groovie/logic/t11hgame.h
index 24e9a919b7..bce2c21f0f 100644
--- a/engines/groovie/logic/t11hgame.h
+++ b/engines/groovie/logic/t11hgame.h
@@ -52,7 +52,7 @@ private:
 	void opGallery();
 	void opTriangle();
 
-	byte opGallerySub(byte *field, int start);
+	byte opGalleryAI(byte *pieceStatus, int depth);
 	int8 opBeehiveGetHexDifference();
 	int8 opBeehiveGetTotal(int8 *hexagons);
 	void inline setScriptVar(uint16 var, byte value);


Commit: 0693fa1885328b00bb4ebafb03f6208a36c6fbd5
    https://github.com/scummvm/scummvm/commit/0693fa1885328b00bb4ebafb03f6208a36c6fbd5
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-21T23:53:54+03:00

Commit Message:
GROOVIE: Fix logic in opGallery

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


diff --git a/engines/groovie/logic/t11hgame.cpp b/engines/groovie/logic/t11hgame.cpp
index 7e18efdc17..92d50df575 100644
--- a/engines/groovie/logic/t11hgame.cpp
+++ b/engines/groovie/logic/t11hgame.cpp
@@ -672,7 +672,7 @@ void T11hGame::opGallery() {
 	int selectedPieces = 0;
 	for (int i = 0; i < kPieceCount; i++) {
 		status1[i] = 0;
-		if (pieceStatus[i + 1] == kPieceSelected) {
+		if (pieceStatus[i] == kPieceSelected) {
 			for (int j = 0; j < kPieceCount; j++)
 				status2[j] = pieceStatus[j];
 
@@ -684,7 +684,7 @@ void T11hGame::opGallery() {
 			while (curLink != 0) {
 				linkedPiece++;
 				status2[curLink - 1] = kPieceUnselected;
-				curLink = kGalleryLinks[linkedPiece - 1][i];
+				curLink = kGalleryLinks[i][linkedPiece - 1];
 			}
 			status1[i] = opGalleryAI(status2, 1);
 			if (status1[i] == kPieceSelected) {
@@ -754,7 +754,7 @@ byte T11hGame::opGalleryAI(byte *pieceStatus, int depth) {
 			while (curLink != 0) {
 				linkedPiece++;
 				status2[curLink - 1] = kPieceUnselected;
-				curLink = kGalleryLinks[linkedPiece - 1][i];
+				curLink = kGalleryLinks[i][linkedPiece - 1];
 			}
 			status1[i] = opGalleryAI(status2, depth == 0 ? 1 : 0);
 			if (!depth && status1[i] == kPieceSelected) {




More information about the Scummvm-git-logs mailing list