summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-06-08 21:55:16 -0600
committerJared Adams <jaxad0127@gmail.com>2010-06-09 00:00:53 -0600
commitec980b3c586fc64d02ad02f31497013908056d52 (patch)
treec8a5c573bf8fc5ed2151f32cb7f8468bba31d72a /src/being.cpp
parent891d14807cd042aa90aed94558c2c8eda66d6859 (diff)
downloadmana-client-ec980b3c586fc64d02ad02f31497013908056d52.tar.gz
mana-client-ec980b3c586fc64d02ad02f31497013908056d52.tar.bz2
mana-client-ec980b3c586fc64d02ad02f31497013908056d52.tar.xz
mana-client-ec980b3c586fc64d02ad02f31497013908056d52.zip
Remove hard-coded frame counts from Being class
Also removes the Monster/Player difference in tmwAthena's Being::logic and moves the particle code from Being::setAttack to Being::Logic for tmwAthena. Reviewed-by: Chuck Miller
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp140
1 files changed, 71 insertions, 69 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 0e09126d..6bef136b 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -72,6 +72,7 @@
#include <cmath>
#define HAIR_FILE "hair.xml"
+#define PARTICLE_LOCATION "graphics/particles/"
static const int DEFAULT_BEING_WIDTH = 32;
static const int DEFAULT_BEING_HEIGHT = 32;
@@ -81,7 +82,6 @@ int Being::mNumberOfHairstyles = 1;
Being::Being(int id, Type type, int subtype, Map *map):
ActorSprite(id),
mInfo(BeingInfo::Unknown),
- mFrame(0),
mWalkTime(0),
mEmotion(0), mEmotionTime(0),
mSpeechTime(0),
@@ -380,7 +380,7 @@ void Being::handleAttack(Being *victim, int damage, AttackType type)
if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- mFrame = 0;
+ reset();
mWalkTime = tick_time;
}
@@ -570,24 +570,27 @@ void Being::setAction(Action action, int attackType)
currentAction = mInfo->getAttack(attackType)->action;
reset();
- int rotation = 0;
- //attack particle effect
- std::string particleEffect = mInfo->getAttack(attackType)
- ->particleEffect;
- if (!particleEffect.empty() && Particle::enabled)
+ if (Net::getNetworkType() == ServerInfo::MANASERV)
{
- switch (mSpriteDirection)
+ int rotation = 0;
+ //attack particle effect
+ std::string particleEffect = mInfo->getAttack(attackType)
+ ->particleEffect;
+ if (!particleEffect.empty() && Particle::enabled)
{
- case DIRECTION_DOWN: rotation = 0; break;
- case DIRECTION_LEFT: rotation = 90; break;
- case DIRECTION_UP: rotation = 180; break;
- case DIRECTION_RIGHT: rotation = 270; break;
- default: break;
+ switch (mSpriteDirection)
+ {
+ case DIRECTION_DOWN: rotation = 0; break;
+ case DIRECTION_LEFT: rotation = 90; break;
+ case DIRECTION_UP: rotation = 180; break;
+ case DIRECTION_RIGHT: rotation = 270; break;
+ default: break;
+ }
+ Particle *p;
+ p = particleEngine->addEffect(particleEffect, 0, 0,
+ rotation);
+ controlParticle(p);
}
- Particle *p;
- p = particleEngine->addEffect(particleEffect, 0, 0,
- rotation);
- controlParticle(p);
}
}
@@ -772,68 +775,67 @@ void Being::logic()
}
else if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
- if (getType() == MONSTER && (mAction != STAND))
- {
- mFrame = (int) ((get_elapsed_time(mWalkTime) * 4) / getWalkSpeed().x);
+ int frameCount = getFrameCount();
- if (mFrame >= 4 && mAction != DEAD)
- nextTile();
- }
- else if (getType() == PLAYER)
+ switch (mAction)
{
- switch (mAction)
- {
- case STAND:
- case SIT:
- case DEAD:
- case HURT:
- break;
-
- case WALK:
- mFrame = (int) ((get_elapsed_time(mWalkTime) * 6)
- / getWalkSpeed().x);
- if (mFrame >= 6)
- nextTile();
- break;
-
- case ATTACK:
- int rotation = 0;
- std::string particleEffect = "";
- int frames = 4;
+ case STAND:
+ case SIT:
+ case DEAD:
+ case HURT:
+ break;
+
+ case WALK:
+ if ((int) ((get_elapsed_time(mWalkTime) * frameCount)
+ / getWalkSpeed().x) >= frameCount)
+ nextTile();
+ break;
+
+ case ATTACK:
+ int rotation = 0;
+ std::string particleEffect = "";
- if (mEquippedWeapon &&
- mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW)
- {
- frames = 5;
- }
+ int curFrame = (get_elapsed_time(mWalkTime) * frameCount)
+ / mAttackSpeed;
- mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed;
+ //attack particle effect
+ if (mEquippedWeapon)
+ {
+ particleEffect = mEquippedWeapon->getParticleEffect();
- //attack particle effect
- if (mEquippedWeapon)
- particleEffect = mEquippedWeapon->getParticleEffect();
+ if (!particleEffect.empty() &&
+ findSameSubstring(particleEffect,
+ PARTICLE_LOCATION).empty())
+ particleEffect = PARTICLE_LOCATION +
+ particleEffect;
+ }
+ else
+ {
+ particleEffect = mInfo->getAttack(mAttackType)
+ ->particleEffect;
+ }
- if (!particleEffect.empty() && Particle::enabled && mFrame == 1)
+ if (!particleEffect.empty() && Particle::enabled
+ && curFrame == 1)
+ {
+ switch (mDirection)
{
- switch (mDirection)
- {
- case DOWN: rotation = 0; break;
- case LEFT: rotation = 90; break;
- case UP: rotation = 180; break;
- case RIGHT: rotation = 270; break;
- default: break;
- }
- Particle *p;
- p = particleEngine->addEffect("graphics/particles/" +
- particleEffect, 0, 0, rotation);
- controlParticle(p);
+ case DOWN: rotation = 0; break;
+ case LEFT: rotation = 90; break;
+ case UP: rotation = 180; break;
+ case RIGHT: rotation = 270; break;
+ default: break;
}
+ Particle *p;
+ p = particleEngine->addEffect(particleEffect, 0, 0,
+ rotation);
+ controlParticle(p);
+ }
- if (mFrame >= frames)
- nextTile();
+ if (curFrame >= frameCount)
+ nextTile();
- break;
- }
+ break;
}
// Update pixel coordinates