UpgradeInfo.h 1.8 KB

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