Otclient  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 
26 #include "declarations.h"
27 #include "mapview.h"
28 #include "effect.h"
29 #include "creature.h"
30 #include "item.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 drawFlags, LightView *lightView = nullptr);
66 
67 public:
68  void clean();
69 
70  void addWalkingCreature(const CreaturePtr& creature);
71  void removeWalkingCreature(const CreaturePtr& creature);
72 
73  void addThing(const ThingPtr& thing, int stackPos);
74  bool removeThing(ThingPtr thing);
75  ThingPtr getThing(int stackPos);
77  bool hasThing(const ThingPtr& thing);
78  int getThingStackPos(const ThingPtr& thing);
80 
86 
87  const Position& getPosition() { return m_position; }
88  int getDrawElevation() { return m_drawElevation; }
89  std::vector<ItemPtr> getItems();
90  std::vector<CreaturePtr> getCreatures();
91  std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
92  std::vector<ThingPtr> getThings() { return m_things; }
94  int getGroundSpeed();
96  int getThingCount() { return m_things.size() + m_effects.size(); }
97  bool isPathable();
98  bool isWalkable(bool ignoreCreatures = false);
99  bool isFullGround();
100  bool isFullyOpaque();
101  bool isSingleDimension();
102  bool isLookPossible();
103  bool isClickable();
104  bool isEmpty();
105  bool isDrawable();
107  bool mustHookSouth();
108  bool mustHookEast();
109  bool hasCreature();
110  bool limitsFloorsView(bool isFreeView = false);
111  bool canErase();
112  int getElevation() const;
113  bool hasElevation(int elevation = 1);
114  void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
115 
116  void remFlag(uint32 flag) { m_flags &= ~flag; }
117  void setFlag(uint32 flag) { m_flags |= flag; }
118  void setFlags(uint32 flags) { m_flags = flags; }
119  bool hasFlag(uint32 flag) { return (m_flags & flag) == flag; }
120  uint32 getFlags() { return m_flags; }
121 
122  void setHouseId(uint32 hid) { m_houseId = hid; }
123  uint32 getHouseId() { return m_houseId; }
124  bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
125 
126  void select() { m_selected = true; }
127  void unselect() { m_selected = false; }
128  bool isSelected() { return m_selected; }
129 
130  TilePtr asTile() { return static_self_cast<Tile>(); }
131 
132 private:
133  void checkTranslucentLight();
134 
135  stdext::packed_vector<CreaturePtr> m_walkingCreatures;
136  stdext::packed_vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
138  Position m_position;
139  uint8 m_drawElevation;
140  uint8 m_minimapColor;
141  uint32 m_flags, m_houseId;
142 
143  stdext::boolean<false> m_selected;
144 };
145 
146 #endif
stdext::packed_vector
Definition: packed_vector.h:34
Tile::getTopMultiUseThing
ThingPtr getTopMultiUseThing()
Definition: tile.cpp:445
Tile::isClickable
bool isClickable()
Definition: tile.cpp:535
Tile::getGroundSpeed
int getGroundSpeed()
Definition: tile.cpp:334
Tile::getThings
std::vector< ThingPtr > getThings()
Definition: tile.h:92
Tile::isDrawable
bool isDrawable()
Definition: tile.cpp:556
Tile::setHouseId
void setHouseId(uint32 hid)
Definition: tile.h:122
Tile::isWalkable
bool isWalkable(bool ignoreCreatures=false)
Definition: tile.cpp:475
Tile::mustHookEast
bool mustHookEast()
Definition: tile.cpp:561
Tile::getTopLookThing
ThingPtr getTopLookThing()
Definition: tile.cpp:358
Tile::addThing
void addThing(const ThingPtr &thing, int stackPos)
Definition: tile.cpp:166
uint32
uint32_t uint32
Definition: types.h:35
Tile::getTopCreature
CreaturePtr getTopCreature()
Definition: tile.cpp:389
Tile::getItems
std::vector< ItemPtr > getItems()
Definition: tile.cpp:302
Tile::hasFlag
bool hasFlag(uint32 flag)
Definition: tile.h:119
Tile::getDrawElevation
int getDrawElevation()
Definition: tile.h:88
Tile::clean
void clean()
Definition: tile.cpp:148
Tile::getGround
ItemPtr getGround()
Definition: tile.cpp:324
TILESTATE_TRASHHOLDER
@ TILESTATE_TRASHHOLDER
Definition: tile.h:48
Tile::limitsFloorsView
bool limitsFloorsView(bool isFreeView=false)
Definition: tile.cpp:585
Tile::getWalkingCreatures
std::vector< CreaturePtr > getWalkingCreatures()
Definition: tile.h:91
Tile::getPosition
const Position & getPosition()
Definition: tile.h:87
TILESTATE_NONE
@ TILESTATE_NONE
Definition: tile.h:35
Tile::mustHookSouth
bool mustHookSouth()
Definition: tile.cpp:569
Tile::addWalkingCreature
void addWalkingCreature(const CreaturePtr &creature)
Definition: tile.cpp:154
TILESTATE_MAGICFIELD
@ TILESTATE_MAGICFIELD
Definition: tile.h:46
Tile::hasTranslucentLight
bool hasTranslucentLight()
Definition: tile.h:106
Tile::getThing
ThingPtr getThing(int stackPos)
Definition: tile.cpp:264
Tile::getThingStackPos
int getThingStackPos(const ThingPtr &thing)
Definition: tile.cpp:284
Tile::removeThing
bool removeThing(ThingPtr thing)
Definition: tile.cpp:234
stdext::boolean< false >
Tile::getMinimapColorByte
uint8 getMinimapColorByte()
Definition: tile.cpp:342
Tile::removeWalkingCreature
void removeWalkingCreature(const CreaturePtr &creature)
Definition: tile.cpp:159
LightView
Definition: lightview.h:37
creature.h
luaobject.h
Tile::canErase
bool canErase()
Definition: tile.cpp:599
uint16
uint16_t uint16
Definition: types.h:36
TILESTATE_DEPOT
@ TILESTATE_DEPOT
Definition: tile.h:50
Tile::draw
void draw(const Point &dest, float scaleFactor, int drawFlags, LightView *lightView=nullptr)
Definition: tile.cpp:42
declarations.h
Tile::asTile
TilePtr asTile()
Definition: tile.h:130
Tile::getFlags
uint32 getFlags()
Definition: tile.h:120
mapview.h
Tile::getCreatures
std::vector< CreaturePtr > getCreatures()
Definition: tile.cpp:314
TILESTATE_PROTECTIONZONE
@ TILESTATE_PROTECTIONZONE
Definition: tile.h:36
TILESTATE_TRANSLUECENT_LIGHT
@ TILESTATE_TRANSLUECENT_LIGHT
Definition: tile.h:51
Position
Definition: position.h:33
Tile::getElevation
int getElevation() const
Definition: tile.cpp:604
Tile::getThingCount
int getThingCount()
Definition: tile.h:96
Tile::getTopUseThing
ThingPtr getTopUseThing()
Definition: tile.cpp:371
Tile::Tile
Tile(const Position &position)
Definition: tile.cpp:34
Tile::isSingleDimension
bool isSingleDimension()
Definition: tile.cpp:517
Tile::isSelected
bool isSelected()
Definition: tile.h:128
Tile::setFlag
void setFlag(uint32 flag)
Definition: tile.h:117
Tile::isFullGround
bool isFullGround()
Definition: tile.cpp:503
TILESTATE_HOUSE
@ TILESTATE_HOUSE
Definition: tile.h:44
Tile::hasElevation
bool hasElevation(int elevation=1)
Definition: tile.cpp:613
Tile::getHouseId
uint32 getHouseId()
Definition: tile.h:123
Tile::setFlags
void setFlags(uint32 flags)
Definition: tile.h:118
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:279
Tile::isFullyOpaque
bool isFullyOpaque()
Definition: tile.cpp:511
Tile::unselect
void unselect()
Definition: tile.h:127
TILESTATE_MAILBOX
@ TILESTATE_MAILBOX
Definition: tile.h:47
Tile::remFlag
void remFlag(uint32 flag)
Definition: tile.h:116
Tile::isHouseTile
bool isHouseTile()
Definition: tile.h:124
TILESTATE_NOLOGOUT
@ TILESTATE_NOLOGOUT
Definition: tile.h:39
Tile::getTopThing
ThingPtr getTopThing()
Definition: tile.cpp:292
effect.h
stdext::shared_object_ptr< Creature >
tileflags_t
tileflags_t
Definition: tile.h:33
Tile::hasCreature
bool hasCreature()
Definition: tile.cpp:577
Tile
Definition: tile.h:56
Tile::getEffect
EffectPtr getEffect(uint16 id)
Definition: tile.cpp:271
Tile::isPathable
bool isPathable()
Definition: tile.cpp:495
Tile::MAX_THINGS
@ MAX_THINGS
Definition: tile.h:60
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:114
Tile::select
void select()
Definition: tile.h:126
Tile::getTopMoveThing
ThingPtr getTopMoveThing()
Definition: tile.cpp:423
TILESTATE_TRASHED
@ TILESTATE_TRASHED
Definition: tile.h:37
Tile::isEmpty
bool isEmpty()
Definition: tile.cpp:551
TILESTATE_TELEPORT
@ TILESTATE_TELEPORT
Definition: tile.h:45
uint8
uint8_t uint8
Definition: types.h:37
TILESTATE_REFRESH
@ TILESTATE_REFRESH
Definition: tile.h:41
Tile::isLookPossible
bool isLookPossible()
Definition: tile.cpp:527
item.h