[Scummvm-git-logs] scummvm master -> 2e146483a1ee5ef441b2c02f61d57133ebf1af75
sev-
sev at scummvm.org
Sun Oct 24 20:19:03 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:
7d348bc185 GROOVIE: Implement more methods for Triangle puzzle
74744a8d8a GROOVIE: Implemented more Triangle subroutines
0d7403c345 GROOVIE: More work on Triangle puzzle
050309d77f GROOVIE: Complete code for Triangle puzzle
2e146483a1 GROOVIE: Added warning for catching undefined behaviour
Commit: 7d348bc1853e85b1fcc5fb4255efeebe35443b1e
https://github.com/scummvm/scummvm/commit/7d348bc1853e85b1fcc5fb4255efeebe35443b1e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-24T23:16:09+03:00
Commit Message:
GROOVIE: Implement more methods for Triangle puzzle
Changed paths:
engines/groovie/logic/triangle.cpp
engines/groovie/logic/triangle.h
diff --git a/engines/groovie/logic/triangle.cpp b/engines/groovie/logic/triangle.cpp
index c0ebfee257..36855f0a8c 100644
--- a/engines/groovie/logic/triangle.cpp
+++ b/engines/groovie/logic/triangle.cpp
@@ -160,7 +160,52 @@ int8 TriangleGame::sub03(int8 player) {
return pos;
}
-void TriangleGame::sub05(int8 *triangleCells, int8 *a2, int8 *a3) {
+void TriangleGame::sub05(int8 *triangleCells, int8 *tempMoves, int8 *tempTriangle) {
+ int8 dest[4];
+
+ for (int i = 0; i < 66; i++)
+ tempTriangle[i] = triangleCells[i];
+
+ int v16 = 3;
+
+ for (int j = 0; j < 66; ++j) {
+ if (triangleCells[j]) {
+ bool flag = false;
+
+ copyLogicRow(j, triangleCells[j], dest);
+ for (int8 *k = dest; *k != 66; k++) {
+ if (j > *k) {
+ if (flag) {
+ if (tempTriangle[j] != tempTriangle[*k])
+ replaceCells(tempTriangle, j, tempTriangle[j], tempTriangle[*k]);
+ } else {
+ flag = true;
+ tempTriangle[j] = tempTriangle[*k];
+ }
+ }
+ }
+ if (!flag)
+ tempTriangle[j] = v16++;
+ }
+ }
+
+ int v11 = 0;
+
+ if (v16 > 3) {
+ for (int v12 = 3; v12 < v16; v12++) {
+ int v14 = v11;
+
+ for (int m = 0; m < 66; m++) {
+ if (tempTriangle[m] == v12)
+ tempMoves[v11++] = m;
+ }
+
+ if (v11 != v14)
+ tempMoves[v11++] = 66;
+ }
+ }
+
+ tempMoves[v11] = 66;
}
void TriangleGame::sub07(int8 *a1, int8 *triangleCells, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
@@ -171,10 +216,10 @@ int8 TriangleGame::sub09(int8 player, int8 *a2, int8 *a3, int8 *a4, int8 *triang
}
int8 TriangleGame::sub10(int8 player, int8 *a2, int8 *triangleCells) {
- int8 *destPtr; // ecx
- byte mask; // [esp+Fh] [ebp-51h]
- int counter; // [esp+10h] [ebp-50h]
- int8 dest[76]; // [esp+14h] [ebp-4Ch] BYREF
+ int8 *destPtr;
+ byte mask;
+ int counter;
+ int8 dest[76];
mask = 0;
counter = 0;
@@ -231,6 +276,13 @@ void TriangleGame::copyLogicRow(int row, int8 key, int8 *dest) {
dest[pos] = 66;
}
+void TriangleGame::replaceCells(int8 *tempTriangle, int limit, int8 from, int8 to) {
+ for (int i = 0; i <= limit; ++i) {
+ if (tempTriangle[i] == from)
+ tempTriangle[i] = to;
+ }
+}
+
namespace {
const int8 triangleLookup1[12] = {
diff --git a/engines/groovie/logic/triangle.h b/engines/groovie/logic/triangle.h
index 6c64a0e26e..65aa83a747 100644
--- a/engines/groovie/logic/triangle.h
+++ b/engines/groovie/logic/triangle.h
@@ -44,6 +44,7 @@ private:
int8 sub12(int8 a1, int8 *a2, int8 *triangleCells, int8 *a4);
void setCell(int8 cellnum, int8 val);
void copyLogicRow(int row, int8 key, int8 *dest);
+ void replaceCells(int8 *tempTriangle, int limit, int8 from, int8 to);
private:
int _triangleCellCount;
Commit: 74744a8d8a55dbd287912d07f964a72eceb234c0
https://github.com/scummvm/scummvm/commit/74744a8d8a55dbd287912d07f964a72eceb234c0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-24T23:16:14+03:00
Commit Message:
GROOVIE: Implemented more Triangle subroutines
Changed paths:
engines/groovie/logic/triangle.cpp
engines/groovie/logic/triangle.h
diff --git a/engines/groovie/logic/triangle.cpp b/engines/groovie/logic/triangle.cpp
index 36855f0a8c..a92d0c502c 100644
--- a/engines/groovie/logic/triangle.cpp
+++ b/engines/groovie/logic/triangle.cpp
@@ -211,8 +211,83 @@ void TriangleGame::sub05(int8 *triangleCells, int8 *tempMoves, int8 *tempTriangl
void TriangleGame::sub07(int8 *a1, int8 *triangleCells, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
}
-int8 TriangleGame::sub09(int8 player, int8 *a2, int8 *a3, int8 *a4, int8 *triangleCells) {
- return 0;
+int8 TriangleGame::sub09(int8 player, int8 *tempTriangle2, int8 *tempTriangle1, int8 *a4, int8 *triangleCells) {
+ int8 movesTable[280];
+
+ int numDir1 = 0;
+ int numDir2 = 0;
+ int numDir3 = 0;
+ int numDir4 = 0;
+ int row = 0;
+
+ for (const int8 *tPtr = &triangleLogicTable[6]; tPtr < &triangleLogicTable[924]; tPtr += 14, row++) {
+ if (!triangleCells[row] && (tempTriangle1[row] & (player == 1 ? 1 : 64)) != 0) {
+ int c1 = 0, c2 = 0, c3 = 0;
+ int mask = 0;
+
+ copyLogicRow(row, player, movesTable);
+
+ for (int8 *movPtr = movesTable; *movPtr != 66; ++movPtr) {
+ int row2 = 0;
+
+ mask |= tempTriangle1[*movPtr];
+
+ for (const int8 *tPtr2 = &triangleLogicTable[6]; tPtr2 < &triangleLogicTable[924]; tPtr2 += 14, row2++) {
+ if (tempTriangle2[row2] == tempTriangle2[*movPtr]) {
+ c1 += (tPtr2[0] == 0) ? 1 : 0;
+ c2 += (tPtr2[1] == 0) ? 1 : 0;
+ c3 += (tPtr2[2] == 0) ? 1 : 0;
+ }
+ }
+ }
+
+ if (c1)
+ mask &= ~4u;
+ if (c2)
+ mask &= ~8u;
+ if (c3)
+ mask &= ~2u;
+
+ if (tPtr[0] || c1) {
+ if (tPtr[1] || c2) {
+ if (tPtr[2] || c3) {
+ if (mask) {
+ if (mask == 0xe) {
+ movesTable[numDir2 + 76] = row;
+ numDir2++;
+ } else if (mask == 2 || mask == 8 || mask == 4) {
+ movesTable[numDir4 + 212] = row;
+ numDir4++;
+ } else {
+ movesTable[numDir3 + 144] = row;
+ numDir3++;
+ }
+ }
+ } else {
+ movesTable[numDir1 + 8] = row;
+ numDir1++;
+ }
+ } else {
+ movesTable[numDir1 + 8] = row;
+ numDir1++;
+ }
+ } else {
+ movesTable[numDir1 + 8] = row;
+ numDir1++;
+ }
+ }
+ }
+
+ if (numDir1)
+ return movesTable[_random.getRandomNumber(numDir1 - 1) + 8];
+ if (numDir2)
+ return movesTable[_random.getRandomNumber(numDir2 - 1) + 76];
+ if (numDir3)
+ return movesTable[_random.getRandomNumber(numDir3 - 1) + 144];
+ if (numDir4)
+ return movesTable[_random.getRandomNumber(numDir4 - 1) + 212];
+
+ return 66;
}
int8 TriangleGame::sub10(int8 player, int8 *a2, int8 *triangleCells) {
@@ -257,6 +332,30 @@ int8 TriangleGame::sub12(int8 player, int8 *a2, int8 *triangleCells, int8 *a4) {
return 0;
}
+int TriangleGame::sub13(int8 row, int8 *triangleCells, int8 *moves) {
+ int pos = 0;
+
+ for (int i = 0; i < 6; i++) {
+ int8 v6 = triangleLogicTable[14 * row + i];
+
+ if (v6 != -1 && !triangleCells[v6]) {
+ int v7 = (i + 1) % 6;
+ int8 v8 = triangleLogicTable[14 * row + v7];
+
+ if (v8 != -1 && !triangleCells[v8]) {
+ int8 v9 = triangleLogicTable[14 * v6 + v7];
+
+ if (v9 != -1 && !triangleCells[v9])
+ moves[pos++] = v9;
+ }
+ }
+ }
+
+ moves[pos] = 66;
+
+ return pos;
+}
+
void TriangleGame::setCell(int8 cellnum, int8 val) {
if (cellnum >= 0 && cellnum < 66) {
++_triangleCellCount;
@@ -283,6 +382,26 @@ void TriangleGame::replaceCells(int8 *tempTriangle, int limit, int8 from, int8 t
}
}
+int copyLookup(int8 *lookup, int8 *from, int8 *dest){
+ int counter = 0;
+
+ if (*lookup == 66) {
+ *dest = 66;
+ return counter;
+ }
+
+ for (; *lookup != 66; lookup++) {
+ for (int8 *ptr = from; *ptr != 66; ptr++) {
+ if (*ptr == *lookup )
+ dest[counter++] = *lookup;
+ }
+ }
+
+ dest[counter] = 66;
+
+ return counter;
+}
+
namespace {
const int8 triangleLookup1[12] = {
diff --git a/engines/groovie/logic/triangle.h b/engines/groovie/logic/triangle.h
index 65aa83a747..38396f9a45 100644
--- a/engines/groovie/logic/triangle.h
+++ b/engines/groovie/logic/triangle.h
@@ -42,9 +42,11 @@ private:
int8 sub09(int8 key, int8 *a2, int8 *a3, int8 *a4, int8 *triangleCells);
int8 sub10(int8 key, int8 *a2, int8 *triangleCells);
int8 sub12(int8 a1, int8 *a2, int8 *triangleCells, int8 *a4);
+ int sub13(int8 row, int8 *triangleCells, int8 *moves);
void setCell(int8 cellnum, int8 val);
void copyLogicRow(int row, int8 key, int8 *dest);
void replaceCells(int8 *tempTriangle, int limit, int8 from, int8 to);
+ int copyLookup(int8 *lookup, int8 *from, int8 *dest);
private:
int _triangleCellCount;
Commit: 0d7403c3456a7851847c237930e6ec0fbefc2b43
https://github.com/scummvm/scummvm/commit/0d7403c3456a7851847c237930e6ec0fbefc2b43
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-24T23:16:14+03:00
Commit Message:
GROOVIE: More work on Triangle puzzle
Changed paths:
engines/groovie/logic/triangle.cpp
engines/groovie/logic/triangle.h
diff --git a/engines/groovie/logic/triangle.cpp b/engines/groovie/logic/triangle.cpp
index a92d0c502c..3f8074a50a 100644
--- a/engines/groovie/logic/triangle.cpp
+++ b/engines/groovie/logic/triangle.cpp
@@ -328,8 +328,154 @@ int8 TriangleGame::sub10(int8 player, int8 *a2, int8 *triangleCells) {
return 66;
}
-int8 TriangleGame::sub12(int8 player, int8 *a2, int8 *triangleCells, int8 *a4) {
- return 0;
+int8 TriangleGame::sub12(int8 player, int8 *tempMoves, int8 *triangleCells, int8 *tempTriangle) {
+ int8 moves[8];
+ int8 tempTriangle1[68];
+ int8 tempTriangle2[68];
+ int8 tempTriangle3[68];
+ int8 tempTriangle4[68];
+
+ int8 result = 66;
+ int maxlen = -1;
+ int8 *startPtr = triangleCells;
+
+ for (int8 *ptr = tempMoves; *ptr != 66; ptr++) {
+ int len = 0;
+ int8 *beg = ptr;
+ int8 p0 = *ptr;
+
+ for (; *ptr != 66; ++ptr)
+ ++len;
+
+ if (len > maxlen && triangleCells[p0] == player) {
+ maxlen = len;
+ startPtr = beg;
+ }
+ }
+
+ tempTriangle4[0] = 66;
+
+ for (int8 *ptr = startPtr; *ptr != 66; ++ptr) {
+ if (sub13(*ptr, triangleCells, moves))
+ collapseLoops(tempTriangle4, moves);
+ }
+
+ int len1 = 0, len2 = 0, len3 = 0;
+
+ tempTriangle1[0] = 66;
+ tempTriangle2[0] = 66;
+ tempTriangle3[0] = 66;
+
+ for (int8 *ptr = tempTriangle4; *ptr != 66; ++ptr) {
+ int8 v13 = 100;
+
+ int8 v15 = triangleLogicTable[14 * *ptr + 11];
+ if (v15 < 100)
+ v13 = triangleLogicTable[14 * *ptr + 11];
+
+ int8 v16 = triangleLogicTable[14 * *ptr + 13];
+ if (v13 > v16)
+ v13 = triangleLogicTable[14 * *ptr + 13];
+
+ int8 v17 = triangleLogicTable[14 * *ptr + 12];
+ if (v13 > v17)
+ v13 = triangleLogicTable[14 * *ptr + 12];
+
+ if (v13 == v15) {
+ tempTriangle1[len1++] = *ptr;
+ } else if (v13 == v17) {
+ tempTriangle2[len2++] = *ptr;
+ } else if (v13 == v16) {
+ tempTriangle3[len3++] = *ptr;
+ }
+ }
+
+ bool flag1 = false, flag2 = false, flag3 = false;
+ tempTriangle3[len3] = 66;
+ tempTriangle2[len2] = 66;
+ tempTriangle1[len1] = 66;
+
+ int8 startVal = tempTriangle[*startPtr];
+
+ switch (startVal) {
+ case 8:
+ flag3 = true;
+ break;
+ case 4:
+ flag2 = true;
+ break;
+ case 2:
+ flag1 = true;
+ break;
+ case 12:
+ flag2 = true;
+ flag3 = flag2;
+ break;
+ case 6:
+ flag1 = true;
+ flag2 = true;
+ break;
+ case 10:
+ flag1 = true;
+ flag3 = true;
+ break;
+ case 14:
+ flag2 = false;
+ flag1 = false;
+ flag3 = flag2;
+ break;
+ default:
+ flag2 = true;
+ flag1 = true;
+ flag3 = flag2;
+ break;
+ }
+
+ int minLen = 101;
+ if (flag1) {
+ for (int8 *ptr = tempTriangle1; *ptr != 66; ++ptr) {
+ int8 part1 = 0;
+ if ((startVal & 8) == 0)
+ part1 = triangleLogicTable[14 * *ptr + 7];
+ int8 part2 = 0;
+ if ((startVal & 4) == 0)
+ part2 = triangleLogicTable[14 * *ptr + 6];
+ if (minLen > part1 + part2) {
+ minLen = part1 + part2;
+ result = *ptr;
+ }
+ }
+ }
+ if (flag2) {
+ for (int8 *ptr = tempTriangle2; *ptr != 66; ++ptr) {
+ int8 part1 = 0;
+ if ((startVal & 8) == 0)
+ part1 = triangleLogicTable[14 * *ptr + 7];
+ int8 part2 = 0;
+ if ((startVal & 2) == 0)
+ part2 = triangleLogicTable[14 * *ptr + 8];
+ if (minLen > part1 + part2) {
+ minLen = part1 + part2;
+ result = *ptr;
+ }
+ }
+ }
+ if (flag3) {
+ for (int8 *ptr = tempTriangle3; *ptr != 66; ++ptr) {
+ int8 part1 = 0;
+ if ((startVal & 2) == 0)
+ part1 = triangleLogicTable[14 * *ptr + 8];
+ int8 part2 = 0;
+ if ((startVal & 4) == 0)
+ part2 = triangleLogicTable[14 * *ptr + 6];
+ if (minLen > part1 + part2) {
+ minLen = part1 + part2;
+ result = *ptr;
+ }
+ }
+ }
+
+ return result;
}
int TriangleGame::sub13(int8 row, int8 *triangleCells, int8 *moves) {
@@ -382,7 +528,7 @@ void TriangleGame::replaceCells(int8 *tempTriangle, int limit, int8 from, int8 t
}
}
-int copyLookup(int8 *lookup, int8 *from, int8 *dest){
+int TriangleGame::copyLookup(int8 *lookup, int8 *start, int8 *dest){
int counter = 0;
if (*lookup == 66) {
@@ -391,8 +537,8 @@ int copyLookup(int8 *lookup, int8 *from, int8 *dest){
}
for (; *lookup != 66; lookup++) {
- for (int8 *ptr = from; *ptr != 66; ptr++) {
- if (*ptr == *lookup )
+ for (int8 *ptr = start; *ptr != 66; ptr++) {
+ if (*ptr == *lookup)
dest[counter++] = *lookup;
}
}
@@ -402,6 +548,28 @@ int copyLookup(int8 *lookup, int8 *from, int8 *dest){
return counter;
}
+void TriangleGame::collapseLoops(int8 *route, int8 *singleRow) {
+ int len = 0;
+ for (int8 *i = route; *i != 66; i++)
+ len++;
+
+ int origlen = len;
+
+
+ for (int8 *i = singleRow; *i != 66; i++) {
+ int j;
+ for (j = 0; j < len; j++) {
+ if (route[j] == *i)
+ break;
+ }
+ if (j == len)
+ route[len++] = *i;
+ }
+
+ if (len != origlen)
+ route[len] = 66;
+}
+
namespace {
const int8 triangleLookup1[12] = {
diff --git a/engines/groovie/logic/triangle.h b/engines/groovie/logic/triangle.h
index 38396f9a45..4c3fca2e26 100644
--- a/engines/groovie/logic/triangle.h
+++ b/engines/groovie/logic/triangle.h
@@ -46,7 +46,8 @@ private:
void setCell(int8 cellnum, int8 val);
void copyLogicRow(int row, int8 key, int8 *dest);
void replaceCells(int8 *tempTriangle, int limit, int8 from, int8 to);
- int copyLookup(int8 *lookup, int8 *from, int8 *dest);
+ int copyLookup(int8 *lookup, int8 *start, int8 *dest);
+ void collapseLoops(int8 *route, int8 *singleRow);
private:
int _triangleCellCount;
Commit: 050309d77f9f0e79040df293e713da70f6a0beb4
https://github.com/scummvm/scummvm/commit/050309d77f9f0e79040df293e713da70f6a0beb4
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-24T23:16:14+03:00
Commit Message:
GROOVIE: Complete code for Triangle puzzle
Changed paths:
engines/groovie/logic/triangle.cpp
engines/groovie/logic/triangle.h
diff --git a/engines/groovie/logic/triangle.cpp b/engines/groovie/logic/triangle.cpp
index 3f8074a50a..9582188f7c 100644
--- a/engines/groovie/logic/triangle.cpp
+++ b/engines/groovie/logic/triangle.cpp
@@ -208,7 +208,173 @@ void TriangleGame::sub05(int8 *triangleCells, int8 *tempMoves, int8 *tempTriangl
tempMoves[v11] = 66;
}
-void TriangleGame::sub07(int8 *a1, int8 *triangleCells, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
+void TriangleGame::sub07(int8 *tempMoves, int8 *triangleCells, int8 *tempTriangle3, int8 *tempTriangle2, int8 *tempTriangle1, int8 *tempMoves2) {
+ int8 singleRow[8];
+ int8 tempTriangle[68];
+ int8 routes[4356];
+
+ for (int i = 0; i < 66; i++) {
+ tempTriangle2[i] = tempTriangle3[i];
+ tempTriangle1[i] = 0;
+ }
+
+ if (*tempMoves != 66) {
+ for (int8 *ptr1 = tempMoves; *ptr1 != 66; ptr1++) {
+ int8 *v45 = &routes[66 * tempTriangle3[*ptr1]];
+ *v45 = 66;
+
+ while (*ptr1 != 66) {
+ copyLogicRow(*ptr1++, 0, singleRow);
+ collapseLoops(v45, singleRow);
+ }
+ }
+
+ for (int8 *ptr2 = tempMoves; *ptr2 != 66; ptr2++) {
+ int8 *j;
+
+ for (j = ptr2; *j != 66; j++)
+ ;
+ for (int8 *k = j + 1; *k != 66; k++) {
+ if (triangleCells[*k] == triangleCells[*ptr2]) {
+ int8 val1 = tempTriangle2[*k];
+ int8 val2 = tempTriangle2[*ptr2];
+
+ if (val1 != val2) {
+ int8 lookupLen = copyLookup(&routes[66 * val2], &routes[66 * val1], tempTriangle);
+ if (lookupLen == 1) {
+ if (triangleCells[*ptr2] == 1) {
+ tempTriangle1[tempTriangle[0]] |= 1u;
+ } else if (triangleCells[*ptr2] == 2) {
+ tempTriangle1[tempTriangle[0]] |= 0x40u;
+ }
+ } else if (lookupLen > 1) {
+ int8 v16 = lookupLen - 1;
+ do {
+ if (triangleCells[*ptr2] == 1) {
+ tempTriangle1[tempTriangle[v16]] |= 0x10u;
+ } else if (triangleCells[*ptr2] == 2) {
+ tempTriangle1[tempTriangle[v16]] |= 0x20u;
+ }
+ } while (v16--);
+
+ collapseLoops(&routes[66 * tempTriangle2[*k]], &routes[66 * tempTriangle2[*ptr2]]);
+ int8 from = tempTriangle2[*ptr2];
+ int8 to = tempTriangle2[*k];
+ for (int m = 0; m < 66; m++) {
+ if (tempTriangle2[m] == from)
+ tempTriangle2[m] = to;
+ }
+ }
+ }
+ }
+ for (; *k != 66; k++)
+ ;
+ }
+ for (; *ptr2 != 66; ptr2++)
+ ;
+ }
+ }
+
+ int8 maxVal = 0;
+ for (int i = 0; i < 66; i++) {
+ if (tempTriangle2[i] > maxVal)
+ maxVal = tempTriangle2[i];
+ }
+
+ int8 len2 = 0;
+
+ for (int i = 3; i <= maxVal; i++) {
+ int8 prevLen2 = len2;
+ for (int j = 0; j < 66; j++) {
+ if (tempTriangle2[j] == i)
+ tempMoves2[len2++] = j;
+ }
+
+ if (prevLen2 != len2)
+ tempMoves2[len2++] = 66;
+ }
+
+ tempMoves2[len2] = 66;
+
+ for (int8 *ptr3 = tempMoves2; *ptr3 != 66; ptr3++) {
+ bool flag1 = false, flag2 = false, flag3 = false;
+ int8 row = tempTriangle2[*ptr3];
+ byte mask1 = 0, mask2 = 0;
+
+ for (int i = 0; i < 66; i++) {
+ if (tempTriangle2[i] == row && triangleCells[i]) {
+ if (triangleCells[i] == 1) {
+ mask1 = 1;
+ mask2 = 16;
+ } else {
+ mask1 = 64;
+ mask2 = 32;
+ }
+ break;
+ }
+ }
+
+ while (*ptr3 != 66) {
+ if (!triangleLogicTable[14 * *ptr3 + 6])
+ flag1 = 1;
+ if (!triangleLogicTable[14 * *ptr3 + 7])
+ flag2 = 1;
+ if (!triangleLogicTable[14 * *ptr3 + 8])
+ flag3 = 1;
+ ++ptr3;
+ }
+
+ if (!flag1) {
+ int8 lookup1 = copyLookup(triangleLookup1, &routes[66 * row], tempTriangle);
+ if (lookup1 == 1) {
+ tempTriangle1[tempTriangle[0]] |= mask1;
+ } else if (lookup1 > 1) {
+ int k = lookup1 - 1;
+ do
+ tempTriangle1[tempTriangle[k]] |= mask2;
+ while (k--);
+ flag1 = 1;
+ }
+ }
+ if (!flag2) {
+ int8 lookup2 = copyLookup(triangleLookup2, &routes[66 * row], tempTriangle);
+ if (lookup2 == 1) {
+ tempTriangle1[tempTriangle[0]] |= mask1;
+ } else if (lookup2 > 1) {
+ int k = lookup2 - 1;
+ do
+ tempTriangle1[tempTriangle[k]] |= mask2;
+ while (k--);
+ flag2 = 1;
+ }
+ }
+ if (!flag3) {
+ int8 lookup3 = copyLookup(triangleLookup3, &routes[66 * row], tempTriangle);
+ if (lookup3 == 1) {
+ tempTriangle1[tempTriangle[0]] |= mask1;
+ } else if (lookup3 > 1) {
+ int k = lookup3 - 1;
+ do
+ tempTriangle1[tempTriangle[k]] |= mask2;
+ while (k--);
+ flag3 = 1;
+ }
+ }
+
+ byte mask3 = 0;
+
+ if (flag1)
+ mask3 = 4;
+ if (flag2)
+ mask3 |= 8u;
+ if (flag3)
+ mask3 |= 2u;
+
+ for (int i = 0; i < 66; i++) {
+ if (tempTriangle2[i] == row)
+ tempTriangle1[i] |= mask3;
+ }
+ }
}
int8 TriangleGame::sub09(int8 player, int8 *tempTriangle2, int8 *tempTriangle1, int8 *a4, int8 *triangleCells) {
@@ -528,7 +694,7 @@ void TriangleGame::replaceCells(int8 *tempTriangle, int limit, int8 from, int8 t
}
}
-int TriangleGame::copyLookup(int8 *lookup, int8 *start, int8 *dest){
+int TriangleGame::copyLookup(const int8 *lookup, int8 *start, int8 *dest){
int counter = 0;
if (*lookup == 66) {
diff --git a/engines/groovie/logic/triangle.h b/engines/groovie/logic/triangle.h
index 4c3fca2e26..91191c8850 100644
--- a/engines/groovie/logic/triangle.h
+++ b/engines/groovie/logic/triangle.h
@@ -38,7 +38,7 @@ private:
int8 sub02();
int8 sub03(int8 player);
void sub05(int8 *triangleCells, int8 *a2, int8 *a3);
- void sub07(int8 *a1, int8 *triangleCells, int8 *a3, int8 *a4, int8 *a5, int8 *a6);
+ void sub07(int8 *tempMoves, int8 *triangleCells, int8 *tempTriangle3, int8 *tempTriangle2, int8 *tempTriangle1, int8 *tempMoves2);
int8 sub09(int8 key, int8 *a2, int8 *a3, int8 *a4, int8 *triangleCells);
int8 sub10(int8 key, int8 *a2, int8 *triangleCells);
int8 sub12(int8 a1, int8 *a2, int8 *triangleCells, int8 *a4);
@@ -46,7 +46,7 @@ private:
void setCell(int8 cellnum, int8 val);
void copyLogicRow(int row, int8 key, int8 *dest);
void replaceCells(int8 *tempTriangle, int limit, int8 from, int8 to);
- int copyLookup(int8 *lookup, int8 *start, int8 *dest);
+ int copyLookup(const int8 *lookup, int8 *start, int8 *dest);
void collapseLoops(int8 *route, int8 *singleRow);
private:
Commit: 2e146483a1ee5ef441b2c02f61d57133ebf1af75
https://github.com/scummvm/scummvm/commit/2e146483a1ee5ef441b2c02f61d57133ebf1af75
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-24T23:18:33+03:00
Commit Message:
GROOVIE: Added warning for catching undefined behaviour
Changed paths:
engines/groovie/logic/triangle.cpp
diff --git a/engines/groovie/logic/triangle.cpp b/engines/groovie/logic/triangle.cpp
index 9582188f7c..0cce1f706e 100644
--- a/engines/groovie/logic/triangle.cpp
+++ b/engines/groovie/logic/triangle.cpp
@@ -150,8 +150,10 @@ int8 TriangleGame::sub03(int8 player) {
pickedMoves[max++] = 32;
if (max)
pos = pickedMoves[_random.getRandomNumber(max - 1)];
- else
+ else {
+ warning("TriangleGame: Undefined behaviour");
pos = tempMoves[0]; // This is uninitalized in this branch
+ }
}
if (pos != 66)
More information about the Scummvm-git-logs
mailing list