Map Editor

RD Core / Commit #3

Commit Map Editor

Alex Alex committed 18/10/2026 23:40 main Patch
436 files +250,791 -0
A RD_Map_Editor/source/brush.h +482-0 View file
@@ -0,0 +1,482 @@
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_BRUSH_H_
19+#define RME_BRUSH_H_
20+#include "main.h"
21+
22+#include "position.h"
23+
24+#include "brush_enums.h"
25+
26+// Thanks to a million forward declarations, we don't have to include any files!
27+// TODO move to a declarations file.
28+class ItemType;
29+class CreatureType;
30+class BaseMap;
31+class House;
32+class Item;
33+class Tile;
34+typedef std::vector<Tile*> TileVector;
35+class AutoBorder;
36+class Brush;
37+class RAWBrush;
38+class DoodadBrush;
39+class TerrainBrush;
40+class GroundBrush;
41+class WallBrush;
42+class WallDecorationBrush;
43+class TableBrush;
44+class CarpetBrush;
45+class DoorBrush;
46+class OptionalBorderBrush;
47+class CreatureBrush;
48+class SpawnBrush;
49+class HouseBrush;
50+class HouseExitBrush;
51+class WaypointBrush;
52+class FlagBrush;
53+class EraserBrush;
54+
55+//=============================================================================
56+// Brushes, holds all brushes
57+
58+typedef std::multimap<std::string, Brush*> BrushMap;
59+
60+class Brushes {
61+public:
62+ Brushes();
63+ ~Brushes();
64+
65+ void init();
66+ void clear();
67+
68+ Brush* getBrush(const std::string& name) const;
69+
70+ void addBrush(Brush* brush);
71+ void removeBrush(const std::string& name);
72+
73+ bool unserializeBorder(pugi::xml_node node, wxArrayString& warnings);
74+ bool unserializeBrush(pugi::xml_node node, wxArrayString& warnings);
75+
76+ const BrushMap& getMap() const {
77+ return brushes;
78+ }
79+
80+protected:
81+ typedef std::map<uint32_t, AutoBorder*> BorderMap;
82+ BrushMap brushes;
83+ BorderMap borders;
84+
85+ friend class AutoBorder;
86+ friend class GroundBrush;
87+};
88+
89+extern Brushes g_brushes;
90+
91+//=============================================================================
92+// Common brush interface
93+
94+class Brush {
95+public:
96+ Brush();
97+ virtual ~Brush();
98+
99+ virtual bool load(pugi::xml_node node, wxArrayString& warnings) {
100+ return true;
101+ }
102+
103+ virtual void draw(BaseMap* map, Tile* tile, void* parameter = nullptr) = 0;
104+ virtual void undraw(BaseMap* map, Tile* tile) = 0;
105+ virtual bool canDraw(BaseMap* map, const Position& position) const = 0;
106+
107+ //
108+ uint32_t getID() const {
109+ return id;
110+ }
111+
112+ virtual std::string getName() const = 0;
113+ virtual void setName(const std::string& newName) {
114+ ASSERT(_MSG("setName attempted on nameless brush!"));
115+ }
116+
117+ virtual int getLookID() const = 0;
118+
119+ virtual bool needBorders() const {
120+ return false;
121+ }
122+
123+ virtual bool canDrag() const {
124+ return false;
125+ }
126+ virtual bool canSmear() const {
127+ return true;
128+ }
129+
130+ virtual bool oneSizeFitsAll() const {
131+ return false;
132+ }
133+
134+ virtual int32_t getMaxVariation() const {
135+ return 0;
136+ }
137+
138+ virtual bool isRaw() const {
139+ return false;
140+ }
141+ virtual bool isDoodad() const {
142+ return false;
143+ }
144+ virtual bool isTerrain() const {
145+ return false;
146+ }
147+ virtual bool isGround() const {
148+ return false;
149+ }
150+ virtual bool isWall() const {
151+ return false;
152+ }
153+ virtual bool isWallDecoration() const {
154+ return false;
155+ }
156+ virtual bool isTable() const {
157+ return false;
158+ }
159+ virtual bool isCarpet() const {
160+ return false;
161+ }
162+ virtual bool isDoor() const {
163+ return false;
164+ }
165+ virtual bool isOptionalBorder() const {
166+ return false;
167+ }
168+ virtual bool isCreature() const {
169+ return false;
170+ }
171+ virtual bool isSpawn() const {
172+ return false;
173+ }
174+ virtual bool isHouse() const {
175+ return false;
176+ }
177+ virtual bool isHouseExit() const {
178+ return false;
179+ }
180+ virtual bool isWaypoint() const {
181+ return false;
182+ }
183+ virtual bool isFlag() const {
184+ return false;
185+ }
186+ virtual bool isEraser() const {
187+ return false;
188+ }
189+
190+ virtual RAWBrush* asRaw() {
191+ return nullptr;
192+ }
193+ virtual DoodadBrush* asDoodad() {
194+ return nullptr;
195+ }
196+ virtual TerrainBrush* asTerrain() {
197+ return nullptr;
198+ }
199+ virtual GroundBrush* asGround() {
200+ return nullptr;
201+ }
202+ virtual WallBrush* asWall() {
203+ return nullptr;
204+ }
205+ virtual WallDecorationBrush* asWallDecoration() {
206+ return nullptr;
207+ }
208+ virtual TableBrush* asTable() {
209+ return nullptr;
210+ }
211+ virtual CarpetBrush* asCarpet() {
212+ return nullptr;
213+ }
214+ virtual DoorBrush* asDoor() {
215+ return nullptr;
216+ }
217+ virtual OptionalBorderBrush* asOptionalBorder() {
218+ return nullptr;
219+ }
220+ virtual CreatureBrush* asCreature() {
221+ return nullptr;
222+ }
223+ virtual SpawnBrush* asSpawn() {
224+ return nullptr;
225+ }
226+ virtual HouseBrush* asHouse() {
227+ return nullptr;
228+ }
229+ virtual HouseExitBrush* asHouseExit() {
230+ return nullptr;
231+ }
232+ virtual WaypointBrush* asWaypoint() {
233+ return nullptr;
234+ }
235+ virtual FlagBrush* asFlag() {
236+ return nullptr;
237+ }
238+ virtual EraserBrush* asEraser() {
239+ return nullptr;
240+ }
241+
242+ bool visibleInPalette() const {
243+ return visible;
244+ }
245+ void flagAsVisible() {
246+ visible = true;
247+ }
248+
249+ bool hasCollection() const {
250+ return usesCollection;
251+ }
252+ void setCollection() {
253+ usesCollection = true;
254+ }
255+
256+
257+
258+protected:
259+ static uint32_t id_counter;
260+ uint32_t id;
261+ bool visible; // Visible in any palette?
262+ bool usesCollection;
263+};
264+
265+//=============================================================================
266+// Terrain brush interface
267+
268+class TerrainBrush : public Brush {
269+public:
270+ TerrainBrush();
271+ virtual ~TerrainBrush();
272+
273+ bool isTerrain() const {
274+ return true;
275+ }
276+ TerrainBrush* asTerrain() {
277+ return static_cast<TerrainBrush*>(this);
278+ }
279+
280+ virtual bool canDraw(BaseMap* map, const Position& position) const {
281+ return true;
282+ }
283+
284+ virtual std::string getName() const {
285+ return name;
286+ }
287+ virtual void setName(const std::string& newName) {
288+ name = newName;
289+ }
290+
291+ virtual int32_t getZ() const {
292+ return 0;
293+ }
294+ virtual int32_t getLookID() const {
295+ return look_id;
296+ }
297+
298+ virtual bool needBorders() const {
299+ return true;
300+ }
301+ virtual bool canDrag() const {
302+ return true;
303+ }
304+
305+ bool friendOf(TerrainBrush* other);
306+
307+protected:
308+ std::vector<uint32_t> friends;
309+ std::string name;
310+ uint16_t look_id;
311+ bool hate_friends;
312+};
313+
314+//=============================================================================
315+// FlagBrush, draw PZ etc.
316+
317+class FlagBrush : public Brush {
318+public:
319+ FlagBrush(uint32_t _flag);
320+ virtual ~FlagBrush();
321+
322+ bool isFlag() const {
323+ return true;
324+ }
325+ FlagBrush* asFlag() {
326+ return static_cast<FlagBrush*>(this);
327+ }
328+
329+ virtual bool canDraw(BaseMap* map, const Position& position) const;
330+ virtual void draw(BaseMap* map, Tile* tile, void* parameter);
331+ virtual void undraw(BaseMap* map, Tile* tile);
332+
333+ virtual bool canDrag() const {
334+ return true;
335+ }
336+ virtual int getLookID() const;
337+ virtual std::string getName() const;
338+ void setZoneId(uint16_t _zoneId) {
339+ zoneId = _zoneId;
340+ }
341+
342+protected:
343+ uint32_t flag;
344+ uint16_t zoneId;
345+};
346+
347+//=============================================================================
348+// Doorbrush, add doors, windows etc.
349+
350+class DoorBrush : public Brush {
351+public:
352+ DoorBrush(DoorType _doortype);
353+ virtual ~DoorBrush();
354+
355+ bool isDoor() const {
356+ return true;
357+ }
358+ DoorBrush* asDoor() {
359+ return static_cast<DoorBrush*>(this);
360+ }
361+
362+ static void switchDoor(Item* door);
363+
364+ virtual bool canDraw(BaseMap* map, const Position& position) const;
365+ virtual void draw(BaseMap* map, Tile* tile, void* parameter);
366+ virtual void undraw(BaseMap* map, Tile* tile);
367+
368+ virtual int getLookID() const;
369+ virtual std::string getName() const;
370+ virtual bool oneSizeFitsAll() const {
371+ return true;
372+ }
373+
374+protected:
375+ DoorType doortype;
376+};
377+
378+//=============================================================================
379+// OptionalBorderBrush, add gravel 'round mountains.
380+
381+class OptionalBorderBrush : public Brush {
382+public:
383+ OptionalBorderBrush();
384+ virtual ~OptionalBorderBrush();
385+
386+ bool isOptionalBorder() const {
387+ return true;
388+ }
389+ OptionalBorderBrush* asOptionalBorder() {
390+ return static_cast<OptionalBorderBrush*>(this);
391+ }
392+
393+ virtual bool canDraw(BaseMap* map, const Position& position) const;
394+ virtual void draw(BaseMap* map, Tile* tile, void* parameter);
395+ virtual void undraw(BaseMap* map, Tile* tile);
396+
397+ virtual bool canDrag() const {
398+ return true;
399+ }
400+ virtual int getLookID() const;
401+ virtual std::string getName() const;
402+};
403+
404+//=============================================================================
405+// Rampbrush, add ramps to mountains.
406+
407+class EraserBrush : public Brush {
408+public:
409+ EraserBrush();
410+ virtual ~EraserBrush();
411+
412+ bool isEraser() const {
413+ return true;
414+ }
415+ EraserBrush* asEraser() {
416+ return static_cast<EraserBrush*>(this);
417+ }
418+
419+ virtual bool canDraw(BaseMap* map, const Position& position) const;
420+ virtual void draw(BaseMap* map, Tile* tile, void* parameter);
421+ virtual void undraw(BaseMap* map, Tile* tile);
422+
423+ virtual bool needBorders() const {
424+ return true;
425+ }
426+ virtual bool canDrag() const {
427+ return true;
428+ }
429+ virtual int getLookID() const;
430+ virtual std::string getName() const;
431+};
432+
433+//=============================================================================
434+// Autoborder, used by GroundBrush, should be transparent to users
435+
436+class AutoBorder {
437+public:
438+ AutoBorder(int _id) :
439+ id(_id), group(0), ground(false) {
440+ for (int i = 0; i < 13; i++) {
441+ tiles[i] = 0;
442+ }
443+ }
444+ ~AutoBorder() { }
445+
446+ static int edgeNameToID(const std::string& edgename);
447+ bool load(pugi::xml_node node, wxArrayString& warnings, GroundBrush* owner = nullptr, uint16_t ground_equivalent = 0);
448+
449+ // Check if this border contains the specified item ID
450+ bool hasItemId(uint16_t id) const {
451+ for (int i = 0; i < 13; ++i) {
452+ if (tiles[i] == id) {
453+ return true;
454+ }
455+ }
456+ return false;
457+ }
458+
459+ // Get the item ID for a specific border alignment
460+ uint16_t getItemId(uint32_t alignment) const {
461+ // For now, just return the first matching tile
462+ if (alignment < 13 && tiles[alignment] != 0) {
463+ return tiles[alignment];
464+ }
465+
466+ // If no direct match, return the first non-zero tile
467+ for (int i = 0; i < 13; ++i) {
468+ if (tiles[i] != 0) {
469+ return tiles[i];
470+ }
471+ }
472+
473+ return 0; // No valid item ID found
474+ }
475+
476+ uint32_t tiles[13];
477+ uint32_t id;
478+ uint16_t group;
479+ bool ground;
480+};
481+
482+#endif
A RD_Map_Editor/source/brush_enums.h +93-0 View file
@@ -0,0 +1,93 @@
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_BRUSH_ENUMS_H_
19+#define RME_BRUSH_ENUMS_H_
20+
21+enum BorderType {
22+ // Border types (also used for carpets)
23+ BORDER_NONE = 0,
24+ NORTH_HORIZONTAL = 1,
25+ EAST_HORIZONTAL = 2,
26+ SOUTH_HORIZONTAL = 3,
27+ WEST_HORIZONTAL = 4,
28+ NORTHWEST_CORNER = 5,
29+ NORTHEAST_CORNER = 6,
30+ SOUTHWEST_CORNER = 7,
31+ SOUTHEAST_CORNER = 8,
32+ NORTHWEST_DIAGONAL = 9,
33+ NORTHEAST_DIAGONAL = 10,
34+ SOUTHEAST_DIAGONAL = 11,
35+ SOUTHWEST_DIAGONAL = 12,
36+ // Additional carpet type
37+ CARPET_CENTER = 13,
38+ // Wall types
39+ WALL_POLE = 0,
40+ WALL_SOUTH_END = 1,
41+ WALL_EAST_END = 2,
42+ WALL_NORTHWEST_DIAGONAL = 3,
43+ WALL_WEST_END = 4,
44+ WALL_NORTHEAST_DIAGONAL = 5,
45+ WALL_HORIZONTAL = 6,
46+ WALL_SOUTH_T = 7,
47+ WALL_NORTH_END = 8,
48+ WALL_VERTICAL = 9,
49+ WALL_SOUTHWEST_DIAGONAL = 10,
50+ WALL_EAST_T = 11,
51+ WALL_SOUTHEAST_DIAGONAL = 12,
52+ WALL_WEST_T = 13,
53+ WALL_NORTH_T = 14,
54+ WALL_INTERSECTION = 15,
55+ WALL_UNTOUCHABLE = 16,
56+ // Table types
57+ TABLE_NORTH_END = 0,
58+ TABLE_SOUTH_END = 1,
59+ TABLE_EAST_END = 2,
60+ TABLE_WEST_END = 3,
61+ TABLE_HORIZONTAL = 4,
62+ TABLE_VERTICAL = 5,
63+ TABLE_ALONE = 6,
64+};
65+
66+enum TileAlignement {
67+ TILE_NORTHWEST = 1,
68+ TILE_NORTH = 2,
69+ TILE_NORTHEAST = 4,
70+ TILE_WEST = 8,
71+ TILE_EAST = 16,
72+ TILE_SOUTHWEST = 32,
73+ TILE_SOUTH = 64,
74+ TILE_SOUTHEAST = 128,
75+ WALLTILE_NORTH = 1,
76+ WALLTILE_WEST = 2,
77+ WALLTILE_EAST = 4,
78+ WALLTILE_SOUTH = 8,
79+};
80+
81+enum DoorType {
82+ WALL_UNDEFINED,
83+ WALL_ARCHWAY,
84+ WALL_DOOR_NORMAL,
85+ WALL_DOOR_LOCKED,
86+ WALL_DOOR_QUEST,
87+ WALL_DOOR_MAGIC,
88+ WALL_DOOR_NORMAL_ALT,
89+ WALL_WINDOW,
90+ WALL_HATCH_WINDOW,
91+};
92+
93+#endif
Top