CBuilding.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * CBuilding.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 "../../constants/EntityIdentifiers.h"
  12. #include "../../LogicalExpression.h"
  13. #include "../../ResourceSet.h"
  14. #include "../../bonuses/BonusList.h"
  15. #include "../../rewardable/Info.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class CTown;
  18. /// a typical building encountered in every castle ;]
  19. /// this is structure available to both client and server
  20. /// contains all mechanics-related data about town structures
  21. class DLL_LINKAGE CBuilding
  22. {
  23. std::string modScope;
  24. std::string identifier;
  25. public:
  26. using TRequired = LogicalExpression<BuildingID>;
  27. CTown * town; // town this building belongs to
  28. TResources resources;
  29. TResources produce;
  30. TRequired requirements;
  31. BuildingID bid; //structure ID
  32. BuildingID upgrade; /// indicates that building "upgrade" can be improved by this, -1 = empty
  33. BuildingSubID::EBuildingSubID subId; /// subtype for special buildings, -1 = the building is not special
  34. std::set<BuildingID> overrideBids; /// the building which bonuses should be overridden with bonuses of the current building
  35. BonusList buildingBonuses;
  36. BonusList onVisitBonuses;
  37. Rewardable::Info rewardableObjectInfo; ///configurable rewards for special buildings
  38. enum EBuildMode
  39. {
  40. BUILD_NORMAL, // 0 - normal, default
  41. BUILD_AUTO, // 1 - auto - building appears when all requirements are built
  42. BUILD_SPECIAL, // 2 - special - building can not be built normally
  43. BUILD_GRAIL // 3 - grail - building requires grail to be built
  44. } mode;
  45. enum ETowerHeight // for lookup towers and some grails
  46. {
  47. HEIGHT_NO_TOWER = 5, // building has not 'lookout tower' ability
  48. HEIGHT_LOW = 10, // low lookout tower, but castle without lookout tower gives radius 5
  49. HEIGHT_AVERAGE = 15,
  50. HEIGHT_HIGH = 20, // such tower is in the Tower town
  51. HEIGHT_SKYSHIP = std::numeric_limits<int>::max() // grail, open entire map
  52. } height;
  53. static const std::map<std::string, CBuilding::EBuildMode> MODES;
  54. static const std::map<std::string, CBuilding::ETowerHeight> TOWER_TYPES;
  55. CBuilding() : town(nullptr), mode(BUILD_NORMAL) {};
  56. const BuildingTypeUniqueID getUniqueTypeID() const;
  57. std::string getJsonKey() const;
  58. std::string getNameTranslated() const;
  59. std::string getDescriptionTranslated() const;
  60. std::string getBaseTextID() const;
  61. std::string getNameTextID() const;
  62. std::string getDescriptionTextID() const;
  63. //return base of upgrade(s) or this
  64. BuildingID getBase() const;
  65. // returns how many times build has to be upgraded to become build
  66. si32 getDistance(const BuildingID & build) const;
  67. STRONG_INLINE
  68. bool IsTradeBuilding() const
  69. {
  70. return bid == BuildingID::MARKETPLACE || subId == BuildingSubID::ARTIFACT_MERCHANT || subId == BuildingSubID::FREELANCERS_GUILD;
  71. }
  72. STRONG_INLINE
  73. bool IsWeekBonus() const
  74. {
  75. return subId == BuildingSubID::STABLES || subId == BuildingSubID::MANA_VORTEX;
  76. }
  77. STRONG_INLINE
  78. bool IsVisitingBonus() const
  79. {
  80. return subId == BuildingSubID::ATTACK_VISITING_BONUS ||
  81. subId == BuildingSubID::DEFENSE_VISITING_BONUS ||
  82. subId == BuildingSubID::SPELL_POWER_VISITING_BONUS ||
  83. subId == BuildingSubID::KNOWLEDGE_VISITING_BONUS ||
  84. subId == BuildingSubID::EXPERIENCE_VISITING_BONUS ||
  85. subId == BuildingSubID::CUSTOM_VISITING_BONUS;
  86. }
  87. void addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const;
  88. friend class CTownHandler;
  89. };
  90. VCMI_LIB_NAMESPACE_END