No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tile.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef TILE_H
  23. #define TILE_H
  24. #include "declarations.h"
  25. #include "mapview.h"
  26. #include "effect.h"
  27. #include "creature.h"
  28. #include "item.h"
  29. #include <framework/luaengine/luaobject.h>
  30. enum tileflags_t
  31. {
  32. TILESTATE_NONE = 0,
  33. TILESTATE_PROTECTIONZONE = 1 << 0,
  34. TILESTATE_TRASHED = 1 << 1,
  35. TILESTATE_OPTIONALZONE = 1 << 2,
  36. TILESTATE_NOLOGOUT = 1 << 3,
  37. TILESTATE_HARDCOREZONE = 1 << 4,
  38. TILESTATE_REFRESH = 1 << 5,
  39. // internal usage
  40. TILESTATE_HOUSE = 1 << 6,
  41. TILESTATE_TELEPORT = 1 << 17,
  42. TILESTATE_MAGICFIELD = 1 << 18,
  43. TILESTATE_MAILBOX = 1 << 19,
  44. TILESTATE_TRASHHOLDER = 1 << 20,
  45. TILESTATE_BED = 1 << 21,
  46. TILESTATE_DEPOT = 1 << 22,
  47. TILESTATE_TRANSLUECENT_LIGHT = 1 << 23,
  48. TILESTATE_LAST = 1 << 24
  49. };
  50. class Tile : public LuaObject
  51. {
  52. public:
  53. enum {
  54. MAX_THINGS = 10
  55. };
  56. Tile(const Position& position);
  57. void draw(const Point& dest, float scaleFactor, int drawFlags, LightView *lightView = nullptr);
  58. public:
  59. void clean();
  60. void addWalkingCreature(const CreaturePtr& creature);
  61. void removeWalkingCreature(const CreaturePtr& creature);
  62. void addThing(const ThingPtr& thing, int stackPos);
  63. bool removeThing(ThingPtr thing);
  64. ThingPtr getThing(int stackPos);
  65. EffectPtr getEffect(uint16 id);
  66. bool hasThing(const ThingPtr& thing);
  67. int getThingStackPos(const ThingPtr& thing);
  68. ThingPtr getTopThing();
  69. ThingPtr getTopLookThing();
  70. ThingPtr getTopUseThing();
  71. CreaturePtr getTopCreature();
  72. ThingPtr getTopMoveThing();
  73. ThingPtr getTopMultiUseThing();
  74. const Position& getPosition() { return m_position; }
  75. int getDrawElevation() { return m_drawElevation; }
  76. std::vector<ItemPtr> getItems();
  77. std::vector<CreaturePtr> getCreatures();
  78. std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
  79. std::vector<ThingPtr> getThings() { return m_things; }
  80. ItemPtr getGround();
  81. int getGroundSpeed();
  82. uint8 getMinimapColorByte();
  83. int getThingCount() { return m_things.size() + m_effects.size(); }
  84. bool isPathable();
  85. bool isWalkable(bool ignoreCreatures = false);
  86. bool isFullGround();
  87. bool isFullyOpaque();
  88. bool isSingleDimension();
  89. bool isLookPossible();
  90. bool isClickable();
  91. bool isEmpty();
  92. bool isDrawable();
  93. bool hasTranslucentLight() { return m_flags & TILESTATE_TRANSLUECENT_LIGHT; }
  94. bool mustHookSouth();
  95. bool mustHookEast();
  96. bool hasCreature();
  97. bool limitsFloorsView(bool isFreeView = false);
  98. bool canErase();
  99. int getElevation() const;
  100. bool hasElevation(int elevation = 1);
  101. void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
  102. void remFlag(uint32 flag) { m_flags &= ~flag; }
  103. void setFlag(uint32 flag) { m_flags |= flag; }
  104. void setFlags(uint32 flags) { m_flags = flags; }
  105. bool hasFlag(uint32 flag) { return (m_flags & flag) == flag; }
  106. uint32 getFlags() { return m_flags; }
  107. void setHouseId(uint32 hid) { m_houseId = hid; }
  108. uint32 getHouseId() { return m_houseId; }
  109. bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
  110. void select() { m_selected = true; }
  111. void unselect() { m_selected = false; }
  112. bool isSelected() { return m_selected; }
  113. TilePtr asTile() { return static_self_cast<Tile>(); }
  114. private:
  115. void checkTranslucentLight();
  116. stdext::packed_vector<CreaturePtr> m_walkingCreatures;
  117. stdext::packed_vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
  118. stdext::packed_vector<ThingPtr> m_things;
  119. Position m_position;
  120. uint8 m_drawElevation;
  121. uint8 m_minimapColor;
  122. uint32 m_flags, m_houseId;
  123. stdext::boolean<false> m_selected;
  124. };
  125. #endif