summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-05 00:15:27 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-05 00:15:27 +0100
commit12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51 (patch)
tree3ceed68ebd672f564c11818efb0a793e43f0acc7 /src
parent81ca2120284ac7fd84e22ee61545b2b789f982e7 (diff)
downloadmana-12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51.tar.gz
mana-12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51.tar.bz2
mana-12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51.tar.xz
mana-12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51.zip
Renamed PATH_NODE to Position as on mainline
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being.cpp16
-rw-r--r--src/being.h24
-rw-r--r--src/map.cpp2
-rw-r--r--src/map.h20
-rw-r--r--src/position.cpp45
-rw-r--r--src/position.h58
8 files changed, 127 insertions, 42 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 94d25cc5..61fc77e8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -328,6 +328,8 @@ SET(SRCS
player.h
player_relations.cpp
player_relations.h
+ position.cpp
+ position.h
properties.h
serverinfo.h
shopitem.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index d8aa5443..4ef07773 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -283,6 +283,8 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \
player.h \
player_relations.cpp \
player_relations.h \
+ position.cpp \
+ position.h \
properties.h \
serverinfo.h \
shopitem.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index 88063ac1..f9c6296c 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -322,29 +322,29 @@ void Being::nextStep()
return;
}
- PATH_NODE node = mPath.front();
+ Position pos = mPath.front();
mPath.pop_front();
int dir = 0;
- if (node.x > mX)
+ if (pos.x > mX)
dir |= RIGHT;
- else if (node.x < mX)
+ else if (pos.x < mX)
dir |= LEFT;
- if (node.y > mY)
+ if (pos.y > mY)
dir |= DOWN;
- else if (node.y < mY)
+ else if (pos.y < mY)
dir |= UP;
setDirection(dir);
- if (mMap->tileCollides(node.x, node.y))
+ if (mMap->tileCollides(pos.x, pos.y))
{
setAction(STAND);
return;
}
- mX = node.x;
- mY = node.y;
+ mX = pos.x;
+ mY = pos.y;
setAction(WALK);
mWalkTime += mWalkSpeed / 10;
}
diff --git a/src/being.h b/src/being.h
index f48ebae2..6319bd47 100644
--- a/src/being.h
+++ b/src/being.h
@@ -28,6 +28,7 @@
#include <SDL_types.h>
#include <set>
+#include "position.h"
#include "sprite.h"
#include "map.h"
#include "animatedsprite.h"
@@ -49,24 +50,6 @@ class Text;
class StatusEffect;
-/**
- * A position along a being's path.
- */
-struct PATH_NODE
-{
- /**
- * Constructor.
- */
- PATH_NODE(unsigned short x, unsigned short y):
- x(x), y(y)
- { }
-
- unsigned short x;
- unsigned short y;
-};
-typedef std::list<PATH_NODE> Path;
-typedef Path::iterator PathIterator;
-
class Being : public Sprite
{
public:
@@ -115,10 +98,7 @@ class Being : public Sprite
/**
* Directions, to be used as bitmask values
*/
- static const char DOWN = 1;
- static const char LEFT = 2;
- static const char UP = 4;
- static const char RIGHT = 8;
+ enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 };
Uint16 mJob; /**< Job (player job, npc, monster, ) */
Uint16 mX, mY; /**< Tile coordinates */
diff --git a/src/map.cpp b/src/map.cpp
index 6e33d255..6170adef 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -485,7 +485,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY)
while (pathX != startX || pathY != startY)
{
// Add the new path node to the start of the path list
- path.push_front(PATH_NODE(pathX, pathY));
+ path.push_front(Position(pathX, pathY));
// Find out the next parent
MetaTile *tile = getMetaTile(pathX, pathY);
diff --git a/src/map.h b/src/map.h
index 6eaf9e43..56183abf 100644
--- a/src/map.h
+++ b/src/map.h
@@ -25,6 +25,7 @@
#include <list>
#include <vector>
+#include "position.h"
#include "properties.h"
class AmbientOverlay;
@@ -35,8 +36,6 @@ class Particle;
class Sprite;
class Tileset;
-struct PATH_NODE;
-
typedef std::vector<Tileset*> Tilesets;
typedef std::list<Sprite*> Sprites;
typedef Sprites::iterator SpriteIterator;
@@ -55,13 +54,13 @@ struct MetaTile
MetaTile():whichList(0) {};
// Pathfinding members
- int Fcost; /**< Estimation of total path cost */
- int Gcost; /**< Cost from start to this location */
- int Hcost; /**< Estimated cost to goal */
- int whichList; /**< No list, open list or closed list */
- int parentX; /**< X coordinate of parent tile */
- int parentY; /**< Y coordinate of parent tile */
- bool walkable; /**< Can beings walk on this tile */
+ int Fcost; /**< Estimation of total path cost */
+ int Gcost; /**< Cost from start to this location */
+ int Hcost; /**< Estimated cost to goal */
+ int whichList; /**< No list, open list or closed list */
+ int parentX; /**< X coordinate of parent tile */
+ int parentY; /**< Y coordinate of parent tile */
+ bool walkable; /**< Can beings walk on this tile */
};
/**
@@ -204,8 +203,7 @@ class Map : public Properties
/**
* Find a path from one location to the next.
*/
- std::list<PATH_NODE>
- findPath(int startX, int startY, int destX, int destY);
+ Path findPath(int startX, int startY, int destX, int destY);
/**
* Adds a sprite to the map.
diff --git a/src/position.cpp b/src/position.cpp
new file mode 100644
index 00000000..cc39a1af
--- /dev/null
+++ b/src/position.cpp
@@ -0,0 +1,45 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "position.h"
+
+std::ostream& operator <<(std::ostream &os, const Position &p)
+{
+ os << "(" << p.x << ", " << p.y << ")";
+ return os;
+}
+
+std::ostream& operator <<(std::ostream &os, const Path &path)
+{
+ Path::const_iterator i = path.begin();
+
+ os << "(";
+ while (i != path.end())
+ {
+ os << *i;
+ ++i;
+ if (i != path.end())
+ os << ", ";
+ }
+ os << ")";
+
+ return os;
+}
diff --git a/src/position.h b/src/position.h
new file mode 100644
index 00000000..7beb3ef7
--- /dev/null
+++ b/src/position.h
@@ -0,0 +1,58 @@
+/*
+ * The Mana World
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef TMW_POSITION_H
+#define TMW_POSITION_H
+
+#include <list>
+#include <iostream>
+
+/**
+ * A position along a being's path.
+ */
+struct Position
+{
+ /**
+ * Constructor.
+ */
+ Position(int x, int y):
+ x(x), y(y)
+ { }
+
+ int x;
+ int y;
+};
+
+typedef std::list<Position> Path;
+typedef Path::iterator PathIterator;
+
+/**
+ * Appends a string representation of a position to the output stream.
+ */
+std::ostream& operator <<(std::ostream &os, const Position &p);
+
+/**
+ * Appends a string representation of a path (sequence of positions) to the
+ * output stream.
+ */
+std::ostream& operator <<(std::ostream &os, const Path &path);
+
+#endif // TMW_POSITION_H