CStackInstance.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * CStackInstance.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 "CStackBasicDescriptor.h"
  12. #include "CCreatureHandler.h"
  13. #include "bonuses/BonusCache.h"
  14. #include "bonuses/CBonusSystemNode.h"
  15. #include "callback/GameCallbackHolder.h"
  16. #include "entities/artifact/CArtifactSet.h"
  17. #include "mapObjects/CGObjectInstance.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class JsonNode;
  20. class CCreature;
  21. class CGHeroInstance;
  22. class CArmedInstance;
  23. class CCreatureArtifactSet;
  24. class JsonSerializeFormat;
  25. class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDescriptor, public CArtifactSet, public ACreature, public GameCallbackHolder
  26. {
  27. BonusValueCache nativeTerrain;
  28. BonusValueCache initiative;
  29. CArmedInstance * armyInstance = nullptr; //stack must be part of some army, army must be part of some object
  30. IGameInfoCallback * getCallback() const final
  31. {
  32. return cb;
  33. }
  34. TExpType totalExperience; //commander needs same amount of exp as hero
  35. public:
  36. struct RandomStackInfo
  37. {
  38. uint8_t level;
  39. uint8_t upgrade;
  40. };
  41. // helper variable used during loading map, when object (hero or town) have creatures that must have same alignment.
  42. std::optional<RandomStackInfo> randomStack;
  43. CArmedInstance * getArmy();
  44. const CArmedInstance * getArmy() const; //stack must be part of some army, army must be part of some object
  45. void setArmy(CArmedInstance * ArmyObj);
  46. TExpType getTotalExperience() const;
  47. TExpType getAverageExperience() const;
  48. virtual bool canGainExperience() const;
  49. template<typename Handler>
  50. void serialize(Handler & h)
  51. {
  52. h & static_cast<CBonusSystemNode &>(*this);
  53. h & static_cast<CStackBasicDescriptor &>(*this);
  54. h & static_cast<CArtifactSet &>(*this);
  55. if(h.hasFeature(Handler::Version::STACK_INSTANCE_ARMY_FIX))
  56. {
  57. // no-op
  58. }
  59. if(h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
  60. {
  61. ObjectInstanceID dummyID;
  62. h & dummyID;
  63. }
  64. else
  65. {
  66. std::shared_ptr<CGObjectInstance> army;
  67. h & army;
  68. }
  69. h & totalExperience;
  70. if(!h.hasFeature(Handler::Version::STACK_INSTANCE_EXPERIENCE_FIX))
  71. {
  72. totalExperience *= getCount();
  73. }
  74. }
  75. void serializeJson(JsonSerializeFormat & handler);
  76. //overrides CBonusSystemNode
  77. std::string bonusToString(const std::shared_ptr<Bonus> & bonus) const override; // how would bonus description look for this particular type of node
  78. ImagePath bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const; //file name of graphics from StackSkills , in future possibly others
  79. //IConstBonusProvider
  80. const IBonusBearer * getBonusBearer() const override;
  81. //INativeTerrainProvider
  82. FactionID getFactionID() const override;
  83. virtual ui64 getPower() const;
  84. /// Returns total market value of resources needed to recruit this unit
  85. virtual ui64 getMarketValue() const;
  86. CCreature::CreatureQuantityId getQuantityID() const;
  87. std::string getQuantityTXT(bool capitalized = true) const;
  88. virtual int getExpRank() const;
  89. virtual int getLevel() const; //different for regular stack and commander
  90. CreatureID getCreatureID() const; //-1 if not available
  91. std::string getName() const; //plural or singular
  92. CStackInstance(IGameInfoCallback * cb);
  93. CStackInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic = false);
  94. CStackInstance(IGameInfoCallback * cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
  95. virtual ~CStackInstance() = default;
  96. void setType(const CreatureID & creID);
  97. void setType(const CCreature * c) final;
  98. void setCount(TQuantity amount) final;
  99. /// Gives specified amount of stack experience that will not be scaled by unit size
  100. void giveAverageStackExperience(TExpType exp);
  101. void giveTotalStackExperience(TExpType exp);
  102. bool valid(bool allowUnrandomized) const;
  103. ArtPlacementMap putArtifact(const ArtifactPosition & pos, const CArtifactInstance * art) override; //from CArtifactSet
  104. void removeArtifact(const ArtifactPosition & pos) override;
  105. ArtBearer bearerType() const override; //from CArtifactSet
  106. std::string nodeName() const override; //from CBonusSystemnode
  107. PlayerColor getOwner() const override;
  108. int32_t getInitiative(int turn = 0) const final;
  109. TerrainId getNativeTerrain() const final;
  110. TerrainId getCurrentTerrain() const;
  111. };
  112. VCMI_LIB_NAMESPACE_END