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