summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-09 20:41:27 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-09 20:41:27 +0000
commit4e2ced304a2013808b2481cceb7622848b073e5b (patch)
tree2cc2c6cbc3f6e17842919530d583f91256dc86e1
parent15014d358424bf5f74a2d9b7afd08692b591a448 (diff)
downloadmana-client-4e2ced304a2013808b2481cceb7622848b073e5b.tar.gz
mana-client-4e2ced304a2013808b2481cceb7622848b073e5b.tar.bz2
mana-client-4e2ced304a2013808b2481cceb7622848b073e5b.tar.xz
mana-client-4e2ced304a2013808b2481cceb7622848b073e5b.zip
Implemented possibility to rotate particle emitters. Implemented interpretation of the attacktype parameter of attack messages and visualize monster attacks other than id 1 with a particle effect. Prepared to get attack particle effects and animation types from the monster database.
-rw-r--r--ChangeLog12
-rw-r--r--src/being.cpp2
-rw-r--r--src/being.h2
-rw-r--r--src/monster.cpp27
-rw-r--r--src/monster.h2
-rw-r--r--src/net/beinghandler.cpp9
-rw-r--r--src/particle.cpp4
-rw-r--r--src/particle.h2
-rw-r--r--src/particleemitter.cpp9
-rw-r--r--src/particleemitter.h2
-rw-r--r--src/resources/monsterinfo.cpp15
-rw-r--r--src/resources/monsterinfo.h8
-rw-r--r--src/utils/minmax.h21
13 files changed, 98 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 0df6b3fc..658239ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-03-09 Philipp Sehmisch <tmw@crushnet.org>
+
+ * src/particle.cpp, src/particle.h, src/particleemitter.cpp,
+ src/particleemitter.h, src/utils/minmax.h: Implemented possibility
+ to rotate particle emitters.
+ * src/being.cpp, src/being.h, src/monster.cpp, src/monster.h,
+ src/net/beinghandler.cpp, src/resources/monsterinfo.cpp,
+ src/resources/monsterinfo.h: Implemented interpretation of the
+ attacktype parameter of attack messages and visualize monster attacks
+ other than id 1 with a particle effect. Prepared to get attack particle
+ effects and animation types from the monster database.
+
2008-03-06 David Athay <ko2fan@gmail.com>
* src/net/guildhandler.cpp, src/net/guildhandler.hpp: Fixed
diff --git a/src/being.cpp b/src/being.cpp
index 20684d8d..a55158c6 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -373,7 +373,7 @@ Being::controlParticle(Particle *particle)
}
void
-Being::setAction(Action action)
+Being::setAction(Action action, int attackType)
{
SpriteAction currentAction = ACTION_INVALID;
switch (action)
diff --git a/src/being.h b/src/being.h
index a2d977db..0b56994e 100644
--- a/src/being.h
+++ b/src/being.h
@@ -262,7 +262,7 @@ class Being : public Sprite
* Sets the current action.
*/
virtual void
- setAction(Action action);
+ setAction(Action action, int attackType = 0);
/**
* Returns the direction the being is facing.
diff --git a/src/monster.cpp b/src/monster.cpp
index ae749017..5fbcfaea 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -25,6 +25,7 @@
#include "animatedsprite.h"
#include "game.h"
+#include "particle.h"
#include "sound.h"
#include "resources/monsterdb.h"
@@ -50,9 +51,11 @@ Monster::getType() const
}
void
-Monster::setAction(Action action)
+Monster::setAction(Action action, int attackType)
{
SpriteAction currentAction = ACTION_INVALID;
+ int rotation = 0;
+ std::string particleEffect;
switch (action)
{
@@ -64,8 +67,26 @@ Monster::setAction(Action action)
sound.playSfx(getInfo().getSound(MONSTER_EVENT_DIE));
break;
case ATTACK:
- currentAction = ACTION_ATTACK;
- mSprites[BASE_SPRITE]->reset();
+ currentAction = getInfo().getAttackAction(attackType);
+
+ //attack particle effect
+ particleEffect = getInfo().getAttackParticleEffect(attackType);
+ if (particleEffect != "")
+ {
+ switch (mDirection)
+ {
+ case DOWN: rotation = 0; break;
+ case LEFT: rotation = 90; break;
+ case UP: rotation = 180; break;
+ case RIGHT: rotation = 270; break;
+ default: break;
+ }
+ mSprites[BASE_SPRITE]->reset();
+ Particle *p;
+ p = particleEngine->addEffect(
+ particleEffect, 0, 0, rotation);
+ controlParticle(p);
+ }
break;
case STAND:
currentAction = ACTION_STAND;
diff --git a/src/monster.h b/src/monster.h
index fc46e11a..585f6f09 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -33,7 +33,7 @@ class Monster : public Being
public:
Monster(Uint16 id, Uint16 job, Map *map);
- virtual void setAction(Action action);
+ virtual void setAction(Action action, int attackType);
virtual Type getType() const;
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 3e55cce9..05795cb1 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -569,10 +569,11 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg)
void BeingHandler::handleBeingAttackMessage(MessageIn &msg)
{
Being *being = beingManager->findBeing(msg.readInt16());
+ int direction = msg.readInt8();
+ int attackType = msg.readInt8();
+
if (!being) return;
- being->setAction(Being::ATTACK);
- int direction = msg.readInt8();
switch (direction)
{
case DIRECTION_UP: being->setDirection(Being::UP); break;
@@ -580,6 +581,10 @@ void BeingHandler::handleBeingAttackMessage(MessageIn &msg)
case DIRECTION_LEFT: being->setDirection(Being::LEFT); break;
case DIRECTION_RIGHT: being->setDirection(Being::RIGHT); break;
}
+
+ logger->log("Attacktype: %d", attackType);
+
+ being->setAction(Being::ATTACK, attackType);
}
void BeingHandler::handleBeingsDamageMessage(MessageIn &msg)
diff --git a/src/particle.cpp b/src/particle.cpp
index dac8c62e..11d91b47 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -212,7 +212,7 @@ Particle::update()
Particle*
Particle::addEffect(const std::string &particleEffectFile,
- int pixelX, int pixelY)
+ int pixelX, int pixelY, int rotation)
{
Particle *newParticle = NULL;
@@ -294,7 +294,7 @@ Particle::addEffect(const std::string &particleEffectFile,
continue;
ParticleEmitter *newEmitter;
- newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap);
+ newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, rotation);
newParticle->addEmitter(newEmitter);
}
diff --git a/src/particle.h b/src/particle.h
index 0dd34065..1859fe62 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -109,7 +109,7 @@ class Particle : public Sprite
*/
Particle*
addEffect(const std::string &particleEffectFile,
- int pixelX, int pixelY);
+ int pixelX, int pixelY, int rotation = 0);
/**
* Creates a standalone text particle.
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 6f66b632..f03490ac 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -38,7 +38,7 @@
#define SIN45 0.707106781f
#define DEG_RAD_FACTOR 0.017453293f
-ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map):
+ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map, int rotation):
mParticleImage(0)
{
mMap = map;
@@ -98,14 +98,13 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
else if (name == "horizontal-angle")
{
mParticleAngleHorizontal = readMinMax(propertyNode, 0.0f);
- mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR;
- mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR;
+ mParticleAngleHorizontal += rotation;
+ mParticleAngleHorizontal *= DEG_RAD_FACTOR;
}
else if (name == "vertical-angle")
{
mParticleAngleVertical = readMinMax(propertyNode, 0.0f);
- mParticleAngleVertical.minVal *= DEG_RAD_FACTOR;
- mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR;
+ mParticleAngleVertical *= DEG_RAD_FACTOR;
}
else if (name == "power")
{
diff --git a/src/particleemitter.h b/src/particleemitter.h
index c9524488..f5ca6232 100644
--- a/src/particleemitter.h
+++ b/src/particleemitter.h
@@ -45,7 +45,7 @@ class ParticleEmitter
/**
* Constructor.
*/
- ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map);
+ ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map, int rotation = 0);
/**
* Copy Constructor (necessary for reference counting of particle images)
diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp
index 0a7e18dc..0ee08e42 100644
--- a/src/resources/monsterinfo.cpp
+++ b/src/resources/monsterinfo.cpp
@@ -70,3 +70,18 @@ MonsterInfo::getSound(MonsterSoundEvent event) const
return i->second->at(rand()%i->second->size());
}
}
+
+const std::string &
+MonsterInfo::getAttackParticleEffect(int attackType) const
+{
+ static std::string something("graphics/particles/attack.particle.xml");
+ static std::string nothing("");
+
+ if (attackType > 1) return something; else return nothing;
+}
+
+SpriteAction
+MonsterInfo::getAttackAction(int attackType) const
+{
+ return ACTION_ATTACK;
+}
diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h
index 3034f10e..3dd18c0f 100644
--- a/src/resources/monsterinfo.h
+++ b/src/resources/monsterinfo.h
@@ -83,6 +83,14 @@ class MonsterInfo
std::string
getSound(MonsterSoundEvent event) const;
+ const std::string &
+ getAttackParticleEffect(int attackType) const;
+
+ SpriteAction
+ getAttackAction(int attackType) const;
+
+
+
private:
std::string mName;
std::string mSprite;
diff --git a/src/utils/minmax.h b/src/utils/minmax.h
index 427c5da7..353c60e7 100644
--- a/src/utils/minmax.h
+++ b/src/utils/minmax.h
@@ -40,6 +40,27 @@ template <typename T> struct MinMax
set(val, val);
}
+ bool operator+= (T arg)
+ {
+ minVal += arg;
+ maxVal += arg;
+ return true;
+ }
+
+ bool operator-= (T arg)
+ {
+ minVal -= arg;
+ maxVal -= arg;
+ return true;
+ }
+
+ bool operator*= (T arg)
+ {
+ minVal *= arg;
+ maxVal *= arg;
+ return true;
+ }
+
T value()
{
return (T)(minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1)));