ArmyManager.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * ArmyManager.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 "../AIUtility.h"
  12. #include "../../../lib/GameConstants.h"
  13. #include "../../../lib/VCMI_Lib.h"
  14. #include "../../../lib/CTownHandler.h"
  15. #include "../../../lib/CBuildingHandler.h"
  16. namespace NKAI
  17. {
  18. class Nullkiller;
  19. struct SlotInfo
  20. {
  21. const CCreature * creature;
  22. int count;
  23. uint64_t power;
  24. };
  25. struct ArmyUpgradeInfo
  26. {
  27. std::vector<SlotInfo> resultingArmy;
  28. uint64_t upgradeValue = 0;
  29. TResources upgradeCost;
  30. void addArmyToBuy(std::vector<SlotInfo> army);
  31. void addArmyToGet(std::vector<SlotInfo> army);
  32. };
  33. class DLL_EXPORT IArmyManager //: public: IAbstractManager
  34. {
  35. public:
  36. virtual ~IArmyManager() = default;
  37. virtual void update() = 0;
  38. virtual ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const = 0;
  39. virtual ui64 howManyReinforcementsCanBuy(
  40. const CCreatureSet * targetArmy,
  41. const CGDwelling * dwelling,
  42. const TResources & availableResources,
  43. uint8_t turn = 0) const = 0;
  44. virtual ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const = 0;
  45. virtual ui64 howManyReinforcementsCanGet(
  46. const IBonusBearer * armyCarrier,
  47. const CCreatureSet * target,
  48. const CCreatureSet * source) const = 0;
  49. virtual std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
  50. virtual std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const = 0;
  51. virtual std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const = 0;
  52. virtual std::vector<SlotInfo> toSlotInfo(std::vector<creInfo> creatures) const = 0;
  53. virtual std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const = 0;
  54. virtual std::vector<creInfo> getArmyAvailableToBuy(
  55. const CCreatureSet * hero,
  56. const CGDwelling * dwelling,
  57. TResources availableRes,
  58. uint8_t turn = 0) const = 0;
  59. virtual uint64_t evaluateStackPower(const Creature * creature, int count) const = 0;
  60. virtual SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const = 0;
  61. virtual ArmyUpgradeInfo calculateCreaturesUpgrade(
  62. const CCreatureSet * army,
  63. const CGObjectInstance * upgrader,
  64. const TResources & availableResources) const = 0;
  65. virtual std::shared_ptr<CCreatureSet> getArmyAvailableToBuyAsCCreatureSet(const CGDwelling * dwelling, TResources availableRes) const = 0;
  66. };
  67. class StackUpgradeInfo;
  68. class DLL_EXPORT ArmyManager : public IArmyManager
  69. {
  70. private:
  71. CPlayerSpecificInfoCallback * cb; //this is enough, but we downcast from CCallback
  72. const Nullkiller * ai;
  73. std::map<CreatureID, SlotInfo> totalArmy;
  74. public:
  75. ArmyManager(CPlayerSpecificInfoCallback * CB, const Nullkiller * ai): cb(CB), ai(ai) {}
  76. void update() override;
  77. ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
  78. ui64 howManyReinforcementsCanBuy(
  79. const CCreatureSet * targetArmy,
  80. const CGDwelling * dwelling,
  81. const TResources & availableResources,
  82. uint8_t turn = 0) const override;
  83. ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const override;
  84. ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;
  85. std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;
  86. std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
  87. std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
  88. std::vector<SlotInfo> toSlotInfo(std::vector<creInfo> creatures) const override;
  89. std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const override;
  90. std::vector<creInfo> getArmyAvailableToBuy(
  91. const CCreatureSet * hero,
  92. const CGDwelling * dwelling,
  93. TResources availableRes,
  94. uint8_t turn = 0) const override;
  95. std::shared_ptr<CCreatureSet> getArmyAvailableToBuyAsCCreatureSet(const CGDwelling * dwelling, TResources availableRes) const override;
  96. uint64_t evaluateStackPower(const Creature * creature, int count) const override;
  97. SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const override;
  98. ArmyUpgradeInfo calculateCreaturesUpgrade(
  99. const CCreatureSet * army,
  100. const CGObjectInstance * upgrader,
  101. const TResources & availableResources) const override;
  102. private:
  103. std::vector<SlotInfo> convertToSlots(const CCreatureSet * army) const;
  104. std::vector<StackUpgradeInfo> getPossibleUpgrades(const CCreatureSet * army, const CGObjectInstance * upgrader) const;
  105. std::vector<StackUpgradeInfo> getHillFortUpgrades(const CCreatureSet * army) const;
  106. std::vector<StackUpgradeInfo> getDwellingUpgrades(const CCreatureSet * army, const CGDwelling * dwelling) const;
  107. };
  108. }