summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-05 00:15:27 +0100
committerIra Rice <irarice@gmail.com>2009-01-05 20:43:04 -0700
commit4b540f3007e18a85a6d31d301526217393792451 (patch)
tree0cd424a18cf65505e32507a9c356a7182f0a489d /src
parentb6e7b6c6cb3ea26157e3a78713cc9621dc46b2d7 (diff)
downloadmana-4b540f3007e18a85a6d31d301526217393792451.tar.gz
mana-4b540f3007e18a85a6d31d301526217393792451.tar.bz2
mana-4b540f3007e18a85a6d31d301526217393792451.tar.xz
mana-4b540f3007e18a85a6d31d301526217393792451.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.h19
-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, 126 insertions, 38 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a7735e41..83f35dfb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -337,6 +337,8 @@ SET(SRCS
player.h
player_relations.cpp
player_relations.h
+ position.cpp
+ position.h
properties.h
sdltruetypefont.cpp
sdltruetypefont.hpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 382f33e0..e89afd8f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -306,6 +306,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
player.h \
player_relations.cpp \
player_relations.h \
+ position.cpp \
+ position.h \
properties.h \
recorder.cpp \
recorder.h \
diff --git a/src/being.cpp b/src/being.cpp
index 07895eb2..aff52757 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -351,29 +351,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 ccb1c4c4..54c9d717 100644
--- a/src/being.h
+++ b/src/being.h
@@ -33,6 +33,7 @@
#include "effectmanager.h"
#include "map.h"
#include "particlecontainer.h"
+#include "position.h"
#include "sprite.h"
#include "gui/speechbubble.h"
@@ -52,24 +53,6 @@ class Particle;
class SpeechBubble;
class Text;
-/**
- * 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;
-
enum Gender {
GENDER_MALE = 0,
GENDER_FEMALE = 1,
diff --git a/src/map.cpp b/src/map.cpp
index 02b046fb..217a14e3 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -480,7 +480,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