ArmyManager.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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;
  29. TResources upgradeCost;
  30. ArmyUpgradeInfo()
  31. : resultingArmy(), upgradeValue(0), upgradeCost()
  32. {
  33. }
  34. };
  35. class DLL_EXPORT IArmyManager //: public: IAbstractManager
  36. {
  37. public:
  38. virtual ~IArmyManager() = default;
  39. virtual void update() = 0;
  40. virtual ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const = 0;
  41. virtual ui64 howManyReinforcementsCanBuy(
  42. const CCreatureSet * targetArmy,
  43. const CGDwelling * dwelling,
  44. const TResources & availableResources) const = 0;
  45. virtual ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const = 0;
  46. virtual ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
  47. virtual std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
  48. virtual std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const = 0;
  49. virtual std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const = 0;
  50. virtual std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling, TResources availableRes) const = 0;
  51. virtual uint64_t evaluateStackPower(const CCreature * creature, int count) const = 0;
  52. virtual SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const = 0;
  53. virtual ArmyUpgradeInfo calculateCreaturesUpgrade(
  54. const CCreatureSet * army,
  55. const CGObjectInstance * upgrader,
  56. const TResources & availableResources) const = 0;
  57. virtual std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const = 0;
  58. virtual std::shared_ptr<CCreatureSet> getArmyAvailableToBuyAsCCreatureSet(const CGDwelling * dwelling, TResources availableRes) const = 0;
  59. };
  60. class StackUpgradeInfo;
  61. class DLL_EXPORT ArmyManager : public IArmyManager
  62. {
  63. private:
  64. CPlayerSpecificInfoCallback * cb; //this is enough, but we downcast from CCallback
  65. const Nullkiller * ai;
  66. std::map<CreatureID, SlotInfo> totalArmy;
  67. public:
  68. ArmyManager(CPlayerSpecificInfoCallback * CB, const Nullkiller * ai): cb(CB), ai(ai) {}
  69. void update() override;
  70. ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
  71. ui64 howManyReinforcementsCanBuy(
  72. const CCreatureSet * targetArmy,
  73. const CGDwelling * dwelling,
  74. const TResources & availableResources) const override;
  75. ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const override;
  76. ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;
  77. std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;
  78. std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
  79. std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
  80. std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling, TResources availableRes) const override;
  81. std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const override;
  82. std::shared_ptr<CCreatureSet> getArmyAvailableToBuyAsCCreatureSet(const CGDwelling * dwelling, TResources availableRes) const override;
  83. uint64_t evaluateStackPower(const CCreature * creature, int count) const override;
  84. SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const override;
  85. ArmyUpgradeInfo calculateCreaturesUpgrade(
  86. const CCreatureSet * army,
  87. const CGObjectInstance * upgrader,
  88. const TResources & availableResources) const override;
  89. private:
  90. std::vector<SlotInfo> convertToSlots(const CCreatureSet * army) const;
  91. std::vector<StackUpgradeInfo> getPossibleUpgrades(const CCreatureSet * army, const CGObjectInstance * upgrader) const;
  92. std::vector<StackUpgradeInfo> getHillFortUpgrades(const CCreatureSet * army) const;
  93. std::vector<StackUpgradeInfo> getDwellingUpgrades(const CCreatureSet * army, const CGDwelling * dwelling) const;
  94. };
  95. }