mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
GROOVIE: Move Beehive puzzle logic to a separate file, more implementation
This commit is contained in:
@@ -22,6 +22,16 @@
|
||||
|
||||
#include "groovie/logic/beehive.h"
|
||||
|
||||
/*
|
||||
* Beehive puzzle
|
||||
*
|
||||
* An infection-style game in which the player must cover more
|
||||
* territory than the computer. It's similar to the microscope puzzle
|
||||
* in the 7th Guest. The playfield is a honeycomb made of 61
|
||||
* hexagons. The hexagons are numbered starting from the top-left
|
||||
* corner, with a direction from bottom left to top right.
|
||||
*/
|
||||
|
||||
namespace Groovie {
|
||||
|
||||
BeehiveGame::BeehiveGame() {
|
||||
@@ -30,4 +40,219 @@ BeehiveGame::BeehiveGame() {
|
||||
BeehiveGame::~BeehiveGame() {
|
||||
}
|
||||
|
||||
void BeehiveGame::run(byte *scriptVariables) {
|
||||
int8 *hexagons = (int8 *)scriptVariables + 25;
|
||||
int8 *hexDifference = (int8 *)scriptVariables + 13;
|
||||
byte op = scriptVariables[14] - 1;
|
||||
|
||||
enum kBeehiveColor {
|
||||
kBeehiveColorYellow = -1,
|
||||
kBeehiveColorRed = 1
|
||||
};
|
||||
|
||||
warning("Beehive subop %d", op);
|
||||
|
||||
int8 v22, v24;
|
||||
int8 tempState[64];
|
||||
|
||||
switch (op) {
|
||||
case 0: // init board's hexagons
|
||||
memset(_beehiveState, 0, 60);
|
||||
_beehiveState[0] = kBeehiveColorYellow;
|
||||
_beehiveState[4] = kBeehiveColorRed;
|
||||
_beehiveState[34] = kBeehiveColorYellow;
|
||||
_beehiveState[60] = kBeehiveColorRed;
|
||||
_beehiveState[56] = kBeehiveColorYellow;
|
||||
_beehiveState[26] = kBeehiveColorRed;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
memset(hexagons, 0, 60);
|
||||
scriptVariables[85] = 0;
|
||||
sub02(&v22, tempState);
|
||||
if (v22) {
|
||||
for (int i = 0; i < v22; i++)
|
||||
scriptVariables[tempState[i] + 25] = 1;
|
||||
} else {
|
||||
*hexDifference = getHexDifference();
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
memset(hexagons, 0, 60);
|
||||
scriptVariables[85] = 0;
|
||||
v24 = 10 * scriptVariables[0] + scriptVariables[1];
|
||||
sub18(v24, &v22, tempState);
|
||||
for (int j = 0; j < v22; j++)
|
||||
scriptVariables[tempState[j] + 25] = 1;
|
||||
scriptVariables[v24 + 25] = 1;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BeehiveGame::sub02(int8 *a1, int8 *a2) {
|
||||
}
|
||||
|
||||
void BeehiveGame::sub18(int8 a1, int8 *a2, int8 *a3) {
|
||||
}
|
||||
|
||||
int8 BeehiveGame::getHexDifference() {
|
||||
return (getTotal(_beehiveState) >= 0 ? 1 : 0) + 5;
|
||||
}
|
||||
|
||||
int8 BeehiveGame::getTotal(int8 *hexagons) {
|
||||
int8 result = 0;
|
||||
|
||||
for (int i = 0; i < 61; i++)
|
||||
result += hexagons[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static const int8 beehiveLogicTable1[368] = {
|
||||
-1, 5, 6, 1, -1, -1,
|
||||
0, 6, 7, 2, -1, -1,
|
||||
1, 7, 8, 3, -1, -1,
|
||||
2, 8, 9, 4, -1, -1,
|
||||
3, 9, 10, -1, -1, -1,
|
||||
-1, 11, 12, 6, 0, -1,
|
||||
5, 12, 13, 7, 1, 0,
|
||||
6, 13, 14, 8, 2, 1,
|
||||
7, 14, 15, 9, 3, 2,
|
||||
8, 15, 16, 10, 4, 3,
|
||||
9, 16, 17, -1, -1, 4,
|
||||
-1, 18, 19, 12, 5, -1,
|
||||
11, 19, 20, 13, 6, 5,
|
||||
12, 20, 21, 14, 7, 6,
|
||||
13, 21, 22, 15, 8, 7,
|
||||
14, 22, 23, 16, 9, 8,
|
||||
15, 23, 24, 17, 10, 9,
|
||||
16, 24, 25, -1, -1, 10,
|
||||
-1, 26, 27, 19, 11, -1,
|
||||
18, 27, 28, 20, 12, 11,
|
||||
19, 28, 29, 21, 13, 12,
|
||||
20, 29, 30, 22, 14, 13,
|
||||
21, 30, 31, 23, 15, 14,
|
||||
22, 31, 32, 24, 16, 15,
|
||||
23, 32, 33, 25, 17, 16,
|
||||
24, 33, 34, -1, -1, 17,
|
||||
-1, -1, 35, 27, 18, -1,
|
||||
26, 35, 36, 28, 19, 18,
|
||||
27, 36, 37, 29, 20, 19,
|
||||
28, 37, 38, 30, 21, 20,
|
||||
29, 38, 39, 31, 22, 21,
|
||||
30, 39, 40, 32, 23, 22,
|
||||
31, 40, 41, 33, 24, 23,
|
||||
32, 41, 42, 34, 25, 24,
|
||||
33, 42, -1, -1, -1, 25,
|
||||
-1, -1, 43, 36, 27, 26,
|
||||
35, 43, 44, 37, 28, 27,
|
||||
36, 44, 45, 38, 29, 28,
|
||||
37, 45, 46, 39, 30, 29,
|
||||
38, 46, 47, 40, 31, 30,
|
||||
39, 47, 48, 41, 32, 31,
|
||||
40, 48, 49, 42, 33, 32,
|
||||
41, 49, -1, -1, 34, 33,
|
||||
-1, -1, 50, 44, 36, 35,
|
||||
43, 50, 51, 45, 37, 36,
|
||||
44, 51, 52, 46, 38, 37,
|
||||
45, 52, 53, 47, 39, 38,
|
||||
46, 53, 54, 48, 40, 39,
|
||||
47, 54, 55, 49, 41, 40,
|
||||
48, 55, -1, -1, 42, 41,
|
||||
-1, -1, 56, 51, 44, 43,
|
||||
50, 56, 57, 52, 45, 44,
|
||||
51, 57, 58, 53, 46, 45,
|
||||
52, 58, 59, 54, 47, 46,
|
||||
53, 59, 60, 55, 48, 47,
|
||||
54, 60, -1, -1, 49, 48,
|
||||
-1, -1, -1, 57, 51, 50,
|
||||
56, -1, -1, 58, 52, 51,
|
||||
57, -1, -1, 59, 53, 52,
|
||||
58, -1, -1, 60, 54, 53,
|
||||
59, -1, -1, -1, 55, 54,
|
||||
0, 0
|
||||
};
|
||||
|
||||
static const int8 beehiveLogicTable2[800] = {
|
||||
-1, -1, 11, 12, 13, 7, 2, -1, -1, -1, -1, -1,
|
||||
-1, 5, 12, 13, 14, 8, 3, -1, -1, -1, -1, -1,
|
||||
0, 6, 13, 14, 15, 9, 4, -1, -1, -1, -1, -1,
|
||||
1, 7, 14, 15, 16, 10, -1, -1, -1, -1, -1, -1,
|
||||
2, 8, 15, 16, 17, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, 18, 19, 20, 13, 7, 1, -1, -1, -1, -1,
|
||||
-1, 11, 19, 20, 21, 14, 8, 2, -1, -1, -1, -1,
|
||||
5, 12, 20, 21, 22, 15, 9, 3, -1, -1, -1, 0,
|
||||
6, 13, 21, 22, 23, 16, 10, 4, -1, -1, -1, 1,
|
||||
7, 14, 22, 23, 24, 17, -1, -1, -1, -1, -1, 2,
|
||||
8, 15, 23, 24, 25, -1, -1, -1, -1, -1, -1, 3,
|
||||
-1, -1, 26, 27, 28, 20, 13, 6, 0, -1, -1, -1,
|
||||
-1, 18, 27, 28, 29, 21, 14, 7, 1, 0, -1, -1,
|
||||
11, 19, 28, 29, 30, 22, 15, 8, 2, 1, 0, 5,
|
||||
12, 20, 29, 30, 31, 23, 16, 9, 3, 2, 1, 6,
|
||||
13, 21, 30, 31, 32, 24, 17, 10, 4, 3, 2, 7,
|
||||
14, 22, 31, 32, 33, 25, -1, -1, -1, 4, 3, 8,
|
||||
15, 23, 32, 33, 34, -1, -1, -1, -1, -1, 4, 9,
|
||||
-1, -1, -1, 35, 36, 28, 20, 12, 5, -1, -1, -1,
|
||||
-1, 26, 35, 36, 37, 29, 21, 13, 6, 5, -1, -1,
|
||||
18, 27, 36, 37, 38, 30, 22, 14, 7, 6, 5, 11,
|
||||
19, 28, 37, 38, 39, 31, 23, 15, 8, 7, 6, 12,
|
||||
20, 29, 38, 39, 40, 32, 24, 16, 9, 8, 7, 13,
|
||||
21, 30, 39, 40, 41, 33, 25, 17, 10, 9, 8, 14,
|
||||
22, 31, 40, 41, 42, 34, -1, -1, -1, 10, 9, 15,
|
||||
23, 32, 41, 42, -1, -1, -1, -1, -1, -1, 10, 16,
|
||||
-1, -1, -1, -1, 43, 36, 28, 19, 11, -1, -1, -1,
|
||||
-1, -1, -1, 43, 44, 37, 29, 20, 12, 11, -1, -1,
|
||||
26, 35, 43, 44, 45, 38, 30, 21, 13, 12, 11, 18,
|
||||
27, 36, 44, 45, 46, 39, 31, 22, 14, 13, 12, 19,
|
||||
28, 37, 45, 46, 47, 40, 32, 23, 15, 14, 13, 20,
|
||||
29, 38, 46, 47, 48, 41, 33, 24, 16, 15, 14, 21,
|
||||
30, 39, 47, 48, 49, 42, 34, 25, 17, 16, 15, 22,
|
||||
31, 40, 48, 49, -1, -1, -1, -1, -1, 17, 16, 23,
|
||||
32, 41, 49, -1, -1, -1, -1, -1, -1, -1, 17, 24,
|
||||
-1, -1, -1, -1, 50, 44, 37, 28, 19, 18, -1, -1,
|
||||
-1, -1, -1, 50, 51, 45, 38, 29, 20, 19, 18, 26,
|
||||
35, 43, 50, 51, 52, 46, 39, 30, 21, 20, 19, 27,
|
||||
36, 44, 51, 52, 53, 47, 40, 31, 22, 21, 20, 28,
|
||||
37, 45, 52, 53, 54, 48, 41, 32, 23, 22, 21, 29,
|
||||
38, 46, 53, 54, 55, 49, 42, 33, 24, 23, 22, 30,
|
||||
39, 47, 54, 55, -1, -1, -1, 34, 25, 24, 23, 31,
|
||||
40, 48, 55, -1, -1, -1, -1, -1, -1, 25, 24, 32,
|
||||
-1, -1, -1, -1, 56, 51, 45, 37, 28, 27, 26, -1,
|
||||
-1, -1, -1, 56, 57, 52, 46, 38, 29, 28, 27, 35,
|
||||
43, 50, 56, 57, 58, 53, 47, 39, 30, 29, 28, 36,
|
||||
44, 51, 57, 58, 59, 54, 48, 40, 31, 30, 29, 37,
|
||||
45, 52, 58, 59, 60, 55, 49, 41, 32, 31, 30, 38,
|
||||
46, 53, 59, 60, -1, -1, -1, 42, 33, 32, 31, 39,
|
||||
47, 54, 60, -1, -1, -1, -1, -1, 34, 33, 32, 40,
|
||||
-1, -1, -1, -1, -1, 57, 52, 45, 37, 36, 35, -1,
|
||||
-1, -1, -1, -1, -1, 58, 53, 46, 38, 37, 36, 43,
|
||||
50, 56, -1, -1, -1, 59, 54, 47, 39, 38, 37, 44,
|
||||
51, 57, -1, -1, -1, 60, 55, 48, 40, 39, 38, 45,
|
||||
52, 58, -1, -1, -1, -1, -1, 49, 41, 40, 39, 46,
|
||||
53, 59, -1, -1, -1, -1, -1, -1, 42, 41, 40, 47,
|
||||
-1, -1, -1, -1, -1, -1, 58, 52, 45, 44, 43, -1,
|
||||
-1, -1, -1, -1, -1, -1, 59, 53, 46, 45, 44, 50,
|
||||
56, -1, -1, -1, -1, -1, 60, 54, 47, 46, 45, 51,
|
||||
57, -1, -1, -1, -1, -1, -1, 55, 48, 47, 46, 52,
|
||||
58, -1, -1, -1, -1, -1, -1, -1, 49, 48, 47, 53,
|
||||
0, 0, 0, 0, 26, 18, 35, 11, 27, 43, 5, 19,
|
||||
36, 50, 0, 12, 28, 44, 56, 6, 20, 37, 51, 1,
|
||||
13, 29, 45, 57, 7, 21, 38, 52, 2, 14, 30, 46,
|
||||
58, 8, 22, 39, 53, 3, 15, 31, 47, 59, 9, 23,
|
||||
40, 54, 4, 16, 32, 48, 60, 10, 24, 41, 55, 17,
|
||||
33, 49, 25, 42, 34, 0, 0, 0
|
||||
};
|
||||
|
||||
} // End of Groovie namespace
|
||||
|
||||
@@ -23,12 +23,25 @@
|
||||
#ifndef GROOVIE_LOGIC_BEEHIVE_H
|
||||
#define GROOVIE_LOGIC_BEEHIVE_H
|
||||
|
||||
#include "common/system.h"
|
||||
|
||||
namespace Groovie {
|
||||
|
||||
class BeehiveGame {
|
||||
public:
|
||||
BeehiveGame();
|
||||
~BeehiveGame();
|
||||
|
||||
void run(byte *scriptVariables);
|
||||
|
||||
private:
|
||||
void sub02(int8 *a1, int8 *a2);
|
||||
void sub18(int8 a1, int8 *a2, int8 *a3);
|
||||
int8 getHexDifference();
|
||||
int8 getTotal(int8 *hexagons);
|
||||
|
||||
int8 _beehiveState[61];
|
||||
|
||||
};
|
||||
|
||||
} // End of Groovie namespace
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
namespace Groovie {
|
||||
|
||||
T11hGame::T11hGame(byte *scriptVariables)
|
||||
: _random("GroovieT11hGame"), _scriptVariables(scriptVariables), _cake(NULL), _beehiveHexagons() {
|
||||
: _random("GroovieT11hGame"), _scriptVariables(scriptVariables), _cake(NULL) {
|
||||
}
|
||||
|
||||
T11hGame::~T11hGame() {
|
||||
@@ -51,7 +51,7 @@ void T11hGame::handleOp(uint8 op) {
|
||||
case 2:
|
||||
debugC(1, kDebugScript, "Groovie::Script Op42 (0x%02X): T11H Beehive Puzzle in the top room (hs.grv)", op);
|
||||
// NOTE: Reused in UHP
|
||||
opBeehive();
|
||||
_beehive.run(_scriptVariables);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
@@ -503,80 +503,6 @@ void T11hGame::clearAIs() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Beehive puzzle
|
||||
*
|
||||
* An infection-style game in which the player must cover more
|
||||
* territory than the computer. It's similar to the microscope puzzle
|
||||
* in the 7th Guest. The playfield is a honeycomb made of 61
|
||||
* hexagons. The hexagons are numbered starting from the top-left
|
||||
* corner, with a direction from bottom left to top right.
|
||||
*/
|
||||
void T11hGame::opBeehive() {
|
||||
// TODO: Finish the logic
|
||||
int8 *hexagons = (int8 *)_scriptVariables + 25;
|
||||
int8 *hexDifference = (int8 *)_scriptVariables + 13;
|
||||
byte op = _scriptVariables[14] - 1;
|
||||
|
||||
enum kBeehiveColor {
|
||||
kBeehiveColorYellow = -1,
|
||||
kBeehiveColorRed = 1
|
||||
};
|
||||
|
||||
warning("Beehive subop %d", op);
|
||||
|
||||
//*hexDifference = 4;
|
||||
*hexDifference = 5; // DEBUG: set the difference to 5 to skip the game
|
||||
|
||||
switch (op) {
|
||||
case 0: // init board's hexagons
|
||||
memset(_beehiveHexagons, 0, 60);
|
||||
_beehiveHexagons[0] = kBeehiveColorYellow;
|
||||
_beehiveHexagons[4] = kBeehiveColorRed;
|
||||
_beehiveHexagons[34] = kBeehiveColorYellow;
|
||||
_beehiveHexagons[60] = kBeehiveColorRed;
|
||||
_beehiveHexagons[56] = kBeehiveColorYellow;
|
||||
_beehiveHexagons[26] = kBeehiveColorRed;
|
||||
break;
|
||||
case 1:
|
||||
memset(hexagons, 0, 60);
|
||||
_scriptVariables[85] = 0;
|
||||
//opBeehiveSub2(); // TODO
|
||||
// TODO: Check opBeehiveSub2()'s result
|
||||
//*hexDifference = opBeehiveGetHexDifference();
|
||||
break;
|
||||
case 2:
|
||||
memset(hexagons, 0, 60);
|
||||
_scriptVariables[85] = 0;
|
||||
//opBeehiveSub4(); // TODO
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int8 T11hGame::opBeehiveGetHexDifference() {
|
||||
return (opBeehiveGetTotal(_beehiveHexagons) >= 0) + 5;
|
||||
}
|
||||
|
||||
int8 T11hGame::opBeehiveGetTotal(int8 *hexagons) {
|
||||
int8 result = 0;
|
||||
|
||||
for (int i = 0; i < 61; i++)
|
||||
result += hexagons[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void T11hGame::opPente() {
|
||||
// FIXME: properly implement Pente game (the final puzzle)
|
||||
// for now just auto-solve the puzzle so the player can continue
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "common/textconsole.h"
|
||||
#include "common/random.h"
|
||||
#include "groovie/logic/beehive.h"
|
||||
|
||||
namespace Groovie {
|
||||
|
||||
@@ -47,14 +48,11 @@ private:
|
||||
|
||||
void opMouseTrap();
|
||||
void opConnectFour();
|
||||
void opBeehive();
|
||||
void opPente();
|
||||
void opGallery();
|
||||
void opTriangle();
|
||||
|
||||
byte opGalleryAI(byte *pieceStatus, int depth);
|
||||
int8 opBeehiveGetHexDifference();
|
||||
int8 opBeehiveGetTotal(int8 *hexagons);
|
||||
void inline setScriptVar(uint16 var, byte value);
|
||||
void inline setScriptVar16(uint16 var, uint16 value);
|
||||
uint16 inline getScriptVar16(uint16 var);
|
||||
@@ -64,7 +62,7 @@ private:
|
||||
T11hCake *_cake;
|
||||
byte *_scriptVariables;
|
||||
|
||||
int8 _beehiveHexagons[61];
|
||||
BeehiveGame _beehive;
|
||||
|
||||
static const byte kGalleryLinks[21][10];
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user