1
/*
2
 *  The Mana World
3
 *  Copyright (C) 2006  The Mana World Development Team
4
 *
5
 *  This file is part of The Mana World.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 */
21
22
#ifndef PARTICLEEMITTER_H
23
#define PARTICLEEMITTER_H
24
25
#include <list>
26
27
#include "utils/xml.h"
28
29
#include "particleemitterprop.h"
30
31
#include "resources/animation.h"
32
33
class Image;
34
class Map;
35
class Particle;
36
37
/**
38
 * Every Particle can have one or more particle emitters that create new
39
 * particles when they are updated
40
 */
41
class ParticleEmitter
42
{
43
    public:
44
        /**
45
         * Constructor.
46
         */
47
        ParticleEmitter(xmlNodePtr emitterNode,  Particle *target, Map *map, int rotation = 0);
48
49
        /**
50
         * Copy Constructor (necessary for reference counting of particle images)
51
         */
52
        ParticleEmitter(const ParticleEmitter &o);
53
54
        /**
55
         * Assignment operator that calls the copy constructor
56
         */
57
        ParticleEmitter & operator=(const ParticleEmitter &o);
58
59
        /**
60
         * Destructor.
61
         */
62
        ~ParticleEmitter();
63
64
        /**
65
         * Spawns new particles
66
         * @return: a list of created particles
67
         */
68
        std::list<Particle *> createParticles(int tick);
69
70
        /**
71
         * Sets the target of the particles that are created
72
         */
73
        void setTarget(Particle *target)
74
        { mParticleTarget = target; };
75
76
    private:
77
        template <typename T> ParticleEmitterProp<T> readParticleEmitterProp(xmlNodePtr propertyNode, T def);
78
79
        /**
80
         * initial position of particles:
81
         */
82
        ParticleEmitterProp<float> mParticlePosX, mParticlePosY, mParticlePosZ;
83
84
        /**
85
         * initial vector of particles:
86
         */
87
        ParticleEmitterProp<float> mParticleAngleHorizontal, mParticleAngleVertical;
88
89
        /**
90
         * Initial velocity of particles
91
         */
92
        ParticleEmitterProp<float> mParticlePower;
93
94
        /*
95
         * Vector changing of particles:
96
         */
97
        ParticleEmitterProp<float> mParticleGravity;
98
        ParticleEmitterProp<int> mParticleRandomness;
99
        ParticleEmitterProp<float> mParticleBounce;
100
        bool mParticleFollow;
101
102
        /*
103
         * Properties of targeting particles:
104
         */
105
        Particle *mParticleTarget;
106
        ParticleEmitterProp<float> mParticleAcceleration;
107
        ParticleEmitterProp<float> mParticleDieDistance;
108
        ParticleEmitterProp<float> mParticleMomentum;
109
110
        /*
111
         * Behavior over time of the particles:
112
         */
113
        ParticleEmitterProp<int> mParticleLifetime;
114
        ParticleEmitterProp<int> mParticleFadeOut;
115
        ParticleEmitterProp<int> mParticleFadeIn;
116
117
        Map *mMap;             /**< Map the particles are spawned on */
118
119
        ParticleEmitterProp<int> mOutput;   /**< Number of particles spawned per update */
120
        ParticleEmitterProp<int> mOutputPause; /**< Pause in frames between two spawns */
121
        int mOutputPauseLeft;
122
123
        /*
124
         * Graphical representation of the particle
125
         */
126
        Image *mParticleImage; /**< Particle image, if used */
127
        Animation mParticleAnimation; /**< Filename of particle animation file */
128
        Animation mParticleRotation; /**< Filename of particle rotation file */
129
        ParticleEmitterProp<float> mParticleAlpha; /**< Opacity of the graphical representation of the particles */
130
131
        /** List of emitters the spawned particles are equipped with */
132
        std::list<ParticleEmitter> mParticleChildEmitters;
133
};
134
#endif