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_GROUND_BRUSH_H
19#define RME_GROUND_BRUSH_H
20
21#include "brush.h"
22
23//=============================================================================
24
25class GroundBrush : public TerrainBrush {
26protected:
27 struct BorderBlock;
28
29public:
30 static void init();
31
32 GroundBrush();
33 virtual ~GroundBrush();
34
35 bool isGround() const {
36 return true;
37 }
38 GroundBrush* asGround() {
39 return static_cast<GroundBrush*>(this);
40 }
41
42 virtual bool load(pugi::xml_node node, wxArrayString& warnings);
43
44 virtual void draw(BaseMap* map, Tile* tile, void* parameter);
45 virtual void undraw(BaseMap* map, Tile* tile);
46 static void doBorders(BaseMap* map, Tile* tile);
47 static const BorderBlock* getBrushTo(GroundBrush* from, GroundBrush* to);
48 static void reborderizeTile(BaseMap* map, Tile* tile);
49
50 virtual int32_t getZ() const {
51 return z_order;
52 }
53 bool useSoloOptionalBorder() const {
54 return use_only_optional;
55 }
56 bool isReRandomizable() const {
57 return randomize;
58 }
59
60 bool hasOuterZilchBorder() const {
61 return has_zilch_outer_border || optional_border;
62 }
63 bool hasInnerZilchBorder() const {
64 return has_zilch_inner_border;
65 }
66 bool hasOuterBorder() const {
67 return has_outer_border || optional_border;
68 }
69 bool hasInnerBorder() const {
70 return has_inner_border;
71 }
72 bool hasOptionalBorder() const {
73 return optional_border != nullptr;
74 }
75
76protected: // Members
77 int32_t z_order;
78 bool has_zilch_outer_border;
79 bool has_zilch_inner_border;
80 bool has_outer_border;
81 bool has_inner_border;
82 AutoBorder* optional_border;
83 bool use_only_optional; // If this is true, there will be no normal border under the gravel
84 bool randomize;
85
86 struct SpecificCaseBlock {
87 SpecificCaseBlock() :
88 match_group(0), group_match_alignment(BORDER_NONE), to_replace_id(0), with_id(0), delete_all(false), keepBorder(false) { }
89 std::vector<uint16_t> items_to_match;
90 uint32_t match_group;
91 BorderType group_match_alignment;
92 uint16_t to_replace_id;
93 uint16_t with_id;
94 bool delete_all;
95 bool keepBorder;
96 };
97
98 struct BorderBlock {
99 bool outer;
100 bool super;
101 uint32_t to;
102
103 AutoBorder* autoborder;
104 std::vector<SpecificCaseBlock*> specific_cases;
105 };
106
107 struct ItemChanceBlock {
108 int chance;
109 uint16_t id;
110 };
111
112 struct BorderCluster {
113 uint32_t alignment;
114 int32_t z;
115 const AutoBorder* border;
116
117 bool operator<(const BorderCluster& other) const {
118 return other.z > z;
119 }
120 };
121
122 std::vector<BorderBlock*> borders;
123 std::vector<ItemChanceBlock> border_items;
124 int total_chance;
125
126public: // Static global members
127 static uint32_t border_types[256];
128};
129
130#endif
131