Pac-Man Evolution
Loading...
Searching...
No Matches
MazeDynamic.h
1/*----------------------------------------------------------------------
2Pac-Man Evolution - Roberto Prieto
3Copyright (C) 2018-2024 MegaStorm Systems
4contact@megastormsystems.com - http://www.megastormsystems.com
5
6This software is provided 'as-is', without any express or implied
7warranty. In no event will the authors be held liable for any damages
8arising from the use of this software.
9
10Permission is granted to anyone to use this software for any purpose,
11including commercial applications, and to alter it and redistribute it
12freely, subject to the following restrictions:
13
141. The origin of this software must not be misrepresented; you must not
15claim that you wrote the original software. If you use this software
16in a product, an acknowledgment in the product documentation would be
17appreciated but is not required.
182. Altered source versions must be plainly marked as such, and must not be
19misrepresented as being the original software.
203. This notice may not be removed or altered from any source distribution.
21
22------------------------------------------------------------------------
23
24MazeGenerator class
25
26Based on Shaun LeBron code (https://github.com/shaunlebron/pacman-mazegen) using "tetris" variant.
27
28------------------------------------------------------------------------ */
29
30#ifndef MAZEDYNAMICPME_H
31#define MAZEDYNAMICPME_H
32
33// Includes and forward definitions
34#include "MemoryManager.h"
35
36//#define DEBUG_GENERATOR
37
38// rows = 9
39// col = 5
40
41class Maze : public CMemPME
42{
43public:
44 Maze(Sint32 iR, Sint32 iC);
45 ~Maze();
46 Sint32 createMaze(vector<Uint8>&);
47
48private:
49 // Cell definition and cells array
50 struct stCell
51 {
52 Sint32 x, y;
53 bool filled;
54 bool connect[4];
55 stCell* next[4];
56 Sint32 no;
57 Sint32 group;
58 // Internal vars
59 Sint32 final_x, final_w;
60 Sint32 final_y, final_h;
61 // Auxiliar flags
62 bool isRaiseHeightCandidate;
63 bool isShrinkWidthCandidate;
64 bool shrinkWidth;
65 bool raiseHeight;
66 bool isJoinCandidate;
67 bool topTunnel;
68 bool singleDeadEndDir;
69 bool isEdgeTunnelCandidate;
70 bool isVoidTunnelCandidate;
71 bool isSingleDeadEndCandidate;
72 bool isDoubleDeadEndCandidate;
73 stCell();
74 #ifdef DEBUG_GENERATOR
75 void info();
76 #endif
77 };
78 vector<stCell> vCells;
79
80 // Internal vars
81 Sint32 tallRows[50];
82 Sint32 narrowCols[50];
83 Sint32 rows;
84 Sint32 cols;
85 Sint32 numFilled; // current count of total cells filled
86 Sint32 numGroups; // current count of cell groups created
87
88 // Private methods
89
90 // Random stuff
91 Sint32 iNumRands;
92 Sint32 getRandomInt(Sint32, Sint32);
93 double getRandomReal();
94 Sint32 suffle(vector<stCell*>&);
95 stCell* randomElement(vector<stCell*>&);
96 Uint32 randSeed[16];
97 Uint32 randState;
98
99 // Maze generation stuff
100 Sint32 reset(); // Reset the map
101 void getOpenCells(stCell&, Sint32, Sint32, vector<Sint32>&);
102 Sint32 getLeftMostEmptyCells(vector<stCell*>&);
103 bool isOpenCell(stCell& c, Sint32 i, Sint32 prevDir = -1, Sint32 size = -1);
104 void connectCell(stCell&, Sint32);
105 void setResizeCandidates();
106 bool cellIsCrossCenter(stCell&);
107 bool canShrinkWidth(Sint32, Sint32);
108 bool chooseNarrowCols();
109 bool canRaiseHeight(Sint32, Sint32);
110 bool chooseTallRows();
111 bool isHori(Sint32, Sint32);
112 bool isVert(Sint32, Sint32);
113 bool isDesirable();
114 void setUpScaleCoords();
115 void reassignGroup(Sint32, Sint32);
116 void joinWalls();
117 void fillCell(stCell&);
118 void selectSingleDeadEnd(stCell*);
119 void replaceGroup(Sint32, Sint32);
120 bool createTunnels();
121 void generate();
122
123 // Convert maze to "tiles" stuff
124 vector<stCell> tileCells; // Todo rename
125 Sint32 subrows, subcols;
126 Sint32 midcols, fullcols;
127 void setTile(Sint32 x, Sint32 y, Uint8 v, vector<Uint8>&);
128 Sint32 getTile(Sint32, Sint32, vector<Uint8>&);
129 void setTileCell(Sint32, Sint32, stCell&);
130 stCell* getTileCell(Sint32, Sint32);
131 bool getTopEnergizerRange(Sint32&, Sint32&, vector<Uint8>&);
132 bool getBotEnergizerRange(Sint32&, Sint32&, vector<Uint8>&);
133 void eraseUntilIntersection(Sint32, Sint32, vector<Uint8>&);
134 Sint32 generateTiles(vector<Uint8>&);
135};
136
137#endif