BuildAnalyzer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 NKAI
  14. {
  15. class Nullkiller;
  16. class DLL_EXPORT BuildingInfo
  17. {
  18. public:
  19. BuildingID id;
  20. TResources buildCost;
  21. TResources buildCostWithPrerequisites;
  22. int creatureGrows;
  23. uint8_t creatureLevel;
  24. TResources creatureCost;
  25. CreatureID creatureID;
  26. CreatureID baseCreatureID;
  27. TResources dailyIncome;
  28. uint8_t prerequisitesCount;
  29. uint64_t armyStrength;
  30. TResources armyCost;
  31. std::string name;
  32. bool exists = false;
  33. bool canBuild = false;
  34. bool notEnoughRes = false;
  35. BuildingInfo();
  36. BuildingInfo(
  37. const CBuilding * building,
  38. const CCreature * creature,
  39. CreatureID baseCreature,
  40. const CGTownInstance * town,
  41. Nullkiller * ai);
  42. std::string toString() const;
  43. };
  44. class DLL_EXPORT TownDevelopmentInfo
  45. {
  46. public:
  47. const CGTownInstance* town;
  48. std::vector<BuildingInfo> toBuild;
  49. std::vector<BuildingInfo> existingDwellings;
  50. TResources townDevelopmentCost;
  51. TResources requiredResources;
  52. TResources armyCost;
  53. uint64_t armyStrength;
  54. HeroRole townRole;
  55. bool hasSomethingToBuild;
  56. TownDevelopmentInfo(const CGTownInstance * town):
  57. town(town),
  58. armyStrength(0),
  59. townRole(HeroRole::SCOUT),
  60. hasSomethingToBuild(false)
  61. {
  62. }
  63. TownDevelopmentInfo() : TownDevelopmentInfo(nullptr) {}
  64. void addBuildingToBuild(const BuildingInfo & building);
  65. void addExistingDwelling(const BuildingInfo & existingDwelling);
  66. };
  67. class DLL_EXPORT BuildAnalyzer
  68. {
  69. private:
  70. TResources requiredResources;
  71. TResources totalDevelopmentCost;
  72. std::vector<TownDevelopmentInfo> developmentInfos;
  73. TResources armyCost;
  74. TResources dailyIncome;
  75. float goldPressure;
  76. Nullkiller * ai;
  77. public:
  78. BuildAnalyzer(Nullkiller * ai) : ai(ai) {}
  79. void update();
  80. TResources getResourcesRequiredNow() const;
  81. TResources getTotalResourcesRequired() const;
  82. const std::vector<TownDevelopmentInfo> & getDevelopmentInfo() const { return developmentInfos; }
  83. TResources getDailyIncome() const { return dailyIncome; }
  84. float getGoldPressure() const { return goldPressure; }
  85. bool isGoldPressureHigh() const;
  86. bool hasAnyBuilding(int32_t alignment, BuildingID bid) const;
  87. private:
  88. BuildingInfo getBuildingOrPrerequisite(
  89. const CGTownInstance* town,
  90. BuildingID toBuild,
  91. bool excludeDwellingDependencies = true) const;
  92. void updateTownDwellings(TownDevelopmentInfo & developmentInfo);
  93. void updateOtherBuildings(TownDevelopmentInfo & developmentInfo);
  94. void updateDailyIncome();
  95. void reset();
  96. };
  97. }