From 81992165f5cf6ddebe7952c694b211b16cc45bd4 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 14 Mar 2015 16:46:50 -0400 Subject: Defined map equality --- src/game.cpp | 2 +- src/map.cpp | 15 +++++++++++++++ src/map.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) 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) playSound("../res/Hit_Hurt5.wav", 0.25); schedule(0.75, [&] () { - if (&curMap != save.map) + if (curMap != *(save.map)) { loadMap(*(save.map)); } 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() Map::Map(const std::string name) { + this->name = name; + xmlDocPtr doc = xmlParseFile(("../maps/" + name + ".xml").c_str()); if (doc == nullptr) { @@ -108,6 +110,8 @@ Map::Map(const Map& map) rightMap = map.rightMap; entities = map.entities; + + name = map.name; } Map::Map(Map&& map) : Map() @@ -135,6 +139,7 @@ void swap(Map& first, Map& second) std::swap(first.leftMap, second.leftMap); std::swap(first.rightMap, second.rightMap); std::swap(first.entities, second.entities); + std::swap(first.name, second.name); } const int* Map::getMapdata() const @@ -178,6 +183,16 @@ void Map::createEntities(std::list>& entities) const } } +bool Map::operator==(const Map& other) const +{ + return name == other.name; +} + +bool Map::operator!=(const Map& other) const +{ + return name != other.name; +} + Map& Map::getNamedMap(const std::string name) { 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 { void setLeftMap(const Map* m); void setRightMap(const Map* m); void createEntities(std::list>& entities) const; + bool operator==(const Map& other) const; + bool operator!=(const Map& other) const; private: struct EntityData { std::string name; @@ -33,6 +35,7 @@ class Map { int* mapdata; char* title; + std::string name; const Map* leftMap = nullptr; const Map* rightMap = nullptr; std::list entities; -- cgit 1.4.1