Otclient 1.0  14/8/2020
tile.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 TILE_H
24 #define TILE_H
25 
27 #include "creature.h"
28 #include "declarations.h"
29 #include "effect.h"
30 #include "item.h"
31 #include "mapview.h"
32 
34 {
42 
43  // internal usage
44  TILESTATE_HOUSE = 1 << 6,
45  TILESTATE_TELEPORT = 1 << 17,
47  TILESTATE_MAILBOX = 1 << 19,
49  TILESTATE_BED = 1 << 21,
50  TILESTATE_DEPOT = 1 << 22,
52 
53  TILESTATE_LAST = 1 << 24
54 };
55 
56 class Tile : public LuaObject
57 {
58 public:
59  enum {
61  };
62 
63  Tile(const Position& position);
64 
65  void draw(const Point& dest, float scaleFactor, int reDrawFlags, LightView* lightView = nullptr);
66  void drawGround(const Point& dest, float scaleFactor, int reDrawFlags, LightView* lightView = nullptr);
67  void drawBottom(const Point& dest, float scaleFactor, int reDrawFlags, LightView* lightView = nullptr);
68  void drawTop(const Point& dest, float scaleFactor, int reDrawFlags, LightView* lightView);
69 
70  void clean();
71 
72  void addWalkingCreature(const CreaturePtr& creature);
73  void removeWalkingCreature(const CreaturePtr& creature);
74 
75  void addThing(const ThingPtr& thing, int stackPos);
76  bool removeThing(const ThingPtr& thing);
77  ThingPtr getThing(int stackPos);
79  bool hasThing(const ThingPtr& thing);
80  int getThingStackPos(const ThingPtr& thing);
82 
88 
89  const Position& getPosition() { return m_position; }
90  int getDrawElevation() { return m_drawElevation; }
91  std::vector<ItemPtr> getItems();
92  std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
93  std::vector<ThingPtr> getThings() { return m_things; }
94  std::vector<CreaturePtr> getCreatures() { return m_creatures; }
96  int getGroundSpeed();
98  int getThingCount() { return m_things.size() + m_effects.size(); }
99  bool isPathable();
100  bool isWalkable(bool ignoreCreatures = false);
101  bool isFullGround();
102  bool isFullyOpaque();
103  bool isSingleDimension();
104  bool isLookPossible();
105  bool isClickable();
106  bool isEmpty();
107  bool isDrawable();
109  bool mustHookSouth();
110  bool mustHookEast();
111  bool hasCreature();
112  bool limitsFloorsView(bool isFreeView = false);
113  bool canErase();
114  int getElevation() const;
115  bool hasElevation(int elevation = 1);
116  void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
117 
118  void remFlag(uint32 flag) { m_flags &= ~flag; }
119  void setFlag(uint32 flag) { m_flags |= flag; }
120  void setFlags(uint32 flags) { m_flags = flags; }
121  bool hasFlag(uint32 flag) { return (m_flags & flag) == flag; }
122  uint32 getFlags() { return m_flags; }
123 
124  void setHouseId(uint32 hid) { m_houseId = hid; }
125  uint32 getHouseId() { return m_houseId; }
126  bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
127 
128  void select() { m_selected = true; }
129  void unselect() { m_selected = false; }
130  bool isSelected() { return m_selected; }
131 
132  TilePtr asTile() { return static_self_cast<Tile>(); }
133 
134  bool hasDisplacement() { return m_countFlag.hasDisplacement > 0; }
135  bool hasLight();
136  void analyzeThing(const ThingPtr& thing, bool add);
137 
138  bool hasGroundToDraw() const { return !m_ground.empty(); }
139  bool hasBottomToDraw() const { return !m_bottomItems.empty() || !m_commonItems.empty() || !m_creatures.empty() || !m_walkingCreatures.empty(); }
140  bool hasTopToDraw() const { return !m_topItems.empty() || !m_effects.empty(); }
141 
142  void cancelListenerPainter();
143 
144 private:
145  void checkTranslucentLight();
146 
147  Position m_position;
148  uint8 m_drawElevation;
149  uint8 m_minimapColor;
150  uint32 m_flags, m_houseId;
151 
152  stdext::boolean<false> m_selected;
153 
154  std::vector<CreaturePtr> m_walkingCreatures;
155  std::vector<ThingPtr> m_things;
156 
157  std::vector<EffectPtr> m_effects;
158  std::vector<ItemPtr> m_ground;
159  std::vector<ItemPtr> m_topItems;
160  std::vector<ItemPtr> m_commonItems;
161  std::vector<ItemPtr> m_bottomItems;
162  std::vector<CreaturePtr> m_creatures;
163 
164  std::vector<ItemPtr> m_animatedItems;
165 
166  struct CountFlag {
167  int fullGround = 0;
168  int notWalkable = 0;
169  int notPathable = 0;
170  int notSingleDimension = 0;
171  int blockProjectile = 0;
172  int mustHookEast = 0;
173  int mustHookSouth = 0;
174  int totalElevation = 0;
175  int hasDisplacement = 0;
176  int isNotPathable = 0;
177  int elevation = 0;
178  int opaque = 0;
179  int hasLight = 0;
180  };
181 
182  CountFlag m_countFlag;
183 
184  CreaturePtr m_localPlayer;
185 };
186 
187 #endif
Tile::getTopMultiUseThing
ThingPtr getTopMultiUseThing()
Definition: tile.cpp:506
Tile::analyzeThing
void analyzeThing(const ThingPtr &thing, bool add)
Definition: tile.cpp:666
Tile::isClickable
bool isClickable()
Definition: tile.cpp:569
Tile::getGroundSpeed
int getGroundSpeed()
Definition: tile.cpp:376
Tile::removeThing
bool removeThing(const ThingPtr &thing)
Definition: tile.cpp:255
Tile::getThings
std::vector< ThingPtr > getThings()
Definition: tile.h:93
Tile::drawGround
void drawGround(const Point &dest, float scaleFactor, int reDrawFlags, LightView *lightView=nullptr)
Definition: tile.cpp:47
Tile::isDrawable
bool isDrawable()
Definition: tile.cpp:584
Tile::setHouseId
void setHouseId(uint32 hid)
Definition: tile.h:124
Tile::hasLight
bool hasLight()
Definition: tile.cpp:629
Tile::isWalkable
bool isWalkable(bool ignoreCreatures=false)
Definition: tile.cpp:528
Tile::mustHookEast
bool mustHookEast()
Definition: tile.cpp:589
Tile::getTopLookThing
ThingPtr getTopLookThing()
Definition: tile.cpp:408
Tile::addThing
void addThing(const ThingPtr &thing, int stackPos)
Definition: tile.cpp:153
uint32
uint32_t uint32
Definition: types.h:35
Tile::getTopCreature
CreaturePtr getTopCreature()
Definition: tile.cpp:461
Tile::getItems
std::vector< ItemPtr > getItems()
Definition: tile.cpp:348
Tile::hasBottomToDraw
bool hasBottomToDraw() const
Definition: tile.h:139
Tile::hasFlag
bool hasFlag(uint32 flag)
Definition: tile.h:121
Tile::getDrawElevation
int getDrawElevation()
Definition: tile.h:90
Tile::clean
void clean()
Definition: tile.cpp:127
Tile::getGround
ItemPtr getGround()
Definition: tile.cpp:360
TILESTATE_TRASHHOLDER
@ TILESTATE_TRASHHOLDER
Definition: tile.h:48
Tile::limitsFloorsView
bool limitsFloorsView(bool isFreeView=false)
Definition: tile.cpp:612
Tile::hasDisplacement
bool hasDisplacement()
Definition: tile.h:134
Tile::getWalkingCreatures
std::vector< CreaturePtr > getWalkingCreatures()
Definition: tile.h:92
Tile::getPosition
const Position & getPosition()
Definition: tile.h:89
TILESTATE_NONE
@ TILESTATE_NONE
Definition: tile.h:35
Tile::mustHookSouth
bool mustHookSouth()
Definition: tile.cpp:598
Tile::addWalkingCreature
void addWalkingCreature(const CreaturePtr &creature)
Definition: tile.cpp:139
TILESTATE_MAGICFIELD
@ TILESTATE_MAGICFIELD
Definition: tile.h:46
Tile::hasTranslucentLight
bool hasTranslucentLight()
Definition: tile.h:108
Tile::MAX_THINGS
@ MAX_THINGS
Definition: tile.h:60
Tile::getThing
ThingPtr getThing(int stackPos)
Definition: tile.cpp:316
Tile::getThingStackPos
int getThingStackPos(const ThingPtr &thing)
Definition: tile.cpp:324
Tile::drawTop
void drawTop(const Point &dest, float scaleFactor, int reDrawFlags, LightView *lightView)
Definition: tile.cpp:109
stdext::boolean< false >
Tile::getMinimapColorByte
uint8 getMinimapColorByte()
Definition: tile.cpp:384
Tile::removeWalkingCreature
void removeWalkingCreature(const CreaturePtr &creature)
Definition: tile.cpp:144
LightView
Definition: lightview.h:37
creature.h
luaobject.h
Tile::canErase
bool canErase()
Definition: tile.cpp:579
uint16
uint16_t uint16
Definition: types.h:36
TILESTATE_DEPOT
@ TILESTATE_DEPOT
Definition: tile.h:50
declarations.h
Tile::asTile
TilePtr asTile()
Definition: tile.h:132
Tile::getFlags
uint32 getFlags()
Definition: tile.h:122
mapview.h
Tile::hasTopToDraw
bool hasTopToDraw() const
Definition: tile.h:140
Tile::getCreatures
std::vector< CreaturePtr > getCreatures()
Definition: tile.h:94
Tile::hasGroundToDraw
bool hasGroundToDraw() const
Definition: tile.h:138
TILESTATE_PROTECTIONZONE
@ TILESTATE_PROTECTIONZONE
Definition: tile.h:36
TILESTATE_TRANSLUECENT_LIGHT
@ TILESTATE_TRANSLUECENT_LIGHT
Definition: tile.h:51
Tile::draw
void draw(const Point &dest, float scaleFactor, int reDrawFlags, LightView *lightView=nullptr)
Definition: tile.cpp:120
Position
Definition: position.h:33
Tile::getElevation
int getElevation() const
Definition: tile.cpp:619
Tile::getThingCount
int getThingCount()
Definition: tile.h:98
Tile::getTopUseThing
ThingPtr getTopUseThing()
Definition: tile.cpp:436
Tile::Tile
Tile(const Position &position)
Definition: tile.cpp:37
Tile::isSingleDimension
bool isSingleDimension()
Definition: tile.cpp:559
Tile::isSelected
bool isSelected()
Definition: tile.h:130
Tile::setFlag
void setFlag(uint32 flag)
Definition: tile.h:119
Tile::isFullGround
bool isFullGround()
Definition: tile.cpp:549
TILESTATE_HOUSE
@ TILESTATE_HOUSE
Definition: tile.h:44
Tile::hasElevation
bool hasElevation(int elevation=1)
Definition: tile.cpp:624
Tile::getHouseId
uint32 getHouseId()
Definition: tile.h:125
Tile::setFlags
void setFlags(uint32 flags)
Definition: tile.h:120
TILESTATE_BED
@ TILESTATE_BED
Definition: tile.h:49
TILESTATE_LAST
@ TILESTATE_LAST
Definition: tile.h:53
Tile::hasThing
bool hasThing(const ThingPtr &thing)
Definition: tile.cpp:333
Tile::isFullyOpaque
bool isFullyOpaque()
Definition: tile.cpp:554
Tile::unselect
void unselect()
Definition: tile.h:129
TILESTATE_MAILBOX
@ TILESTATE_MAILBOX
Definition: tile.h:47
Tile::remFlag
void remFlag(uint32 flag)
Definition: tile.h:118
Tile::isHouseTile
bool isHouseTile()
Definition: tile.h:126
Tile::cancelListenerPainter
void cancelListenerPainter()
Definition: tile.cpp:656
TILESTATE_NOLOGOUT
@ TILESTATE_NOLOGOUT
Definition: tile.h:39
Tile::getTopThing
ThingPtr getTopThing()
Definition: tile.cpp:338
effect.h
stdext::shared_object_ptr< Creature >
tileflags_t
tileflags_t
Definition: tile.h:33
Tile::hasCreature
bool hasCreature()
Definition: tile.cpp:607
Tile
Definition: tile.h:56
Tile::getEffect
EffectPtr getEffect(uint16 id)
Definition: tile.cpp:367
Tile::isPathable
bool isPathable()
Definition: tile.cpp:544
TPoint< int >
TILESTATE_OPTIONALZONE
@ TILESTATE_OPTIONALZONE
Definition: tile.h:38
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
TILESTATE_HARDCOREZONE
@ TILESTATE_HARDCOREZONE
Definition: tile.h:40
Tile::overwriteMinimapColor
void overwriteMinimapColor(uint8 color)
Definition: tile.h:116
Tile::select
void select()
Definition: tile.h:128
Tile::getTopMoveThing
ThingPtr getTopMoveThing()
Definition: tile.cpp:492
TILESTATE_TRASHED
@ TILESTATE_TRASHED
Definition: tile.h:37
Tile::isEmpty
bool isEmpty()
Definition: tile.cpp:574
TILESTATE_TELEPORT
@ TILESTATE_TELEPORT
Definition: tile.h:45
Tile::drawBottom
void drawBottom(const Point &dest, float scaleFactor, int reDrawFlags, LightView *lightView=nullptr)
Definition: tile.cpp:59
uint8
uint8_t uint8
Definition: types.h:37
TILESTATE_REFRESH
@ TILESTATE_REFRESH
Definition: tile.h:41
Tile::isLookPossible
bool isLookPossible()
Definition: tile.cpp:564
item.h