BuildAnalyzer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 buildCostWithPrerequisits;
  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), armyStrength(0), toBuild(), townDevelopmentCost(), requiredResources(), townRole(HeroRole::SCOUT), hasSomethingToBuild(false)
  58. {
  59. }
  60. TownDevelopmentInfo() : TownDevelopmentInfo(nullptr) {}
  61. void addBuildingToBuild(const BuildingInfo & building);
  62. void addExistingDwelling(const BuildingInfo & existingDwelling);
  63. };
  64. class DLL_EXPORT BuildAnalyzer
  65. {
  66. private:
  67. TResources requiredResources;
  68. TResources totalDevelopmentCost;
  69. std::vector<TownDevelopmentInfo> developmentInfos;
  70. TResources armyCost;
  71. TResources dailyIncome;
  72. float goldPreasure;
  73. Nullkiller * ai;
  74. public:
  75. BuildAnalyzer(Nullkiller * ai) : ai(ai) {}
  76. void update();
  77. TResources getResourcesRequiredNow() const;
  78. TResources getTotalResourcesRequired() const;
  79. const std::vector<TownDevelopmentInfo> & getDevelopmentInfo() const { return developmentInfos; }
  80. TResources getDailyIncome() const { return dailyIncome; }
  81. float getGoldPreasure() const { return goldPreasure; }
  82. bool hasAnyBuilding(int32_t alignment, BuildingID bid) const;
  83. private:
  84. BuildingInfo getBuildingOrPrerequisite(
  85. const CGTownInstance* town,
  86. BuildingID toBuild,
  87. bool excludeDwellingDependencies = true) const;
  88. void updateTownDwellings(TownDevelopmentInfo & developmentInfo);
  89. void updateOtherBuildings(TownDevelopmentInfo & developmentInfo);
  90. void updateDailyIncome();
  91. void reset();
  92. };
  93. }