ScummVM API documentation
dalmatiansmaze.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef MEDIASTATION_MINIGAMES_DALMATIANSMAZE_H
23#define MEDIASTATION_MINIGAMES_DALMATIANSMAZE_H
24
25#include "mediastation/actor.h"
26
27namespace MediaStation {
28
29namespace MazeMinigame {
30
31enum CellDirectionMask {
32 kWest = 0x01,
33 kSouth = 0x02,
34 kEast = 0x04,
35 kNorth = 0x08
36};
37
38enum CellGraphType {
39 kObstacleCell = 0,
40 kDeadEndNode = 1,
41 kJunctionNode = 2,
42 kCorridorCell = 3,
43};
44
45// A row/column position within the maze grid.
46struct CellCoord {
47 int16 row = 0;
48 int16 column = 0;
49
50 CellCoord(int16 row_ = 0, int16 column_ = 0) : row(row_), column(column_) {}
51
52 bool operator==(const CellCoord &other) const {
53 return row == other.row && column == other.column;
54 }
55};
56
57class Cell { // MazeElem
58public:
59 Cell(int16 directionMask = 0) : _directionMask(directionMask) {};
60
61 CellGraphType getType() const;
62 Common::Array<int16> _validNeighbors;
63
64private:
65 int16 _directionMask = 0;
66};
67
68// The original compressed the maze space down to "segments" (corridors connecting
69// junction/dead-end nodes) and used a pre-computed routing table for each level.
70// This seems way overkill for a 10x16 maze, so this reimplementation just does BFS.
71//
72// Another improvement from the original is that the linear cell indexing is purely
73// an implementation detail here. Callers address cells by coordinate and receive paths
74// back as coordinates.
75class CellGrid {
76public:
77 CellGrid(int16 rowCount, int16 columnCount);
78 void setDirections(const Common::Array<int16> &directionMasks);
79
80 // The shortest path from start to end inclusive, as coordinates.
81 // Empty if the two cells are not connected.
82 Common::Array<CellCoord> shortestPath(CellCoord start, CellCoord end) const;
83 int32 paddedIndexForCoord(CellCoord coord);
84
85private:
86 int16 indexForCoord(CellCoord coord) const;
87 CellCoord coordForIndex(int16 index) const;
88 Cell &at(CellCoord coord);
89 Common::Array<uint> buildShortestPath(uint startIndex, uint endIndex) const;
90
91 int16 _rows = 0;
92 int16 _columns = 0;
94};
95
96// A simple maze with one player (puppy) and one enemy (Cruella). This translates the
97// padded cell indexing that scripts use to and from actual grid coordinates.
98class Maze {
99public:
100 Maze(const Common::Array<ScriptValue> &args); // newMaze_init
101 ~Maze();
102
103 void solve(const Common::Array<ScriptValue> &args, ScriptValue &returnValue); // newMaze_solve
104
105private:
106 CellGrid *_grid = nullptr;
107};
108
109} // End of namespace MazeMinigame
110
111} // End of namespace MediaStation
112
113#endif
Definition: dalmatiansmaze.h:75
Definition: dalmatiansmaze.h:57
Definition: dalmatiansmaze.h:98
Definition: scriptvalue.h:35
Definition: dalmatiansmaze.h:46