map_region.h

main 175 lines · 4 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#ifndef RME_MAP_REGION_H
19#define RME_MAP_REGION_H
20
21#include "position.h"
22
23class Tile;
24class Floor;
25class BaseMap;
26
27class TileLocation {
28 TileLocation();
29
30public:
31 ~TileLocation();
32
33 TileLocation(const TileLocation&) = delete;
34 TileLocation& operator=(const TileLocation&) = delete;
35
36protected:
37 Tile* tile;
38 Position position;
39 size_t spawn_count;
40 size_t waypoint_count;
41 size_t town_count;
42 HouseExitList* house_exits; // Any house exits pointing here
43
44public:
45 // Access tile
46 // Can't set directly since that does not update tile count
47 Tile* get() {
48 return tile;
49 }
50 const Tile* get() const {
51 return tile;
52 }
53
54 int size() const;
55 bool empty() const;
56
57 Position getPosition() const {
58 return position;
59 }
60
61 int getX() const {
62 return position.x;
63 }
64 int getY() const {
65 return position.y;
66 }
67 int getZ() const {
68 return position.z;
69 }
70
71 size_t getSpawnCount() const {
72 return spawn_count;
73 }
74 void increaseSpawnCount() {
75 spawn_count++;
76 }
77 void decreaseSpawnCount() {
78 spawn_count--;
79 }
80 size_t getWaypointCount() const {
81 return waypoint_count;
82 }
83 void increaseWaypointCount() {
84 waypoint_count++;
85 }
86 void decreaseWaypointCount() {
87 waypoint_count--;
88 }
89 size_t getTownCount() const {
90 return town_count;
91 }
92 void increaseTownCount() {
93 town_count++;
94 }
95 void decreaseTownCount() {
96 town_count--;
97 }
98 HouseExitList* createHouseExits() {
99 if (house_exits) {
100 return house_exits;
101 }
102 return house_exits = newd HouseExitList;
103 }
104 HouseExitList* getHouseExits() {
105 return house_exits;
106 }
107
108 friend class Floor;
109 friend class QTreeNode;
110 friend class Waypoints;
111};
112
113class Floor {
114public:
115 Floor(int x, int y, int z);
116 TileLocation locs[MAP_LAYERS];
117};
118
119// This is not a QuadTree, but a HexTree (16 child nodes to every node), so the name is abit misleading
120class QTreeNode {
121public:
122 QTreeNode(BaseMap& map);
123 virtual ~QTreeNode();
124
125 QTreeNode(const QTreeNode&) = delete;
126 QTreeNode& operator=(const QTreeNode&) = delete;
127
128 QTreeNode* getLeaf(int x, int y); // Might return nullptr
129 QTreeNode* getLeafForce(int x, int y); // Will never return nullptr, it will create the node if it's not there
130
131 // Coordinates are NOT relative
132 TileLocation* createTile(int x, int y, int z);
133 TileLocation* getTile(int x, int y, int z);
134 Tile* setTile(int x, int y, int z, Tile* tile);
135 void clearTile(int x, int y, int z);
136
137 Floor* createFloor(int x, int y, int z);
138 Floor* getFloor(uint32_t z) {
139 ASSERT(isLeaf);
140 return array[z];
141 }
142 Floor** getFloors() {
143 return array;
144 }
145
146 void setVisible(bool overground, bool underground);
147 void setVisible(uint32_t client, bool underground, bool value);
148 bool isVisible(uint32_t client, bool underground);
149 void clearVisible(uint32_t client);
150
151 void setRequested(bool underground, bool r);
152 bool isVisible(bool underground);
153 bool isRequested(bool underground);
154
155protected:
156 BaseMap& map;
157 uint32_t visible;
158
159 bool isLeaf;
160 union {
161 QTreeNode* child[MAP_LAYERS];
162 Floor* array[MAP_LAYERS];
163 /*
164 #if 16 != MAP_LAYERS
165 # error "You need to rewrite the QuadTree in order to handle more or less than 16 floors"
166 #endif
167 */
168 };
169
170 friend class BaseMap;
171 friend class MapIterator;
172};
173
174#endif
175
Top