summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-11 15:47:35 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-11 15:47:35 +0000
commit8da32105732949b4b0273c718d118bcfae70a1c9 (patch)
tree0a354974d48268cfaafcdb1e06b498fa26a59c1e /src/map.cpp
parentf9ce4e302cb3ed203d89a7a18e10b7ad4f11519c (diff)
downloadmana-client-8da32105732949b4b0273c718d118bcfae70a1c9.tar.gz
mana-client-8da32105732949b4b0273c718d118bcfae70a1c9.tar.bz2
mana-client-8da32105732949b4b0273c718d118bcfae70a1c9.tar.xz
mana-client-8da32105732949b4b0273c718d118bcfae70a1c9.zip
Merged 0.0 changes from revision 2825 to 2898 to trunk.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 1cdc1077..1bd8f235 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -282,35 +282,35 @@ Map::setWalk(int x, int y, bool walkable)
bool
Map::getWalk(int x, int y)
{
- // Check for being walkable
- if (tileCollides(x, y)) {
- return false;
- }
+ return !tileCollides(x, y) && !occupied(x, y);
+}
- /*
- // Check for collision with a being
+bool
+Map::occupied(int x, int y)
+{
Beings &beings = beingManager->getAll();
- for (BeingIterator i = beings.begin(); i != beings.end(); i++) {
+ for (BeingIterator i = beings.begin(); i != beings.end(); i++)
+ {
// job 45 is a portal, they don't collide
- if ((*i)->mX / 32 == x && (*i)->mY / 32 == y && (*i)->mJob != 45) {
- return false;
+ if ((*i)->mX / 32 == x && (*i)->mY / 32 == y && (*i)->mJob != 45)
+ {
+ return true;
}
}
- */
- return true;
+ return false;
}
bool
Map::tileCollides(int x, int y)
{
- // You can't walk outside of the map
- if (x < 0 || y < 0 || x >= mWidth || y >= mHeight) {
- return true;
- }
+ return !(contains(x, y) && mMetaTiles[x + y * mWidth].walkable);
+}
- // Check if the tile is walkable
- return !mMetaTiles[x + y * mWidth].walkable;
+bool
+Map::contains(int x, int y)
+{
+ return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
}
void
@@ -355,8 +355,9 @@ 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 not walkable
- if (!getWalk(destX, destY)) return path;
+ // 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);
@@ -395,16 +396,15 @@ Map::findPath(int startX, int startY, int destX, int destY)
// Skip if if we're checking the same tile we're leaving from,
// or if the new location falls outside of the map boundaries
- if ((dx == 0 && dy == 0) ||
- (x < 0 || y < 0 || x >= mWidth || y >= mHeight))
+ if ((dx == 0 && dy == 0) || !contains(x, y))
{
continue;
}
MetaTile *newTile = getMetaTile(x, y);
- // Skip if the tile is on the closed list or is not walkable
- if (newTile->whichList == mOnClosedList || !getWalk(x, y))
+ // Skip if the tile is on the closed list or collides
+ if (newTile->whichList == mOnClosedList || tileCollides(x, y))
{
continue;
}
@@ -441,6 +441,13 @@ Map::findPath(int startX, int startY, int destX, int destY)
++Gcost;
}
+ // It costs extra to walk through a being (needs to be enough
+ // to make it more attractive to walk around).
+ if (occupied(x, y))
+ {
+ Gcost += 30;
+ }
+
// Skip if Gcost becomes too much
// Warning: probably not entirely accurate
if (Gcost > 20 * basicCost)