Otclient 1.0  14/8/2020
thingtype.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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 THINGTYPE_H
24 #define THINGTYPE_H
25 
26 #include "animator.h"
27 #include "declarations.h"
28 
33 #include <framework/net/server.h>
35 
38 
43 };
44 
52 };
53 
54 enum ThingAttr : uint8 {
93 
94  // additional
97 
99  ThingAttrNoMoveAnimation = 253, // 10.10: real value is 16, but we need to do this for backwards compatibility
100  ThingAttrChargeable = 254, // deprecated
102 };
103 
109 };
110 
111 struct MarketData {
112  std::string name;
113  int category;
118 };
119 
120 struct Light {
121  Light() { intensity = 0; color = 215; }
124 };
125 
126 class ThingType : public LuaObject
127 {
128 public:
129  ThingType();
130 
131  void unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr& fin);
132  void unserializeOtml(const OTMLNodePtr& node);
133 
134  void serialize(const FileStreamPtr& fin);
135  void exportImage(const std::string& fileName);
136 
137  void draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, int reDrawFlags = Otc::ReDrawThing, LightView* lightView = nullptr);
138 
139  uint16 getId() { return m_id; }
140  ThingCategory getCategory() { return m_category; }
141  bool isNull() { return m_null; }
142  bool hasAttr(ThingAttr attr) { return m_attribs.has(attr); }
143 
144  Size getSize() { return m_size; }
145  int getWidth() { return m_size.width(); }
146  int getHeight() { return m_size.height(); }
147  int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
148  int getRealSize() { return m_realSize; }
149  int getLayers() { return m_layers; }
150  int getNumPatternX() { return m_numPatternX; }
151  int getNumPatternY() { return m_numPatternY; }
152  int getNumPatternZ() { return m_numPatternZ; }
153  int getAnimationPhases();
154  AnimatorPtr getAnimator() { return m_animator; }
155  AnimatorPtr getIdleAnimator() { return m_idleAnimator; }
156 
157  Point getDisplacement() { return m_displacement; }
158  int getDisplacementX() { return getDisplacement().x; }
159  int getDisplacementY() { return getDisplacement().y; }
160  int getElevation() { return m_elevation; }
161 
162  int getGroundSpeed() { return m_attribs.get<uint16>(ThingAttrGround); }
163  int getMaxTextLength() { return m_attribs.has(ThingAttrWritableOnce) ? m_attribs.get<uint16>(ThingAttrWritableOnce) : m_attribs.get<uint16>(ThingAttrWritable); }
164  Light getLight() { return m_attribs.get<Light>(ThingAttrLight); }
165  int getMinimapColor() { return m_attribs.get<uint16>(ThingAttrMinimapColor); }
166  int getLensHelp() { return m_attribs.get<uint16>(ThingAttrLensHelp); }
167  int getClothSlot() { return m_attribs.get<uint16>(ThingAttrCloth); }
169  bool isGround() { return m_attribs.has(ThingAttrGround); }
170  bool isGroundBorder() { return m_attribs.has(ThingAttrGroundBorder); }
171  bool isOnBottom() { return m_attribs.has(ThingAttrOnBottom); }
172  bool isOnTop() { return m_attribs.has(ThingAttrOnTop); }
173  bool isContainer() { return m_attribs.has(ThingAttrContainer); }
174  bool isStackable() { return m_attribs.has(ThingAttrStackable); }
175  bool isForceUse() { return m_attribs.has(ThingAttrForceUse); }
176  bool isMultiUse() { return m_attribs.has(ThingAttrMultiUse); }
177  bool isWritable() { return m_attribs.has(ThingAttrWritable); }
178  bool isChargeable() { return m_attribs.has(ThingAttrChargeable); }
179  bool isWritableOnce() { return m_attribs.has(ThingAttrWritableOnce); }
180  bool isFluidContainer() { return m_attribs.has(ThingAttrFluidContainer); }
181  bool isSplash() { return m_attribs.has(ThingAttrSplash); }
182  bool isNotWalkable() { return m_attribs.has(ThingAttrNotWalkable); }
183  bool isNotMoveable() { return m_attribs.has(ThingAttrNotMoveable); }
184  bool blockProjectile() { return m_attribs.has(ThingAttrBlockProjectile); }
185  bool isNotPathable() { return m_attribs.has(ThingAttrNotPathable); }
186  bool isPickupable() { return m_attribs.has(ThingAttrPickupable); }
187  bool isHangable() { return m_attribs.has(ThingAttrHangable); }
188  bool isHookSouth() { return m_attribs.has(ThingAttrHookSouth); }
189  bool isHookEast() { return m_attribs.has(ThingAttrHookEast); }
190  bool isRotateable() { return m_attribs.has(ThingAttrRotateable); }
191  bool hasLight() { return m_attribs.has(ThingAttrLight); }
192  bool isDontHide() { return m_attribs.has(ThingAttrDontHide); }
193  bool isTranslucent() { return m_attribs.has(ThingAttrTranslucent); }
194  bool hasDisplacement() { return m_attribs.has(ThingAttrDisplacement); }
195  bool hasElevation() { return m_attribs.has(ThingAttrElevation); }
196  bool isLyingCorpse() { return m_attribs.has(ThingAttrLyingCorpse); }
197  bool isAnimateAlways() { return m_attribs.has(ThingAttrAnimateAlways); }
198  bool hasMiniMapColor() { return m_attribs.has(ThingAttrMinimapColor); }
199  bool hasLensHelp() { return m_attribs.has(ThingAttrLensHelp); }
200  bool isFullGround() { return m_attribs.has(ThingAttrFullGround); }
201  bool isIgnoreLook() { return m_attribs.has(ThingAttrLook); }
202  bool isCloth() { return m_attribs.has(ThingAttrCloth); }
203  bool isMarketable() { return m_attribs.has(ThingAttrMarket); }
204  bool isUsable() { return m_attribs.has(ThingAttrUsable); }
205  bool isWrapable() { return m_attribs.has(ThingAttrWrapable); }
206  bool isUnwrapable() { return m_attribs.has(ThingAttrUnwrapable); }
207  bool isTopEffect() { return m_attribs.has(ThingAttrTopEffect); }
208  bool isOpaque() { return isFullGround() || hasTexture() && getTexture(0)->isOpaque(); }
209 
210  std::vector<int> getSprites() { return m_spritesIndex; }
211 
212  // additional
213  float getOpacity() { return m_opacity; }
214  bool isNotPreWalkable() { return m_attribs.has(ThingAttrNotPreWalkable); }
215  void setPathable(bool var);
216  int getExactHeight();
217  const TexturePtr& getTexture(int animationPhase);
218 
219  void startListenerPainter(float duration);
220  bool cancelListenerPainter();
221 
222 private:
223  bool hasTexture() const { return !m_textures.empty(); }
224 
225  static Size getBestTextureDimension(int w, int h, int count);
226  uint getSpriteIndex(int w, int h, int l, int x, int y, int z, int a);
227  uint getTextureIndex(int l, int x, int y, int z);
228 
229  ThingCategory m_category;
230  uint16 m_id;
231  bool m_null;
233 
234  Size m_size;
235  Point m_displacement;
236  AnimatorPtr m_animator;
237  AnimatorPtr m_idleAnimator;
238  int m_animationPhases;
239  int m_exactSize;
240  int m_realSize;
241  int m_numPatternX, m_numPatternY, m_numPatternZ;
242  int m_layers;
243  int m_elevation;
244  int m_exactHeight;
245  float m_opacity;
246  std::string m_customImage;
247 
248  std::vector<int> m_spritesIndex;
249  std::vector<TexturePtr> m_textures;
250  std::vector<std::vector<Rect>> m_texturesFramesRects;
251  std::vector<std::vector<Rect>> m_texturesFramesOriginRects;
252  std::vector<std::vector<Point>> m_texturesFramesOffsets;
253 
254  uint_fast8_t m_countPainterListeningRef;
255  ScheduledEventPtr m_painterListeningEvent;
256 };
257 
258 #endif
ThingAttrSplash
@ ThingAttrSplash
Definition: thingtype.h:66
SpriteMaskGreen
@ SpriteMaskGreen
Definition: thingtype.h:106
ThingType::isWritable
bool isWritable()
Definition: thingtype.h:177
ThingAttrNoMoveAnimation
@ ThingAttrNoMoveAnimation
Definition: thingtype.h:99
ThingAttrLyingCorpse
@ ThingAttrLyingCorpse
Definition: thingtype.h:81
ThingType::isHookEast
bool isHookEast()
Definition: thingtype.h:189
ThingType::isWritableOnce
bool isWritableOnce()
Definition: thingtype.h:179
ThingType::getHeight
int getHeight()
Definition: thingtype.h:146
MarketData::requiredLevel
uint16 requiredLevel
Definition: thingtype.h:114
ThingAttrTopEffect
@ ThingAttrTopEffect
Definition: thingtype.h:92
FrameGroupIdle
@ FrameGroupIdle
Definition: thingtype.h:41
ThingAttrFullGround
@ ThingAttrFullGround
Definition: thingtype.h:85
ThingCategoryMissile
@ ThingCategoryMissile
Definition: thingtype.h:49
Light::Light
Light()
Definition: thingtype.h:121
ThingType::getMinimapColor
int getMinimapColor()
Definition: thingtype.h:165
ThingType::isHookSouth
bool isHookSouth()
Definition: thingtype.h:188
ThingType::isUsable
bool isUsable()
Definition: thingtype.h:204
TPoint::y
T y
Definition: point.h:83
z
gc sort z
Definition: CMakeLists.txt:176
ThingType::cancelListenerPainter
bool cancelListenerPainter()
Definition: thingtype.cpp:677
ThingAttrNotMoveable
@ ThingAttrNotMoveable
Definition: thingtype.h:68
ThingAttrHookEast
@ ThingAttrHookEast
Definition: thingtype.h:74
ThingType::isSplash
bool isSplash()
Definition: thingtype.h:181
ThingType::getElevation
int getElevation()
Definition: thingtype.h:160
ThingAttrGround
@ ThingAttrGround
Definition: thingtype.h:55
ThingType::getSize
Size getSize()
Definition: thingtype.h:144
FrameGroupDefault
@ FrameGroupDefault
Definition: thingtype.h:40
SpriteMaskRed
@ SpriteMaskRed
Definition: thingtype.h:105
ThingAttrMinimapColor
@ ThingAttrMinimapColor
Definition: thingtype.h:83
ThingType::getMaxTextLength
int getMaxTextLength()
Definition: thingtype.h:163
ThingAttrHangable
@ ThingAttrHangable
Definition: thingtype.h:72
ThingAttrNotWalkable
@ ThingAttrNotWalkable
Definition: thingtype.h:67
ThingLastCategory
@ ThingLastCategory
Definition: thingtype.h:51
ThingAttrChargeable
@ ThingAttrChargeable
Definition: thingtype.h:100
ThingType::startListenerPainter
void startListenerPainter(float duration)
Definition: thingtype.cpp:661
ThingAttrUsable
@ ThingAttrUsable
Definition: thingtype.h:89
ThingAttrOnTop
@ ThingAttrOnTop
Definition: thingtype.h:58
ThingAttrRotateable
@ ThingAttrRotateable
Definition: thingtype.h:75
coordsbuffer.h
ThingType::isMultiUse
bool isMultiUse()
Definition: thingtype.h:176
ThingAttrWritableOnce
@ ThingAttrWritableOnce
Definition: thingtype.h:64
ThingAttrWritable
@ ThingAttrWritable
Definition: thingtype.h:63
ThingType::ThingType
ThingType()
Definition: thingtype.cpp:37
ThingType::hasLight
bool hasLight()
Definition: thingtype.h:191
MarketData::category
int category
Definition: thingtype.h:113
ThingAttrFloorChange
@ ThingAttrFloorChange
Definition: thingtype.h:98
ThingType::getOpacity
float getOpacity()
Definition: thingtype.h:213
Otc::ReDrawThing
@ ReDrawThing
Definition: const.h:56
ThingType::isLyingCorpse
bool isLyingCorpse()
Definition: thingtype.h:196
declarations.h
ThingType::unserializeOtml
void unserializeOtml(const OTMLNodePtr &node)
Definition: thingtype.cpp:410
ThingType::getWidth
int getWidth()
Definition: thingtype.h:145
ThingType::getLight
Light getLight()
Definition: thingtype.h:164
ThingAttrGroundBorder
@ ThingAttrGroundBorder
Definition: thingtype.h:56
ThingAttrDisplacement
@ ThingAttrDisplacement
Definition: thingtype.h:79
ThingCategoryEffect
@ ThingCategoryEffect
Definition: thingtype.h:48
ThingAttrCloth
@ ThingAttrCloth
Definition: thingtype.h:87
ThingType::getAnimationPhases
int getAnimationPhases()
Definition: thingtype.cpp:637
ThingType::getMarketData
MarketData getMarketData()
Definition: thingtype.h:168
TSize::width
int width() const
Definition: size.h:43
ThingType::isOnTop
bool isOnTop()
Definition: thingtype.h:172
stdext::dynamic_storage< uint8 >
ThingType::isNotPathable
bool isNotPathable()
Definition: thingtype.h:185
ThingType::isOnBottom
bool isOnBottom()
Definition: thingtype.h:171
ThingInvalidCategory
@ ThingInvalidCategory
Definition: thingtype.h:50
ThingType::isTranslucent
bool isTranslucent()
Definition: thingtype.h:193
LightView
Definition: lightview.h:37
ThingType::isOpaque
bool isOpaque()
Definition: thingtype.h:208
luaobject.h
uint16
uint16_t uint16
Definition: types.h:36
ThingType::serialize
void serialize(const FileStreamPtr &fin)
Definition: thingtype.cpp:53
ThingType::isFluidContainer
bool isFluidContainer()
Definition: thingtype.h:180
ThingType::hasAttr
bool hasAttr(ThingAttr attr)
Definition: thingtype.h:142
ThingType::getNumPatternX
int getNumPatternX()
Definition: thingtype.h:150
ThingType::getTexture
const TexturePtr & getTexture(int animationPhase)
Definition: thingtype.cpp:476
ThingType::hasLensHelp
bool hasLensHelp()
Definition: thingtype.h:199
FrameGroupType
FrameGroupType
Definition: thingtype.h:39
ThingType::unserialize
void unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr &fin)
Definition: thingtype.cpp:140
SpriteMaskBlue
@ SpriteMaskBlue
Definition: thingtype.h:107
Light::intensity
uint8 intensity
Definition: thingtype.h:122
ThingAttrLook
@ ThingAttrLook
Definition: thingtype.h:86
stdext::dynamic_storage::has
bool has(const Key &k) const
Definition: dynamic_storage.h:49
ThingType::getId
uint16 getId()
Definition: thingtype.h:139
ThingAttrMultiUse
@ ThingAttrMultiUse
Definition: thingtype.h:62
declarations.h
ThingType::isRotateable
bool isRotateable()
Definition: thingtype.h:190
declarations.h
uint
unsigned int uint
Definition: types.h:31
ThingCategoryCreature
@ ThingCategoryCreature
Definition: thingtype.h:47
ThingType::isDontHide
bool isDontHide()
Definition: thingtype.h:192
ThingType::blockProjectile
bool blockProjectile()
Definition: thingtype.h:184
ThingType::getSprites
std::vector< int > getSprites()
Definition: thingtype.h:210
ThingAttrNotPathable
@ ThingAttrNotPathable
Definition: thingtype.h:70
ThingType::getGroundSpeed
int getGroundSpeed()
Definition: thingtype.h:162
ThingAttrDontHide
@ ThingAttrDontHide
Definition: thingtype.h:77
ThingType::isTopEffect
bool isTopEffect()
Definition: thingtype.h:207
MarketData::tradeAs
uint16 tradeAs
Definition: thingtype.h:117
ThingCategoryItem
@ ThingCategoryItem
Definition: thingtype.h:46
ThingType::isWrapable
bool isWrapable()
Definition: thingtype.h:205
ThingType::getDisplacement
Point getDisplacement()
Definition: thingtype.h:157
ThingType::isForceUse
bool isForceUse()
Definition: thingtype.h:175
TPoint::x
T x
Definition: point.h:83
ThingType::isAnimateAlways
bool isAnimateAlways()
Definition: thingtype.h:197
ThingAttrTranslucent
@ ThingAttrTranslucent
Definition: thingtype.h:78
ThingAttr
ThingAttr
Definition: thingtype.h:54
ThingType::hasMiniMapColor
bool hasMiniMapColor()
Definition: thingtype.h:198
ThingType::isFullGround
bool isFullGround()
Definition: thingtype.h:200
ThingType
Definition: thingtype.h:126
MarketData::showAs
uint16 showAs
Definition: thingtype.h:116
ThingAttrWrapable
@ ThingAttrWrapable
Definition: thingtype.h:90
ThingType::getLensHelp
int getLensHelp()
Definition: thingtype.h:166
stdext::dynamic_storage::get
T get(const Key &k) const
Definition: dynamic_storage.h:48
ThingType::getAnimator
AnimatorPtr getAnimator()
Definition: thingtype.h:154
ThingType::isStackable
bool isStackable()
Definition: thingtype.h:174
ThingType::isPickupable
bool isPickupable()
Definition: thingtype.h:186
FrameGroupMoving
@ FrameGroupMoving
Definition: thingtype.h:42
ThingType::isChargeable
bool isChargeable()
Definition: thingtype.h:178
ThingAttrElevation
@ ThingAttrElevation
Definition: thingtype.h:80
ThingType::isNotWalkable
bool isNotWalkable()
Definition: thingtype.h:182
ThingType::isNull
bool isNull()
Definition: thingtype.h:141
ThingType::isContainer
bool isContainer()
Definition: thingtype.h:173
ThingType::getExactHeight
int getExactHeight()
Definition: thingtype.cpp:646
ThingType::getIdleAnimator
AnimatorPtr getIdleAnimator()
Definition: thingtype.h:155
TSize::height
int height() const
Definition: size.h:44
ThingLastAttr
@ ThingLastAttr
Definition: thingtype.h:101
ThingType::getClothSlot
int getClothSlot()
Definition: thingtype.h:167
texture.h
ThingAttrAnimateAlways
@ ThingAttrAnimateAlways
Definition: thingtype.h:82
stdext::shared_object_ptr< FileStream >
ThingAttrLight
@ ThingAttrLight
Definition: thingtype.h:76
ThingAttrHookSouth
@ ThingAttrHookSouth
Definition: thingtype.h:73
ThingType::isGround
bool isGround()
Definition: thingtype.h:169
ThingType::isHangable
bool isHangable()
Definition: thingtype.h:187
ThingType::hasDisplacement
bool hasDisplacement()
Definition: thingtype.h:194
ThingType::isMarketable
bool isMarketable()
Definition: thingtype.h:203
ThingType::isNotMoveable
bool isNotMoveable()
Definition: thingtype.h:183
ThingType::isCloth
bool isCloth()
Definition: thingtype.h:202
ThingAttrOpacity
@ ThingAttrOpacity
Definition: thingtype.h:95
ThingAttrPickupable
@ ThingAttrPickupable
Definition: thingtype.h:71
Light::color
uint8 color
Definition: thingtype.h:123
SpriteMaskYellow
@ SpriteMaskYellow
Definition: thingtype.h:108
ThingType::exportImage
void exportImage(const std::string &fileName)
Definition: thingtype.cpp:380
Texture::isOpaque
bool isOpaque() const
Definition: texture.h:57
MarketData
Definition: thingtype.h:111
Light
Definition: thingtype.h:120
scheduledevent.h
ThingAttrBlockProjectile
@ ThingAttrBlockProjectile
Definition: thingtype.h:69
ThingType::hasElevation
bool hasElevation()
Definition: thingtype.h:195
ThingCategory
ThingCategory
Definition: thingtype.h:45
ThingType::isGroundBorder
bool isGroundBorder()
Definition: thingtype.h:170
ThingType::setPathable
void setPathable(bool var)
Definition: thingtype.cpp:629
ThingAttrForceUse
@ ThingAttrForceUse
Definition: thingtype.h:61
MarketData::name
std::string name
Definition: thingtype.h:112
ThingAttrUnwrapable
@ ThingAttrUnwrapable
Definition: thingtype.h:91
ThingAttrMarket
@ ThingAttrMarket
Definition: thingtype.h:88
TPoint< int >
ThingType::getCategory
ThingCategory getCategory()
Definition: thingtype.h:140
ThingType::draw
void draw(const Point &dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, int reDrawFlags=Otc::ReDrawThing, LightView *lightView=nullptr)
Definition: thingtype.cpp:428
ThingAttrStackable
@ ThingAttrStackable
Definition: thingtype.h:60
server.h
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
ThingType::getDisplacementX
int getDisplacementX()
Definition: thingtype.h:158
MarketData::restrictVocation
uint16 restrictVocation
Definition: thingtype.h:115
ThingAttrFluidContainer
@ ThingAttrFluidContainer
Definition: thingtype.h:65
ThingType::isIgnoreLook
bool isIgnoreLook()
Definition: thingtype.h:201
ThingType::isNotPreWalkable
bool isNotPreWalkable()
Definition: thingtype.h:214
ThingAttrNotPreWalkable
@ ThingAttrNotPreWalkable
Definition: thingtype.h:96
ThingType::getLayers
int getLayers()
Definition: thingtype.h:149
TSize< int >
ThingType::getDisplacementY
int getDisplacementY()
Definition: thingtype.h:159
ThingAttrLensHelp
@ ThingAttrLensHelp
Definition: thingtype.h:84
ThingAttrOnBottom
@ ThingAttrOnBottom
Definition: thingtype.h:57
ThingType::getNumPatternZ
int getNumPatternZ()
Definition: thingtype.h:152
ThingType::getExactSize
int getExactSize(int layer=0, int xPattern=0, int yPattern=0, int zPattern=0, int animationPhase=0)
Definition: thingtype.cpp:618
ThingAttrContainer
@ ThingAttrContainer
Definition: thingtype.h:59
uint8
uint8_t uint8
Definition: types.h:37
ThingType::isUnwrapable
bool isUnwrapable()
Definition: thingtype.h:206
animator.h
SpriteMask
SpriteMask
Definition: thingtype.h:104
ThingType::getRealSize
int getRealSize()
Definition: thingtype.h:148
ThingType::getNumPatternY
int getNumPatternY()
Definition: thingtype.h:151