diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-10-16 16:58:01 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-10-16 16:58:01 +0000 |
commit | a8a422352df3441d3cf0da967dc94b42c2c21239 (patch) | |
tree | a2dc1fab9a990ac85aadf431a459269dcedd0c98 /src/map.cpp | |
parent | c7098a346b948c5c36a551e2f2135b4ef3094125 (diff) | |
download | mana-a8a422352df3441d3cf0da967dc94b42c2c21239.tar.gz mana-a8a422352df3441d3cf0da967dc94b42c2c21239.tar.bz2 mana-a8a422352df3441d3cf0da967dc94b42c2c21239.tar.xz mana-a8a422352df3441d3cf0da967dc94b42c2c21239.zip |
Some code improvements.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/map.cpp b/src/map.cpp index 37b7292a..449f72e9 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -22,14 +22,16 @@ */ #include "map.h" + +#include <algorithm> +#include <queue> + #include "tileset.h" #include "being.h" #include "graphics.h" #include "resources/image.h" #include "sprite.h" -#include <queue> - MetaTile::MetaTile(): whichList(0) { @@ -161,29 +163,26 @@ Map::setTileWithGid(int x, int y, int layer, int gid) } } +class ContainsGidFunctor +{ + public: + bool operator() (Tileset* set) + { + return (set->getFirstGid() <= gid && + gid - set->getFirstGid() < (int)set->spriteset.size()); + } + int gid; +} containsGid; + Tileset* Map::getTilesetWithGid(int gid) { Tilesets::iterator i; - Tileset *set = NULL; - // Find the tileset with the highest firstGid below/equal to gid - for (i = tilesets.begin(); i != tilesets.end(); ++i) - { - if ((*i)->getFirstGid() <= gid) { - set = (*i); - } - else { - break; - } - } + containsGid.gid = gid; + i = find_if(tilesets.begin(), tilesets.end(), containsGid); - if (set && (gid - set->getFirstGid()) < (int)set->spriteset.size()) - { - return set; - } - - return NULL; + return (i == tilesets.end()) ? NULL : *i; } Image* @@ -207,22 +206,21 @@ Map::setWalk(int x, int y, bool walkable) bool Map::getWalk(int x, int y) { - // If walkable, check for colliding into a being - if (!tileCollides(x, y)) { - std::list<Being*>::iterator i = beings.begin(); - while (i != beings.end()) { - Being *being = (*i); - // Collision when non-portal being is found at this location - if (being->x == x && being->y == y && being->job != 45) { - return false; - } - i++; - } - return true; - } - else { + // Check for being walkable + if (tileCollides(x, y)) { return false; } + + // Check for collision with a being + std::list<Being*>::iterator i = beings.begin(); + for (i = beings.begin(); i != beings.end(); i++) { + // job 45 is a portal, they don't collide + if ((*i)->x == x && (*i)->y == y && (*i)->job != 45) { + return false; + } + } + + return true; } bool |