/
DungeonGenerator.h
114 lines (90 loc) · 2.92 KB
/
DungeonGenerator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
#include "Algorithms.h"
#include <time.h>
#include <iostream>
#define MAX_COLS 100
namespace ProceduralGeneration
{
class DungeonGenerator
{
protected:
// member variables
std::vector<vector<TileType>> m_map;
int m_width, m_height;
Coord m_startPosition;
int m_seed;
PseudoRandom m_random;
// functions
DungeonGenerator(int width, int height, Coord startPosition);
void InitDungeon();
void AddToDungeon(CoordList* floorData, std::vector<Wall>* wallData);
void AddToDungeon(CoordList* data, TileType type);
public:
~DungeonGenerator() { }
virtual void Generate() = 0; // abstract function
//int** GetMap() { return m_map; }
TileType GetSpaceValue(int x, int y) { return m_map[y][x]; }
void DrawDungeon();
};
struct RandomWalkParameters
{
RandomWalkParameters(int iterations, int walkLength, bool startRandomly)
{
this->iterations = iterations;
this->walkLength = walkLength;
this->startRandomly = startRandomly;
}
int iterations;
int walkLength;
bool startRandomly;
};
// Subclass 1
class RandomWalkGenerator : public DungeonGenerator
{
public:
RandomWalkGenerator(int width, int height, Coord position, int iterations = 10, int walkLength = 10, bool startRandomly = true);
~RandomWalkGenerator() {}
virtual void Generate() override;
CoordList RunRandomWalk(Coord startPosition);
protected:
Coord m_position;
int m_iterations;
int m_walkLength;
bool m_startRandomly;
};
// Subclass 2
class CorridorFirstGenerator : public RandomWalkGenerator
{
int m_corridorLength, m_TotalCorridors;
float m_roomPercent;
public:
CorridorFirstGenerator(int dungeonWidth, int dungeonHeight, Coord startPosition = {0, 0},
int corridorLength = 30, int totalCorridors = 10, float roomPercent = 0.5f,
RandomWalkParameters parameters = { 10, 10, true});
void Generate() override;
private:
void CreateRoomsAtDeadEnd(CoordList* deadEnds, CoordList& roomFloors);
CoordList FindAllDeadEnds(CoordList* floorPositions);
CoordList CreateRooms(CoordList* potentialRoomPositions);
void CreateCorridors(CoordList& floorPositions, CoordList& potentialRoomPositions);
};
// Subclass 3
class RoomFirstGenerator : public RandomWalkGenerator
{
// member variables
int m_minRoomWidth, m_minRoomHeight;
int m_offset;
bool m_randomWalkRooms = false;
public:
RoomFirstGenerator(int dungeonWidth, int dungeonHeight, Coord startPosition,
int minRoomWidth = 4, int minRoomHeight = 4, int offset = 1, bool randomWalkRooms = false,
RandomWalkParameters paramater = { 0, 0, 0});
void Generate() override;
private:
CoordList ConnectRooms(CoordList roomCenters);
CoordList CreateCorridor(Coord currentRoomCenter, Coord destination);
Coord FindClosestPointTo(Coord currentRoomCenter, CoordList roomCenters);
CoordList CreateSimpleRooms(std::vector<Boundary> rooms);
CoordList CreateRandomWalkRooms(std::vector<Boundary> roomsList);
};
}