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