GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/actormanager.h Lines: 0 11 0.0 %
Date: 2017-11-29 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-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 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();
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, const int y, const ActorTypeT
134
                         type = ActorType::Unknown) const A_WARN_UNUSED;
135
136
        /**
137
         * Returns a being at the specific pixel.
138
         */
139
        Being *findBeingByPixel(const int x, const int y,
140
                                const AllPlayers allPlayers = AllPlayers_false)
141
                                const A_WARN_UNUSED;
142
143
        /**
144
         * Returns a beings at the specific pixel.
145
         */
146
        void findBeingsByPixel(STD_VECTOR<ActorSprite*> &beings,
147
                               const int x, const int y,
148
                               const AllPlayers allPlayers) const;
149
150
        /**
151
         * Returns a portal at the specific tile.
152
         */
153
        Being *findPortalByTile(const int x, const int y) const A_WARN_UNUSED;
154
155
        /**
156
         * Returns a specific FloorItem, by id.
157
         */
158
        FloorItem *findItem(const BeingId id) const A_WARN_UNUSED;
159
160
        /**
161
         * Returns a FloorItem at specific coordinates.
162
         */
163
        FloorItem *findItem(const int x, const int y) const A_WARN_UNUSED;
164
165
        /**
166
         * Returns a being nearest to specific coordinates.
167
         *
168
         * @param x           X coordinate in pixels.
169
         * @param y           Y coordinate in pixels.
170
         * @param maxTileDist Maximal distance in tiles. If minimal distance is
171
         *                    larger, no being is returned.
172
         * @param type        The type of being to look for.
173
         */
174
        Being *findNearestLivingBeing(const int x, const int y,
175
                                      int maxTileDist,
176
                                      const ActorTypeT type,
177
                                      const Being *const excluded)
178
                                      const A_WARN_UNUSED;
179
180
        /**
181
         * Returns a being nearest to another being.
182
         *
183
         * @param aroundBeing The being to search around.
184
         * @param maxTileDist Maximal distance in tiles. If minimal distance is
185
         *                    larger, no being is returned.
186
         * @param type        The type of being to look for.
187
         */
188
        Being *findNearestLivingBeing(const Being *const aroundBeing,
189
                                      const int maxTileDist,
190
                                      const ActorTypeT type,
191
                                      const AllowSort allowSort)
192
                                      const A_WARN_UNUSED;
193
194
        /**
195
         * Finds a being by name and (optionally) by type.
196
         */
197
        Being *findBeingByName(const std::string &name,
198
                               const ActorTypeT
199
                               type = ActorType::Unknown)
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
207
                                 = ActorType::Unknown) const A_WARN_UNUSED;
208
209
       /**
210
        * Finds most damaged player, non-enemy and alive
211
        * \param maxTileDist maximal distance.
212
        */
213
        Being *findMostDamagedPlayer(const int maxTileDist)
214
                                     const A_WARN_UNUSED;
215
216
       /**
217
        * Finds the nearest player who has PVP on,
218
        * or just the nearest player if map pvp is on
219
        */
220
        Being *findNearestPvpPlayer() const A_WARN_UNUSED;
221
222
#ifdef TMWA_SUPPORT
223
       /**
224
        * Heal all players in distance.
225
        *
226
        * \param maxdist maximal distance. If minimal distance is larger,
227
        *                no being is returned
228
        */
229
//        void HealAllTargets(Being *aroundBeing, int maxdist,
230
//                                            ActorTypeT type) const;
231
232
        void healTarget() const;
233
234
        void heal(const Being *const target) const;
235
236
        void itenplz() const;
237
#endif  // TMWA_SUPPORT
238
239
        /**
240
         * Returns the whole list of beings.
241
         */
242
        const ActorSprites &getAll() const A_CONST;
243
244
        /**
245
         * Returns true if the given ActorSprite is in the manager's list,
246
         * false otherwise.
247
         *
248
         * \param actor the ActorSprite to search for
249
         */
250
        bool hasActorSprite(const ActorSprite *const actor)
251
                            const A_WARN_UNUSED;
252
253
        /**
254
         * Performs ActorSprite logic and deletes ActorSprite scheduled to be
255
         * deleted.
256
         */
257
        void logic();
258
259
        /**
260
         * Destroys all ActorSprites except the local player
261
         */
262
        void clear();
263
264
        void addBlock(const BeingId id);
265
266
        void deleteBlock(const BeingId id);
267
268
        bool isBlocked(const BeingId id) const;
269
270
        void printAllToChat();
271
272
        void printBeingsToChat(const std::string &header) const;
273
274
        static void printBeingsToChat(const STD_VECTOR<Being*> &beings,
275
                                      const std::string &header);
276
277
        void getPlayerNames(StringVect &names,
278
                            const NpcNames npcNames) const;
279
280
        void getMobNames(StringVect &names) const;
281
282
        void updatePlayerNames() const;
283
284
        void updatePlayerColors() const;
285
286
        void updatePlayerGuild() const;
287
288
#ifdef TMWA_SUPPORT
289
        void parseLevels(std::string levels) const;
290
#endif  // TMWA_SUPPORT
291
292
        bool pickUpAll(const int x1,
293
                       const int y1,
294
                       const int x2,
295
                       const int y2,
296
                       const bool serverBuggy = false) const;
297
298
        bool pickUpNearest(const int x, const int y, int maxdist) const;
299
300
        void optionChanged(const std::string &name) override final;
301
302
        void removeAttackMob(const std::string &name);
303
304
        void removePickupItem(const std::string &name);
