summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2008-02-12 19:49:37 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2008-02-12 19:49:37 +0000
commit79dfa4db0cc7d307fe52f1959a30f117efacaa00 (patch)
treec44cd018b8f9f320fb2a1f0c8aed47a24ac14e2b /src
parent34e9c3e9125ef800ef47e2594cf23853deddccfb (diff)
downloadmana-79dfa4db0cc7d307fe52f1959a30f117efacaa00.tar.gz
mana-79dfa4db0cc7d307fe52f1959a30f117efacaa00.tar.bz2
mana-79dfa4db0cc7d307fe52f1959a30f117efacaa00.tar.xz
mana-79dfa4db0cc7d307fe52f1959a30f117efacaa00.zip
Made pathfinding not halt on collision destination tile, made moving around with mouse smoother. Added possibility to pass through players with key controls.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp6
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/localplayer.cpp4
-rw-r--r--src/map.cpp13
-rw-r--r--src/map.h5
5 files changed, 11 insertions, 19 deletions
diff --git a/src/being.cpp b/src/being.cpp
index ad60dc2f..e76370fd 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -339,6 +339,12 @@ Being::nextStep()
setDirection(dir);
+ if (mMap->tileCollides(node.x, node.y))
+ {
+ setAction(STAND);
+ return;
+ }
+
mX = node.x;
mY = node.y;
setAction(WALK);
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index d99b48ba..3a297f66 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -423,7 +423,7 @@ Viewport::mousePressed(gcn::MouseEvent &event)
player_node->pickUp(item);
}
// Just walk around
- else if (mMap->getWalk(tilex, tiley))
+ else
{
// XXX XXX XXX REALLY UGLY!
Uint8 *keys = SDL_GetKeyState(NULL);
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 1b65d9bb..3b8dda9e 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -223,11 +223,11 @@ void LocalPlayer::walk(unsigned char dir)
dy = 0;
// Choose a straight direction when diagonal target is blocked
- if (dx && dy && !mMap->getWalk(mX + dx, mY + dy))
+ if (dx && dy && mMap->tileCollides(mX + dx, mY + dy))
dx = 0;
// Walk to where the player can actually go
- if ((dx || dy) && mMap->getWalk(mX + dx, mY + dy))
+ if ((dx || dy) && !mMap->tileCollides(mX + dx, mY + dy))
{
setDestination(mX + dx, mY + dy);
}
diff --git a/src/map.cpp b/src/map.cpp
index 2dbf9cb6..c8bdc574 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -276,11 +276,6 @@ void Map::setWalk(int x, int y, bool walkable)
mMetaTiles[x + y * mWidth].walkable = walkable;
}
-bool Map::getWalk(int x, int y) const
-{
- return !tileCollides(x, y) && !occupied(x, y);
-}
-
bool Map::occupied(int x, int y) const
{
Beings &beings = beingManager->getAll();
@@ -340,10 +335,6 @@ Path Map::findPath(int startX, int startY, int destX, int destY)
// Declare open list, a list with open tiles sorted on F cost
std::priority_queue<Location> openList;
- // Return empty path when destination collides
- if (tileCollides(destX, destY))
- return path;
-
// Reset starting tile's G cost to 0
MetaTile *startTile = getMetaTile(startX, startY);
startTile->Gcost = 0;
@@ -388,8 +379,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY)
MetaTile *newTile = getMetaTile(x, y);
- // Skip if the tile is on the closed list or collides
- if (newTile->whichList == mOnClosedList || tileCollides(x, y))
+ // Skip if the tile is on the closed list or collides unless its the destination tile
+ if (newTile->whichList == mOnClosedList || tileCollides(x, y) && !(x == destX && y == destY))
{
continue;
}
diff --git a/src/map.h b/src/map.h
index 5c7fe1e9..fab7bfb7 100644
--- a/src/map.h
+++ b/src/map.h
@@ -134,11 +134,6 @@ class Map : public Properties
void setWalk(int x, int y, bool walkable);
/**
- * Tell if a tile is walkable or not, includes checking beings.
- */
- bool getWalk(int x, int y) const;
-
- /**
* Tell if a tile collides, not including a check on beings.
*/
bool tileCollides(int x, int y) const;