BuildAnalyzer.h 2.6 KB

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