305
306
        void addPriorityAttackMob(const std::string &name);
307
308
        void addAttackMob(const std::string &name);
309
310
        void addIgnoreAttackMob(const std::string &name);
311
312
        void addPickupItem(const std::string &name);
313
314
        void addIgnorePickupItem(const std::string &name);
315
316
        void setPriorityAttackMobs(const std::list<std::string> &mobs)
317
        { mPriorityAttackMobs = mobs; }
318
319
        void setAttackMobs(const std::list<std::string> &mobs)
320
        { mAttackMobs = mobs; }
321
322
        int getPriorityAttackMobsSize() const noexcept2 A_WARN_UNUSED
323
        { return CAST_S32(mPriorityAttackMobs.size()); }
324
325
        int getAttackMobsSize() const noexcept2 A_WARN_UNUSED
326
        { return CAST_S32(mAttackMobs.size()); }
327
328
        int getPickupItemsSize() const noexcept2 A_WARN_UNUSED
329
        { return CAST_S32(mPickupItems.size()); }
330
331
#define defList(list1, mob) \
332
        bool isIn##list1##List(const std::string &name) const A_WARN_UNUSED\
333
        { return m##list1##mob##Set.find(name) != m##list1##mob##Set.end(); }\
334
        void rebuild##list1##mob();\
335
        std::set<std::string> get##list1##mob##Set() const noexcept2\
336
                                                   A_WARN_UNUSED\
337
        { return m##list1##mob##Set; }\
338
        std::list<std::string> get##list1##mob() const noexcept2 A_WARN_UNUSED\
339
        { return m##list1##mob; }
340
341
        defList(Attack, Mobs)
342
        defList(PriorityAttack, Mobs)
343
        defList(IgnoreAttack, Mobs)
344
        defList(Pickup, Items)
345
        defList(IgnorePickup, Items)
346
347
        const StringIntMap &getAttackMobsMap() const noexcept2 A_WARN_UNUSED
348
        { return mAttackMobsMap; }
349
350
        const StringIntMap &getPriorityAttackMobsMap() const noexcept2
351
                                                     A_WARN_UNUSED
352
        { return mPriorityAttackMobsMap; }
353
354
        int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED;
355
356
        int getPriorityAttackMobIndex(const std::string &name)
357
                                      const A_WARN_UNUSED;
358
359
        int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED;
360
361
        static int getIndexByName(const std::string &name,
362
                                  const StringIntMap &map)
363
                                  A_WARN_UNUSED;
364
365
        bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED;
366
367
        bool checkDefaultPickup() const A_WARN_UNUSED;
368
369
        void updateEffects(const std::map<BeingTypeId, int> &addEffects,
370
                           const std::set<BeingTypeId> &removeEffects) const;
371
372
        void updateBadges() const;
373
374
        void updateNameId(const std::string &name,
375
                          const BeingId beingId);
376
377
        void updateSeenPlayers(const std::set<std::string> &onlinePlayers);
378
379
        std::string getSeenPlayerById(const BeingId id) const;
380
381
        size_t size() const
382
        { return mActors.size(); }
383
384
        void removeRoom(const int chatId);
385
386
        void updateRoom(const ChatObject *const newChat);
387
388
        std::string findCharById(const int32_t id);
389
390
        void addChar(const int32_t id,
391
                     const std::string &name);
392
393
#ifndef UNITTESTS
394
    protected:
395
#endif  // UNITTESTS
396
        bool validateBeing(const Being *const aroundBeing,
397
                           Being *const being,
398
                           const ActorTypeT &type,
399
                           const Being *const excluded = nullptr,
400
                           const int maxCost = 20) const A_WARN_UNUSED;
401
402
        Being *findNearestLivingBeing(const Being *const aroundBeing,
403
                                      const int maxdist,
404
                                      const ActorTypeT &type,
405
                                      const int x, const int y,
406
                                      const Being *const excluded,
407
                                      const AllowSort allowSort)
408
                                      const A_WARN_UNUSED;
409
410
        void loadAttackList();
411
412
        void storeAttackList() const;
413
414
        ActorSprites mActors;
415
        ActorSprites mDeleteActors;
416
        ActorSpritesMap mActorsIdMap;
417
        IdNameMapping mIdName;
418
        std::set<BeingId> mBlockedBeings;
419
        std::map<int32_t, std::string> mChars;
420
        Map *mMap;
421
#ifdef TMWA_SUPPORT
422
        std::string mSpellHeal1;
423
        std::string mSpellHeal2;
424
        std::string mSpellItenplz;
425
#endif  // TMWA_SUPPORT
426
427
        bool mTargetDeadPlayers;
428
        bool mTargetOnlyReachable;
429
        bool mCyclePlayers;
430
        bool mCycleMonsters;
431
        bool mCycleNPC;
432
        bool mExtMouseTargeting;
433
        bool mEnableIdCollecting;
434
435
#define defVarsP(mob) \
436
        std::list<std::string> mPriority##mob;\
437
        std::set<std::string> mPriority##mob##Set;\
438
        StringIntMap mPriority##mob##Map;
439
440
#define defVars(mob) \
441
        std::list<std::string> m##mob;\
442
        std::set<std::string> m##mob##Set;\
443
        StringIntMap m##mob##Map;\
444
        std::list<std::string> mIgnore##mob;\
445
        std::set<std::string> mIgnore##mob##Set;
446
447
        defVarsP(AttackMobs)
448
        defVars(AttackMobs)
449
        defVars(PickupItems)
450
};
451
452
extern ActorManager *actorManager;
453
454
#endif  // ACTORMANAGER_H