Otclient  14/8/2020
houses.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 HOUSES_H
24 #define HOUSES_H
25 
26 #include "declarations.h"
27 #include "tile.h"
28 
30 
32 {
39 };
40 
41 class House : public LuaObject
42 {
43 public:
44  House();
45  House(uint32 hId, const std::string& name = "", const Position& pos=Position());
46  ~House() { m_tiles.clear(); }
47 
48  void setTile(const TilePtr& tile);
49  TilePtr getTile(const Position& pos);
50 
51  void setName(const std::string& name) { m_attribs.set(HouseAttrName, name); }
52  std::string getName() { return m_attribs.get<std::string>(HouseAttrName); }
53 
54  void setId(uint32 hId) { m_attribs.set(HouseAttrId, hId); }
55  uint32 getId() { return m_attribs.get<uint32>(HouseAttrId); }
56 
57  void setTownId(uint32 tid) { m_attribs.set(HouseAttrTown, tid); }
58  uint32 getTownId() { return m_attribs.get<uint32>(HouseAttrTown); }
59 
60  void setSize(uint32 s) { m_attribs.set(HouseAttrSize, s); }
61  uint32 getSize() { return m_attribs.get<uint32>(HouseAttrSize); }
62 
63  void setRent(uint32 r) { m_attribs.set(HouseAttrRent, r); }
64  uint32 getRent() { return m_attribs.get<uint32>(HouseAttrRent); }
65 
66  void setEntry(const Position& p) { m_attribs.set(HouseAttrEntry, p); }
67  Position getEntry() { return m_attribs.get<Position>(HouseAttrEntry); }
68 
69  void addDoor(const ItemPtr& door);
70  void removeDoor(const ItemPtr& door) { removeDoorById(door->getDoorId()); }
71  void removeDoorById(uint32 doorId);
72 
73 protected:
74  void load(const TiXmlElement* elem);
75  void save(TiXmlElement* elem);
76 
77 private:
79  TileMap m_tiles;
80  ItemVector m_doors;
81  uint32 m_lastDoorId;
82  stdext::boolean<false> m_isGuildHall;
83 
84  friend class HouseManager;
85 };
86 
87 class HouseManager {
88 public:
89  HouseManager();
90 
91  void addHouse(const HousePtr& house);
92  void removeHouse(uint32 houseId);
93  HousePtr getHouse(uint32 houseId);
94  HousePtr getHouseByName(std::string name);
95 
96  void load(const std::string& fileName);
97  void save(const std::string& fileName);
98 
99  void sort();
100  void clear() { m_houses.clear(); }
101  HouseList getHouseList() { return m_houses; }
102  HouseList filterHouses(uint32 townId);
103 
104 private:
105  HouseList m_houses;
106 
107 protected:
108  HouseList::iterator findHouse(uint32 houseId);
109 };
110 
111 extern HouseManager g_houses;
112 
113 #endif
stdext::packed_storage::get
T get(Key id) const
Definition: packed_storage.h:80
HouseList
std::list< HousePtr > HouseList
Definition: declarations.h:83
TileMap
std::unordered_map< Position, TilePtr, PositionHasher > TileMap
Definition: declarations.h:88
House::~House
~House()
Definition: houses.h:46
HouseAttrTown
@ HouseAttrTown
Definition: houses.h:35
HouseManager::findHouse
HouseList::iterator findHouse(uint32 houseId)
Definition: houses.cpp:199
HouseAttrSize
@ HouseAttrSize
Definition: houses.h:37
HouseAttr
HouseAttr
Definition: houses.h:31
House::getTownId
uint32 getTownId()
Definition: houses.h:58
uint32
uint32_t uint32
Definition: types.h:35
HouseManager::sort
void sort()
Definition: houses.cpp:205
House::setName
void setName(const std::string &name)
Definition: houses.h:51
House::getName
std::string getName()
Definition: houses.h:52
stdext::boolean< false >
luaobject.h
HouseManager::load
void load(const std::string &fileName)
Definition: houses.cpp:136
House::addDoor
void addDoor(const ItemPtr &door)
Definition: houses.cpp:56
House::setTownId
void setTownId(uint32 tid)
Definition: houses.h:57
HouseAttrName
@ HouseAttrName
Definition: houses.h:34
g_houses
HouseManager g_houses
Definition: houses.cpp:27
declarations.h
HouseManager::getHouse
HousePtr getHouse(uint32 houseId)
Definition: houses.cpp:123
House::getRent
uint32 getRent()
Definition: houses.h:64
House::setTile
void setTile(const TilePtr &tile)
Definition: houses.cpp:41
HouseAttrEntry
@ HouseAttrEntry
Definition: houses.h:36
House::setRent
void setRent(uint32 r)
Definition: houses.h:63
Position
Definition: position.h:33
House::save
void save(TiXmlElement *elem)
Definition: houses.cpp:90
HouseManager::addHouse
void addHouse(const HousePtr &house)
Definition: houses.cpp:110
House::setId
void setId(uint32 hId)
Definition: houses.h:54
stdext::packed_storage< uint8 >
HouseAttrId
@ HouseAttrId
Definition: houses.h:33
House::removeDoorById
void removeDoorById(uint32 doorId)
Definition: houses.cpp:63
HouseManager::HouseManager
HouseManager()
Definition: houses.cpp:106
HouseManager::getHouseByName
HousePtr getHouseByName(std::string name)
Definition: houses.cpp:129
House::getSize
uint32 getSize()
Definition: houses.h:61
HouseManager::filterHouses
HouseList filterHouses(uint32 townId)
Definition: houses.cpp:190
House::getEntry
Position getEntry()
Definition: houses.h:67
House
Definition: houses.h:41
House::getTile
TilePtr getTile(const Position &pos)
Definition: houses.cpp:48
House::load
void load(const TiXmlElement *elem)
Definition: houses.cpp:71
House::House
House()
Definition: houses.cpp:29
stdext::shared_object_ptr< Tile >
Item::getDoorId
uint8 getDoorId()
Definition: item.h:110
ItemVector
std::vector< ItemPtr > ItemVector
Definition: declarations.h:87
HouseManager::getHouseList
HouseList getHouseList()
Definition: houses.h:101
House::setSize
void setSize(uint32 s)
Definition: houses.h:60
TiXmlElement
Definition: tinyxml.h:943
HouseManager
Definition: houses.h:87
House::setEntry
void setEntry(const Position &p)
Definition: houses.h:66
stdext::packed_storage::set
void set(Key id, const T &value)
Definition: packed_storage.h:47
HouseManager::clear
void clear()
Definition: houses.h:100
House::getId
uint32 getId()
Definition: houses.h:55
HouseManager::removeHouse
void removeHouse(uint32 houseId)
Definition: houses.cpp:116
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
tile.h
HouseAttrRent
@ HouseAttrRent
Definition: houses.h:38
House::removeDoor
void removeDoor(const ItemPtr &door)
Definition: houses.h:70
uint8
uint8_t uint8
Definition: types.h:37
HouseManager::save
void save(const std::string &fileName)
Definition: houses.cpp:165