forked from nekiro/TFS-1.5-Downgrades
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtown.h
98 lines (83 loc) · 2.18 KB
/
town.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2019 Mark Samman <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FS_TOWN_H
#define FS_TOWN_H
#include "position.h"
class Town
{
public:
explicit Town(uint32_t id) : id(id) {}
const Position& getTemplePosition() const {
return templePosition;
}
const std::string& getName() const {
return name;
}
void setTemplePos(Position pos) {
templePosition = pos;
}
void setName(std::string name) {
this->name = std::move(name);
}
uint32_t getID() const {
return id;
}
private:
uint32_t id;
std::string name;
Position templePosition;
};
using TownMap = std::map<uint32_t, Town*>;
class Towns
{
public:
Towns() = default;
~Towns() {
for (const auto& it : townMap) {
delete it.second;
}
}
// non-copyable
Towns(const Towns&) = delete;
Towns& operator=(const Towns&) = delete;
bool addTown(uint32_t townId, Town* town) {
return townMap.emplace(townId, town).second;
}
Town* getTown(const std::string& townName) const {
for (const auto& it : townMap) {
if (strcasecmp(townName.c_str(), it.second->getName().c_str()) == 0) {
return it.second;
}
}
return nullptr;
}
Town* getTown(uint32_t townId) const {
auto it = townMap.find(townId);
if (it == townMap.end()) {
return nullptr;
}
return it->second;
}
const TownMap& getTowns() const {
return townMap;
}
private:
TownMap townMap;
};
#endif // FS_TOWN_H