~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/actorsprite.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  The ManaPlus Client
3
 
 *  Copyright (C) 2010  The Mana Developers
4
 
 *  Copyright (C) 2011-2013  The ManaPlus Developers
5
 
 *
6
 
 *  This file is part of The ManaPlus Client.
7
 
 *
8
 
 *  This program is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License as published by
10
 
 *  the Free Software Foundation; either version 2 of the License, or
11
 
 *  any later version.
12
 
 *
13
 
 *  This program is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *  GNU General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU General Public License
19
 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 */
21
 
 
22
 
#ifndef ACTORSPRITE_H
23
 
#define ACTORSPRITE_H
24
 
 
25
 
#include "actor.h"
26
 
#include "compoundsprite.h"
27
 
#include "localconsts.h"
28
 
#include "map.h"
29
 
#include "particlecontainer.h"
30
 
 
31
 
#include <SDL_types.h>
32
 
 
33
 
#include <set>
34
 
#include <list>
35
 
 
36
 
#include "localconsts.h"
37
 
 
38
 
class AnimatedSprite;
39
 
class StatusEffect;
40
 
class ActorSpriteListener;
41
 
 
42
 
class ActorSprite : public CompoundSprite, public Actor
43
 
{
44
 
public:
45
 
    enum Type
46
 
    {
47
 
        UNKNOWN = 0,
48
 
        PLAYER,
49
 
        NPC,
50
 
        MONSTER,
51
 
        FLOOR_ITEM,
52
 
        PORTAL,
53
 
        PET,
54
 
        AVATAR
55
 
    };
56
 
 
57
 
    enum TargetCursorSize
58
 
    {
59
 
        TC_SMALL = 0,
60
 
        TC_MEDIUM,
61
 
        TC_LARGE,
62
 
        NUM_TC
63
 
    };
64
 
 
65
 
    enum TargetCursorType
66
 
    {
67
 
        TCT_NONE = -1,
68
 
        TCT_NORMAL = 0,
69
 
        TCT_IN_RANGE,
70
 
        NUM_TCT
71
 
    };
72
 
 
73
 
    explicit ActorSprite(const int id);
74
 
 
75
 
    A_DELETE_COPY(ActorSprite)
76
 
 
77
 
    ~ActorSprite();
78
 
 
79
 
    int getId() const A_WARN_UNUSED
80
 
    { return mId; }
81
 
 
82
 
    void setId(const int id)
83
 
    { mId = id; }
84
 
 
85
 
    /**
86
 
     * Returns the type of the ActorSprite.
87
 
     */
88
 
    virtual Type getType() const A_WARN_UNUSED
89
 
    { return UNKNOWN; }
90
 
 
91
 
    virtual bool draw(Graphics *const graphics,
92
 
                      const int offsetX, const int offsetY) const override;
93
 
 
94
 
    virtual bool drawSpriteAt(Graphics *const graphics,
95
 
                              const int x, const int y) const;
96
 
 
97
 
    virtual void logic();
98
 
 
99
 
    static void actorLogic();
100
 
 
101
 
    void setMap(Map *const map) override;
102
 
 
103
 
    /**
104
 
     * Gets the way the object blocks pathfinding for other objects
105
 
     */
106
 
    virtual Map::BlockType getBlockType() const A_WARN_UNUSED
107
 
    { return Map::BLOCKTYPE_NONE; }
108
 
 
109
 
    /**
110
 
     * Take control of a particle.
111
 
     */
112
 
    void controlParticle(Particle *const particle);
113
 
 
114
 
    /**
115
 
     * Returns the required size of a target cursor for this being.
116
 
     */
117
 
    virtual TargetCursorSize getTargetCursorSize() const A_WARN_UNUSED
118
 
    { return TC_MEDIUM; }
119
 
 
120
 
    virtual int getTargetOffsetX() const A_WARN_UNUSED
121
 
    { return 0; }
122
 
 
123
 
    virtual int getTargetOffsetY() const A_WARN_UNUSED
124
 
    { return 0; }
125
 
 
126
 
    /**
127
 
     * Sets the target animation for this actor.
128
 
     */
129
 
    void setTargetType(const TargetCursorType type);
130
 
 
131
 
    /**
132
 
     * Untargets the actor.
133
 
     */
134
 
    void untarget()
135
 
    { mUsedTargetCursor = nullptr; }
136
 
 
137
 
    /**
138
 
     * Sets the actor's stun mode. If zero, the being is `normal', otherwise it
139
 
     * is `stunned' in some fashion.
140
 
     */
141
 
    void setStunMode(const uint16_t stunMode)
142
 
    {
143
 
        if (mStunMode != stunMode)
144
 
            updateStunMode(mStunMode, stunMode);
145
 
        mStunMode = stunMode;
146
 
    }
147
 
 
148
 
    void setStatusEffect(const int index, const bool active);
149
 
 
150
 
    /**
151
 
     * A status effect block is a 16 bit mask of status effects. We assign each
152
 
     * such flag a block ID of offset + bitnr.
153
 
     *
154
 
     * These are NOT the same as the status effect indices.
155
 
     */
156
 
    void setStatusEffectBlock(const int offset, const uint16_t flags);
157
 
 
158
 
    virtual void setAlpha(const float alpha) override
159
 
    { CompoundSprite::setAlpha(alpha); }
160
 
 
161
 
    virtual float getAlpha() const override A_WARN_UNUSED
162
 
    { return CompoundSprite::getAlpha(); }
163
 
 
164
 
    virtual int getWidth() const override A_WARN_UNUSED
165
 
    { return CompoundSprite::getWidth(); }
166
 
 
167
 
    virtual int getHeight() const override A_WARN_UNUSED
168
 
    { return CompoundSprite::getHeight(); }
169
 
 
170
 
    static void load();
171
 
 
172
 
    static void unload();
173
 
 
174
 
    /**
175
 
     * Add an ActorSprite listener.
176
 
     */
177
 
    void addActorSpriteListener(ActorSpriteListener *const listener);
178
 
 
179
 
    /**
180
 
     * Remove an ActorSprite listener.
181
 
     */
182
 
    void removeActorSpriteListener(ActorSpriteListener *const listener);
183
 
 
184
 
protected:
185
 
    /**
186
 
     * Notify self that the stun mode has been updated. Invoked by
187
 
     * setStunMode if something changed.
188
 
     */
189
 
    virtual void updateStunMode(const int oldMode, const int newMode);
190
 
 
191
 
    /**
192
 
     * Notify self that a status effect has flipped.
193
 
     * The new flag is passed.
194
 
     */
195
 
    virtual void updateStatusEffect(const int index, const bool newStatus);
196
 
 
197
 
    /**
198
 
     * Handle an update to a status or stun effect
199
 
     *
200
 
     * \param The StatusEffect to effect
201
 
     * \param effectId -1 for stun, otherwise the effect index
202
 
     */
203
 
    virtual void handleStatusEffect(StatusEffect *const effect,
204
 
                                    const int effectId);
205
 
 
206
 
    void setupSpriteDisplay(const SpriteDisplay &display,
207
 
                            const bool forceDisplay = true,
208
 
                            const int imageType = 0,
209
 
                            const std::string &color = "");
210
 
 
211
 
    std::set<int> mStatusEffects;   /**< set of active status effects */
212
 
 
213
 
    ParticleList mStunParticleEffects;
214
 
    ParticleVector mStatusParticleEffects;
215
 
    ParticleList mChildParticleEffects;
216
 
    int mId;
217
 
    uint16_t mStunMode;               /**< Stun mode; zero if not stunned */
218
 
 
219
 
private:
220
 
    /** Load the target cursors into memory */
221
 
    static void initTargetCursor();
222
 
 
223
 
    /** Remove the target cursors from memory */
224
 
    static void cleanupTargetCursors();
225
 
 
226
 
    /** Animated target cursors. */
227
 
    static AnimatedSprite *targetCursor[NUM_TCT][NUM_TC];
228
 
 
229
 
    static bool loaded;
230
 
 
231
 
    /** Target cursor being used */
232
 
    AnimatedSprite *mUsedTargetCursor;
233
 
 
234
 
    typedef std::list<ActorSpriteListener*> ActorSpriteListeners;
235
 
    typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator;
236
 
    ActorSpriteListeners mActorSpriteListeners;
237
 
 
238
 
    int mCursorPaddingX;
239
 
    int mCursorPaddingY;
240
 
 
241
 
    /** Reset particle status effects on next redraw? */
242
 
    bool mMustResetParticles;
243
 
};
244
 
 
245
 
#endif  // ACTORSPRITE_H