summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-16 22:49:25 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-16 22:49:25 +0000
commit5026eca4d9818d32fe69571c1c621aa318bc4d48 (patch)
treee6bb7e0d962f4ca64f19b91c58b338eee1597aff /src
parent9ee453c73292d460eda49129beddf00d21ea81c7 (diff)
downloadmana-client-5026eca4d9818d32fe69571c1c621aa318bc4d48.tar.gz
mana-client-5026eca4d9818d32fe69571c1c621aa318bc4d48.tar.bz2
mana-client-5026eca4d9818d32fe69571c1c621aa318bc4d48.tar.xz
mana-client-5026eca4d9818d32fe69571c1c621aa318bc4d48.zip
Added new barber by Neko-mon and moved being logic into Being class.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp50
-rw-r--r--src/being.h15
-rw-r--r--src/engine.cpp33
-rw-r--r--src/main.cpp2
4 files changed, 55 insertions, 45 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 00d06a15..8fe61f14 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -40,8 +40,9 @@ PATH_NODE::PATH_NODE(unsigned short x, unsigned short y):
void add_node(Being *being)
{
beings.push_back(being);
+
// If the being is a player, request the name
- if (being-> job < 10) {
+ if (being->isPlayer()) {
WFIFOW(0) = net_w_value(0x0094);
WFIFOL(2) = net_l_value(RFIFOL(2));
WFIFOSET(6);
@@ -96,7 +97,7 @@ unsigned int findPlayer(unsigned short x, unsigned short y)
for (i = beings.begin(); i != beings.end(); i++) {
Being *being = (*i);
// Check if is a player
- if (being->job < 10 && being->x == x && being->y == y) {
+ if (being->isPlayer() && being->x == x && being->y == y) {
return being->id;
}
}
@@ -109,7 +110,7 @@ unsigned int findMonster(unsigned short x, unsigned short y)
for (i = beings.begin(); i != beings.end(); i++) {
Being *being = (*i);
// Check if is a MONSTER that is alive
- if (being->job > 200 && being->x == x && being->y == y &&
+ if (being->isMonster() && being->x == x && being->y == y &&
being->action != MONSTER_DEAD)
{
return being->id;
@@ -164,11 +165,11 @@ Being::Being():
emotion(0), emotion_time(0),
text_x(0), text_y(0),
weapon(0),
+ aspd(350),
+ hairStyle(1), hairColor(1),
speech_time(0),
damage_time(0),
- showSpeech(false), showDamage(false),
- aspd(350),
- hairStyle(1), hairColor(1)
+ showSpeech(false), showDamage(false)
{
strcpy(name, "");
}
@@ -204,7 +205,7 @@ void Being::setDestination(int destX, int destY)
void Being::setHairColor(int color)
{
hairColor = color;
- if (hairColor < 1 || hairColor > 11)
+ if (hairColor < 1 || hairColor > NR_HAIR_COLORS + 1)
{
hairColor = 1;
}
@@ -286,6 +287,41 @@ void Being::nextStep()
frame = 0;
}
+void Being::logic()
+{
+ if (isPlayer())
+ {
+ switch (action) {
+ case WALK:
+ frame = (get_elapsed_time(walk_time) * 4) / speed;
+ if (frame >= 4) {
+ nextStep();
+ }
+ break;
+ case ATTACK:
+ frame = (get_elapsed_time(walk_time) * 4) / aspd;
+ if (frame >= 4) {
+ nextStep();
+ }
+ break;
+ }
+
+ if (emotion != 0) {
+ emotion_time--;
+ if (emotion_time == 0) {
+ emotion = 0;
+ }
+ }
+ }
+
+ if (get_elapsed_time(speech_time) > 5000) {
+ showSpeech = false;
+ }
+ if (get_elapsed_time(damage_time) > 3000) {
+ showDamage = false;
+ }
+}
+
void Being::drawSpeech(Graphics *graphics)
{
// Draw speech above this being
diff --git a/src/being.h b/src/being.h
index 8224a729..a2390f89 100644
--- a/src/being.h
+++ b/src/being.h
@@ -56,14 +56,11 @@ class Being
unsigned short speed;
unsigned char emotion;
unsigned char emotion_time;
- unsigned int text_x, text_y; // temp solution to fix speech position
+ unsigned int text_x, text_y; // temp solution to fix speech position
unsigned short weapon;
char name[24];
- unsigned int speech_time;
- unsigned int damage_time;
- bool showSpeech, showDamage;
- unsigned short aspd; // attack speed
+ unsigned short aspd; /**< Attack speed */
/**
* Constructor.
@@ -136,6 +133,11 @@ class Being
void nextStep();
/**
+ * Performs being logic.
+ */
+ void logic();
+
+ /**
* Draws the speech text above the being.
*/
void drawSpeech(Graphics *graphics);
@@ -165,6 +167,9 @@ class Being
std::string speech;
std::string damage;
unsigned short hairStyle, hairColor;
+ unsigned int speech_time;
+ unsigned int damage_time;
+ bool showSpeech, showDamage;
};
/** Add a Being to the list */
diff --git a/src/engine.cpp b/src/engine.cpp
index adda6d06..2d93a842 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -272,38 +272,7 @@ void Engine::logic()
{
Being *being = (*beingIterator);
- if (being->job < 10) { // A player
- switch (being->action) {
- case WALK:
- being->frame = (get_elapsed_time(being->walk_time) * 4) /
- (being->speed);
- if (being->frame >= 4) {
- being->nextStep();
- }
- break;
- case ATTACK:
- being->frame = (get_elapsed_time(being->walk_time) * 4) /
- (being->aspd);
- if (being->frame >= 4) {
- being->nextStep();
- }
- break;
- default:
- break;
- }
-
- if (being->emotion != 0) {
- being->emotion_time--;
- if (being->emotion_time == 0) {
- being->emotion = 0;
- }
- }
- }
-
- if (get_elapsed_time(being->speech_time) > 5000)
- being->showSpeech = false;
- if (get_elapsed_time(being->damage_time) > 3000)
- being->showDamage = false;
+ being->logic();
if (being->action == MONSTER_DEAD && being->frame >= 20) {
delete being;
diff --git a/src/main.cpp b/src/main.cpp
index 923ceb9c..daa41569 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -250,7 +250,7 @@ void init_engine()
const SDL_VideoInfo *vi = SDL_GetVideoInfo();
logger->log("Possible to create hardware surfaces: %s",
- ((vi->hw_available) ? "yes" : "no "));
+ ((vi->hw_available) ? "yes" : "no"));
logger->log("Window manager available: %s",
((vi->wm_available) ? "yes" : "no"));
logger->log("Accelerated hardware to hardware blits: %s",