GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/actorsprite.h Lines: 2 36 5.6 %
Date: 2017-11-29 Branches: 0 2 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  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 BEING_ACTORSPRITE_H
23
#define BEING_ACTORSPRITE_H
24
25
#include "being/actor.h"
26
#include "being/compoundsprite.h"
27
28
#include "const/resources/map/map.h"
29
30
#include "enums/being/actortype.h"
31
#include "enums/being/targetcursorsize.h"
32
#include "enums/being/targetcursortype.h"
33
34
#include "enums/simpletypes/beingid.h"
35
#include "enums/simpletypes/enable.h"
36
#include "enums/simpletypes/forcedisplay.h"
37
#include "enums/simpletypes/isstart.h"
38
39
#include "enums/resources/displaytype.h"
40
41
#include "enums/resources/map/blocktype.h"
42
43
#include "particle/particlelist.h"
44
#include "particle/particlevector.h"
45
46
#include "localconsts.h"
47
48
class AnimatedSprite;
49
class StatusEffect;
50
class ActorSpriteListener;
51
52
struct SpriteDisplay;
53
54
class ActorSprite notfinal : public CompoundSprite, public Actor
55
{
56
    public:
57
        explicit ActorSprite(const BeingId id);
58
59
        A_DELETE_COPY(ActorSprite)
60
61
        virtual ~ActorSprite();
62
63
        BeingId getId() const noexcept2 A_WARN_UNUSED
64
10
        { return mId; }
65
66
        void setId(const BeingId id) noexcept2
67
        { mId = id; }
68
69
        /**
70
         * Returns the type of the ActorSprite.
71
         */
72
        virtual ActorTypeT getType() const noexcept2 A_WARN_UNUSED
73
        { return ActorType::Unknown; }
74
75
        virtual void logic();
76
77
        void setMap(Map *const map) override;
78
79
        /**
80
         * Gets the way the object blocks pathfinding for other objects
81
         */
82
        virtual BlockTypeT getBlockType() const A_WARN_UNUSED
83
        { return BlockType::NONE; }
84
85
        /**
86
         * Take control of a particle. Particle can be auto deleted.
87
         */
88
        void controlAutoParticle(Particle *const particle);
89
90
        /**
91
         * Take control of a particle. Owner must remove particle by self.
92
         */
93
        void controlCustomParticle(Particle *const particle);
94
95
        /**
96
         * Returns the required size of a target cursor for this being.
97
         */
98
        virtual TargetCursorSizeT getTargetCursorSize() const A_WARN_UNUSED
99
        { return TargetCursorSize::MEDIUM; }
100
101
        virtual int getTargetOffsetX() const A_WARN_UNUSED
102
        { return 0; }
103
104
        virtual int getTargetOffsetY() const A_WARN_UNUSED
105
        { return 0; }
106
107
        /**
108
         * Sets the target animation for this actor.
109
         */
110
        void setTargetType(const TargetCursorTypeT type);
111
112
        /**
113
         * Untargets the actor.
114
         */
115
        void untarget()
116
4
        { mUsedTargetCursor = nullptr; }
117
118
        void setStatusEffect(const int32_t index,
119
                             const Enable active,
120
                             const IsStart start);
121
122
        void setStatusEffectOpitons(const uint32_t option,
123
                                    const uint32_t opt1,
124
                                    const uint32_t opt2,
125
                                    const uint32_t opt3);
126
127
        void setStatusEffectOpitons(const uint32_t option,
128
                                    const uint32_t opt1,
129
                                    const uint32_t opt2);
130
131
        void setStatusEffectOpiton0(const uint32_t option);
132
133
        void setAlpha(const float alpha) override final
134
        { CompoundSprite::setAlpha(alpha); }
135
136
        float getAlpha() const override final A_WARN_UNUSED
137
        { return CompoundSprite::getAlpha(); }
138
139
        int getWidth() const override A_WARN_UNUSED
140
        { return CompoundSprite::getWidth(); }
141
142
        int getHeight() const override A_WARN_UNUSED
143
        { return CompoundSprite::getHeight(); }
144
145
        static void load();
146
147
        static void unload();
148
149
        /**
150
         * Add an ActorSprite listener.
151
         */
152
        void addActorSpriteListener(ActorSpriteListener *const listener);
153
154
        /**
155
         * Remove an ActorSprite listener.
156
         */
157
        void removeActorSpriteListener(ActorSpriteListener *const listener);
158
159
        int getActorX() const A_WARN_UNUSED
160
        { return getPixelX() - mapTileSize / 2; }
161
162
        int getActorY() const A_WARN_UNUSED
163
        { return getPixelY() - mapTileSize; }
164
165
        void setPoison(const bool b)
166
        { mPoison = b; }
167
168
        bool getPoison() const A_WARN_UNUSED
169
        { return mPoison; }
170
171
        void setHaveCart(const bool b)
172
        { mHaveCart = b; }
173
174
        bool getHaveCart() const A_WARN_UNUSED
175
        { return mHaveCart; }
176
177
        virtual void setRiding(const bool b)
178
        { mHorseId = b ? 1 : 0; }
179
180
        virtual void setTrickDead(const bool b)
181
        { mTrickDead = b; }
182
183
        bool isTrickDead() const A_WARN_UNUSED
184
        { return mTrickDead; }
185
186
        const std::set<int32_t> &getStatusEffects() const A_WARN_UNUSED
187
        { return mStatusEffects; }
188
189
        std::string getStatusEffectsString() const;
190
191
        virtual void stopCast(const bool b A_UNUSED)
192
        { }
193
194
        size_t getParticlesCount() const
195
        {
196
            return mStatusParticleEffects.usedSize() +
197
                mChildParticleEffects.size();
198
        }
199
200
        void controlParticleDeleted(const Particle *const particle);
201
202
    protected:
203
        /**
204
         * A status effect block is a 16 bit mask of status effects. We assign
205
         * each such flag a block ID of offset + bitnr.
206
         *
207
         * These are NOT the same as the status effect indices.
208
         */
209
        void setStatusEffectBlock(const int offset,
210
                                  const uint16_t newEffects);
211
212
        /**
213
         * Notify self that a status effect has flipped.
214
         * The new flag is passed.
215
         */
216
        virtual void updateStatusEffect(const int32_t index,
217
                                        const Enable newStatus,
218
                                        const IsStart start);
219
220
        /**
221
         * Handle an update to a status or stun effect
222
         *
223
         * \param The StatusEffect to effect
224
         * \param effectId -1 for stun, otherwise the effect index
225
         */
226
        virtual void handleStatusEffect(const StatusEffect *const effect,
227
                                        const int32_t effectId,
228
                                        const Enable newStatus,
229
                                        const IsStart start);
230
231
        void setupSpriteDisplay(const SpriteDisplay &display,
232
                                const ForceDisplay forceDisplay,
233
                                const DisplayTypeT displayType,
234
                                const std::string &color);
235
236
        /** Load the target cursors into memory */
237
        static void initTargetCursor();
238
239
        /** Remove the target cursors from memory */
240
        static void cleanupTargetCursors();
241
242
        /** Animated target cursors. */
243
        static AnimatedSprite *targetCursor
244
            [CAST_SIZE(TargetCursorType::NUM_TCT)]
245
            [CAST_SIZE(TargetCursorSize::NUM_TC)];
246
247
        static bool loaded;
248
249
        /**< set of active status effects */
250
        std::set<int32_t> mStatusEffects;
251
252
        ParticleVector mStatusParticleEffects;
253
        ParticleList mChildParticleEffects;
254
        int mHorseId;
255
        BeingId mId;
256
257
        /** Target cursor being used */
258
        AnimatedSprite *mUsedTargetCursor;
259
260
        typedef std::list<ActorSpriteListener*> ActorSpriteListeners;
261
        typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator;
262
        ActorSpriteListeners mActorSpriteListeners;
263
264
        int mCursorPaddingX;
265
        int mCursorPaddingY;
266
267
        /** Reset particle status effects on next redraw? */
268
        bool mMustResetParticles;
269
        bool mPoison;
270
        bool mHaveCart;
271
        bool mTrickDead;
272
};
273
274
#endif  // BEING_ACTORSPRITE_H