raw_brush.cpp

main 109 lines · 2.9 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#include "main.h"
19#include "gui.h"
20
21#include "raw_brush.h"
22#include "settings.h"
23#include "items.h"
24#include "basemap.h"
25
26//=============================================================================
27// RAW brush
28
29RAWBrush::RAWBrush(uint16_t itemid) :
30 Brush() {
31 ItemType& it = g_items[itemid];
32 if (it.id == 0) {
33 itemtype = nullptr;
34 } else {
35 itemtype = &it;
36 }
37}
38
39RAWBrush::~RAWBrush() {
40 ////
41}
42
43int RAWBrush::getLookID() const {
44 if (itemtype) {
45 return itemtype->clientID;
46 }
47 return 0;
48}
49
50uint16_t RAWBrush::getItemID() const {
51 return itemtype->id;
52}
53
54std::string RAWBrush::getName() const {
55 if (!itemtype) {
56 return "RAWBrush";
57 }
58
59 if (itemtype->hookSouth) {
60 return i2s(itemtype->id) + " - " + itemtype->name + " (Hook South)";
61 } else if (itemtype->hookEast) {
62 return i2s(itemtype->id) + " - " + itemtype->name + " (Hook East)";
63 }
64
65 return i2s(itemtype->id) + " - " + itemtype->name + itemtype->editorsuffix;
66}
67
68void RAWBrush::undraw(BaseMap* map, Tile* tile) {
69 if (tile->ground && tile->ground->getID() == itemtype->id) {
70 delete tile->ground;
71 tile->ground = nullptr;
72 }
73 for (ItemVector::iterator iter = tile->items.begin(); iter != tile->items.end();) {
74 Item* item = *iter;
75 if (item->getID() == itemtype->id) {
76 delete item;
77 iter = tile->items.erase(iter);
78 } else {
79 ++iter;
80 }
81 }
82}
83
84void RAWBrush::draw(BaseMap* map, Tile* tile, void* parameter) {
85 if (!itemtype) {
86 return;
87 }
88
89 bool b = parameter ? *reinterpret_cast<bool*>(parameter) : false;
90 if ((g_settings.getInteger(Config::RAW_LIKE_SIMONE) && !b) && itemtype->alwaysOnBottom && itemtype->alwaysOnTopOrder == 2) {
91 for (ItemVector::iterator iter = tile->items.begin(); iter != tile->items.end();) {
92 Item* item = *iter;
93 if (item->getTopOrder() == itemtype->alwaysOnTopOrder) {
94 delete item;
95 iter = tile->items.erase(iter);
96 } else {
97 ++iter;
98 }
99 }
100 }
101 Item* new_item = Item::Create(itemtype->id);
102 if (new_item) {
103 if (g_gui.IsCurrentActionIDEnabled()) {
104 new_item->setActionID(g_gui.GetCurrentActionID());
105 }
106 tile->addItem(new_item);
107 }
108}
109
Top