BuildAnalyzer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 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 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 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. private:
  72. BuildingInfo getBuildingOrPrerequisite(
  73. const CGTownInstance* town,
  74. BuildingID toBuild,
  75. bool excludeDwellingDependencies = true) const;
  76. void updateTownDwellings(TownDevelopmentInfo & developmentInfo);
  77. void updateOtherBuildings(TownDevelopmentInfo & developmentInfo);
  78. void updateDailyIncome();
  79. void reset();
  80. };