ArmyManager.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 void update() = 0;
  37. virtual ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const = 0;
  38. virtual ui64 howManyReinforcementsCanBuy(
  39. const CCreatureSet * h,
  40. const CGDwelling * t,
  41. const TResources & availableResources) const = 0;
  42. virtual ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const = 0;
  43. virtual ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
  44. virtual std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
  45. virtual std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const = 0;
  46. virtual std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const = 0;
  47. virtual std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling, TResources availableRes) const = 0;
  48. virtual uint64_t evaluateStackPower(const CCreature * creature, int count) const = 0;
  49. virtual SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const = 0;
  50. virtual ArmyUpgradeInfo calculateCreateresUpgrade(
  51. const CCreatureSet * army,
  52. const CGObjectInstance * upgrader,
  53. const TResources & availableResources) const = 0;
  54. virtual std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const = 0;
  55. };
  56. struct 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 * h,
  69. const CGDwelling * t,
  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. uint64_t evaluateStackPower(const CCreature * creature, int count) const override;
  79. SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const override;
  80. ArmyUpgradeInfo calculateCreateresUpgrade(
  81. const CCreatureSet * army,
  82. const CGObjectInstance * upgrader,
  83. const TResources & availableResources) const override;
  84. private:
  85. std::vector<SlotInfo> convertToSlots(const CCreatureSet * army) const;
  86. std::vector<StackUpgradeInfo> getPossibleUpgrades(const CCreatureSet * army, const CGObjectInstance * upgrader) const;
  87. std::vector<StackUpgradeInfo> getHillFortUpgrades(const CCreatureSet * army) const;
  88. std::vector<StackUpgradeInfo> getDwellingUpgrades(const CCreatureSet * army, const CGDwelling * dwelling) const;
  89. };