CGCreature.h 3.1 KB

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