CSimpleArmy.h 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * CSimpleArmy.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "GameConstants.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class IArmyDescriptor
  14. {
  15. public:
  16. virtual void clearSlots() = 0;
  17. virtual bool setCreature(SlotID slot, CreatureID cre, TQuantity count) = 0;
  18. };
  19. using TSimpleSlots = std::map<SlotID, std::pair<CreatureID, TQuantity>>;
  20. //simplified version of CCreatureSet
  21. class DLL_LINKAGE CSimpleArmy : public IArmyDescriptor
  22. {
  23. public:
  24. TSimpleSlots army;
  25. void clearSlots() override
  26. {
  27. army.clear();
  28. }
  29. bool setCreature(SlotID slot, CreatureID cre, TQuantity count) override
  30. {
  31. assert(!vstd::contains(army, slot));
  32. army[slot] = std::make_pair(cre, count);
  33. return true;
  34. }
  35. operator bool() const
  36. {
  37. return !army.empty();
  38. }
  39. template <typename Handler> void serialize(Handler &h)
  40. {
  41. h & army;
  42. }
  43. };
  44. VCMI_LIB_NAMESPACE_END