1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19
20#include "town.h"
21
22#include "map.h"
23#include "tile.h"
24
25Towns::Towns() {
26 ////
27}
28
29Towns::~Towns() {
30 clear();
31}
32
33void Towns::clear() {
34 TownMap::const_iterator it = begin();
35 while (it != end()) {
36 delete it->second;
37 ++it;
38 }
39 towns.clear();
40}
41
42bool Towns::addTown(Town* town) {
43 TownMap::iterator it = find(town->getID());
44 if (it != end()) {
45 return false;
46 }
47 towns[town->getID()] = town;
48 return true;
49}
50
51uint32_t Towns::getEmptyID() {
52 uint32_t empty = 0;
53 for (TownMap::iterator it = begin(); it != end(); ++it) {
54 if (it->second->getID() > empty) {
55 empty = it->second->getID();
56 }
57 }
58 return empty + 1;
59}
60
61Town* Towns::getTown(std::string& name) {
62 for (TownMap::iterator it = begin(); it != end(); ++it) {
63 if (it->second->getName() == name) {
64 return it->second;
65 }
66 }
67 return nullptr;
68}
69
70Town* Towns::getTown(uint32_t id) {
71 TownMap::iterator it = find(id);
72 if (it != end()) {
73 return it->second;
74 }
75 return nullptr;
76}
77
78void Town::setTemplePosition(const Position& pos) {
79 templepos = pos;
80}
81