CGCreature.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. enum Action {
  18. FIGHT = -2, FLEE = -1, JOIN_FOR_FREE = 0 //values > 0 mean gold price
  19. };
  20. enum Character {
  21. COMPLIANT = 0, FRIENDLY = 1, AGRESSIVE = 2, HOSTILE = 3, SAVAGE = 4
  22. };
  23. ui32 identifier; //unique code for this monster (used in missions)
  24. 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)
  25. std::string message; //message printed for attacking hero
  26. TResources resources; // resources given to hero that has won with monsters
  27. ArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none
  28. bool neverFlees; //if true, the troops will never flee
  29. bool notGrowingTeam; //if true, number of units won't grow
  30. ui64 temppower; //used to handle fractional stack growth for tiny stacks
  31. bool refusedJoining;
  32. void onHeroVisit(const CGHeroInstance * h) const override;
  33. std::string getHoverText(PlayerColor player) const override;
  34. std::string getHoverText(const CGHeroInstance * hero) const override;
  35. void initObj(CRandomGenerator & rand) override;
  36. void newTurn(CRandomGenerator & rand) const override;
  37. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  38. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  39. //stack formation depends on position,
  40. bool containsUpgradedStack() const;
  41. int getNumberOfStacks(const CGHeroInstance *hero) const;
  42. struct DLL_LINKAGE formationInfo // info about merging stacks after battle back into one
  43. {
  44. si32 basicType;
  45. ui8 upgrade; //random seed used to determine number of stacks and is there's upgraded stack
  46. template <typename Handler> void serialize(Handler &h, const int version)
  47. {
  48. h & basicType;
  49. h & upgrade;
  50. }
  51. } formation;
  52. template <typename Handler> void serialize(Handler &h, const int version)
  53. {
  54. h & static_cast<CArmedInstance&>(*this);
  55. h & identifier;
  56. h & character;
  57. h & message;
  58. h & resources;
  59. h & gainedArtifact;
  60. h & neverFlees;
  61. h & notGrowingTeam;
  62. h & temppower;
  63. h & refusedJoining;
  64. h & formation;
  65. }
  66. protected:
  67. void setPropertyDer(ui8 what, ui32 val) override;
  68. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  69. private:
  70. void fight(const CGHeroInstance *h) const;
  71. void flee( const CGHeroInstance * h ) const;
  72. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  73. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  74. 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)
  75. void giveReward(const CGHeroInstance * h) const;
  76. };
  77. VCMI_LIB_NAMESPACE_END