ArmyManager.h 4.7 KB

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