BuildAnalyzer.h 2.5 KB

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