-
Notifications
You must be signed in to change notification settings - Fork 4
/
DungeonMap.h
169 lines (148 loc) · 4.37 KB
/
DungeonMap.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef __DUNGEONMAP_H__
#define __DUNGEONMAP_H__
#include "JMDefs.h"
#include "JLinkList.h"
#define DUNG_CREATE_STEP_INVALID -1
#define DUNG_CREATE_STEP_MAKE_ROOM 0
#define DUNG_CREATE_STEP_MAKE_HALLWAY 1
#define DUNG_CREATE_STEP_MAX 2
#define MAX_RECURDEPTH 10
#define DIR_NONE -1
#define DIR_NORTH 0
#define DIR_SOUTH 1
#define DIR_WEST 2
#define DIR_EAST 3
#define DUNG_HALL_MINLENGTH 2
#define DUNG_HALL_MAXLENGTH 8
class CDungeonCreationStep
{
public:
CDungeonCreationStep():
m_dwIndex(DUNG_CREATE_STEP_INVALID),
m_dwDirection(DIR_NONE),
m_dwRecurDepth(MAX_RECURDEPTH)
{
m_vPos.Init();
m_rcArea.Init(0,0,0,0);
m_pdwVisited = new bool[4];
memset(m_pdwVisited, false, 4);
};
~CDungeonCreationStep(){};
int m_dwIndex;
int m_dwDirection;
int m_dwRecurDepth;
JIVector m_vPos;
JRect m_rcArea;
bool *m_pdwVisited;
};
// CDungeonMapTile:
// the info needed for map generation
// and display of the map, one per tile
// on the current level.
class CDungeonMapTile
{
// Member variables
public:
CDungeonMapTile():
m_uiType(DUNG_IDX_INVALID),
m_Rect(),
m_dwFlags(0)
{};
~CDungeonMapTile() {};
Uint8 GetType() const { return m_uiType; };
void SetType(Uint8 type) { m_uiType = type; };
int GetFlags() const { return m_dwFlags; };
void SetFlags(int type) { m_dwFlags = type; };
protected:
private:
Uint8 m_uiType; // what kind of tile is this? (floor, wall, door, etc)
JRect m_Rect; // What are this tiles coordinates in world space? (ltrb)
int m_dwFlags; // 32 bits to use as you please. Please reference here what's using them (or the .h)
// Member functions
public:
void SetLink( CLink <CDungeonMapTile> *link ) { m_pllLink = link; };
protected:
private:
CLink <CDungeonMapTile> *m_pllLink; // My link into the Used Space list (or another list)
};
// CDungeonMap:
// holder class for dungeon generation
// algorithm.
class CDungeonMap
{
// Member variables
public:
CDungeonMap():
m_dmtTiles(NULL),
m_llUsedSpace(NULL),
m_stkDungeonMapCreation(NULL)
{
m_stkDungeonMapCreation = new JStack<CDungeonCreationStep>;
};
~CDungeonMap()
{
Term();
};
protected:
void Term()
{
if( m_dmtTiles )
{
delete [] m_dmtTiles;
m_dmtTiles = NULL;
}
};
private:
CDungeonMapTile *m_dmtTiles; // 1 DungeonMapTile per tile, has "graphical" info (size, location, type, ...)
JLinkList<CDungeonMapTile> *m_llUsedSpace;
JStack<CDungeonCreationStep> *m_stkDungeonMapCreation;
// Member functions
public:
void CreateDungeon(const int depth);
void InitDungeonCreate( JIVector &vOrigin );
bool CreateOneStep();
int Opposite( int direction );
CDungeonCreationStep *MakeRoomStep( const JIVector &vPos, const int direction, const int recurdepth );
CDungeonCreationStep *MakeHallStep( const JIVector &vPos, const int direction, const int recurdepth );
void GetRoomRect(JRect &rcRoom, const int direction);
void GetHallRect(JRect &rcHall, const int direction);
JIVector &GetWallOrigin(CDungeonCreationStep *pStep, const int direction);
JIVector &GetHallOrigin(CDungeonCreationStep *pStep);
Uint8 GetdtdIndex( JIVector vPos )
{
if( GetTile(vPos) )
{
return GetTile(vPos)->GetType();
}
return (Uint8)-1;
};
int GetFlags( JIVector vPos )
{
if( GetTile(vPos) )
{
return GetTile(vPos)->GetFlags();
}
return -1;
};
protected:
int CheckArea( const JRect *rcCheck, const int direction, bool bIsHallway );
bool CheckArea( CDungeonCreationStep *pStep );
bool CheckInterior( CDungeonCreationStep *pStep );
bool CheckBorder( CDungeonCreationStep *pStep );
void FillArea( const Uint8 type, JRect *rcFill, const int direction, JIVector *vOrigin, bool bIsHallway );
void FillArea( const CDungeonCreationStep *pStep );
void MakeRoom( const JIVector *vPos, const int direction, const int recurdepth );
void MakeHall( const JIVector *vPos, const int direction, const int recurdepth );
CDungeonMapTile *GetTile(JIVector vPos)
{
if( m_dmtTiles == NULL
|| vPos.x < 0 || vPos.y < 0
|| vPos.y > DUNG_HEIGHT || vPos.x > DUNG_WIDTH )
{
return NULL;
}
return &m_dmtTiles[vPos.y * DUNG_WIDTH + vPos.x];
}
private:
};
#endif // __DUNGEONMAP_H__