CArmedInstance.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/CBonusSystemNode.h"
  14. #include "../../bonuses/BonusCache.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 { return this; }
  34. const CArmedInstance * getArmy() const final { return this; }
  35. //////////////////////////////////////////////////////////////////////////
  36. //IConstBonusProvider
  37. const IBonusBearer* getBonusBearer() const override;
  38. void attachToBonusSystem(CGameState & gs) override;
  39. void detachFromBonusSystem(CGameState & gs) override;
  40. void restoreBonusSystem(CGameState & gs) override;
  41. //////////////////////////////////////////////////////////////////////////
  42. CArmedInstance(IGameInfoCallback *cb);
  43. CArmedInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bool isHypothetic);
  44. PlayerColor getOwner() const override
  45. {
  46. return this->tempOwner;
  47. }
  48. TerrainId getCurrentTerrain() const;
  49. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  50. template <typename Handler> void serialize(Handler &h)
  51. {
  52. h & static_cast<CGObjectInstance&>(*this);
  53. h & static_cast<CBonusSystemNode&>(*this);
  54. h & static_cast<CCreatureSet&>(*this);
  55. if(!h.saving && h.loadingGamestate)
  56. attachUnitsToArmy();
  57. }
  58. };
  59. VCMI_LIB_NAMESPACE_END