summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 16:46:50 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 16:46:50 -0400
commit81992165f5cf6ddebe7952c694b211b16cc45bd4 (patch)
treee9d2a7f2959f8d0474a7bd5aba866e3539deefee /src
parent6eaefb4dd401a1c5e9cc7fb8e909521e045c0710 (diff)
downloadtherapy-81992165f5cf6ddebe7952c694b211b16cc45bd4.tar.gz
therapy-81992165f5cf6ddebe7952c694b211b16cc45bd4.tar.bz2
therapy-81992165f5cf6ddebe7952c694b211b16cc45bd4.zip
Defined map equality
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp2
-rw-r--r--src/map.cpp15
-rw-r--r--src/map.h3
3 files changed, 19 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp index 68c0a13..a36c56f 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -151,7 +151,7 @@ void Game::playerDie(Entity& player, const Map& curMap)
151 playSound("../res/Hit_Hurt5.wav", 0.25); 151 playSound("../res/Hit_Hurt5.wav", 0.25);
152 152
153 schedule(0.75, [&] () { 153 schedule(0.75, [&] () {
154 if (&curMap != save.map) 154 if (curMap != *(save.map))
155 { 155 {
156 loadMap(*(save.map)); 156 loadMap(*(save.map));
157 } 157 }
diff --git a/src/map.cpp b/src/map.cpp index 2be5071..5119d85 100644 --- a/src/map.cpp +++ b/src/map.cpp
@@ -17,6 +17,8 @@ Map::Map()
17 17
18Map::Map(const std::string name) 18Map::Map(const std::string name)
19{ 19{
20 this->name = name;
21
20 xmlDocPtr doc = xmlParseFile(("../maps/" + name + ".xml").c_str()); 22 xmlDocPtr doc = xmlParseFile(("../maps/" + name + ".xml").c_str());
21 if (doc == nullptr) 23 if (doc == nullptr)
22 { 24 {
@@ -108,6 +110,8 @@ Map::Map(const Map& map)
108 rightMap = map.rightMap; 110 rightMap = map.rightMap;
109 111
110 entities = map.entities; 112 entities = map.entities;
113
114 name = map.name;
111} 115}
112 116
113Map::Map(Map&& map) : Map() 117Map::Map(Map&& map) : Map()
@@ -135,6 +139,7 @@ void swap(Map& first, Map& second)
135 std::swap(first.leftMap, second.leftMap); 139 std::swap(first.leftMap, second.leftMap);
136 std::swap(first.rightMap, second.rightMap); 140 std::swap(first.rightMap, second.rightMap);
137 std::swap(first.entities, second.entities); 141 std::swap(first.entities, second.entities);
142 std::swap(first.name, second.name);
138} 143}
139 144
140const int* Map::getMapdata() const 145const int* Map::getMapdata() const
@@ -178,6 +183,16 @@ void Map::createEntities(std::list<std::shared_ptr<Entity>>& entities) const
178 } 183 }
179} 184}
180 185
186bool Map::operator==(const Map& other) const
187{
188 return name == other.name;
189}
190
191bool Map::operator!=(const Map& other) const
192{
193 return name != other.name;
194}
195
181Map& Map::getNamedMap(const std::string name) 196Map& Map::getNamedMap(const std::string name)
182{ 197{
183 if (maps.count(name) == 0) 198 if (maps.count(name) == 0)
diff --git a/src/map.h b/src/map.h index fa2edcc..a562bec 100644 --- a/src/map.h +++ b/src/map.h
@@ -25,6 +25,8 @@ class Map {
25 void setLeftMap(const Map* m); 25 void setLeftMap(const Map* m);
26 void setRightMap(const Map* m); 26 void setRightMap(const Map* m);
27 void createEntities(std::list<std::shared_ptr<Entity>>& entities) const; 27 void createEntities(std::list<std::shared_ptr<Entity>>& entities) const;
28 bool operator==(const Map& other) const;
29 bool operator!=(const Map& other) const;
28 private: 30 private:
29 struct EntityData { 31 struct EntityData {
30 std::string name; 32 std::string name;
@@ -33,6 +35,7 @@ class Map {
33 35
34 int* mapdata; 36 int* mapdata;
35 char* title; 37 char* title;
38 std::string name;
36 const Map* leftMap = nullptr; 39 const Map* leftMap = nullptr;
37 const Map* rightMap = nullptr; 40 const Map* rightMap = nullptr;
38 std::list<EntityData> entities; 41 std::list<EntityData> entities;