forked from capisce/mazecompositor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
map.h
176 lines (144 loc) · 3.84 KB
/
map.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
170
171
172
173
174
175
176
/*
* Copyright (c) 2012 Samuel Rødal
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef MAP_H
#define MAP_H
#include <QByteArray>
#include <QTime>
#include <QVector>
#include <QVector3D>
#include <qmath.h>
class Portal
{
public:
enum Type
{
Corridor,
Gate
};
Portal(const QVector3D &pos, const QVector3D &normal, Type type = Gate, qreal scale = 1)
: m_pos(pos)
, m_normal(normal)
, m_type(type)
, m_scale(scale)
, m_target(0)
{
}
void setType(Type type) { m_type = type; }
void setScale(qreal scale) { m_scale = scale; }
Portal *target() const { return m_target; }
void setTarget(Portal *target) { m_target = target; }
QVector3D pos() const { return m_pos; }
QVector3D normal() const { return m_normal; }
Type type() const { return m_type; }
qreal scale() const { return m_scale; }
private:
QVector3D m_pos;
QVector3D m_normal;
Type m_type;
qreal m_scale;
Portal *m_target;
};
class Map
{
public:
enum CellType
{
Wall,
Light,
Empty
};
Map();
int dimX() const { return m_dimX; }
int dimY() const { return m_dimY; }
bool contains(int x, int y) const
{
return x >= 0 && x < m_dimX && y >= 0 && y < m_dimY;
}
CellType type(int x, int y) const
{
switch (m_map.at(y * m_dimX + x)) {
case ' ':
return Empty;
case 'o':
return Light;
default:
return Wall;
}
}
bool occupied(int x, int y) const
{
return !empty(x, y) || m_occupied.at(y * m_dimX + x);
}
bool occupied(const QVector3D &pos) const
{
return occupied(qFloor(pos.x()), qFloor(pos.z()));
}
bool empty(int x, int y) const
{
return type(x, y) != Wall;
}
bool operator()(int x, int y) const
{
return empty(x, y);
}
int zone(const QVector3D &pos) const
{
return zone(qFloor(pos.x()), qFloor(pos.z()));
}
int zone(int x, int y) const
{
return m_zones.value(y * m_dimX + x, -1);
}
QVector<QVector3D> lights(int zone) const;
int maxLights() const
{
return m_maxLights;
}
QList<QVector<QVector3D> > tiles(int zone) const
{
return m_tiles.at(zone);
}
int numZones() const
{
return m_lights.size();
}
int numPortals() const
{
return m_portals.size();
}
const Portal *portal(int i) const
{
return m_portals.at(i);
}
private:
QByteArray m_map;
QVector<int> m_zones;
QVector<bool> m_occupied;
int m_dimX;
int m_dimY;
QTime m_time;
QVector<QVector<QVector3D> > m_lights;
QVector<QList<QVector<QVector3D > > > m_tiles;
QVector<Portal *> m_portals;
int m_maxLights;
};
#endif