GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/being.h Lines: 19 120 15.8 %
Date: 2018-06-18 21:15:35 Branches: 0 34 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2018  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef BEING_BEING_H
24
#define BEING_BEING_H
25
26
#include "position.h"
27
28
#include "enums/being/badgeindex.h"
29
#include "enums/being/reachable.h"
30
31
#include "enums/gui/usercolorid.h"
32
33
#include "enums/simpletypes/move.h"
34
35
#include "enums/being/visiblenamepos.h"
36
37
#include "resources/beinginfo.h"
38
#include "resources/beingslot.h"
39
40
#include "being/actorsprite.h"
41
42
#include "enums/being/attacktype.h"
43
#include "enums/being/badgedrawtype.h"
44
#include "enums/being/beingaction.h"
45
#include "enums/being/gender.h"
46
47
#include "listeners/configlistener.h"
48
49
#include "localconsts.h"
50
51
static const int DEFAULT_BEING_WIDTH = 32;
52
static const int DEFAULT_BEING_HEIGHT = 32;
53
54
class AnimatedSprite;
55
class BeingCacheEntry;
56
class CastingEffect;
57
class Color;
58
class Equipment;
59
class FlashText;
60
class Guild;
61
class ItemInfo;
62
class Particle;
63
class Party;
64
class SpeechBubble;
65
class Text;
66
67
struct ChatObject;
68
struct HorseInfo;
69
struct MissileInfo;
70
struct SkillInfo;
71
struct ParticleInfo;
72
73
extern volatile time_t cur_time;
74
75
struct NextSoundInfo final
76
{
77
206
    NextSoundInfo() noexcept2 :
78
        sound(nullptr),
79
        x(0),
80
        y(0),
81
206
        time(0)
82
    {
83
    }
84
85
    A_DELETE_COPY(NextSoundInfo)
86
87
    const SoundInfo *sound;
88
    int x;
89
    int y;
90
    int time;
91
};
92
93
class Being notfinal : public ActorSprite,
94
                       public ConfigListener
