summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-21 13:31:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-21 13:31:36 +0000
commite0a956b4045ca09631d9a9a616ca675f2c1f4a78 (patch)
treeb98a0bf6970c76a226436effed21f44611015e4f /src/being.cpp
parentad12a9189f33e65de827219eb573a6e63c7862c9 (diff)
downloadmana-client-e0a956b4045ca09631d9a9a616ca675f2c1f4a78.tar.gz
mana-client-e0a956b4045ca09631d9a9a616ca675f2c1f4a78.tar.bz2
mana-client-e0a956b4045ca09631d9a9a616ca675f2c1f4a78.tar.xz
mana-client-e0a956b4045ca09631d9a9a616ca675f2c1f4a78.zip
Some refactoring of Being class.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp113
1 files changed, 89 insertions, 24 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 18b78289..b9632424 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -24,6 +24,7 @@
#include <stdio.h>
#include "astar.h"
#include "being.h"
+#include "game.h"
Being *player_node = NULL;
@@ -117,24 +118,11 @@ void sort() {
beings.sort(BeingCompare());
}
-void empty_path(Being *being) {
- if (being) {
- PATH_NODE *temp = being->path;
- PATH_NODE *next;
- while (temp) {
- next = temp->next;
- delete temp;
- temp = next;
- }
- being->path = NULL;
- }
-}
-
Being::Being() {
id = 0; job = 0;
action = 0; frame = 0;
path = NULL; speech = NULL; speech_time = 0;
- tick_time = 0; speed = 150;
+ walk_time = 0; speed = 150;
emotion = 0; emotion_time = 0;
text_x = 0; text_y = 0;
hair_style = 1; hair_color = 1;
@@ -144,17 +132,94 @@ Being::Being() {
}
Being::~Being() {
- if (path) {
- PATH_NODE *temp = path;
- PATH_NODE *next;
- while (temp) {
- next = temp->next;
- delete temp;
- temp = next;
- }
- path = NULL;
- }
+ clearPath();
if (speech) {
free(speech);
}
}
+
+void Being::clearPath() {
+ PATH_NODE *temp = path;
+ PATH_NODE *next;
+ while (temp) {
+ next = temp->next;
+ delete temp;
+ temp = next;
+ }
+ path = NULL;
+}
+
+void Being::setPath(PATH_NODE *path)
+{
+ clearPath();
+ this->path = path;
+ if (path != NULL) {
+ direction = 0;
+ if (path->next) {
+ if (path->next->x > path->x && path->next->y > path->y)
+ direction = SE;
+ else if (path->next->x < path->x && path->next->y > path->y)
+ direction = SW;
+ else if (path->next->x > path->x && path->next->y < path->y)
+ direction = NE;
+ else if (path->next->x < path->x && path->next->y < path->y)
+ direction = NW;
+ else if (path->next->x > path->x)
+ direction = EAST;
+ else if (path->next->x < path->x)
+ direction = WEST;
+ else if (path->next->y > path->y)
+ direction = SOUTH;
+ else if (path->next->y < path->y)
+ direction = NORTH;
+ }
+ PATH_NODE *pn = path;
+ this->path = path->next;
+ free(pn);
+ x = this->path->x;
+ y = this->path->y;
+ action = WALK;
+ walk_time = tick_time;
+ frame = 0;
+ }
+}
+
+bool Being::hasPath()
+{
+ return path != NULL;
+}
+
+void Being::nextStep()
+{
+ if (path->next) {
+ int old_x, old_y, new_x, new_y;
+ old_x = path->x;
+ old_y = path->y;
+ path = path->next;
+ new_x = path->x;
+ new_y = path->y;
+ direction = 0;
+
+ if (new_x > old_x) {
+ if (new_y > old_y) direction = SE;
+ else if (new_y < old_y) direction = NE;
+ else direction = EAST;
+ }
+ else if (new_x < old_x) {
+ if (new_y > old_y) direction = SW;
+ else if (new_y < old_y) direction = NW;
+ else direction = WEST;
+ }
+ else {
+ if (new_y > old_y) direction = SOUTH;
+ else if (new_y < old_y) direction = NORTH;
+ }
+
+ x = path->x;
+ y = path->y;
+ } else {
+ action = STAND;
+ }
+ frame = 0;
+ walk_time = tick_time;
+}