Otclient  14/8/2020
towns.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 TOWNS_H
24 #define TOWNS_H
25 
26 #include "declarations.h"
28 
29 class Town : public LuaObject
30 {
31 public:
32  Town() { }
33  Town(uint32 tid, const std::string& name, const Position& pos=Position());
34 
35  void setId(uint32 tid) { m_id = tid; }
36  void setName(const std::string& name) { m_name = name; }
37  void setPos(const Position& pos) { m_pos = pos; }
38 
39  uint32 getId() { return m_id; }
40  std::string getName() { return m_name; }
41  Position getPos() { return m_pos; }
42 
43 private:
44  uint32 m_id;
45  std::string m_name;
46  Position m_pos; // temple pos
47 };
48 
50 {
51 public:
52  TownManager();
53 
54  void addTown(const TownPtr& town);
55  void removeTown(uint32 townId);
56  const TownPtr& getTown(uint32 townId);
57  const TownPtr& getTownByName(std::string name);
58 
59  void sort();
60  TownList getTowns() { return m_towns; }
61  void clear() { m_towns.clear(); m_nullTown = nullptr; }
62 
63 private:
64  TownList m_towns;
65  TownPtr m_nullTown;
66 
67 protected:
68  TownList::iterator findTown(uint32 townId);
69 };
70 
71 extern TownManager g_towns;
72 
73 #endif
TownManager
Definition: towns.h:49
TownManager::removeTown
void removeTown(uint32 townId)
Definition: towns.cpp:45
Town::Town
Town()
Definition: towns.h:32
TownManager::findTown
TownList::iterator findTown(uint32 townId)
Definition: towns.cpp:70
uint32
uint32_t uint32
Definition: types.h:35
TownManager::clear
void clear()
Definition: towns.h:61
Town::setPos
void setPos(const Position &pos)
Definition: towns.h:37
luaobject.h
Town::setId
void setId(uint32 tid)
Definition: towns.h:35
TownManager::TownManager
TownManager()
Definition: towns.cpp:34
TownManager::sort
void sort()
Definition: towns.cpp:76
TownManager::getTownByName
const TownPtr & getTownByName(std::string name)
Definition: towns.cpp:61
declarations.h
Town::getId
uint32 getId()
Definition: towns.h:39
Position
Definition: position.h:33
TownManager::getTown
const TownPtr & getTown(uint32 townId)
Definition: towns.cpp:52
TownList
std::list< TownPtr > TownList
Definition: declarations.h:84
Town
Definition: towns.h:29
TownManager::getTowns
TownList getTowns()
Definition: towns.h:60
stdext::shared_object_ptr< Town >
g_towns
TownManager g_towns
Definition: towns.cpp:25
Town::getPos
Position getPos()
Definition: towns.h:41
TownManager::addTown
void addTown(const TownPtr &town)
Definition: towns.cpp:39
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
Town::getName
std::string getName()
Definition: towns.h:40
Town::setName
void setName(const std::string &name)
Definition: towns.h:36