CGCreature.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * CGCreature.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 "army/CArmedInstance.h"
  12. #include "../ResourceSet.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map
  15. {
  16. public:
  17. using CArmedInstance::CArmedInstance;
  18. enum Action {
  19. FIGHT = -2, FLEE = -1, JOIN_FOR_FREE = 0 //values > 0 mean gold price
  20. };
  21. enum class Character : int8_t {
  22. COMPLIANT = 0,
  23. FRIENDLY = 1,
  24. AGGRESSIVE = 2,
  25. HOSTILE = 3,
  26. SAVAGE = 4,
  27. CUSTOM = 5
  28. };
  29. enum class UpgradedStackPresence : int8_t {
  30. RANDOM = -1,
  31. NEVER = 0,
  32. ALWAYS = 1
  33. };
  34. Character initialCharacter = Character::COMPLIANT;
  35. int8_t agression = 0; // h3 range: -4 -> compliant, 10 -> savage, set on init
  36. MetaString message; //message printed for attacking hero
  37. TResources resources; // resources given to hero that has won with monsters
  38. ArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none
  39. bool neverFlees = false; //if true, the troops will never flee
  40. bool notGrowingTeam = false; //if true, number of units won't grow
  41. int64_t temppower = 0; //used to handle fractional stack growth for tiny stacks
  42. int64_t stacksCount = -1; // the split stack count specified in a HotA 1.7 map (0 - one more, -1 - default, -2 one less, -3 average)
  43. UpgradedStackPresence upgradedStackPresence = UpgradedStackPresence::RANDOM;
  44. int8_t joiningPercentage = -1;
  45. bool joinOnlyForMoney = false;
  46. bool refusedJoining = false;
  47. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  48. std::string getHoverText(PlayerColor player) const override;
  49. std::string getHoverText(const CGHeroInstance * hero) const override;
  50. std::string getPopupText(PlayerColor player) const override;
  51. std::string getPopupText(const CGHeroInstance * hero) const override;
  52. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  53. void initObj(IGameRandomizer & gameRandomizer) override;
  54. void pickRandomObject(IGameRandomizer & gameRandomizer) override;
  55. void newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const override;
  56. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  57. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
  58. CreatureID getCreatureID() const;
  59. const CCreature * getCreature() const;
  60. TQuantity getJoiningAmount() const;
  61. //stack formation depends on position,
  62. bool containsUpgradedStack() const;
  63. int getNumberOfStacks(const CGHeroInstance *hero) const;
  64. template <typename Handler> void serialize(Handler &h)
  65. {
  66. h & static_cast<CArmedInstance&>(*this);
  67. if(h.version >= Handler::Version::HOTA_MAP_FORMAT_EXTENSIONS_2)
  68. {
  69. h & initialCharacter;
  70. }
  71. else
  72. {
  73. int32_t identifier = 0;
  74. h & identifier;
  75. }
  76. h & agression;
  77. h & message;
  78. h & resources;
  79. h & gainedArtifact;
  80. h & neverFlees;
  81. h & notGrowingTeam;
  82. h & temppower;
  83. h & refusedJoining;
  84. h & formation;
  85. if(h.version >= Handler::Version::HOTA_MAP_STACK_COUNT)
  86. h & stacksCount;
  87. if(h.version >= Handler::Version::HOTA_MAP_FORMAT_EXTENSIONS_2)
  88. h & joiningPercentage;
  89. if(h.version >= Handler::Version::HOTA_MAP_FORMAT_EXTENSIONS)
  90. {
  91. h & upgradedStackPresence;
  92. h & joinOnlyForMoney;
  93. }
  94. }
  95. protected:
  96. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  97. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  98. private:
  99. void fight(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  100. void flee(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  101. void fleeDecision(IGameEventCallback & gameEvents, const CGHeroInstance * h, ui32 pursue) const;
  102. void joinDecision(IGameEventCallback & gameEvents, const CGHeroInstance * h, int cost, ui32 accept) const;
  103. int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
  104. void giveReward(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  105. std::string getMonsterLevelText() const;
  106. int getDefaultNumberOfStacks(const CGHeroInstance * hero) const;
  107. int getNumberOfStacksFromBonus(const CGHeroInstance * hero) const;
  108. ui32 hashByPosition() const;
  109. };
  110. VCMI_LIB_NAMESPACE_END