houses.h

main 114 lines · 3.5 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
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
23#ifndef HOUSES_H
24#define HOUSES_H
25
26#include "declarations.h"
27#include "tile.h"
28
29#include <framework/luaengine/luaobject.h>
30
31enum HouseAttr : uint8
32{
33 HouseAttrId,
34 HouseAttrName,
35 HouseAttrTown,
36 HouseAttrEntry,
37 HouseAttrSize,
38 HouseAttrRent
39};
40
41class House : public LuaObject
42{
43public:
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
73protected:
74 void load(const TiXmlElement* elem);
75 void save(TiXmlElement* elem);
76
77private:
78 stdext::packed_storage<uint8> m_attribs;
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
87class HouseManager {
88public:
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
104private:
105 HouseList m_houses;
106
107protected:
108 HouseList::iterator findHouse(uint32 houseId);
109};
110
111extern HouseManager g_houses;
112
113#endif
114
Top