CArmedInstance.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * CArmedInstance.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 "CCreatureSet.h"
  12. #include "../CGObjectInstance.h"
  13. #include "../../bonuses/BonusCache.h"
  14. #include "../../bonuses/CBonusSystemNode.h"
  15. #include <vcmi/Entity.h>
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class BattleInfo;
  18. class CGameState;
  19. class JsonSerializeFormat;
  20. class DLL_LINKAGE CArmedInstance: public CGObjectInstance, public CBonusSystemNode, public CCreatureSet, public IConstBonusProvider
  21. {
  22. private:
  23. BonusValueCache nonEvilAlignmentMix;
  24. void attachUnitsToArmy();
  25. protected:
  26. virtual CBonusSystemNode & whereShouldBeAttached(CGameState & gs);
  27. virtual CBonusSystemNode & whatShouldBeAttached();
  28. public:
  29. BattleInfo * battle; //set to the current battle, if engaged
  30. void randomizeArmy(FactionID type);
  31. virtual void updateMoraleBonusFromArmy();
  32. void armyChanged() override;
  33. CArmedInstance * getArmy() final
  34. {
  35. return this;
  36. }
  37. const CArmedInstance * getArmy() const final
  38. {
  39. return this;
  40. }
  41. //////////////////////////////////////////////////////////////////////////
  42. //IConstBonusProvider
  43. const IBonusBearer * getBonusBearer() const override;
  44. void attachToBonusSystem(CGameState & gs) override;
  45. void detachFromBonusSystem(CGameState & gs) override;
  46. void restoreBonusSystem(CGameState & gs) override;
  47. //////////////////////////////////////////////////////////////////////////
  48. CArmedInstance(IGameInfoCallback * cb);
  49. CArmedInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic);
  50. PlayerColor getOwner() const override
  51. {
  52. return this->tempOwner;
  53. }
  54. TerrainId getCurrentTerrain() const;
  55. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  56. template<typename Handler>
  57. void serialize(Handler & h)
  58. {
  59. h & static_cast<CGObjectInstance &>(*this);
  60. h & static_cast<CBonusSystemNode &>(*this);
  61. h & static_cast<CCreatureSet &>(*this);
  62. if(!h.saving && h.loadingGamestate)
  63. attachUnitsToArmy();
  64. }
  65. };
  66. VCMI_LIB_NAMESPACE_END