UpgradeInfo.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * UpgradeInfo.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 "../lib/constants/EntityIdentifiers.h"
  12. #include "../lib/ResourceSet.h"
  13. #include <boost/container/small_vector.hpp>
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class DLL_LINKAGE UpgradeInfo
  16. {
  17. public:
  18. UpgradeInfo() = delete;
  19. UpgradeInfo(CreatureID base)
  20. : oldID(base), isAvailable(true)
  21. {
  22. }
  23. CreatureID oldID; //creature to be upgraded
  24. const boost::container::small_vector<CreatureID, 4> & getAvailableUpgrades() const
  25. {
  26. static const boost::container::small_vector<CreatureID, 4> emptyUpgrades;
  27. return (isAvailable && !upgradesIDs.empty()) ? upgradesIDs : emptyUpgrades;
  28. }
  29. const CreatureID & getUpgrade() const
  30. {
  31. return upgradesIDs.back();
  32. }
  33. const ResourceSet & getUpgradeCostsFor(CreatureID id) const
  34. {
  35. auto idIt = std::find(upgradesIDs.begin(), upgradesIDs.end(), id);
  36. assert(idIt != upgradesIDs.end());
  37. return upgradesCosts[std::distance(upgradesIDs.begin(), idIt)];
  38. }
  39. const boost::container::small_vector<ResourceSet, 4> & getAvailableUpgradeCosts() const
  40. {
  41. static const boost::container::small_vector<ResourceSet, 4> emptyCosts;
  42. return (isAvailable && !upgradesCosts.empty()) ? upgradesCosts : emptyCosts;
  43. }
  44. const ResourceSet & getUpgradeCosts() const
  45. {
  46. return upgradesCosts.back();
  47. }
  48. bool canUpgrade() const
  49. {
  50. return !upgradesIDs.empty() && isAvailable;
  51. }
  52. bool hasUpgrades() const
  53. {
  54. return !upgradesIDs.empty();
  55. }
  56. // Adds a new upgrade and ensures alignment and sorted order
  57. void addUpgrade(const CreatureID & upgradeID, const Creature * creature, int costPercentageModifier = 100);
  58. auto size() const
  59. {
  60. return upgradesIDs.size();
  61. }
  62. private:
  63. boost::container::small_vector<CreatureID, 4> upgradesIDs; //possible upgrades
  64. boost::container::small_vector<ResourceSet, 4> upgradesCosts; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>; cost is for single unit (not entire stack)
  65. bool isAvailable; // flag for unavailableUpgrades like in miniHillFort from HoTA
  66. };
  67. VCMI_LIB_NAMESPACE_END