diff options
author | Roderic Morris <roderic@ccs.neu.edu> | 2009-07-01 20:28:34 -0400 |
---|---|---|
committer | Roderic Morris <roderic@ccs.neu.edu> | 2009-07-01 20:41:47 -0400 |
commit | 2ea700fc0388d843795b71a9d259876ce975926f (patch) | |
tree | a64bdc3163f0ffb1663e34c3dae8de0c34953220 /src/game-server/map.cpp | |
parent | 6b794e76f8f046dca632299e443129c4f5ca3382 (diff) | |
download | manaserv-2ea700fc0388d843795b71a9d259876ce975926f.tar.gz manaserv-2ea700fc0388d843795b71a9d259876ce975926f.tar.bz2 manaserv-2ea700fc0388d843795b71a9d259876ce975926f.tar.xz manaserv-2ea700fc0388d843795b71a9d259876ce975926f.zip |
Remove complex path finding for players. Add a simple path finding algorithm to map.
Diffstat (limited to 'src/game-server/map.cpp')
-rw-r--r-- | src/game-server/map.cpp | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp index 3821b0a8..87321141 100644 --- a/src/game-server/map.cpp +++ b/src/game-server/map.cpp @@ -167,8 +167,56 @@ MetaTile *Map::getMetaTile(int x, int y) static int const basicCost = 100; -std::list<PATH_NODE> -Map::findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost) + +std::list<PATH_NODE> Map::findSimplePath(int startX, int startY, + int destX, int destY, + unsigned char walkmask) +{ + // Path to be built up (empty by default) + std::list<PATH_NODE> path; + int positionX = startX, positionY = startY; + int directionX, directionY; + // Checks our path up to 1 tiles, if a blocking tile is found + // We go to the last good tile, and break out of the loop + while(true) + { + // need to find a way to just get negative or positive 1 or 0 + // assume this is right for now. + directionX = destX - positionX; + directionY = destY - positionY; + + if (directionX > 0) + directionX = 1; + else if(directionX < 0) + directionX = -1; + + if (directionY > 0) + directionY = 1; + else if(directionY < 0) + directionY = -1; + + positionX += directionX; + positionY += directionY; + + if (getWalk(positionX, positionY, walkmask)) + { + path.push_back(PATH_NODE(positionX, positionY)); + + if ((positionX == destX) && (positionY == destY)) + { + return path; + } + } + else + { + return path; + } + } +} + +std::list<PATH_NODE> Map::findPath(int startX, int startY, + int destX, int destY, + unsigned char walkmask, int maxCost) { // Path to be built up (empty by default) std::list<PATH_NODE> path; |