summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorRoderic Morris <roderic@ccs.neu.edu>2009-07-01 20:39:28 -0400
committerRoderic Morris <roderic@ccs.neu.edu>2009-07-01 20:41:17 -0400
commit0bca1b9756a93d876cbf4a411b47634b87775162 (patch)
tree50eb8a593b1499c694add8e582823dc78b1459cb /src/map.cpp
parentcc8faa31bfae9f7bbce453a4ae69ef3d6eacbb96 (diff)
downloadMana-0bca1b9756a93d876cbf4a411b47634b87775162.tar.gz
Mana-0bca1b9756a93d876cbf4a411b47634b87775162.tar.bz2
Mana-0bca1b9756a93d876cbf4a411b47634b87775162.tar.xz
Mana-0bca1b9756a93d876cbf4a411b47634b87775162.zip
Remove complex path finding for players. Add a simple path finding algorithm to map.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp44
1 files changed, 44 insertions, 0 deletions
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,