summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-02-24 21:46:08 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-02-24 23:03:22 +0100
commit253e2c0af1f88d38dc92d62d82b230711ef2f874 (patch)
treef158cfbe56900bf7ca31bbed51ae07928b854dc0 /src
parent4cb11db37aeb8052e1fef94965bc48bbc949e7f9 (diff)
downloadmana-client-253e2c0af1f88d38dc92d62d82b230711ef2f874.tar.gz
mana-client-253e2c0af1f88d38dc92d62d82b230711ef2f874.tar.bz2
mana-client-253e2c0af1f88d38dc92d62d82b230711ef2f874.tar.xz
mana-client-253e2c0af1f88d38dc92d62d82b230711ef2f874.zip
Some code cleanups
Reviewed-by: Jared Adams
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp35
-rw-r--r--src/being.h9
-rw-r--r--src/map.cpp3
3 files changed, 18 insertions, 29 deletions
diff --git a/src/being.cpp b/src/being.cpp
index ce6c9e1b..d78f38ab 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -127,7 +127,7 @@ void Being::setPosition(const Vector &pos)
(int)pos.y - getHeight() - mText->getHeight() - 6);
}
-Position Being::checkNodeOffsets(Position position)
+Position Being::checkNodeOffsets(const Position &position) const
{
// Pre-computing character's position in tiles
const int tx = position.x / 32;
@@ -164,7 +164,7 @@ Position Being::checkNodeOffsets(Position position)
// where a player can approach an obstacle by walking from slightly
// under, diagonally. First part to the walk on water bug.
//if (offsetY < 16 && !mMap->getWalk(posX, posY - 1, getWalkMask()))
- //fy = 16;
+ // fy = 16;
return Position(tx * 32 + fx, ty * 32 + fy);
}
@@ -178,22 +178,17 @@ void Being::setDestination(int dstX, int dstY)
return;
}
- // Check the walkability of the destination:
- // If the destination is unwalkable,
- // don't bother finding a path or set a destination.
+ // If the destination is unwalkable, don't bother trying to get there
if (!mMap->getWalk(dstX / 32, dstY / 32))
return;
- // We check the destination in order to handle
- // surrounding blocking tiles gracefully...
Position dest = checkNodeOffsets(dstX, dstY);
mDest.x = dest.x;
mDest.y = dest.y;
int srcX = mPos.x;
int srcY = mPos.y;
- // We initialize an empty path...
- Path thisPath = Path();
+ Path thisPath;
if (mMap)
{
@@ -225,16 +220,12 @@ void Being::setDestination(int dstX, int dstY)
int i = 0;
while (it != thisPath.end())
{
- it->x = (it->x * 32) + startX + (changeX * i);
- it->y = (it->y * 32) + startY + (changeY * i);
-
- // We check each path node and correct the
- // tile position's offsets whenever needed.
- Position pos = checkNodeOffsets(*it);
- it->x = pos.x;
- it->y = pos.y;
- i++;
- it++;
+ // A position that is valid on the start and end tile is not
+ // necessarily valid on all the tiles in between, so check the offsets.
+ *it = checkNodeOffsets(it->x * 32 + startX + changeX * i,
+ it->y * 32 + startY + changeY * i);
+ i++;
+ it++;
}
// Remove the last path node, as it's more clever to go to mDest instead.
@@ -254,6 +245,7 @@ void Being::clearPath()
void Being::setPath(const Path &path)
{
mPath = path;
+
if ((Net::getNetworkType() == ServerInfo::EATHENA) &&
mAction != WALK && mAction != DEAD)
{
@@ -368,13 +360,9 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type)
}
if (type != CRITICAL)
- {
effectManager->trigger(26, this);
- }
else
- {
effectManager->trigger(28, this);
- }
}
}
@@ -382,6 +370,7 @@ void Being::handleAttack(Being *victim, int damage, AttackType type)
{
if (this != player_node)
setAction(Being::ATTACK, 1);
+
if (getType() == PLAYER && victim)
{
if (mEquippedWeapon)
diff --git a/src/being.h b/src/being.h
index 5140717c..ff21825c 100644
--- a/src/being.h
+++ b/src/being.h
@@ -648,12 +648,11 @@ class Being : public Sprite, public ConfigListener
Vector mDest; /**< destination coordinates. */
/**
- * Check the current position against surrounding
- * blocking tiles, and correct the position offset within
- * tile when needed.
+ * Check the current position against surrounding blocking tiles, and
+ * correct the position offset within tile when needed.
*/
- Position checkNodeOffsets(Position position);
- Position checkNodeOffsets(int x, int y)
+ Position checkNodeOffsets(const Position &position) const;
+ Position checkNodeOffsets(int x, int y) const
{ return checkNodeOffsets(Position(x, y)); }
private:
diff --git a/src/map.cpp b/src/map.cpp
index 6d332d48..da3f2185 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -601,7 +601,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
std::priority_queue<Location> openList;
// Return when destination not walkable
- if (!getWalk(destX, destY, walkmask)) return path;
+ if (!getWalk(destX, destY, walkmask))
+ return path;
// Reset starting tile's G cost to 0
MetaTile *startTile = getMetaTile(startX, startY);