CCreatureSet.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef __CCREATURESET_H__
  2. #define __CCREATURESET_H__
  3. #include "../global.h"
  4. #include <map>
  5. #include "HeroBonus.h"
  6. class CCreature;
  7. class CGHeroInstance;
  8. class CArmedInstance;
  9. //a few typedefs for CCreatureSet
  10. typedef si32 TSlot;
  11. typedef si32 TQuantity;
  12. typedef ui32 TCreature; //creature id
  13. const int ARMY_SIZE = 7;
  14. class DLL_EXPORT CStackInstance : public CBonusSystemNode
  15. {
  16. public:
  17. int idRand; //hlp variable used during loading game -> "id" placeholder for randomization
  18. const CArmedInstance *armyObj; //stack must be part of some army, army must be part of some object
  19. const CCreature *type;
  20. TQuantity count;
  21. ui32 getMinDamage() const;
  22. ui32 getMaxDamage() const;
  23. ui32 experience; //TODO: handle
  24. //TODO: stack artifacts
  25. template <typename Handler> void serialize(Handler &h, const int version)
  26. {
  27. h & static_cast<CBonusSystemNode&>(*this);
  28. h & armyObj & type & count & experience;
  29. }
  30. //overrides CBonusSystemNode
  31. void getParents(TCNodes &out, const CBonusSystemNode *source = NULL) const; //retrieves list of parent nodes (nodes to inherit bonuses from), source is the prinary asker
  32. int getQuantityID() const;
  33. std::string getQuantityTXT(bool capitalized = true) const;
  34. void init();
  35. CStackInstance();
  36. CStackInstance(TCreature id, TQuantity count, const CArmedInstance *ArmyObj = NULL);
  37. CStackInstance(const CCreature *cre, TQuantity count);
  38. void setType(int creID);
  39. };
  40. typedef std::map<TSlot, CStackInstance> TSlots;
  41. class DLL_EXPORT CCreatureSet //seven combined creatures
  42. {
  43. public:
  44. TSlots slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
  45. ui8 formation; //false - wide, true - tight
  46. const CStackInstance operator[](TSlot slot) const;
  47. const TSlots &Slots() const {return slots;}
  48. void addToSlot(TSlot slot, TCreature cre, TQuantity count, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
  49. void addToSlot(TSlot slot, const CStackInstance &stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
  50. void addStack(TSlot slot, const CStackInstance &stack); //adds new stack to the army, slot must be empty
  51. bool setCreature (TSlot slot, TCreature type, TQuantity quantity); //slots 0 to 6, if quantity=0, erases stack
  52. void clear();
  53. void setFormation(bool tight);
  54. void setStackCount(TSlot slot, TQuantity count); //stack must exist!
  55. void eraseStack(TSlot slot);
  56. const CStackInstance& getStack(TSlot slot) const;
  57. const CCreature* getCreature(TSlot slot) const; //workaround of map issue;
  58. int getAmount (TSlot slot) const;
  59. TSlot getSlotFor(TCreature creature, ui32 slotsAmount=ARMY_SIZE) const; //returns -1 if no slot available
  60. bool mergableStacks(std::pair<TSlot, TSlot> &out, TSlot preferable = -1) const; //looks for two same stacks, returns slot positions;
  61. bool validTypes(bool allowUnrandomized = false) const; //checks if all types of creatures are set properly
  62. bool slotEmpty(TSlot slot) const;
  63. int stacksCount() const;
  64. virtual bool needsLastStack() const; //true if last stack cannot be taken
  65. int getArmyStrength() const; //sum of AI values of creatures
  66. ui64 getPower (TSlot slot) const; //value of specific stack
  67. std::string getRoughAmount (TSlot slot) const; //rough size of specific stack
  68. bool contains(const CStackInstance *stack) const;
  69. template <typename Handler> void serialize(Handler &h, const int version)
  70. {
  71. h & slots & formation;
  72. }
  73. operator bool() const
  74. {
  75. return slots.size() > 0;
  76. }
  77. void sweep();
  78. };
  79. #endif // __CCREATURESET_H__