2012-07-15 01:34:24 +02:00
|
|
|
/*
|
2013-01-08 19:21:54 +01:00
|
|
|
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
2012-07-15 01:34:24 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HOUSES_H
|
|
|
|
#define HOUSES_H
|
|
|
|
|
|
|
|
#include "declarations.h"
|
|
|
|
#include "tile.h"
|
|
|
|
|
2012-07-14 19:17:03 +02:00
|
|
|
#include <framework/luaengine/luaobject.h>
|
2012-07-18 16:36:46 +02:00
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
enum HouseAttr : uint8
|
2012-07-18 16:36:46 +02:00
|
|
|
{
|
2012-07-20 07:45:11 +02:00
|
|
|
HouseAttrId,
|
|
|
|
HouseAttrName,
|
|
|
|
HouseAttrTown,
|
|
|
|
HouseAttrEntry,
|
|
|
|
HouseAttrSize,
|
|
|
|
HouseAttrRent
|
2012-07-18 16:36:46 +02:00
|
|
|
};
|
2012-07-15 01:34:24 +02:00
|
|
|
|
|
|
|
class House : public LuaObject
|
|
|
|
{
|
|
|
|
public:
|
2012-09-14 23:38:21 +02:00
|
|
|
House();
|
2012-07-15 01:34:24 +02:00
|
|
|
House(uint32 hId, const std::string& name = "", const Position& pos=Position());
|
2013-08-04 14:21:12 +02:00
|
|
|
~House() { m_tiles.clear(); }
|
2012-07-15 01:34:24 +02:00
|
|
|
|
|
|
|
void setTile(const TilePtr& tile);
|
2013-08-04 14:21:12 +02:00
|
|
|
TilePtr getTile(const Position& pos);
|
2012-09-14 23:38:21 +02:00
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
void setName(const std::string& name) { m_attribs.set(HouseAttrName, name); }
|
2012-09-14 23:38:21 +02:00
|
|
|
std::string getName() { return m_attribs.get<std::string>(HouseAttrName); }
|
|
|
|
|
|
|
|
void setId(uint32 hId) { m_attribs.set(HouseAttrId, hId); }
|
|
|
|
uint32 getId() { return m_attribs.get<uint32>(HouseAttrId); }
|
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
void setTownId(uint32 tid) { m_attribs.set(HouseAttrTown, tid); }
|
2012-09-14 23:38:21 +02:00
|
|
|
uint32 getTownId() { return m_attribs.get<uint32>(HouseAttrTown); }
|
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
void setSize(uint32 s) { m_attribs.set(HouseAttrSize, s); }
|
2012-09-14 23:38:21 +02:00
|
|
|
uint32 getSize() { return m_attribs.get<uint32>(HouseAttrSize); }
|
2012-07-18 16:36:46 +02:00
|
|
|
|
2012-09-14 23:38:21 +02:00
|
|
|
void setRent(uint32 r) { m_attribs.set(HouseAttrRent, r); }
|
2012-07-20 07:45:11 +02:00
|
|
|
uint32 getRent() { return m_attribs.get<uint32>(HouseAttrRent); }
|
2012-09-14 23:38:21 +02:00
|
|
|
|
|
|
|
void setEntry(const Position& p) { m_attribs.set(HouseAttrEntry, p); }
|
|
|
|
Position getEntry() { return m_attribs.get<Position>(HouseAttrEntry); }
|
2012-07-15 01:34:24 +02:00
|
|
|
|
2013-08-04 14:21:12 +02:00
|
|
|
void addDoor(const ItemPtr& door);
|
|
|
|
void removeDoor(const ItemPtr& door) { removeDoorById(door->getDoorId()); }
|
|
|
|
void removeDoorById(uint32 doorId);
|
|
|
|
|
2012-07-15 01:34:24 +02:00
|
|
|
protected:
|
|
|
|
void load(const TiXmlElement* elem);
|
2013-08-04 14:21:12 +02:00
|
|
|
void save(TiXmlElement* elem);
|
2012-07-15 01:34:24 +02:00
|
|
|
|
|
|
|
private:
|
2012-08-01 09:49:09 +02:00
|
|
|
stdext::packed_storage<uint8> m_attribs;
|
2012-07-18 16:36:46 +02:00
|
|
|
TileMap m_tiles;
|
2013-08-04 14:21:12 +02:00
|
|
|
ItemVector m_doors;
|
|
|
|
uint32 m_lastDoorId;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<false> m_isGuildHall;
|
2012-07-15 01:34:24 +02:00
|
|
|
|
2012-09-14 23:38:21 +02:00
|
|
|
friend class HouseManager;
|
2012-07-15 01:34:24 +02:00
|
|
|
};
|
|
|
|
|
2012-09-14 23:38:21 +02:00
|
|
|
class HouseManager {
|
2012-07-15 01:34:24 +02:00
|
|
|
public:
|
2012-09-14 23:38:21 +02:00
|
|
|
HouseManager();
|
|
|
|
|
2012-07-15 01:34:24 +02:00
|
|
|
void addHouse(const HousePtr& house);
|
|
|
|
void removeHouse(uint32 houseId);
|
2013-08-04 14:21:12 +02:00
|
|
|
HousePtr getHouse(uint32 houseId);
|
|
|
|
HousePtr getHouseByName(std::string name);
|
2012-07-15 01:34:24 +02:00
|
|
|
|
2012-09-14 23:38:21 +02:00
|
|
|
void load(const std::string& fileName);
|
|
|
|
void save(const std::string& fileName);
|
2012-07-15 01:34:24 +02:00
|
|
|
|
2014-01-18 16:57:17 +01:00
|
|
|
void sort();
|
2013-08-04 14:21:12 +02:00
|
|
|
void clear() { m_houses.clear(); }
|
|
|
|
HouseList getHouseList() { return m_houses; }
|
|
|
|
HouseList filterHouses(uint32 townId);
|
|
|
|
|
2014-01-18 15:09:26 +01:00
|
|
|
private:
|
2012-07-15 01:34:24 +02:00
|
|
|
HouseList m_houses;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
HouseList::iterator findHouse(uint32 houseId);
|
|
|
|
};
|
|
|
|
|
2012-09-14 23:38:21 +02:00
|
|
|
extern HouseManager g_houses;
|
|
|
|
|
2012-07-15 01:34:24 +02:00
|
|
|
#endif
|