GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/actormanager.h Lines: 0 11 0.0 %
Date: 2018-11-12 Branches: 0 0 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 ACTORMANAGER_H
24
#define ACTORMANAGER_H
25
26
#include "enums/being/actortype.h"
27
28
#include "enums/resources/item/itemtype.h"
29
30
#include "enums/simpletypes/allowsort.h"
31
#include "enums/simpletypes/allplayers.h"
32
#include "enums/simpletypes/beingid.h"
33
#include "enums/simpletypes/beingtypeid.h"
34
#include "enums/simpletypes/damaged.h"
35
#include "enums/simpletypes/identified.h"
36
#include "enums/simpletypes/itemcolor.h"
37
#include "enums/simpletypes/npcnames.h"
38
39
#include "listeners/configlistener.h"
40
41
#include "utils/cast.h"
42
#include "utils/stringmap.h"
43
#include "utils/stringvector.h"
44
45
#include <list>
46
#include <set>
47
48
#include "localconsts.h"
49
50
class ActorSprite;
51
class Being;
52
class FloorItem;
53
class LocalPlayer;
54
class Map;
55
56
struct ChatObject;
57
58
typedef std::set<ActorSprite*> ActorSprites;
59
typedef ActorSprites::iterator ActorSpritesIterator;
60
typedef ActorSprites::const_iterator ActorSpritesConstIterator;
61
typedef std::map<BeingId, ActorSprite*> ActorSpritesMap;
62
typedef ActorSpritesMap::iterator ActorSpritesMapIterator;
63
typedef ActorSpritesMap::const_iterator ActorSpritesMapConstIterator;
64
65
typedef std::map<BeingId, std::set<std::string> > IdNameMapping;
66
typedef IdNameMapping::const_iterator IdNameMappingCIter;
67
68
class ActorManager final : public ConfigListener
69
{
70
    public:
71
        ActorManager();
72
73
        A_DELETE_COPY(ActorManager)
74
75
        ~ActorManager() override final;
76
77
        /**
78
         * Sets the map on which ActorSprites are created.
79
         */
80
        void setMap(Map *const map);
81
82
        /**
83
         * Sets the current player.
84
         */
85
        void setPlayer(LocalPlayer *const player) A_NONNULL(2);
86
87
        /**
88
         * Create a Being and add it to the list of ActorSprites.
89
         */
90
        Being *createBeing(const BeingId id,
91
                           const ActorTypeT type,
92
                           const BeingTypeId subtype) A_WARN_UNUSED;
93
94
        static Being *cloneBeing(const Being *const srcBeing,
95
                                 const int dx, const int dy,
96
                                 const int id);
97
98
        /**
99
         * Create a FloorItem and add it to the list of ActorSprites.
100
         */
101
        FloorItem *createItem(const BeingId id,
102
                              const int itemId,
103
                              const int x, const int y,
104
                              const ItemTypeT itemType,
105
                              const int amount,
106
                              const int refine,
107
                              const ItemColor color,
108
                              const Identified identified,
109
                              const Damaged damaged,
110
                              const int subX, const int subY,
111
                              const int *const cards);
112
113
        /**
114
         * Destroys the given ActorSprite at the end of
115
         * ActorManager::logic.
116
         */
117
        void destroy(ActorSprite *const actor);
118
119
        void erase(ActorSprite *const actor);
120
121
        void undelete(const ActorSprite *const actor);
122
123
        /**
124
         * Returns a specific Being, by id;
125
         */
126
        Being *findBeing(const BeingId id) const A_WARN_UNUSED;
127
128
        ActorSprite *findActor(const BeingId id) const A_WARN_UNUSED;
129
130
        /**
131
         * Returns a being at specific coordinates.
132
         */
133
        Being *findBeing(const int x,
134
                         const int y,
135
                         const ActorTypeT type) const A_WARN_UNUSED;
136
137
        /**
138
         * Returns a being at the specific pixel.
139
         */
140
        Being *findBeingByPixel(const int x, const int y,
141
                                const AllPlayers allPlayers)
142
                                const A_WARN_UNUSED;
143
144
        /**
145
         * Returns a beings at the specific pixel.
146
         */
147
        void findBeingsByPixel(STD_VECTOR<ActorSprite*> &beings,
148
                               const int x, const int y,
149
                               const AllPlayers allPlayers) const;
150
151
        /**
152
         * Returns a portal at the specific tile.
153
         */
154
        Being *findPortalByTile(const int x, const int y) const A_WARN_UNUSED;
155
156
        /**
157
         * Returns a specific FloorItem, by id.
158
         */
159
        FloorItem *findItem(const BeingId id) const A_WARN_UNUSED;
160
161
        /**
162
         * Returns a FloorItem at specific coordinates.
163
         */
164
        FloorItem *findItem(const int x, const int y) const A_WARN_UNUSED;
165
166
        /**
167
         * Returns a being nearest to specific coordinates.
168
         *
169
         * @param x           X coordinate in pixels.
170
         * @param y           Y coordinate in pixels.
171
         * @param maxTileDist Maximal distance in tiles. If minimal distance is
172
         *                    larger, no being is returned.
173
         * @param type        The type of being to look for.
174
         */
175
        Being *findNearestLivingBeing(const int x, const int y,
176
                                      int maxTileDist,
177
                                      const ActorTypeT type,
178
                                      const Being *const excluded)
179
                                      const A_WARN_UNUSED;
180
181
        /**
182
         * Returns a being nearest to another being.
183
         *
184
         * @param aroundBeing The being to search around.
185
         * @param maxTileDist Maximal distance in tiles. If minimal distance is
186
         *                    larger, no being is returned.
187
         * @param type        The type of being to look for.
188
         */
189
        Being *findNearestLivingBeing(const Being *const aroundBeing,
190
                                      const int maxTileDist,
191
                                      const ActorTypeT type,
192
                                      const AllowSort allowSort)
193
                                      const A_WARN_UNUSED;
194
195
        /**
196
         * Finds a being by name and (optionally) by type.
197
         */
198
        Being *findBeingByName(const std::string &name,
199
                               const ActorTypeT type)
200
                               const A_WARN_UNUSED;
201
202
       /**
203
        * Finds a nearest being by name and (optionally) by type.
204
        */
205
        Being *findNearestByName(const std::string &name,
206
                                 const ActorTypeT &type) const A_WARN_UNUSED;
207
208
       /**
209
        * Finds most damaged player, non-enemy and alive
210
        * \param maxTileDist maximal distance.
211
        */
212
        Being *findMostDamagedPlayer(const int maxTileDist)
213
                                     const A_WARN_UNUSED;
214
215
       /**
216
        * Finds the nearest player who has PVP on,
217
        * or just the nearest player if map pvp is on
218
        */
219
        Being *findNearestPvpPlayer() const A_WARN_UNUSED;
220
221
#ifdef TMWA_SUPPORT
222
       /**
223
        * Heal all players in distance.
224
        *
225
        * \param maxdist maximal distance. If minimal distance is larger,
226
        *                no being is returned
227
        */
228
//        void HealAllTargets(Being *aroundBeing, int maxdist,
229
//                                            ActorTypeT type) const;
230
231
        void healTarget() const;
232
233
        void heal(const Being *const target) const;
234
235
        void itenplz() const;
236
#endif  // TMWA_SUPPORT
237
238
        /**
239
         * Returns the whole list of beings.
240
         */
241
        const ActorSprites &getAll() const A_CONST;
242
243
        /**
244
         * Returns true if the given ActorSprite is in the manager's list,
245
         * false otherwise.
246
         *
247
         * \param actor the ActorSprite to search for
248
         */
249
        bool hasActorSprite(const ActorSprite *const actor)
250
                            const A_WARN_UNUSED;
251
252
        /**
253
         * Performs ActorSprite logic and deletes ActorSprite scheduled to be
254
         * deleted.
255
         */
256
        void logic();
257
258
        /**
259
         * Destroys all ActorSprites except the local player
260
         */
261
        void clear();
262
263
        void addBlock(const BeingId id);
264
265
        void deleteBlock(const BeingId id);
266
267
        bool isBlocked(const BeingId id) const;
268
269
        void printAllToChat();
270
271
        void printBeingsToChat(const std::string &header) const;
272
273
        static void printBeingsToChat(const STD_VECTOR<Being*> &beings,
274
                                      const std::string &header);
275
276
        void getPlayerNames(StringVect &names,
277
                            const NpcNames npcNames) const;
278
279
        void getMobNames(StringVect &names) const;
280
281
        void updatePlayerNames() const;
282
283
        void updatePlayerColors() const;
284
285
        void updatePlayerGuild() const;
286
287
#ifdef TMWA_SUPPORT
288
        void parseLevels(std::string levels) const;
289
#endif  // TMWA_SUPPORT
290
291
        bool pickUpAll(const int x1,
292
                       const int y1,
293
                       const int x2,
294
                       const int y2,
295
                       const bool serverBuggy) const;
296
297
        bool pickUpNearest(const int x, const int y, int maxdist) const;
298
299
        void optionChanged(const std::string &name) override final;
300
301
        void removeAttackMob(const std::string &name);
302
303
        void removePickupItem(const std::string &name);
304
305
        void addPriorityAttackMob(const std::string &name);
306
307
        void addAttackMob(const std::string &name);
308
309
        void addIgnoreAttackMob(const std::string &name);
310
311
        void addPickupItem(const std::string &name);
312
313
        void addIgnorePickupItem(const std::string &name);
314
315
        void setPriorityAttackMobs(const std::list<std::string> &mobs)
316
        { mPriorityAttackMobs = mobs; }
317
318
        void setAttackMobs(const std::list<std::string> &mobs)
319
        { mAttackMobs = mobs; }
320
321
        int getPriorityAttackMobsSize() const noexcept2 A_WARN_UNUSED
322
        { return CAST_S32(mPriorityAttackMobs.size()); }
323
324
        int getAttackMobsSize() const noexcept2 A_WARN_UNUSED
325
        { return CAST_S32(mAttackMobs.size()); }
326
327
        int getPickupItemsSize() const noexcept2 A_WARN_UNUSED
328
        { return CAST_S32(mPickupItems.size()); }
329
330
#define defList(list1, mob) \
331
        bool isIn##list1##List(const std::string &name) const A_WARN_UNUSED\
332
        { return m##list1##mob##Set.find(name) != m##list1##mob##Set.end(); }\
333
        void rebuild##list1##mob();\
334
        std::set<std::string> get##list1##mob##Set() const noexcept2\
335
                                                   A_WARN_UNUSED\
336
        { return m##list1##mob##Set; }\
337
        std::list<std::string> get##list1##mob() const noexcept2 A_WARN_UNUSED\
338
        { return m##list1##mob; }
339
340
        defList(Attack, Mobs)
341
        defList(PriorityAttack, Mobs)
342
        defList(IgnoreAttack, Mobs)
343
        defList(Pickup, Items)
344
        defList(IgnorePickup, Items)
345
346
        const StringIntMap &getAttackMobsMap() const noexcept2 A_WARN_UNUSED
347
        { return mAttackMobsMap; }
348
349
        const StringIntMap &getPriorityAttackMobsMap() const noexcept2
350
                                                     A_WARN_UNUSED
351
        { return mPriorityAttackMobsMap; }
352
353
        int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED;
354
355
        int getPriorityAttackMobIndex(const std::string &name)
356
                                      const A_WARN_UNUSED;
357
358
        int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED;
359
360
        static int getIndexByName(const std::string &name,
361
                                  const StringIntMap &map)
362
                                  A_WARN_UNUSED;
363
364
        bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED;
365
366
        bool checkDefaultPickup() const A_WARN_UNUSED;
367
368
        void updateEffects(const std::map<BeingTypeId, int> &addEffects,
369
                           const std::set<BeingTypeId> &removeEffects) const;
370
371
        void updateBadges() const;
372
373
        void updateNameId(const std::string &name,
374
                          const BeingId beingId);
375
376
        void updateSeenPlayers(const std::set<std::string> &onlinePlayers);
377
378
        std::string getSeenPlayerById(const BeingId id) const;
379
380
        size_t size() const
381
        { return mActors.size(); }
382
383
        void removeRoom(const int chatId);
384
385
        void updateRoom(const ChatObject *const newChat);
386
387
        std::string findCharById(const int32_t id);
388
389
        void addChar(const int32_t id,
390
                     const std::string &name);
391
392
#ifndef UNITTESTS
393
    protected:
394
#endif  // UNITTESTS
395
        bool validateBeing(const Being *const aroundBeing,
396
                           Being *const being,
397
                           const ActorTypeT &type,
398
                           const Being *const excluded,
399
                           const int maxCost) const A_WARN_UNUSED;
400
401
        Being *findNearestLivingBeing(const Being *const aroundBeing,
402
                                      const int maxdist,
403
                                      const ActorTypeT &type,
404
                                      const int x, const int y,
405
                                      const Being *const excluded,
406
                                      const AllowSort allowSort)
407
                                      const A_WARN_UNUSED;
408
409
        void loadAttackList();
410
411
        void storeAttackList() const;
412
413
        ActorSprites mActors;
414
        ActorSprites mDeleteActors;
415
        ActorSpritesMap mActorsIdMap;
416
        IdNameMapping mIdName;
417
        std::set<BeingId> mBlockedBeings;
418
        std::map<int32_t, std::string> mChars;
419
        Map *mMap;
420
#ifdef TMWA_SUPPORT
421
        std::string mSpellHeal1;
422
        std::string mSpellHeal2;
423
        std::string mSpellItenplz;
424
#endif  // TMWA_SUPPORT
425
426
        bool mTargetDeadPlayers;
427
        bool mTargetOnlyReachable;
428
        bool mCyclePlayers;
429
        bool mCycleMonsters;
430
        bool mCycleNPC;
431
        bool mExtMouseTargeting;
432
        bool mEnableIdCollecting;
433
434
#define defVarsP(mob) \
435
        std::list<std::string> mPriority##mob;\
436
        std::set<std::string> mPriority##mob##Set;\
437
        StringIntMap mPriority##mob##Map;
438
439
#define defVars(mob) \
440
        std::list<std::string> m##mob;\
441
        std::set<std::string> m##mob##Set;\
442
        StringIntMap m##mob##Map;\
443
        std::list<std::string> mIgnore##mob;\
444
        std::set<std::string> mIgnore##mob##Set;
445
446
        defVarsP(AttackMobs)
447
        defVars(AttackMobs)
448
        defVars(PickupItems)
449
};
450
451
extern ActorManager *actorManager;
452
453
#endif  // ACTORMANAGER_H