CGCreature.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 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; //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; //if true, the troops will never flee
  30. bool notGrowingTeam; //if true, number of units won't grow
  31. ui64 temppower; //used to handle fractional stack growth for tiny stacks
  32. bool refusedJoining;
  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. void initObj(CRandomGenerator & rand) override;
  37. void newTurn(CRandomGenerator & rand) const override;
  38. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  39. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  40. //stack formation depends on position,
  41. bool containsUpgradedStack() const;
  42. int getNumberOfStacks(const CGHeroInstance *hero) const;
  43. struct DLL_LINKAGE formationInfo // info about merging stacks after battle back into one
  44. {
  45. si32 basicType;
  46. ui8 upgrade; //random seed used to determine number of stacks and is there's upgraded stack
  47. template <typename Handler> void serialize(Handler &h, const int version)
  48. {
  49. h & basicType;
  50. h & upgrade;
  51. }
  52. } formation;
  53. template <typename Handler> void serialize(Handler &h, const int version)
  54. {
  55. h & static_cast<CArmedInstance&>(*this);
  56. h & identifier;
  57. h & character;
  58. h & message;
  59. h & resources;
  60. h & gainedArtifact;
  61. h & neverFlees;
  62. h & notGrowingTeam;
  63. h & temppower;
  64. h & refusedJoining;
  65. h & formation;
  66. }
  67. protected:
  68. void setPropertyDer(ui8 what, ui32 val) override;
  69. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  70. private:
  71. void fight(const CGHeroInstance *h) const;
  72. void flee( const CGHeroInstance * h ) const;
  73. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  74. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  75. 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)
  76. void giveReward(const CGHeroInstance * h) const;
  77. };
  78. VCMI_LIB_NAMESPACE_END