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