CGCreature.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 = -1; //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(IGameEventCallback & gameEvents, 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(IGameRandomizer & gameRandomizer) override;
  40. void pickRandomObject(IGameRandomizer & gameRandomizer) override;
  41. void newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const override;
  42. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  43. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
  44. CreatureID getCreatureID() const;
  45. const CCreature * getCreature() const;
  46. TQuantity getJoiningAmount() const;
  47. //stack formation depends on position,
  48. bool containsUpgradedStack() const;
  49. int getNumberOfStacks(const CGHeroInstance *hero) const;
  50. template <typename Handler> void serialize(Handler &h)
  51. {
  52. h & static_cast<CArmedInstance&>(*this);
  53. h & identifier;
  54. h & character;
  55. h & message;
  56. h & resources;
  57. h & gainedArtifact;
  58. h & neverFlees;
  59. h & notGrowingTeam;
  60. h & temppower;
  61. h & refusedJoining;
  62. h & formation;
  63. }
  64. protected:
  65. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  66. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  67. private:
  68. void fight(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  69. void flee(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  70. void fleeDecision(IGameEventCallback & gameEvents, const CGHeroInstance * h, ui32 pursue) const;
  71. void joinDecision(IGameEventCallback & gameEvents, const CGHeroInstance * h, int cost, ui32 accept) const;
  72. 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)
  73. void giveReward(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  74. std::string getMonsterLevelText() const;
  75. };
  76. VCMI_LIB_NAMESPACE_END