]> Shamusworld >> Repos - guemap/blob - src/globals.h
a39836cac6d052c0f26ffe0c4655dfb4b4952073
[guemap] / src / globals.h
1 //
2 // GUEmap
3 // (C) 1997-2007 Christopher J. Madsen
4 // (C) 2019 James Hammons
5 //
6 // GUEmap is licensed under either version 2 of the GPL, or (at your option)
7 // any later version.  See LICENSE file for details.
8 //
9
10 #ifndef __GLOBALS_H__
11 #define __GLOBALS_H__
12
13 #include <QtWidgets>
14 #include <QObject>
15 #include <assert.h>
16 #include <stdint.h>
17 #include <algorithm>
18 #include <string>
19 #include <vector>
20
21 #define ASSERT(x) assert(x)
22
23 using namespace std;
24
25 typedef uint16_t RoomNum;
26 typedef uint8_t  EdgeType;
27 typedef uint8_t  RoomFlags;
28
29 const int
30         gridX        = 120,      // PORT 0.25 in
31         gridY        = 72,       // PORT 0.15 in
32         maxPages     = 250,
33         maxRooms     = 65535,
34         roomWidth    = 3 * gridX,
35         roomHeight   = 3 * gridY;
36
37 const EdgeType
38         etNormal     = 0x00,
39         etUp         = 0x01,
40         etDown       = 0x02,
41         etIn         = 0x03,
42         etOut        = 0x04,
43         etDirection  = 0x07,
44         etObstructed = 0x08,
45         etNoExit     = 0x10,
46         etUnexplored = 0x20,
47         etOneWay     = 0x40,
48         etLoopBack   = 0x80,
49         etNoRoom2    = etNoExit | etUnexplored | etLoopBack,
50         etSpecial    = etObstructed | etNoExit | etOneWay | etUnexplored | etLoopBack;
51
52 const RoomFlags
53         rfBorder = 0x01,
54         rfCorner = 0x02;
55
56 enum RoomCorner
57 {
58         rcNone = -1,
59         rcN, rcS, rcE, rcW,
60         rcNE, rcNW, rcSE, rcSW,
61         rcNNE, rcNNW, rcSSE, rcSSW,
62         rcCorner,
63         rcNumCorners,
64         rcUp = rcNumCorners, rcDown, rcIn, rcOut,
65         rcNumDirections
66 };
67
68 struct MapEdge
69 {
70         RoomNum room1, room2;
71         RoomCorner end1, end2;
72         EdgeType type1, type2;
73
74         MapEdge();
75         MapEdge(RoomNum r1, RoomNum r2, EdgeType t1, EdgeType t2, RoomCorner e1, RoomCorner e2);
76         void Swap(void);
77         MapEdge Swapped(void) const;
78         bool HasRoom(RoomNum);
79 };
80
81 struct MapPage
82 {
83         QPoint pos;
84
85         MapPage(): pos(0, 0) {}
86         bool operator==(const MapPage & o) const { return pos == o.pos; }
87 };
88
89 struct MapRoom
90 {
91         QPoint pos;
92         string name;
93         string note;
94         RoomFlags flags;
95
96         MapRoom();
97         MapRoom(const MapRoom & o);
98         MapRoom & operator=(const MapRoom & source);
99         QRect getRect(void);
100         QRect getTranslatedRect(QPoint);
101         QPoint GetCenter(void);
102         RoomFlags isCorner(void) const;
103         bool operator!=(const MapRoom & mr) const;
104 };
105
106
107 typedef string::size_type       StrIdx;
108 typedef string::iterator        StrItr;
109 typedef string::const_iterator  StrConstItr;
110
111 typedef vector<uint8_t>         ByteVec;
112 typedef ByteVec::iterator       ByteItr;
113 typedef ByteVec::const_iterator ByteConstItr;
114 //typedef ByteVec::size_type      VecSize;
115
116 typedef vector<uint16_t>        WordVec;
117
118 typedef vector<MapEdge>         EdgeVec;
119 typedef EdgeVec::iterator       EdgeItr;
120 typedef EdgeVec::const_iterator EdgeConstItr;
121
122 typedef vector<MapPage>         PageVec;
123 typedef PageVec::iterator       PageItr;
124 typedef PageVec::const_iterator PageConstItr;
125
126 typedef vector<MapRoom *>       RoomVec;
127 typedef RoomVec::iterator       RoomItr;
128 typedef RoomVec::const_iterator RoomConstItr;
129 //typedef Array<MapRoom, RoomVec> RoomArray;
130
131 typedef ByteVec                 PageNumVec;
132 typedef ByteVec::iterator       PNItr;
133 typedef ByteVec::const_iterator PNConstItr;
134
135 typedef WordVec                 RoomNumVec;
136 typedef WordVec::iterator       RNItr;
137 typedef WordVec::const_iterator RNConstItr;
138
139 #include "array.h"
140
141 // Exported functions
142 void trimLeft(string & s);
143 void trimRight(string & s);
144 QAction * CreateAction(QString name, QString tooltip, QString statustip,
145         QIcon icon, QKeySequence key, bool checkable = false, QObject * parent = 0);
146 QAction * CreateAction(QString name, QString tooltip, QString statustip,
147         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable = false,
148         QObject * parent = 0);
149 double Magnitude(QPointF);
150 QPointF UnitVector(QPointF);
151 double Angle(QPointF);
152 double Angle(QPoint);
153 double Dot(QPointF, QPointF);
154 double Determinant(QPointF, QPointF);
155 double ParameterOfLineAndPoint(QPointF tail, QPointF head, QPointF point);
156
157 #endif  // __GLOBALS_H__
158