95
{
96
    public:
97
        friend class ActorManager;
98
        friend class BeingEquipBackend;
99
        friend class LocalPlayer;
100
101
        /**
102
         * Constructor.
103
         *
104
         * @param id      a unique being id
105
         * @param subtype partly determines the type of the being
106
         * @param map     the map the being is on
107
         */
108
        Being(const BeingId id,
109
              const ActorTypeT type);
110
111
        A_DELETE_COPY(Being)
112
113
        ~Being() override;
114
115
24
        ActorTypeT getType() const restrict2 noexcept2 override final
116
                           A_WARN_UNUSED
117
48
        { return mType; }
118
119
        /**
120
         * Removes all path nodes from this being.
121
         */
122
        void clearPath() restrict2;
123
124
        /**
125
         * Returns the time spent in the current action.
126
         */
127
        int getActionTime() const restrict2 noexcept2 A_WARN_UNUSED
128
        { return mActionTime; }
129
130
        /**
131
         * Set the current action time.
132
         * @see Ea::BeingHandler that set it to tick time.
133
         */
134
        void setActionTime(const int actionTime) restrict2 noexcept2
135
        { mActionTime = actionTime; }
136
137
        /**
138
         * Makes this being take the next tile of its path.
139
         */
140
        virtual void nextTile() restrict2;
141
142
        /**
143
         * Creates a path for the being from current position to ex and ey
144
         */
145
        void setDestination(const int dstX,
146
                            const int dstY) restrict2;
147
148
        void setCachedDestination(const int dstX,
149
                                  const int dstY) restrict2 noexcept2
150
        { mCachedX = dstX; mCachedY = dstY; }
151
152
        int getCachedX() const noexcept2 A_WARN_UNUSED
153
        { return mCachedX; }
154
155
        int getCachedY() const noexcept2 A_WARN_UNUSED
156
        { return mCachedY; }
157
158
        /**
159
         * Returns the destination for this being.
160
         */
161
        const Vector &getDestination() const restrict2 noexcept2 A_WARN_UNUSED
162
        { return mDest; }
163
164
        /**
165
         * Returns the tile x coord
166
         */
167
4
        int getTileX() const restrict2 noexcept2 override A_WARN_UNUSED
168
4
        { return mX; }
169
170
        /**
171
         * Returns the tile y coord
172
         */
173
4
        int getTileY() const restrict2 noexcept2 override A_WARN_UNUSED
174
4
        { return mY; }
175
176
        /**
177
         * Sets the tile x and y coord
178
         */
179
        void setTileCoords(const int x, const int y) restrict2;
180
181
        /**
182
         * Puts a "speech balloon" above this being for the specified amount
183
         * of time.
184
         *
185
         * @param text The text that should appear.
186
         * @param time The amount of time the text should stay in milliseconds.
187
         */
188
        void setSpeech(const std::string &restrict text) restrict2;
189
190
        /**
191
         * Puts a damage bubble above this being.
192
         *
193
         * @param attacker the attacking being
194
         * @param amount the amount of damage recieved (0 means miss)
195
         * @param type the attack type
196
         * @param attackId the attack id
197
         * @param level the skill level
198
         */
199
        void takeDamage(Being *restrict const attacker,
200
                        const int amount,
201
                        const AttackTypeT type,
202
                        const int attackId,
203
                        const int level) restrict2;
204
205
        /**
206
         * Handles an attack of another being by this being.
207
         *
208
         * @param victim the victim being
209
         * @param damage the amount of damage dealt (0 means miss)
210
         * @param attackId the attack id
211
         */
212
        void handleAttack(Being *restrict const victim,
213
                          const int damage,
214
                          const int attackId) restrict2;
215
216
        void handleSkillCasting(Being *restrict const victim,
217
                                const int skillId,
218
                                const int skillLevel) restrict2;
219
220
        void handleSkill(Being *restrict const victim,
221
                         const int damage,
222
                         const int skillId,
223
                         const int skillLevel) restrict2;
224
225
        const ItemInfo *getEquippedWeapon() const restrict2 A_WARN_UNUSED
226
        { return mEquippedWeapon; }
227
228
        /**
229
         * Returns the name of the being.
230
         */
231
        const std::string &getName() const restrict2 noexcept2 A_WARN_UNUSED
232
68
        { return mName; }
233
234
        const std::string &getExtName() const restrict2 noexcept2 A_WARN_UNUSED
235
        { return mExtName; }
236
237
        /**
238
         * Sets the name for the being.
239
         *
240
         * @param name The name that should appear.
241
         */
242
        void setName(const std::string &restrict name) restrict2;
243
244
        bool getShowName() const noexcept2 A_WARN_UNUSED
245
14
        { return mShowName; }
246
247
        void setShowName(const bool doShowName) restrict2;
248
249
        /**
250
         * Sets the name of the party the being is in. Shown in BeingPopup.
251
         */
252
        void setPartyName(const std::string &restrict name) restrict2;
253
254
        const std::string &getPartyName() const restrict2 noexcept2
255
                                        A_WARN_UNUSED
256
        { return mPartyName; }
257
258
        const std::string &getGuildName() const restrict2 noexcept2
259
                                        A_WARN_UNUSED
260
        { return mGuildName; }
261
262
        const std::string &getClanName() const restrict2 noexcept2
263
                                       A_WARN_UNUSED
264
        { return mClanName; }
265
266
        /**
267
         * Sets the name of the primary guild the being is in. Shown in
268
         * BeingPopup (eventually).
269
         */
270
        void setGuildName(const std::string &restrict name) restrict2;
271
272
        void setGuildPos(const std::string &restrict pos) restrict2;
273
274
        void setClanName(const std::string &restrict name) restrict2;
275
276
        /**
277
         * Adds a guild to the being.
278
         */
279
        void addGuild(Guild *restrict const guild) restrict2;
280
281
        /**
282
         * Removers a guild from the being.
283
         */
284
        void removeGuild(const int id) restrict2;
285
286
        /**
287
         * Returns a pointer to the specified guild that the being is in.
288
         */
289
        const Guild *getGuild(const std::string &restrict guildName)
290
                              const restrict2 A_WARN_UNUSED;
291
292
        /**
293
         * Returns a pointer to the specified guild that the being is in.
294
         */
295
        const Guild *getGuild(const int id) const restrict2 A_WARN_UNUSED;
296
297
        /**
298
         * Returns a pointer to the specified guild that the being is in.
299
         */
300
        Guild *getGuild() const restrict2 A_WARN_UNUSED;
301
302
        /**
303
         * Returns all guilds the being is in.
304
         */
305
        const std::map<int, Guild*> &getGuilds() const restrict2 noexcept2
306
                                               A_WARN_UNUSED
307
        { return mGuilds; }
308
309
        /**
310
         * Removes all guilds the being is in.
311
         */
312
        void clearGuilds() restrict2;
313
314
        /**
315
         * Get number of guilds the being belongs to.
316
         */
317
        int16_t getNumberOfGuilds() const restrict2 A_WARN_UNUSED
318
        { return CAST_S16(mGuilds.size()); }
319
320
        bool isInParty() const restrict2 noexcept2 A_WARN_UNUSED
321
14
        { return mParty != nullptr; }
322
323
        void setParty(Party *restrict const party) restrict2;
324
325
        void setGuild(Guild *restrict const guild) restrict2;
326
327
        void updateGuild() restrict2;
328
329
        Party *getParty() const restrict2 noexcept2 A_WARN_UNUSED
330
2
        { return mParty; }
331
332
        void setSprite(const unsigned int slot,
333
                       const int id,
334
                       std::string color,
335
                       ItemColor colorId) restrict2;
336
337
        void setSpriteColor(const unsigned int slot,
338
                            const int id,
339
                            const std::string &color) restrict2;
340
341
        void setSpriteColorId(const unsigned int slot,
342
                              const int id,
343
                              ItemColor colorId) restrict2;
344
345
        void setSpriteCards(const unsigned int slot,
346
                            const int id,
347
                            const CardsList &restrict cards) restrict2;
348
349
        void setSpriteId(const unsigned int slot,
350
                         const int id) restrict2;
351
352
        void unSetSprite(const unsigned int slot) restrict2;
353
354
        void setWeaponId(const int id) restrict2;
355
356
        void setTempSprite(const unsigned int slot,
357
                           const int id) restrict2;
358
359
        void setHairTempSprite(const unsigned int slot,
360
                               const int id) restrict2;
361
362
        void updateSprite(const unsigned int slot,
363
                          const int id,
364
                          const std::string &restrict color)
365
                          restrict2;
366
367
        void setHairColorSpriteID(const unsigned int slot,
368
                                  const int id) restrict2;
369
370
        void setSpriteColor(const unsigned int slot,
371
                            const std::string &restrict color) restrict2;
372
373
        /**
374
         * Get the number of layers used to draw the being
375
         */
376
        int getNumberOfLayers() const restrict2 override A_WARN_UNUSED
377
        { return CompoundSprite::getNumberOfLayers(); }
378
379
        /**
380
         * Performs being logic.
381
         */
382
        void logic() restrict2 override;
383
384
        void botLogic() restrict2;
385
386
        /**
387
         * Draws the speech text above the being.
388
         */
389
        void drawSpeech(const int offsetX,
390
                        const int offsetY) restrict2;
391
392
        /**
393
         * Draws the emotion picture above the being.
394
         */
395
        void drawEmotion(Graphics *restrict const graphics,
396
                         const int offsetX,
397
                         const int offsetY) const restrict2 A_NONNULL(2);
398
399
        BeingTypeId getSubType() const restrict2 noexcept2 A_WARN_UNUSED
400
        { return mSubType; }
401
402
         /**
403
          * Set Being's subtype (mostly for view for monsters and NPCs)
404
          */
405
        void setSubtype(const BeingTypeId subtype,
406
                        const uint16_t look) restrict2;
407
408
        const BeingInfo *getInfo() const restrict2 noexcept2 A_WARN_UNUSED
409
        { return mInfo; }
410
411
        TargetCursorSizeT getTargetCursorSize() const restrict2 override final
412
                                              A_WARN_UNUSED;
413
414
        int getTargetOffsetX() const restrict2 override A_WARN_UNUSED
415
        {
416
            if (mInfo == nullptr)
417
                return 0;
418
            return mInfo->getTargetOffsetX();
419
        }
420
421
        int getTargetOffsetY() const restrict2 override A_WARN_UNUSED
422
        {
423
            if (mInfo == nullptr)
424
                return 0;
425
            return mInfo->getTargetOffsetY();
426
        }
427
428
        /**
429
         * Gets the way the object is blocked by other objects.
430
         */
431
        virtual unsigned char getBlockWalkMask() const restrict2 A_WARN_UNUSED
432
        {
433
            if (mInfo == nullptr)
434
                return 0;
435
            return mInfo->getBlockWalkMask();
436
        }
437
438
        /**
439
         * Gets the way the monster blocks pathfinding for other objects
440
         */
441
        BlockTypeT getBlockType() const restrict2 override A_WARN_UNUSED
442
        {
443
            if (mInfo == nullptr)
444
                return BlockType::NONE;
445
            return mInfo->getBlockType();
446
        }
447
448
        /**
449
         * Sets the walk speed in pixels per second.
450
         */
451
        void setWalkSpeed(const int speed) restrict2
452
        { mWalkSpeed = speed; mSpeed = speed; }
453
454
        /**
455
         * Gets the walk speed in pixels per second.
456
         */
457
        int getWalkSpeed() const restrict2 noexcept2 A_WARN_UNUSED
458
188
        { return mWalkSpeed; }
459
460
        /**
461
         * Sets the attack speed.
462
         */
463
        void setAttackSpeed(const int speed) restrict2 noexcept2
464
        { mAttackSpeed = speed; }
465
466
        /**
467
         * Gets the attack speed.
468
         */
469
        int getAttackSpeed() const restrict2 noexcept2 A_WARN_UNUSED
470
        { return mAttackSpeed; }
471
472
        /**
473
         * Sets the current action.
474
         */
475
        virtual void setAction(const BeingActionT &restrict action,
476
                               const int attackId) restrict2;
477
478
        /**
479
         * Get the being's action currently performed.
480
         */
481
        BeingActionT getCurrentAction() const restrict2 noexcept2 A_WARN_UNUSED
482
        { return mAction; }
483
484
        /**
485
         * Returns whether this being is still alive.
486
         */
487
        bool isAlive() const restrict2 noexcept2 A_WARN_UNUSED
488
        { return mAction != BeingAction::DEAD; }
489
490
        /**
491
         * Returns the current direction.
492
         */
493
        uint8_t getDirection() const restrict2 noexcept2 A_WARN_UNUSED
494
        { return mDirection; }
495
496
        /**
497
         * Sets the current direction.
498
         */
499
        virtual void setDirection(const uint8_t direction) restrict2;
500
501
        void setDirectionDelayed(const uint8_t direction) restrict2 noexcept2
502
        { mDirectionDelayed = direction; }
503
504
        uint8_t getDirectionDelayed() const restrict2 noexcept2 A_WARN_UNUSED
505
        { return mDirectionDelayed; }
506
507
        /**
508
         * Returns the direction the being is facing.
509
         */
510
        SpriteDirection::Type getSpriteDirection() const restrict2 noexcept2
511
                                                 A_WARN_UNUSED
512
        { return mSpriteDirection; }
513
514
        void setPixelPositionF(const Vector &restrict pos) restrict2 override;
515
516
        /**
517
         * Overloaded method provided for convenience.
518
         *
519
         * @see setPosition(const Vector &pos)
520
         */
521
        inline void setPixelPositionF(const float x,
522
                                      const float y,
523
                                      const float z) restrict2 A_INLINE
524
        { setPixelPositionF(Vector(x, y, z)); }
525
526
        /**
527
         * Returns the horizontal size of the current base sprite of the being.
528
         */
529
        int getWidth() const restrict2 override final A_WARN_UNUSED
530
        { return std::max(CompoundSprite::getWidth(), DEFAULT_BEING_WIDTH); }
531
532
        /**
533
         * Returns the vertical size of the current base sprite of the being.
534
         */
535
        int getHeight() const restrict2 override final A_WARN_UNUSED
536
        { return std::max(CompoundSprite::getHeight(), DEFAULT_BEING_HEIGHT); }
537
538
        /**
539
         * Shoots a missile particle from this being, to target being
540
         */
541
        void fireMissile(Being *restrict const victim,
542
                         const MissileInfo &restrict missile) const restrict2;
543
544
        /**
545
         * Returns the path this being is following. An empty path is returned
546
         * when this being isn't following any path currently.
547
         */
548
        const Path &getPath() const restrict2 noexcept2 A_WARN_UNUSED
549
        { return mPath; }
550
551
        int getDistance() const restrict2 noexcept2 A_WARN_UNUSED
552
        { return mDistance; }
553
554
        void setDistance(const int n) restrict2 noexcept2
555
        { mDistance = n; }
556
557
        /**
558
         * Set the Emoticon type and time displayed above
559
         * the being.
560
         */
561
        void setEmote(const uint8_t emotion,
562
                      const int emote_time) restrict2;
563
564
        void setState(const uint8_t state) restrict2;
565
566
        void drawPlayerSprites(Graphics *restrict const  graphics,
567
                               const int posX,
568
                               const int posY) const
569
                               restrict2 A_NONNULL(2);
570
571
        void drawSpritesSDL(Graphics *restrict const graphics,
572
                            const int posX,
573
                            const int posY) const
574
                            restrict2 override final A_NONNULL(2);
575
576
        void drawHpBar(Graphics *restrict const graphics,
577
                       const int maxHP,
578
                       const int hp,
579
                       const int damage,
580
                       const UserColorIdT color1,
581
                       const UserColorIdT color2,
582
                       const int x,
583
                       const int y,
584
                       const int width,
585
                       const int height) const restrict2 A_NONNULL(2);
586
587
        void optionChanged(const std::string &restrict value)
588
                           restrict2 override;
589
590
        void flashName(const int time) restrict2;
591
592
        int getDamageTaken() const restrict2 noexcept2 A_WARN_UNUSED
593
2
        { return mDamageTaken; }
594
595
        void setDamageTaken(const int damage) restrict2 noexcept2
596
        { mDamageTaken = damage; }
597
598
        void updateName() restrict2;
599
600
        void setLevel(const int n) restrict2 noexcept2
601
        { mLevel = n; }
602
603
        virtual int getLevel() const restrict2 A_WARN_UNUSED
604
        { return mLevel; }
605
606
        void setReachable(const ReachableT n) restrict2 noexcept2
607
        { mReachable = n; }
608
609
        ReachableT getReachable() const restrict2 noexcept2 A_WARN_UNUSED
610
        { return mReachable; }
611
612
        static void reReadConfig();
613
614
        static BeingCacheEntry* getCacheEntry(const BeingId id) A_WARN_UNUSED;
615
616
        void addToCache() const restrict2;
617
618
        bool updateFromCache() restrict2;
619
620
        /**
621
         * Sets the gender of this being.
622
         */
623
        virtual void setGender(const GenderT gender) restrict2;
624
625
        GenderT getGender() const restrict2 noexcept2 A_WARN_UNUSED
626
        { return mGender; }
627
628
        /**
629
         * Return sprite sit action for current environment.
630
         */
631
        std::string getSitAction() const restrict2 A_WARN_UNUSED;
632
633
        std::string getCastAction() const restrict2 A_WARN_UNUSED;
634
635
        std::string getCastAction(const SkillInfo *restrict const skill) const
636
                                  restrict2 A_WARN_UNUSED;
637
638
        std::string getMoveAction() const restrict2 A_WARN_UNUSED;
639
640
        std::string getDeadAction() const restrict2 A_WARN_UNUSED;
641
642
        std::string getStandAction() const restrict2 A_WARN_UNUSED;
643
644
        std::string getSpawnAction() const restrict2 A_WARN_UNUSED;
645
646
        std::string getWeaponAttackAction(const ItemInfo *restrict const
647
                                          weapon) const
648
                                          restrict2 A_WARN_UNUSED;
649
650
        std::string getAttackAction() const restrict2 A_WARN_UNUSED;
651
652
        std::string getAttackAction(const Attack *restrict const attack1) const
653
                                    restrict2 A_WARN_UNUSED;
654
655
        /**
656
         * Whether or not this player is a GM.
657
         */
658
        bool isGM() const restrict2 noexcept2 A_WARN_UNUSED
659
4
        { return mIsGM; }
660
661
        /**
662
         * Triggers whether or not to show the name as a GM name.
663
         */
664
        void setGM(const bool gm) restrict2;
665
666
        bool canTalk() const restrict2 noexcept2 A_WARN_UNUSED
667
        { return mType == ActorType::Npc; }
668
669
        void talkTo() const restrict2;
670
671
        void draw(Graphics *restrict const graphics,
672
                  const int offsetX,
673
                  const int offsetY) const
674
                  restrict2 override final A_NONNULL(2);
675
676
        void drawPlayer(Graphics *restrict const graphics,
677
                        const int offsetX,
678
                        const int offsetY) const
679
                        restrict2 A_NONNULL(2);
680
681
        void drawOther(Graphics *restrict const graphics,
682
                       const int offsetX,
683
                       const int offsetY) const
684
                       restrict2 A_NONNULL(2);
685
686
        void drawNpc(Graphics *restrict const graphics,
687
                     const int offsetX,
688
                     const int offsetY) const
689
                     restrict2 A_NONNULL(2);
690
691
        void drawMonster(Graphics *restrict const graphics,
692
                         const int offsetX,
693
                         const int offsetY) const
694
                         restrict2 A_NONNULL(2);
695
696
        void drawPortal(Graphics *restrict const graphics,
697
                        const int offsetX,
698
                        const int offsetY) const
699
                        restrict2 A_NONNULL(2);
700
701
        void drawBasic(Graphics *restrict const graphics,
702
                       const int x,
703
                       const int y) const restrict2 A_NONNULL(2);
704
705
        void setMoveTime() restrict2 noexcept2
706
        { mMoveTime = cur_time; }
707
708
        void setAttackTime() restrict2 noexcept2
709
        { mAttackTime = cur_time; }
710
711
        void setTalkTime() restrict2 noexcept2
712
        { mTalkTime = cur_time; }
713
714
        void setTestTime() restrict2 noexcept2
715
        { mTestTime = cur_time; }
716
717
        void setOtherTime() restrict2 noexcept2
718
        { mOtherTime = cur_time; }
719
720
        time_t getMoveTime() const restrict2 noexcept2
721
        { return mMoveTime; }
722
723
        time_t getAttackTime() const restrict2 noexcept2
724
        { return mAttackTime; }
725
726
        time_t getTalkTime() const restrict2 noexcept2
727
        { return mTalkTime; }
728
729
        time_t getTestTime() const restrict2 noexcept2
730
        { return mTestTime; }
731
732
        time_t getOtherTime() const restrict2 noexcept2
733
        { return mOtherTime; }
734
735
        void resetCounters() restrict2;
736
737
        void updateColors() restrict2;
738
739
        void setEnemy(const bool n) restrict2 noexcept2
740
        { mEnemy = n; }
741
742
        const std::string &getIp() const restrict2 noexcept2 A_WARN_UNUSED
743
        { return mIp; }
744
745
        void setIp(const std::string &restrict ip) restrict2 noexcept2
746
        { mIp = ip; }
747
748
        unsigned int getPvpRank() const restrict2 noexcept2 A_WARN_UNUSED
749
        { return mPvpRank; }
750
751
        void setPvpRank(const unsigned int rank) restrict2 noexcept2
752
        { mPvpRank = rank; }
753
754
        void setHP(const int hp) restrict2;
755
756
        void setMaxHP(const int hp) restrict2;
757
758
        int getHP() const restrict2 noexcept2 A_WARN_UNUSED
759
        { return mHP; }
760
761
        int getMaxHP() const restrict2 noexcept2 A_WARN_UNUSED
762
        { return mMaxHP; }
763
764
        uint8_t calcDirection(const int dstX,
765
                              const int dstY) const restrict2 A_WARN_UNUSED;
766
767
        uint8_t calcDirection() const restrict2 A_WARN_UNUSED;
768
769
        void setAttackDelay(const int n) restrict2 noexcept2
770
        { mAttackDelay = n; }
771
772
        int getAttackDelay() const restrict2 noexcept2 A_WARN_UNUSED
773
        { return mAttackDelay; }
774
775
        int getMinHit() const restrict2 noexcept2 A_WARN_UNUSED
776
        { return mMinHit; }
777
778
        void setMinHit(const int n) restrict2 noexcept2
779
        { mMinHit = n; }
780
781
        int getMaxHit() const restrict2 noexcept2 A_WARN_UNUSED
782
        { return mMaxHit; }
783
784
        void setMaxHit(const int n) restrict2 noexcept2
785
        { mMaxHit = n; }
786
787
        int getCriticalHit() const restrict2 A_WARN_UNUSED
788
        { return mCriticalHit; }
789
790
        void setCriticalHit(const int n) restrict2 noexcept2
791
        { mCriticalHit = n; }
792
793
        void updateHit(const int amount) restrict2;
794
795
        Equipment *getEquipment() restrict2 A_WARN_UNUSED;
796
797
        void undressItemById(const int id) restrict2;
798
799
        int getGoodStatus() const restrict2 noexcept2 A_WARN_UNUSED
800
14
        { return mGoodStatus; }
801
802
        void setGoodStatus(const int n) restrict2 noexcept2
803
12
        { mGoodStatus = n; }
804
805
        std::string getGenderSign() const restrict2 A_WARN_UNUSED;
806
807
        std::string getGenderSignWithSpace() const restrict2 A_WARN_UNUSED;
808
809
        void updateComment() restrict2;
810
811
        const std::string getComment() const restrict2 noexcept2 A_WARN_UNUSED
812
        { return mComment; }
813
814
        void setComment(const std::string &restrict n) restrict2 noexcept2
815
        { mComment = n; }
816
817
        static void clearCache();
818
819
        static std::string loadComment(const std::string &restrict name,
820
                                       const ActorTypeT &restrict type)
821
                                       A_WARN_UNUSED;
822
823
        static void saveComment(const std::string &restrict name,
824
                                const std::string &restrict comment,
825
                                const ActorTypeT &restrict type);
826
827
        bool isAdvanced() const restrict2 noexcept2 A_WARN_UNUSED
828
        { return mAdvanced; }
829
830
        void setAdvanced(const bool n) restrict2
831
        { mAdvanced = n; addToCache(); }
832
833
        bool isBuyShopEnabled() const restrict2 A_WARN_UNUSED;
834
835
        bool isSellShopEnabled() const restrict2 A_WARN_UNUSED;
836
837
        void enableShop(const bool b) restrict2;
838
839
        /**
840
         * Sets the attack range.
841
         */
842
        void setAttackRange(const int range) restrict2 noexcept2
843
        { mAttackRange = range; }
844
845
/*
846
        void attack(Being *restrict target = nullptr,
847
                    bool keep = false,
848
                    bool dontChangeEquipment = false) restrict2;
849
850
        void attack2(Being *restrict target = nullptr,
851
                     bool keep = false,
852
                     bool dontChangeEquipment = false) restrict2;
853
*/
854
855
        void updatePercentHP() restrict2;
856
857
        void setRaceName(const std::string &restrict name) restrict2 noexcept2
858
        { mRaceName = name; }
859
860
        std::string getRaceName() const restrict2 noexcept2 A_WARN_UNUSED
861
4
        { return mRaceName; }
862
863
        int getSpriteID(const int slot) const restrict2 A_WARN_UNUSED;
864
865
        const BeingSlot &getSpriteSlot(const int slot) const
866
                                       restrict2 A_WARN_UNUSED;
867
868
        ItemColor getSpriteColor(const int slot) const restrict2 A_WARN_UNUSED;
869
870
        void setHairStyle(const unsigned int slot,
871
                          const int id) restrict2;
872
873
        void setHairColor(const unsigned int slot,
874
                          const ItemColor color) restrict2;
875
876
        void setHairColor(const ItemColor color) restrict2 noexcept2
877
        { mHairColor = color; }
878
879
        void setSpriteSlot(const unsigned int slot,
880
                           const BeingSlot &beingSlot);
881
882
        ItemColor getHairColor() const noexcept2 A_WARN_UNUSED
883
        { return mHairColor; }
884
885
        void recalcSpritesOrder() restrict2;
886
887
        int getHitEffect(const Being *restrict const attacker,
888
                         const AttackTypeT type,
889
                         const int attackId,
890
                         const int level) const restrict2 A_WARN_UNUSED;
891
892
        CursorT getHoverCursor() const restrict2 A_WARN_UNUSED
893
        {
894
            return mInfo != nullptr ?
895
                mInfo->getHoverCursor() : Cursor::CURSOR_POINTER;
896
        }
897
898
        void addAfkEffect() restrict2;
899
900
        void removeAfkEffect() restrict2;
901
902
        void updateAwayEffect() restrict2;
903
904
        void addSpecialEffect(const int effect) restrict2;
905
906
        void removeSpecialEffect() restrict2;
907
908
        void addEffect(const std::string &restrict name) restrict2;
909
910
        void setOwner(Being *restrict const owner) restrict2 noexcept2
911
        { mOwner = owner; }
912
913
        Being *getOwner() const restrict2 noexcept2
914
        { return mOwner; }
915
916
        void playSfx(const SoundInfo &sound,
917
                     Being *const being,
918
                     const bool main,
919
                     const int x, const int y) const restrict2;
920
921
        uint16_t getLook() const restrict2 noexcept2
922
        { return mLook; }
923
924
        void setLook(const uint16_t look) restrict2;
925
926
        constexpr2 static uint8_t genderToInt(const GenderT sex)
927
                                              A_CONST A_WARN_UNUSED
928
        {
929
            switch (sex)
930
            {
931
                case Gender::FEMALE:
932
                case Gender::UNSPECIFIED:
933
                default:
934
                    return 0;
935
                case Gender::MALE:
936
                    return 1;
937
                case Gender::OTHER:
938
                    return 3;
939
            }
940
        }
941
942
        constexpr2 static GenderT intToGender(const uint8_t sex)
943
                                              A_CONST A_WARN_UNUSED
944
        {
945
            switch (sex)
946
            {
947
                case 0:
948
                default:
949
                    return Gender::FEMALE;
950
                case 1:
951
                    return Gender::MALE;
952
                case 3:
953
                    return Gender::OTHER;
954
            }
955
        }
956
957
        NextSoundInfo mNextSound;
958
959
        /**
960
         * Sets the new path for this being.
961
         */
962
        void setPath(const Path &restrict path) restrict2;
963
964
        int getSortPixelY() const restrict2 override A_WARN_UNUSED
965
        { return CAST_S32(mPos.y) - mYDiff - mSortOffsetY; }
966
967
        void setMap(Map *restrict const map) restrict2 override;
968
969
        void recreateItemParticles() restrict2;
970
971
        void incUsage() restrict2 noexcept2
972
        { mUsageCounter ++; }
973
974
        int decUsage() restrict2 noexcept2
975
        { return --mUsageCounter; }
976
977
        virtual int getLastAttackX() const restrict2
978
        { return mLastAttackX; }
979
980
        virtual int getLastAttackY() const restrict2
981
        { return mLastAttackY; }
982
983
        void drawHomunculus(Graphics *restrict const graphics,
984
                            const int offsetX,
985
                            const int offsetY) const
986
                            restrict2 A_NONNULL(2);
987
988
        void drawMercenary(Graphics *restrict const graphics,
989
                           const int offsetX,
990
                           const int offsetY) const
991
                           restrict2 A_NONNULL(2);
992
993
        void drawElemental(Graphics *restrict const graphics,
994
                           const int offsetX,
995
                           const int offsetY) const
996
                           restrict2 A_NONNULL(2);
997
998
        void setTrickDead(const bool b) restrict2 override final;
999
1000
        void setChat(ChatObject *restrict const obj) restrict2;
1001
1002
        ChatObject *getChat() const restrict2 noexcept2
1003
        { return mChat; }
1004
1005
        void setRiding(const bool b) restrict2 override final;
1006
1007
        void setHorse(const int horseId) restrict2;
1008
1009
        void removeHorse() restrict2;
1010
1011
        void setSellBoard(const std::string &restrict text) restrict2;
1012
1013
        std::string getSellBoard() const restrict2 noexcept2 A_WARN_UNUSED
1014
        { return mSellBoard; }
1015
1016
        void setBuyBoard(const std::string &restrict text) restrict2;
1017
1018
        std::string getBuyBoard() const restrict2 noexcept2 A_WARN_UNUSED
1019
        { return mBuyBoard; }
1020
1021
        void setSpiritBalls(const unsigned int balls) restrict2;
1022
1023
        unsigned int getSpiritBalls() const restrict2 noexcept2 A_WARN_UNUSED
1024
        { return mSpiritBalls; }
1025
1026
        void stopCast(const bool b) override final;
1027
1028
        void setCreatorId(const BeingId id)
1029
        { mCreatorId = id; }
1030
1031
        BeingId getCreatorId() const noexcept2 A_WARN_UNUSED
1032
        { return mCreatorId; }
1033
1034
        void setKarma(const int karma) restrict2 noexcept2
1035
        { mKarma = karma; }
1036
1037
        int getKarma() const restrict2 noexcept2 A_WARN_UNUSED
1038
        { return mKarma; }
1039
1040
        void setManner(const int manner) restrict2 noexcept2
1041
        { mManner = manner; }
1042
1043
        int getManner() const restrict2 noexcept2 A_WARN_UNUSED
1044
        { return mManner; }
1045
1046
        void disableBotAi() restrict2 noexcept2
1047
        { mBotAi = false; }
1048
1049
        void enableBotAi() restrict2 noexcept2
1050
        { mBotAi = true; }
1051
1052
        int getAreaSize() const restrict2 noexcept2 A_WARN_UNUSED
1053
        { return mAreaSize; }
1054
1055
        void setAreaSize(const int areaSize) restrict2 noexcept2
1056
        { mAreaSize = areaSize; }
1057
1058
        void setTeamId(const uint16_t teamId) restrict2;
1059
1060
        void showTeamBadge(const bool show) restrict2;
1061
1062
        void showGuildBadge(const bool show) restrict2;
1063
1064
        void showClanBadge(const bool show) restrict2;
1065
1066
        void showGmBadge(const bool show) restrict2;
1067
1068
        void showPartyBadge(const bool show) restrict2;
1069
1070
        void showNameBadge(const bool show) restrict2;
1071
1072
        void showShopBadge(const bool show) restrict2;
1073
1074
        void showInactiveBadge(const bool show) restrict2;
1075
1076
        void showAwayBadge(const bool show) restrict2;
1077
1078
        void showBadges(const bool show) restrict2;
1079
1080
        void setLanguageId(const int lang) restrict2 noexcept2;
1081
1082
        int getLanguageId() restrict2 noexcept2 A_WARN_UNUSED
1083
        { return mLanguageId; }
1084
1085
        uint16_t getTeamId() const restrict2 noexcept2 A_WARN_UNUSED
1086
        { return mTeamId; }
1087
1088
        virtual void setGroupId(const int id);
1089
1090
        int getGroupId() const noexcept2 A_WARN_UNUSED
1091
2
        { return mGroupId; }
1092
1093
        void serverRemove() restrict2 noexcept2;
1094
1095
        void addCast(const int dstX,
1096
                     const int dstY,
1097
                     const int skillId,
1098
                     const int skillLevel,
1099
                     const int range,
1100
                     const int waitTimeTicks);
1101
1102
        void fixDirectionOffsets(int &offsetX,
1103
                                 int &offsetY) const;
1104
1105
        bool getAllowNpcEquipment() const noexcept2 A_WARN_UNUSED
1106
        { return mAllowNpcEquipment; }
1107
1108
        static Being *createBeing(const BeingId id,
1109
                                  const ActorTypeT type,
1110
                                  const BeingTypeId subtype,
1111
                                  Map *const map);
1112
1113
    protected:
1114
        void drawPlayerSpriteAt(Graphics *restrict const graphics,
1115
                                const int x,
1116
                                const int y) const restrict2 A_NONNULL(2);
1117
1118
        void drawOtherSpriteAt(Graphics *restrict const graphics,
1119
                               const int x,
1120
                               const int y) const restrict2 A_NONNULL(2);
1121
1122
        void drawNpcSpriteAt(Graphics *restrict const graphics,
1123
                             const int x,
1124
                             const int y) const restrict2 A_NONNULL(2);
1125
1126
        void drawPortalSpriteAt(Graphics *restrict const graphics,
1127
                                const int x,
1128
                                const int y) const restrict2 A_NONNULL(2);
1129
1130
        void drawMonsterSpriteAt(Graphics *restrict const graphics,
1131
                                 const int x,
1132
                                 const int y) const restrict2 A_NONNULL(2);
1133
1134
        void drawHomunculusSpriteAt(Graphics *restrict const graphics,
1135
                                    const int x,
1136
                                    const int y) const restrict2 A_NONNULL(2);
1137
1138
        void drawMercenarySpriteAt(Graphics *restrict const graphics,
1139
                                   const int x,
1140
                                   const int y) const restrict2 A_NONNULL(2);
1141
1142
        void drawElementalSpriteAt(Graphics *restrict const graphics,
1143
                                   const int x,
1144
                                   const int y) const restrict2 A_NONNULL(2);
1145
1146
        void drawCompound(Graphics *const graphics,
1147
                          const int posX,
1148
                          const int posY) const A_NONNULL(2);
1149
1150
        /**
1151
         * Updates name's location.
1152
         */
1153
        virtual void updateCoords() restrict2;
1154
1155
        void showName() restrict2;
1156
1157
        void addItemParticles(const int id,
1158
                              const SpriteDisplay &restrict display) restrict2;
1159
1160
        void addItemParticlesCards(const int id,
1161
                                   const SpriteDisplay &restrict display,
1162
                                   const CardsList &restrict cards) restrict2;
1163
1164
        void removeAllItemsParticles() restrict2;
1165
1166
        void removeItemParticles(const int id) restrict2;
1167
1168
        void createSpeechBubble() restrict2;
1169
1170
        void setDefaultNameColor(const UserColorIdT defaultColor) restrict2;
1171
1172
        void updateBadgesCount() restrict2;
1173
1174
        static int getDefaultEffectId(const AttackTypeT &restrict type);
1175
1176
        BeingInfo *restrict mInfo;
1177
        AnimatedSprite *restrict mEmotionSprite;
1178
        AnimatedSprite *restrict mAnimationEffect;
1179
        CastingEffect *restrict mCastingEffect;
1180
        AnimatedSprite *restrict mBadges[BadgeIndex::BadgeIndexSize];
1181
1182
        std::string mSpriteAction;
1183
        std::string mName;              /**< Name of being */
1184
        std::string mExtName;           /**< Full name of being */
1185
        std::string mRaceName;
1186
        std::string mPartyName;
1187
        std::string mGuildName;
1188
        std::string mClanName;
1189
        std::string mSpeech;
1190
1191
        /**
1192
         * Holds a text object when the being displays it's name, 0 otherwise
1193
         */
1194
        FlashText *restrict mDispName;
1195
        const Color *restrict mNameColor;
1196
1197
        /** Engine-related infos about weapon. */
1198
        const ItemInfo *restrict mEquippedWeapon;
1199
1200
        Path mPath;
1201
        Text *restrict mText;
1202
        const Color *restrict mTextColor;
1203
1204
        Vector mDest;  /**< destination coordinates. */
1205
1206
        typedef std::map<int, ParticleInfo*> SpriteParticleInfo;
1207
        typedef SpriteParticleInfo::iterator SpriteParticleInfoIter;
1208
1209
        STD_VECTOR<BeingSlot> mSlots;
1210
        SpriteParticleInfo mSpriteParticles;
1211
1212
        // Character guild information
1213
        std::map<int, Guild*> mGuilds;
1214
        Party *mParty;
1215
1216
        int mActionTime;      /**< Time spent in current action */
1217
        int mEmotionTime;     /**< Time until emotion disappears */
1218
1219
        /** Time until the last speech sentence disappears */
1220
        int mSpeechTime;
1221
        int mAttackSpeed;     /**< Attack speed */
1222
1223
        int mLevel;
1224
        int mGroupId;
1225
        int mAttackRange;
1226
        int mLastAttackX;
1227
        int mLastAttackY;
1228
1229
        int mPreStandTime;
1230
1231
        GenderT mGender;
1232
        BeingActionT mAction;
1233
        BeingTypeId mSubType;       /**< Subtype (graphical view, basically) */
1234
        uint8_t mDirection;         /**< Facing direction */
1235
        uint8_t mDirectionDelayed;  /**< Facing direction */
1236
        SpriteDirection::Type mSpriteDirection;  /**< Facing direction */
1237
        bool mShowName;
1238
        bool mIsGM;
1239
1240
    protected:
1241
        void postInit(const BeingTypeId subType,
1242
                      Map *const map);
1243
1244
        void updateBadgesPosition();
1245
1246
        /**
1247
         * Calculates the offset in the given directions.
1248
         * If walking in direction 'neg' the value is negated.
1249
         */
1250
        template<signed char pos, signed char neg>
1251
        int getOffset() const restrict2 A_WARN_UNUSED;
1252
1253
        int searchSlotValue(const STD_VECTOR<int> &restrict slotRemap,
1254
                            const int val) const restrict2 A_WARN_UNUSED;
1255
1256
        static void searchSlotValueItr(STD_VECTOR<int>::iterator &restrict it,
1257
                                       int &idx,
1258
                                       STD_VECTOR<int> &restrict slotRemap,
1259
                                       const int val);
1260
1261
        void addSpiritBalls(const unsigned int balls,
1262
                            const int effectId) restrict2;
1263
1264
        void removeSpiritBalls(const unsigned int balls) restrict2;
1265
1266
        void dumpSprites() const restrict2;
1267
1268
        void drawBeingCursor(Graphics *const graphics,
1269
                             const int offsetX,
1270
                             const int offsetY) const A_NONNULL(2);
1271
1272
        void drawCasting(Graphics *const graphics,
1273
                         const int offsetX,
1274
                         const int offsetY) const A_NONNULL(2);
1275
1276
        void updateBotFollow(int dstX,
1277
                             int dstY,
1278
                             const int divX,
1279
                             const int divY);
1280
1281
        void moveBotTo(int dstX,
1282
                       int dstY);
1283
1284
        void updateBotDirection(const int dstX,
1285
                                const int dstY);
1286
1287
        void botFixOffset(int &restrict dstX,
1288
                          int &restrict dstY) const;
1289
1290
        const ActorTypeT mType;
1291
1292
        /** Speech Bubble components */
1293
        SpeechBubble *restrict mSpeechBubble;
1294
1295
        /**
1296
         * Walk speed for x and y movement values.
1297
         * In pixels per second.
1298
         * @see MILLISECONDS_IN_A_TICK
1299
         */
1300
        int mWalkSpeed;
1301
        int mSpeed;
1302
        std::string mIp;
1303
        int *restrict mSpriteRemap A_NONNULLPOINTER;
1304
        int *restrict mSpriteHide A_NONNULLPOINTER;
1305
        int *restrict mSpriteDraw A_NONNULLPOINTER;
1306
        std::string mComment;
1307
        std::string mBuyBoard;
1308
        std::string mSellBoard;
1309
        Being *restrict mOwner;
1310
        Particle *restrict mSpecialParticle;
1311
        ChatObject *restrict mChat;
1312
        HorseInfo *restrict mHorseInfo;
1313
        STD_VECTOR<AnimatedSprite*> mDownHorseSprites;
1314
        STD_VECTOR<AnimatedSprite*> mUpHorseSprites;
1315
        STD_VECTOR<Particle*> mSpiritParticles;
1316
1317
        int mX;             // position in tiles
1318
        int mY;             // position in tiles
1319
        int mCachedX;
1320
        int mCachedY;
1321
        int mSortOffsetY;  // caculated offset in pixels based on mPixelOffsetY
1322
        int mPixelOffsetY;  // tile height offset in pixels
1323
                            // calculated between tiles
1324
        int mFixedOffsetY;  // fixed tile height offset in pixels for tile
1325
        uint8_t mOldHeight;
1326
1327
        int mDamageTaken;
1328
        int mHP;
1329
        int mMaxHP;
1330
        int mDistance;
1331
        ReachableT mReachable;
1332
        int mGoodStatus;
1333
1334
        static time_t mUpdateConfigTime;
1335
        static unsigned int mConfLineLim;
1336
        static int mSpeechType;
1337
        static bool mHighlightMapPortals;
1338
        static bool mHighlightMonsterAttackRange;
1339
        static bool mLowTraffic;
1340
        static bool mDrawHotKeys;
1341
        static bool mShowBattleEvents;
1342
        static bool mShowMobHP;
1343
        static bool mShowOwnHP;
1344
        static bool mShowGender;
1345
        static bool mShowLevel;
1346
        static bool mShowPlayersStatus;
1347
        static bool mEnableReorderSprites;
1348
        static bool mHideErased;
1349
        static Move mMoveNames;
1350
        static bool mUseDiagonal;
1351
        static BadgeDrawType::Type mShowBadges;
1352
        static int mAwayEffect;
1353
        static VisibleNamePos::Type mVisibleNamePos;
1354
1355
        time_t mMoveTime;
1356
        time_t mAttackTime;
1357
        time_t mTalkTime;
1358
        time_t mOtherTime;
1359
        time_t mTestTime;
1360
        int mAttackDelay;
1361
        int mMinHit;
1362
        int mMaxHit;
1363
        int mCriticalHit;
1364
        unsigned int mPvpRank;
1365
        unsigned int mNumber;
1366
        unsigned int mSpiritBalls;
1367
        int mUsageCounter;
1368
        int mKarma;
1369
        int mManner;
1370
        int mAreaSize;
1371
        int mCastEndTime;
1372
        int mLanguageId;
1373
        int mBadgesX;
1374
        int mBadgesY;
1375
        BeingId mCreatorId;
1376
        uint16_t mTeamId;
1377
        uint16_t mLook;
1378
        uint16_t mBadgesCount;
1379
        ItemColor mHairColor;
1380
        bool mErased;
1381
        bool mEnemy;
1382
        bool mGotComment;
1383
        bool mAdvanced;
1384
        bool mShop;
1385
        bool mAway;
1386
        bool mInactive;
1387
        bool mNeedPosUpdate;
1388
        bool mBotAi;
1389
        bool mAllowNpcEquipment;
1390
};
1391
1392
extern std::list<BeingCacheEntry*> beingInfoCache;
1393
1394
#endif  // BEING_BEING_H