From 0bca1b9756a93d876cbf4a411b47634b87775162 Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Wed, 1 Jul 2009 20:39:28 -0400 Subject: Remove complex path finding for players. Add a simple path finding algorithm to map. --- src/map.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 4e12ac97..61fcdfe8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -490,6 +490,50 @@ const std::string &Map::getName() const return getProperty("mapname"); } +Path Map::findSimplePath(int startX, int startY, + int destX, int destY, + unsigned char walkmask) +{ + // Path to be built up (empty by default) + Path 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) + { + 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(Position(positionX, positionY)); + + if ((positionX == destX) && (positionY == destY)) + { + return path; + } + } + else + { + return path; + } + } +} + static int const basicCost = 100; Path Map::findPath(int startX, int startY, int destX, int destY, -- cgit v1.2.3-70-g09d2