tile.h

main 198 lines · 6.3 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#ifndef TILE_H
24#define TILE_H
25
26#include "declarations.h"
27#include "mapview.h"
28#include "effect.h"
29#include "creature.h"
30#include "item.h"
31#include <framework/luaengine/luaobject.h>
32#include <framework/stdext/time.h>
33
34enum tileflags_t
35{
36 TILESTATE_NONE = 0,
37 TILESTATE_PROTECTIONZONE = 1 << 0,
38 TILESTATE_TRASHED = 1 << 1,
39 TILESTATE_OPTIONALZONE = 1 << 2,
40 TILESTATE_NOLOGOUT = 1 << 3,
41 TILESTATE_HARDCOREZONE = 1 << 4,
42 TILESTATE_REFRESH = 1 << 5,
43
44 // internal usage
45 TILESTATE_HOUSE = 1 << 6,
46 TILESTATE_TELEPORT = 1 << 17,
47 TILESTATE_MAGICFIELD = 1 << 18,
48 TILESTATE_MAILBOX = 1 << 19,
49 TILESTATE_TRASHHOLDER = 1 << 20,
50 TILESTATE_BED = 1 << 21,
51 TILESTATE_DEPOT = 1 << 22,
52 TILESTATE_TRANSLUECENT_LIGHT = 1 << 23,
53
54 TILESTATE_LAST = 1 << 24
55};
56
57class Tile : public LuaObject
58{
59public:
60 enum {
61 MAX_THINGS = 10
62 };
63
64 Tile(const Position& position);
65
66 void calculateCorpseCorrection();
67
68 void drawGround(const Point& dest, LightView* lightView = nullptr);
69 void drawBottom(const Point& dest, LightView* lightView = nullptr);
70 void drawCreatures(const Point& dest, LightView* lightView = nullptr);
71 void drawTop(const Point& dest, LightView* lightView = nullptr);
72 void drawTexts(Point dest);
73 void drawWidget(Point dest);
74
75public:
76 void clean();
77
78 void addWalkingCreature(const CreaturePtr& creature);
79 void removeWalkingCreature(const CreaturePtr& creature);
80
81 void addThing(const ThingPtr& thing, int stackPos);
82 bool removeThing(ThingPtr thing);
83 ThingPtr getThing(int stackPos);
84 EffectPtr getEffect(uint16 id);
85 bool hasThing(const ThingPtr& thing);
86 int getThingStackPos(const ThingPtr& thing);
87 ThingPtr getTopThing();
88
89 ThingPtr getTopLookThing();
90 ThingPtr getTopLookThingEx(Point offset);
91 ThingPtr getTopUseThing();
92 CreaturePtr getTopCreature();
93 CreaturePtr getTopCreatureEx(Point offset);
94 ThingPtr getTopMoveThing();
95 ThingPtr getTopMultiUseThing();
96 ThingPtr getTopMultiUseThingEx(Point offset);
97
98 const Position& getPosition() { return m_position; }
99 int getDrawElevation() { return m_drawElevation; }
100 std::vector<ItemPtr> getItems();
101 std::vector<CreaturePtr> getCreatures();
102 std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
103 std::vector<ThingPtr> getThings() { return m_things; }
104 std::vector<EffectPtr> getEffects() { return m_effects; }
105 ItemPtr getGround();
106 int getGroundSpeed();
107 bool isBlocking() { return m_blocking != 0; }
108 uint8 getMinimapColorByte();
109 int getThingCount() { return m_things.size() + m_effects.size(); }
110 bool isPathable();
111 bool isWalkable(bool ignoreCreatures = false);
112 bool isFullGround();
113 bool isFullyOpaque();
114 bool isSingleDimension();
115 bool isLookPossible();
116 bool isBlockingProjectile();
117 bool isClickable();
118 bool isEmpty();
119 bool isDrawable();
120 bool hasTranslucentLight() { return m_flags & TILESTATE_TRANSLUECENT_LIGHT; }
121 bool mustHookSouth();
122 bool mustHookEast();
123 bool hasCreature();
124 bool hasBlockingCreature();
125 bool limitsFloorsView(bool isFreeView = false);
126 bool canErase();
127 int getElevation();
128 bool hasElevation(int elevation = 1);
129 void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
130
131 void remFlag(uint32 flag) { m_flags &= ~flag; }
132 void setFlag(uint32 flag) { m_flags |= flag; }
133 void setFlags(uint32 flags) { m_flags = flags; }
134 bool hasFlag(uint32 flag) { return (m_flags & flag) == flag; }
135 uint32 getFlags() { return m_flags; }
136
137 void setHouseId(uint32 hid) { m_houseId = hid; }
138 uint32 getHouseId() { return m_houseId; }
139 bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
140
141 void select() { m_selected = true; }
142 void unselect() { m_selected = false; }
143 bool isSelected() { return m_selected; }
144
145 TilePtr asTile() { return static_self_cast<Tile>(); }
146
147 void setSpeed(uint16_t speed, uint8_t blocking) {
148 m_speed = speed;
149 m_blocking = blocking;
150 }
151
152 void setText(const std::string& text, Color color);
153 std::string getText();
154 void setTimer(int time, Color color);
155 int getTimer();
156 void setFill(Color color);
157 void resetFill() { m_fill = Color::alpha; }
158
159 bool canShoot(int distance);
160
161 void setWidget(UIWidgetPtr widget) { m_widget = widget; }
162 UIWidgetPtr getWidget() { return m_widget; }
163 void removeWidget() {
164 if (m_widget) {
165 m_widget->destroy();
166 m_widget = nullptr;
167 }
168 }
169
170private:
171 void checkTranslucentLight();
172
173 std::vector<CreaturePtr> m_walkingCreatures;
174 std::vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
175 std::vector<ThingPtr> m_things;
176 Position m_position;
177 uint8 m_drawElevation;
178 uint8 m_minimapColor;
179 uint32 m_flags, m_houseId;
180 uint16 m_speed = 0;
181 uint8 m_blocking = 0;
182
183 uint32_t m_lastCreature = 0;
184 int m_topCorrection = 0;
185 int m_topDraws = 0;
186
187 stdext::boolean<false> m_selected;
188
189 ticks_t m_timer = 0;
190 StaticTextPtr m_timerText;
191 StaticTextPtr m_text;
192 Color m_fill = Color::alpha;
193
194 UIWidgetPtr m_widget;
195};
196
197#endif
198
Top