]> Shamusworld >> Repos - guemap/blob - src/globals.h
Fix room adding to work properly, misc. small changes.
[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 Clear(void);
77         void Swap(void);
78         MapEdge Swapped(void) const;
79         bool HasRoom(RoomNum);
80 };
81
82 struct MapPage
83 {
84         QPoint pos;
85
86         MapPage(): pos(0, 0) {}
87         bool operator==(const MapPage & o) const { return pos == o.pos; }
88 };
89
90 struct MapRoom
91 {
92         QPoint pos;
93         string name;
94         string note;
95         RoomFlags flags;
96
97         MapRoom();
98         MapRoom(const MapRoom & o);
99         MapRoom & operator=(const MapRoom & source);
100         QRect getRect(void);
101         QRect getTranslatedRect(QPoint);
102         QPoint GetCenter(void);
103         RoomFlags isCorner(void) const;
104         bool operator!=(const MapRoom & mr) const;
105 };
106
107
108 typedef string::size_type       StrIdx;
109 typedef string::iterator        StrItr;
110 typedef string::const_iterator  StrConstItr;
111
112 typedef vector<uint8_t>         ByteVec;
113 typedef ByteVec::iterator       ByteItr;
114 typedef ByteVec::const_iterator ByteConstItr;
115 //typedef ByteVec::size_type      VecSize;
116
117 typedef vector<uint16_t>        WordVec;
118
119 typedef vector<MapEdge>         EdgeVec;
120 typedef EdgeVec::iterator       EdgeItr;
121 typedef EdgeVec::const_iterator EdgeConstItr;
122
123 typedef vector<MapPage>         PageVec;
124 typedef PageVec::iterator       PageItr;
125 typedef PageVec::const_iterator PageConstItr;
126
127 typedef vector<MapRoom *>       RoomVec;
128 typedef RoomVec::iterator       RoomItr;
129 typedef RoomVec::const_iterator RoomConstItr;
130 //typedef Array<MapRoom, RoomVec> RoomArray;
131
132 typedef ByteVec                 PageNumVec;
133 typedef ByteVec::iterator       PNItr;
134 typedef ByteVec::const_iterator PNConstItr;
135
136 typedef WordVec                 RoomNumVec;
137 typedef WordVec::iterator       RNItr;
138 typedef WordVec::const_iterator RNConstItr;
139
140 #include "array.h"
141
142 // Exported functions
143 void trimLeft(string & s);
144 void trimRight(string & s);
145 QAction * CreateAction(QString name, QString tooltip, QString statustip,
146         QIcon icon, QKeySequence key, bool checkable = false, QObject * parent = 0);
147 QAction * CreateAction(QString name, QString tooltip, QString statustip,
148         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable = false,
149         QObject * parent = 0);
150 double Magnitude(QPointF);
151 QPointF UnitVector(QPointF);
152 double Angle(QPointF);
153 double Angle(QPoint);
154 double Dot(QPointF, QPointF);
155 double Determinant(QPointF, QPointF);
156 double ParameterOfLineAndPoint(QPointF tail, QPointF head, QPointF point);
157
158 #endif  // __GLOBALS_H__
159