CGCreature.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "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 Character {
  22. COMPLIANT = 0, FRIENDLY = 1, AGGRESSIVE = 2, HOSTILE = 3, SAVAGE = 4
  23. };
  24. ui32 identifier; //unique code for this monster (used in missions)
  25. si8 character = 0; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage)
  26. MetaString message; //message printed for attacking hero
  27. TResources resources; // resources given to hero that has won with monsters
  28. ArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none
  29. bool neverFlees = false; //if true, the troops will never flee
  30. bool notGrowingTeam = false; //if true, number of units won't grow
  31. int64_t temppower = 0; //used to handle fractional stack growth for tiny stacks
  32. bool refusedJoining = false;
  33. void onHeroVisit(const CGHeroInstance * h) const override;
  34. std::string getHoverText(PlayerColor player) const override;
  35. std::string getHoverText(const CGHeroInstance * hero) const override;
  36. std::string getPopupText(PlayerColor player) const override;
  37. std::string getPopupText(const CGHeroInstance * hero) const override;
  38. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  39. void initObj(vstd::RNG & rand) override;
  40. void pickRandomObject(vstd::RNG & rand) override;
  41. void newTurn(vstd::RNG & rand) const override;
  42. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  43. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  44. CreatureID getCreature() const;
  45. //stack formation depends on position,
  46. bool containsUpgradedStack() const;
  47. int getNumberOfStacks(const CGHeroInstance *hero) const;
  48. template <typename Handler> void serialize(Handler &h)
  49. {
  50. h & static_cast<CArmedInstance&>(*this);
  51. h & identifier;
  52. h & character;
  53. h & message;
  54. h & resources;
  55. h & gainedArtifact;
  56. h & neverFlees;
  57. h & notGrowingTeam;
  58. h & temppower;
  59. h & refusedJoining;
  60. h & formation;
  61. }
  62. protected:
  63. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  64. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  65. private:
  66. void fight(const CGHeroInstance *h) const;
  67. void flee( const CGHeroInstance * h ) const;
  68. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  69. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  70. 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)
  71. void giveReward(const CGHeroInstance * h) const;
  72. std::string getMonsterLevelText() const;
  73. };
  74. VCMI_LIB_NAMESPACE_END