GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/actorsprite.h Lines: 2 36 5.6 %
Date: 2018-09-20 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-2018  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
        ~ActorSprite() override;
62
63
        BeingId getId() const noexcept2 A_WARN_UNUSED
64
5
        { 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
2
        { 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
         * Notify self that a status effect has flipped.
205
         * The new flag is passed.
206
         */
207
        virtual void updateStatusEffect(const int32_t index,
208
                                        const Enable newStatus,
209
                                        const IsStart start);
210
211
        /**
212
         * Handle an update to a status or stun effect
213
         *
214
         * \param The StatusEffect to effect
215
         * \param effectId -1 for stun, otherwise the effect index
216
         */
217
        virtual void handleStatusEffect(const StatusEffect *const effect,
218
                                        const int32_t effectId,
219
                                        const Enable newStatus,
220
                                        const IsStart start);
221
222
        void setupSpriteDisplay(const SpriteDisplay &display,
223
                                const ForceDisplay forceDisplay,
224
                                const DisplayTypeT displayType,
225
                                const std::string &color);
226
227
        /** Load the target cursors into memory */
228
        static void initTargetCursor();
229
230
        /** Remove the target cursors from memory */
231
        static void cleanupTargetCursors();
232
233
        /** Animated target cursors. */
234
        static AnimatedSprite *targetCursor
235
            [CAST_SIZE(TargetCursorType::NUM_TCT)]
236
            [CAST_SIZE(TargetCursorSize::NUM_TC)];
237
238
        static bool loaded;
239
240
        /**< set of active status effects */
241
        std::set<int32_t> mStatusEffects;
242
243
        ParticleVector mStatusParticleEffects;
244
        ParticleList mChildParticleEffects;
245
        int mHorseId;
246
        BeingId mId;
247
248
        /** Target cursor being used */
249
        AnimatedSprite *mUsedTargetCursor;
250
251
        typedef std::list<ActorSpriteListener*> ActorSpriteListeners;
252
        typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator;
253
        ActorSpriteListeners mActorSpriteListeners;
254
255
        int mCursorPaddingX;
256
        int mCursorPaddingY;
257
258
        /** Reset particle status effects on next redraw? */
259
        bool mMustResetParticles;
260
        bool mPoison;
261
        bool mHaveCart;
262
        bool mTrickDead;
263
};
264
265
#endif  // BEING_ACTORSPRITE_H