ManaPlus
actormanager.h
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef ACTORMANAGER_H
25 #define ACTORMANAGER_H
26 
27 #include "enums/being/actortype.h"
28 
30 
39 
41 
42 #include "utils/cast.h"
43 #include "utils/stringmap.h"
44 #include "utils/stringvector.h"
45 
46 #include <list>
47 #include <set>
48 
49 #include "localconsts.h"
50 
51 class ActorSprite;
52 class Being;
53 class FloorItem;
54 class LocalPlayer;
55 class Map;
56 
57 struct ChatObject;
58 
59 typedef std::set<ActorSprite*> ActorSprites;
60 typedef ActorSprites::iterator ActorSpritesIterator;
61 typedef ActorSprites::const_iterator ActorSpritesConstIterator;
62 typedef std::map<BeingId, ActorSprite*> ActorSpritesMap;
63 typedef ActorSpritesMap::iterator ActorSpritesMapIterator;
64 typedef ActorSpritesMap::const_iterator ActorSpritesMapConstIterator;
65 
66 typedef std::map<BeingId, std::set<std::string> > IdNameMapping;
67 typedef IdNameMapping::const_iterator IdNameMappingCIter;
68 
70 {
71  public:
72  ActorManager();
73 
75 
76  ~ActorManager() override final;
77 
81  void setMap(Map *const map);
82 
86  void setPlayer(LocalPlayer *const player) A_NONNULL(2);
87 
91  Being *createBeing(const BeingId id,
92  const ActorTypeT type,
93  const BeingTypeId subtype) A_WARN_UNUSED;
94 
95  static Being *cloneBeing(const Being *const srcBeing,
96  const int dx, const int dy,
97  const int id);
98 
102  FloorItem *createItem(const BeingId id,
103  const int itemId,
104  const int x, const int y,
105  const ItemTypeT itemType,
106  const int amount,
107  const int refine,
108  const ItemColor color,
109  const Identified identified,
110  const Damaged damaged,
111  const int subX, const int subY,
112  const int *const cards);
113 
118  void destroy(ActorSprite *const actor);
119 
120  void erase(ActorSprite *const actor);
121 
122  void undelete(const ActorSprite *const actor);
123 
127  Being *findBeing(const BeingId id) const A_WARN_UNUSED;
128 
129  ActorSprite *findActor(const BeingId id) const A_WARN_UNUSED;
130 
134  Being *findBeing(const int x,
135  const int y,
136  const ActorTypeT type) const A_WARN_UNUSED;
137 
141  Being *findBeingByPixel(const int x, const int y,
142  const AllPlayers allPlayers)
143  const A_WARN_UNUSED;
144 
148  void findBeingsByPixel(STD_VECTOR<ActorSprite*> &beings,
149  const int x, const int y,
150  const AllPlayers allPlayers) const;
151 
155  Being *findPortalByTile(const int x, const int y) const A_WARN_UNUSED;
156 
160  FloorItem *findItem(const BeingId id) const A_WARN_UNUSED;
161 
165  FloorItem *findItem(const int x, const int y) const A_WARN_UNUSED;
166 
176  Being *findNearestLivingBeing(const int x, const int y,
177  int maxTileDist,
178  const ActorTypeT type,
179  const Being *const excluded)
180  const A_WARN_UNUSED;
181 
190  Being *findNearestLivingBeing(const Being *const aroundBeing,
191  const int maxTileDist,
192  const ActorTypeT type,
193  const AllowSort allowSort)
194  const A_WARN_UNUSED;
195 
199  Being *findBeingByName(const std::string &name,
200  const ActorTypeT type)
201  const A_WARN_UNUSED;
202 
206  Being *findNearestByName(const std::string &name,
207  const ActorTypeT &type) const A_WARN_UNUSED;
208 
213  Being *findMostDamagedPlayer(const int maxTileDist)
214  const A_WARN_UNUSED;
215 
221 
222 #ifdef TMWA_SUPPORT
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 
242  const ActorSprites &getAll() const A_CONST;
243 
250  bool hasActorSprite(const ActorSprite *const actor)
251  const A_WARN_UNUSED;
252 
257  void logic();
258 
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) 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 
323  { return CAST_S32(mPriorityAttackMobs.size()); }
324 
326  { return CAST_S32(mAttackMobs.size()); }
327 
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 
342  defList(PriorityAttack, Mobs)
343  defList(IgnoreAttack, Mobs)
344  defList(Pickup, Items)
345  defList(IgnorePickup, Items)
346 
348  { return mAttackMobsMap; }
349 
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)
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,
400  const int maxCost) 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 
418  std::set<BeingId> mBlockedBeings;
419  std::map<int32_t, std::string> mChars;
421 #ifdef TMWA_SUPPORT
422  std::string mSpellHeal1;
423  std::string mSpellHeal2;
424  std::string mSpellItenplz;
425 #endif // TMWA_SUPPORT
426 
431  bool mCycleNPC;
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
std::set< ActorSprite * > ActorSprites
Definition: actormanager.h:57
#define defList(list1, mob)
Definition: actormanager.h:331
IdNameMapping::const_iterator IdNameMappingCIter
Definition: actormanager.h:67
std::map< BeingId, std::set< std::string > > IdNameMapping
Definition: actormanager.h:66
std::map< BeingId, ActorSprite * > ActorSpritesMap
Definition: actormanager.h:62
ActorSprites::const_iterator ActorSpritesConstIterator
Definition: actormanager.h:61
ActorSprites::iterator ActorSpritesIterator
Definition: actormanager.h:60
ActorSpritesMap::iterator ActorSpritesMapIterator
Definition: actormanager.h:63
ActorSpritesMap::const_iterator ActorSpritesMapConstIterator
Definition: actormanager.h:64
#define defVars(mob)
Definition: actormanager.h:440
#define defVarsP(mob)
Definition: actormanager.h:435
ActorManager * actorManager
ActorType ::T ActorTypeT
Definition: actortype.h:43
bool AllowSort
Definition: allowsort.h:30
bool AllPlayers
Definition: allplayers.h:30
int BeingId
Definition: beingid.h:30
int BeingTypeId
Definition: beingtypeid.h:30
#define CAST_S32
Definition: cast.h:30
std::string findCharById(const int32_t id)
int getPriorityAttackMobIndex(const std::string &name) const
void updatePlayerColors() const
void setPlayer(LocalPlayer *const player)
ActorSprites mDeleteActors
Definition: actormanager.h:415
bool pickUpAll(const int x1, const int y1, const int x2, const int y2, const bool serverBuggy) const
Being * findPortalByTile(const int x, const int y) const
Being * findNearestLivingBeing(const int x, const int y, int maxTileDist, const ActorTypeT type, const Being *const excluded) const
IdNameMapping mIdName
Definition: actormanager.h:417
void findBeingsByPixel(std::vector< ActorSprite * > &beings, const int x, const int y, const AllPlayers allPlayers) const
bool hasActorSprite(const ActorSprite *const actor) const
Being * findMostDamagedPlayer(const int maxTileDist) const
void setAttackMobs(const std::list< std::string > &mobs)
Definition: actormanager.h:319
Being * findBeing(const BeingId id) const
void updateRoom(const ChatObject *const newChat)
void parseLevels(std::string levels) const
bool mCycleMonsters
Definition: actormanager.h:430
void updateBadges() const
Being * findNearestPvpPlayer() const
void heal(const Being *const target) const
void printAllToChat()
bool mEnableIdCollecting
Definition: actormanager.h:433
static Being * cloneBeing(const Being *const srcBeing, const int dx, const int dy, const int id)
std::string mSpellHeal1
Definition: actormanager.h:422
bool mCyclePlayers
Definition: actormanager.h:429
bool mExtMouseTargeting
Definition: actormanager.h:432
bool mTargetOnlyReachable
Definition: actormanager.h:428
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
bool checkDefaultPickup() const
void addAttackMob(const std::string &name)
void destroy(ActorSprite *const actor)
void addIgnorePickupItem(const std::string &name)
void itenplz() const
void getMobNames(StringVect &names) const
const StringIntMap & getPriorityAttackMobsMap() const
Definition: actormanager.h:350
void addChar(const int32_t id, const std::string &name)
int getPickupItemsSize() const
Definition: actormanager.h:328
size_t size() const
Definition: actormanager.h:381
void undelete(const ActorSprite *const actor)
std::list< std::string > mPickupItems
Definition: actormanager.h:449
void addIgnoreAttackMob(const std::string &name)
void addBlock(const BeingId id)
void setMap(Map *const map)
std::string getSeenPlayerById(const BeingId id) const
void updateNameId(const std::string &name, const BeingId beingId)
void removeAttackMob(const std::string &name)
bool mTargetDeadPlayers
Definition: actormanager.h:427
std::list< std::string > mAttackMobs
Definition: actormanager.h:448
void optionChanged(const std::string &name)
std::string mSpellItenplz
Definition: actormanager.h:424
void updateEffects(const std::map< BeingTypeId, int > &addEffects, const std::set< BeingTypeId > &removeEffects) const
void removeRoom(const int chatId)
ActorSprite * findActor(const BeingId id) const
int getPriorityAttackMobsSize() const
Definition: actormanager.h:322
void updatePlayerNames() const
ActorSprites mActors
Definition: actormanager.h:414
StringIntMap mAttackMobsMap
Definition: actormanager.h:448
void addPickupItem(const std::string &name)
void storeAttackList() const
int getPickupItemIndex(const std::string &name) const
std::string mSpellHeal2
Definition: actormanager.h:423
void updatePlayerGuild() const
int getAttackMobsSize() const
Definition: actormanager.h:325
FloorItem * findItem(const BeingId id) const
Being * findNearestByName(const std::string &name, const ActorTypeT &type) const
std::set< BeingId > mBlockedBeings
Definition: actormanager.h:418
bool validateBeing(const Being *const aroundBeing, Being *const being, const ActorTypeT &type, const Being *const excluded, const int maxCost) const
std::list< std::string > mPriorityAttackMobs
Definition: actormanager.h:447
void deleteBlock(const BeingId id)
void loadAttackList()
bool isBlocked(const BeingId id) const
Being * createBeing(const BeingId id, const ActorTypeT type, const BeingTypeId subtype)
void healTarget() const
void removePickupItem(const std::string &name)
bool checkForPickup(const FloorItem *const item) const
void addPriorityAttackMob(const std::string &name)
Being * findBeingByPixel(const int x, const int y, const AllPlayers allPlayers) const
const ActorSprites & getAll() const A_CONST
FloorItem * createItem(const BeingId id, const int itemId, const int x, const int y, const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, const Identified identified, const Damaged damaged, const int subX, const int subY, const int *const cards)
StringIntMap mPriorityAttackMobsMap
Definition: actormanager.h:447
const StringIntMap & getAttackMobsMap() const
Definition: actormanager.h:347
void printBeingsToChat(const std::string &header) const
ActorSpritesMap mActorsIdMap
Definition: actormanager.h:416
int getAttackMobIndex(const std::string &name) const
void setPriorityAttackMobs(const std::list< std::string > &mobs)
Definition: actormanager.h:316
void erase(ActorSprite *const actor)
bool pickUpNearest(const int x, const int y, int maxdist) const
void getPlayerNames(StringVect &names, const NpcNames npcNames) const
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
std::map< int32_t, std::string > mChars
Definition: actormanager.h:419
static int getIndexByName(const std::string &name, const StringIntMap &map)
Definition: being.h:96
Definition: map.h:75
bool Damaged
Definition: damaged.h:30
bool Identified
Definition: identified.h:30
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
Definition: pickup.h:31
bool NpcNames
Definition: npcnames.h:30
std::map< std::string, int > StringIntMap
Definition: stringmap.h:28
std::vector< std::string > StringVect
Definition: stringvector.h:29
Definition: attack.h:30