BuildAnalyzer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * BuildAnalyzer.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/ResourceSet.h"
  13. namespace NK2AI
  14. {
  15. class ArmyManager;
  16. class Nullkiller;
  17. class DLL_EXPORT BuildingInfo
  18. {
  19. public:
  20. BuildingID id = BuildingID::NONE;
  21. TResources buildCost;
  22. TResources buildCostWithPrerequisites;
  23. int creatureGrowth = 0;
  24. uint8_t creatureLevel = 0; /// @link CCreature::level
  25. TResources creatureUnitCost;
  26. CreatureID creatureID = CreatureID::NONE;
  27. CreatureID baseCreatureID = CreatureID::NONE;
  28. TResources dailyIncome;
  29. uint8_t prerequisitesCount = 0;
  30. uint64_t armyStrength = 0;
  31. TResources armyCost; // creatureCost * creatureGrows
  32. std::string name;
  33. bool isBuilt = false;
  34. bool isBuildable = false;
  35. bool isMissingResources = false;
  36. BuildingInfo();
  37. BuildingInfo(
  38. const CBuilding * building,
  39. const CCreature * creature,
  40. CreatureID baseCreature,
  41. const CGTownInstance * town,
  42. const std::unique_ptr<ArmyManager> & armyManager);
  43. std::string toString() const;
  44. };
  45. class DLL_EXPORT TownDevelopmentInfo
  46. {
  47. public:
  48. const CGTownInstance* town;
  49. std::vector<BuildingInfo> toBuild;
  50. std::vector<BuildingInfo> built;
  51. TResources townDevelopmentCost;
  52. TResources requiredResources;
  53. TResources armyCost;
  54. uint64_t armyStrength = 0;
  55. TownDevelopmentInfo(const CGTownInstance * town) : town(town) {}
  56. TownDevelopmentInfo() : TownDevelopmentInfo(nullptr) {}
  57. void addBuildingToBuild(const BuildingInfo & bi);
  58. void addBuildingBuilt(const BuildingInfo & bi);
  59. };
  60. class DLL_EXPORT BuildAnalyzer
  61. {
  62. TResources requiredResources;
  63. TResources totalDevelopmentCost;
  64. std::vector<TownDevelopmentInfo> developmentInfos;
  65. TResources armyCost;
  66. TResources dailyIncome;
  67. float goldPressure = 0;
  68. Nullkiller * aiNk;
  69. public:
  70. explicit BuildAnalyzer(Nullkiller * aiNk) : aiNk(aiNk) {}
  71. void update();
  72. TResources getResourcesRequiredNow() const;
  73. TResources getTotalResourcesRequired() const;
  74. const std::vector<TownDevelopmentInfo> & getDevelopmentInfo() const { return developmentInfos; }
  75. TResources getDailyIncome() const { return dailyIncome; }
  76. float getGoldPressure() const { return goldPressure; }
  77. bool isGoldPressureOverMax() const;
  78. bool isBuilt(FactionID alignment, BuildingID bid) const;
  79. void reset();
  80. static float calculateGoldPressure(TResource lockedGold, float armyCostGold, float economyDevelopmentCost, float freeGold, float dailyIncomeGold);
  81. static TResources calculateDailyIncome(const std::vector<const CGObjectInstance *> & objects, const std::vector<const CGTownInstance *> & townInfos);
  82. static void updateDwellings(TownDevelopmentInfo& developmentInfo, std::unique_ptr<ArmyManager>& armyManager, std::shared_ptr<CCallback>& cc);
  83. static void updateOtherBuildings(TownDevelopmentInfo& developmentInfo, std::unique_ptr<ArmyManager>& armyManager, std::shared_ptr<CCallback>& cc);
  84. static BuildingInfo getBuildingOrPrerequisite(
  85. const CGTownInstance* town,
  86. BuildingID b,
  87. std::unique_ptr<ArmyManager> & armyManager,
  88. std::shared_ptr<CCallback> & cc,
  89. bool excludeDwellingDependencies = true);
  90. static int32_t approximateInGold(const TResources & res);
  91. static TResources withoutGold(TResources other);
  92. };
  93. }