CArmedInstance.h 2.0 KB

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