summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-23 16:29:49 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-23 16:29:49 +0000
commit2003fd3534a312128c620e7e36902ac07045516e (patch)
treea98804c83f3d568756344943fbd580531195429b
parentb81f47c9b5fa2709af4d6e6e0669c604f3f273b1 (diff)
downloadmana-client-2003fd3534a312128c620e7e36902ac07045516e.tar.gz
mana-client-2003fd3534a312128c620e7e36902ac07045516e.tar.bz2
mana-client-2003fd3534a312128c620e7e36902ac07045516e.tar.xz
mana-client-2003fd3534a312128c620e7e36902ac07045516e.zip
Restored Being::setDestination, a pointer to the current map is now kept as a member in Being.
-rw-r--r--src/being.cpp14
-rw-r--r--src/being.h18
-rw-r--r--src/game.cpp24
-rw-r--r--src/gui/gui.cpp4
-rw-r--r--src/map.h2
5 files changed, 45 insertions, 17 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 069172c3..b4f1e042 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -179,6 +179,7 @@ Being::Being():
aspd(350),
m_weapon(0),
m_id(0),
+ map(0),
hairStyle(1), hairColor(1),
speech_time(0),
damage_time(0),
@@ -192,6 +193,14 @@ Being::~Being()
clearPath();
}
+void Being::setDestination(int destX, int destY)
+{
+ if (!map)
+ return;
+
+ setPath(map->findPath(x, y, destX, destY));
+}
+
void Being::clearPath()
{
path.clear();
@@ -250,6 +259,11 @@ void Being::setDamage(const std::string &text, int time)
showDamage = true;
}
+void Being::setMap(Map *map)
+{
+ this->map = map;
+}
+
void Being::setName(char *text)
{
strcpy(name, text);
diff --git a/src/being.h b/src/being.h
index bb5c5393..ec933d90 100644
--- a/src/being.h
+++ b/src/being.h
@@ -26,11 +26,14 @@
#include <list>
#include <string>
+
#include "graphics.h"
#define NR_HAIR_STYLES 5
#define NR_HAIR_COLORS 10
+class Map;
+
struct PATH_NODE {
/**
* Constructor.
@@ -74,9 +77,9 @@ class Being
void clearPath();
/**
- * Sets the new path for this being.
+ * Sets a new destination for this being to walk to.
*/
- void setPath(std::list<PATH_NODE> path);
+ void setDestination(int destX, int destY);
/**
* Puts a "speech balloon" above this being for the specified amount
@@ -186,9 +189,15 @@ class Being
*/
void setId(unsigned int id);
+ /**
+ * Set the map the being is on
+ */
+ void setMap(Map *map);
+
private:
unsigned short m_weapon;
unsigned int m_id; /**< Unique id */
+ Map *map;
std::list<PATH_NODE> path;
std::string speech;
@@ -197,6 +206,11 @@ class Being
unsigned int speech_time;
unsigned int damage_time;
bool showSpeech, showDamage;
+
+ /**
+ * Sets the new path for this being.
+ */
+ void setPath(std::list<PATH_NODE> path);
};
/** Add a Being to the list */
diff --git a/src/game.cpp b/src/game.cpp
index 4feb097e..01efc71f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -171,6 +171,7 @@ void do_init()
player_node->speed = 150;
player_node->setHairColor(char_info->hair_color);
player_node->setHairStyle(char_info->hair_style);
+ player_node->setMap(tiledMap);
if (char_info->weapon == 11) {
char_info->weapon = 2;
@@ -679,9 +680,7 @@ void do_input()
// Allow keyboard control to interrupt an existing path
if ((xDirection != 0 || yDirection != 0) && player_node->action == WALK)
- player_node->setPath(tiledMap->findPath(
- player_node->x, player_node->y,
- x, y));
+ player_node->setDestination(x, y);
if (player_node->action != WALK)
{
@@ -701,9 +700,7 @@ void do_input()
tiledMap->getWalk(x + xDirection, y + yDirection))
{
walk(x + xDirection, y + yDirection, Direction);
- player_node->setPath(tiledMap->findPath(
- player_node->x, player_node->y,
- x + xDirection, y + yDirection));
+ player_node->setDestination(x + xDirection, y + yDirection);
}
else if (Direction != DIR_NONE)
{
@@ -898,6 +895,7 @@ void do_parse()
being->y = get_y(RFIFOP(46));
being->direction = get_direction(RFIFOP(46));
being->setWeapon(RFIFOW(18));
+ being->setMap(tiledMap);
add_node(being);
}
else
@@ -946,6 +944,7 @@ void do_parse()
being = new Being();
being->setId(RFIFOL(2));
being->job = RFIFOW(14);
+ being->setMap(tiledMap);
add_node(being);
}
@@ -976,6 +975,7 @@ void do_parse()
being = new Being();
being->setId(RFIFOL(2));
being->job = RFIFOW(14);
+ being->setMap(tiledMap);
add_node(being);
}
@@ -984,10 +984,9 @@ void do_parse()
being->y = get_src_y(RFIFOP(50));
being->speed = RFIFOW(6);
being->job = RFIFOW(14);
- being->setPath(tiledMap->findPath(
- being->x, being->y,
+ being->setDestination(
get_dest_x(RFIFOP(50)),
- get_dest_y(RFIFOP(50))));
+ get_dest_y(RFIFOP(50)));
break;
case SMSG_MOVE_PLAYER_BEING:
@@ -999,6 +998,7 @@ void do_parse()
being = new Being();
being->setId(RFIFOL(2));
being->job = RFIFOW(14);
+ being->setMap(tiledMap);
add_node(being);
}
@@ -1010,10 +1010,9 @@ void do_parse()
being->setWeaponById(RFIFOW(18));
being->setHairColor(RFIFOW(32));
- being->setPath(tiledMap->findPath(
- being->x, being->y,
+ being->setDestination(
get_dest_x(RFIFOP(50)),
- get_dest_y(RFIFOP(50))));
+ get_dest_y(RFIFOP(50)));
break;
// NPC dialog
@@ -1216,6 +1215,7 @@ void do_parse()
player_node->frame = 0;
player_node->x = RFIFOW(18);
player_node->y = RFIFOW(20);
+ player_node->setMap(tiledMap);
current_npc = 0;
// Send "map loaded"
WFIFOW(0) = net_w_value(0x007d);
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index c93061a2..cf98dde9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -235,9 +235,7 @@ void Gui::mousePress(int mx, int my, int button)
if (state == GAME && tiledMap->getWalk(tilex, tiley)) {
walk(tilex, tiley, 0);
- player_node->setPath(tiledMap->findPath(
- player_node->x, player_node->y,
- tilex, tiley));
+ player_node->setDestination(tilex, tiley);
autoTarget = NULL;
}
diff --git a/src/map.h b/src/map.h
index 02bea4a2..bb49fca7 100644
--- a/src/map.h
+++ b/src/map.h
@@ -29,6 +29,8 @@
#include "resources/image.h"
#include <list>
+struct PATH_NODE;
+
/**
* A meta tile stores additional information about a location on a tile map.
* This is information that doesn't need to be repeated for each tile in each