diff options
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/src/map.cpp b/src/map.cpp deleted file mode 100644 index e3725b2..0000000 --- a/src/map.cpp +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | #include "map.h" | ||
2 | #include <cstdlib> | ||
3 | #include <cstring> | ||
4 | #include <map> | ||
5 | #include "entityfactory.h" | ||
6 | #include "entity.h" | ||
7 | #include "game.h" | ||
8 | #include "consts.h" | ||
9 | |||
10 | Map::Map(int id) | ||
11 | { | ||
12 | this->id = id; | ||
13 | mapdata = (int*) calloc(1, sizeof(int)); | ||
14 | } | ||
15 | |||
16 | Map::Map(const Map& map) | ||
17 | { | ||
18 | mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); | ||
19 | memcpy(mapdata, map.mapdata, MAP_WIDTH*MAP_HEIGHT*sizeof(int)); | ||
20 | |||
21 | id = map.id; | ||
22 | title = map.title; | ||
23 | adjacents = map.adjacents; | ||
24 | entities = map.entities; | ||
25 | } | ||
26 | |||
27 | Map::Map(Map&& map) : Map() | ||
28 | { | ||
29 | swap(*this, map); | ||
30 | } | ||
31 | |||
32 | Map::~Map() | ||
33 | { | ||
34 | free(mapdata); | ||
35 | } | ||
36 | |||
37 | Map& Map::operator= (Map map) | ||
38 | { | ||
39 | swap(*this, map); | ||
40 | |||
41 | return *this; | ||
42 | } | ||
43 | |||
44 | void swap(Map& first, Map& second) | ||
45 | { | ||
46 | std::swap(first.mapdata, second.mapdata); | ||
47 | std::swap(first.title, second.title); | ||
48 | std::swap(first.adjacents, second.adjacents); | ||
49 | std::swap(first.id, second.id); | ||
50 | std::swap(first.entities, second.entities); | ||
51 | } | ||
52 | |||
53 | int Map::getID() const | ||
54 | { | ||
55 | return id; | ||
56 | } | ||
57 | |||
58 | const int* Map::getMapdata() const | ||
59 | { | ||
60 | return mapdata; | ||
61 | } | ||
62 | |||
63 | std::string Map::getTitle() const | ||
64 | { | ||
65 | return title; | ||
66 | } | ||
67 | |||
68 | void Map::createEntities(std::list<std::shared_ptr<Entity>>& entities) const | ||
69 | { | ||
70 | for (auto data : this->entities) | ||
71 | { | ||
72 | auto entity = EntityFactory::createNamedEntity(data.name, data.items); | ||
73 | entity->position = data.position; | ||
74 | |||
75 | entities.push_back(entity); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | bool Map::operator==(const Map& other) const | ||
80 | { | ||
81 | return id == other.id; | ||
82 | } | ||
83 | |||
84 | bool Map::operator!=(const Map& other) const | ||
85 | { | ||
86 | return id != other.id; | ||
87 | } | ||
88 | |||
89 | Map::MoveType Map::moveTypeForShort(std::string str) | ||
90 | { | ||
91 | if (str == "wrap") return MoveType::Wrap; | ||
92 | if (str == "warp") return MoveType::Warp; | ||
93 | if (str == "reverseWarp") return MoveType::ReverseWarp; | ||
94 | |||
95 | return MoveType::Wall; | ||
96 | } | ||
97 | |||
98 | Map::MoveDir Map::moveDirForShort(std::string str) | ||
99 | { | ||
100 | if (str == "right") return MoveDir::Right; | ||
101 | if (str == "up") return MoveDir::Up; | ||
102 | if (str == "down") return MoveDir::Down; | ||
103 | |||
104 | return MoveDir::Left; | ||
105 | } | ||
106 | |||
107 | static const Map::Adjacent defaultAdjacent {}; | ||
108 | const Map::Adjacent& Map::getAdjacent(MoveDir dir) const | ||
109 | { | ||
110 | if (adjacents.count(dir) > 0) | ||
111 | { | ||
112 | return adjacents.at(dir); | ||
113 | } else { | ||
114 | return defaultAdjacent; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | bool Map::moveTypeTakesMap(MoveType type) | ||
119 | { | ||
120 | switch (type) | ||
121 | { | ||
122 | case MoveType::Wall: return false; | ||
123 | case MoveType::Wrap: return false; | ||
124 | case MoveType::Warp: return true; | ||
125 | case MoveType::ReverseWarp: return true; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | void Map::setMapdata(int* mapdata) | ||
130 | { | ||
131 | free(this->mapdata); | ||
132 | this->mapdata = mapdata; | ||
133 | } | ||
134 | |||
135 | void Map::setTitle(std::string title) | ||
136 | { | ||
137 | this->title = title; | ||
138 | } | ||
139 | |||
140 | void Map::setAdjacent(MoveDir dir, MoveType type, int map) | ||
141 | { | ||
142 | Adjacent& cur = adjacents[dir]; | ||
143 | cur.type = type; | ||
144 | if (map != -1) cur.map = map; | ||
145 | } | ||
146 | |||
147 | void Map::addEntity(EntityData& data) | ||
148 | { | ||
149 | entities.push_back(data); | ||
150 | } | ||
151 | |||