diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-05 15:19:10 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-05 15:19:10 +0000 |
commit | 17798683ebebbc92510ba5244aa3455c2138869d (patch) | |
tree | a3c3b99944327a577aaf2000278c6a28453634e6 | |
parent | 9770f22a2846c68dbeea0780d595ad49ea6c490d (diff) | |
download | mana-17798683ebebbc92510ba5244aa3455c2138869d.tar.gz mana-17798683ebebbc92510ba5244aa3455c2138869d.tar.bz2 mana-17798683ebebbc92510ba5244aa3455c2138869d.tar.xz mana-17798683ebebbc92510ba5244aa3455c2138869d.zip |
Removed superfluous getPathWalk method in favor of getWalk.
-rw-r--r-- | src/astar.cpp | 47 | ||||
-rw-r--r-- | src/map.cpp | 5 | ||||
-rw-r--r-- | src/map.h | 8 |
3 files changed, 23 insertions, 37 deletions
diff --git a/src/astar.cpp b/src/astar.cpp index d6e60227..f3e8acb0 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -1,8 +1,11 @@ #include "astar.h" -#define MAP_WIDTH 200 +#define MAP_WIDTH 200 #define MAP_HEIGHT 200 +#define WALKABLE 0 +#define NOT_WALKABLE 1 + // path-related constants const int numberPeople = 1; int onClosedList = 10; @@ -43,7 +46,7 @@ int H_cost[MAP_WIDTH * MAP_HEIGHT + 2]; int pathLength; /**< length of the FOUND path for critter */ int pathLocation; /**< current position along the chosen path for critter */ -int* path_bank; +int* path_bank = NULL; // Path reading variables int pathStatus; @@ -72,8 +75,8 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) if (s_x == e_x && s_y == e_y && pathLocation > 0) return NULL; else if (s_x == e_x && s_y == e_y && pathLocation == 0) return NULL; - // If dest tile is NOT_WALKABLE, return that it's a NOT_FOUND path. - if (tiledMap.getPathWalk(e_x, e_y) == NOT_WALKABLE) { + // If dest tile is not walkable, return that it's a NOT_FOUND path. + if (!tiledMap.getWalk(e_x, e_y)) { xPath = s_x; yPath = s_y; return NULL; @@ -185,24 +188,26 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) // closed list have already been considered and can now // be ignored). if (whichList[a][b] != onClosedList) { - // If not a wall/obstacle square. - if (tiledMap.getPathWalk(a, b) != NOT_WALKABLE) { + // If not a wall/obstacle square. + if (tiledMap.getWalk(a, b)) { // Don't cut across corners corner = WALKABLE; - if (a == parentXval-1) { - if (b == parentYval-1) { - if (tiledMap.getPathWalk(parentXval - 1, parentYval) == NOT_WALKABLE || tiledMap.getPathWalk(parentXval, parentYval - 1) == NOT_WALKABLE) // cera slash + + if (a == parentXval - 1) { + if (b == parentYval - 1) { + if (!tiledMap.getWalk(parentXval - 1, parentYval) || !tiledMap.getWalk(parentXval, parentYval - 1)) // cera slash corner = NOT_WALKABLE; } else if (b == parentYval + 1) { - if (tiledMap.getPathWalk(parentXval, parentYval + 1) == NOT_WALKABLE || tiledMap.getPathWalk(parentXval - 1, parentYval) == NOT_WALKABLE) + if (!tiledMap.getWalk(parentXval, parentYval + 1) || !tiledMap.getWalk(parentXval - 1, parentYval)) corner = NOT_WALKABLE; } - } else if (a == parentXval + 1) { + } + else if (a == parentXval + 1) { if (b == parentYval - 1) { - if (tiledMap.getPathWalk(parentXval, parentYval - 1) == NOT_WALKABLE || tiledMap.getPathWalk(parentXval + 1, parentYval) == NOT_WALKABLE) + if (!tiledMap.getWalk(parentXval, parentYval - 1) || !tiledMap.getWalk(parentXval + 1, parentYval)) corner = NOT_WALKABLE; } else if (b == parentYval + 1) { - if (tiledMap.getPathWalk(parentXval + 1, parentYval) == NOT_WALKABLE || tiledMap.getPathWalk(parentXval, parentYval + 1) == NOT_WALKABLE) + if (!tiledMap.getWalk(parentXval + 1, parentYval) || !tiledMap.getWalk(parentXval, parentYval + 1)) corner = NOT_WALKABLE; } } @@ -430,8 +435,8 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) do { // Work backwards 2 integers cellPosition = cellPosition - 2; - path_bank [cellPosition] = pathX; - path_bank [cellPosition+1] = pathY; + path_bank[cellPosition] = pathX; + path_bank[cellPosition + 1] = pathY; // Look up the parent of the current cell. tempx = parentX[pathX][pathY]; pathY = parentY[pathX][pathY]; @@ -440,17 +445,11 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) } while (pathX != s_x || pathY != s_y); - char stringa[80]; - sprintf(stringa,"%i %i",s_x,s_y); - PATH_NODE *ret = NULL, *temp = NULL; pathLocation = 1; ret = new PATH_NODE(s_x, s_y); temp = ret; - //alert(stringa,"","","","",0,0); - while(pathLocation<pathLength) { - sprintf(stringa, "%i %i", path_bank[pathLocation * 2 - 2], - path_bank[pathLocation * 2 - 1]); + while (pathLocation < pathLength) { temp->next = new PATH_NODE( path_bank[pathLocation * 2 - 2], path_bank[pathLocation * 2 - 1]); @@ -478,8 +477,8 @@ void ReadPath(int pathfinderID) // Set pathLocation to 1st step pathLocation = 1; while (pathLocation<pathLength) { - int a = path_bank [pathLocation * 2 - 2]; - int b = path_bank [pathLocation * 2 - 1]; + int a = path_bank[pathLocation * 2 - 2]; + int b = path_bank[pathLocation * 2 - 1]; pathLocation = pathLocation + 1; // Draw dotted path whichList[a][b] = 3; diff --git a/src/map.cpp b/src/map.cpp index ef4e06eb..2b8e6dac 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -70,11 +70,6 @@ bool Map::getWalk(int x, int y) { return ret; } -int Map::getPathWalk(int x, int y) { - if (getWalk(x, y)) return 0; - else return 1; -} - void Map::setTile(int x, int y, int layer, unsigned short id) { if (layer == 0) { id <<= 6; @@ -26,9 +26,6 @@ #define TILESET_WIDTH 30 -#define WALKABLE 0 -#define NOT_WALKABLE 1 - /** Struct representing a tile. A tile is composed of 3 layers. 1st: Ground layer (used for grass, water, ...) -> bit 0-9 of data 2nd: Fringe layer (objects that are overlapped by the player) -> bit 10-19 of data @@ -90,11 +87,6 @@ class Map bool getWalk(int x, int y); /** - * Tell if a tile is walkable or not (0=walkable,1=not walkable) - */ - int getPathWalk(int x, int y); - - /** * Returns the width of this map. */ int getWidth(); |