BattleFieldHandler.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * BattleFieldHandler.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 <vcmi/EntityService.h>
  12. #include <vcmi/Entity.h>
  13. #include "HeroBonus.h"
  14. #include "GameConstants.h"
  15. #include "IHandlerBase.h"
  16. #include "Terrain.h"
  17. #include "battle/BattleHex.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class BattleFieldInfo : public EntityT<BattleField>
  20. {
  21. public:
  22. BattleField battlefield;
  23. std::vector<std::shared_ptr<Bonus>> bonuses;
  24. bool isSpecial;
  25. std::string graphics;
  26. std::string name;
  27. std::string identifier;
  28. std::string icon;
  29. si32 iconIndex;
  30. std::vector<BattleHex> impassableHexes;
  31. BattleFieldInfo()
  32. : BattleFieldInfo(BattleField::NONE, "")
  33. {
  34. }
  35. BattleFieldInfo(BattleField battlefield, std::string identifier)
  36. :bonuses(), isSpecial(false), battlefield(battlefield), identifier(identifier), graphics(), icon(), iconIndex(battlefield.getNum()), impassableHexes(), name(identifier)
  37. {
  38. }
  39. int32_t getIndex() const override;
  40. int32_t getIconIndex() const override;
  41. const std::string & getName() const override;
  42. const std::string & getJsonKey() const override;
  43. void registerIcons(const IconRegistar & cb) const override;
  44. BattleField getId() const override;
  45. template <typename Handler> void serialize(Handler & h, const int version)
  46. {
  47. h & name;
  48. h & identifier;
  49. h & isSpecial;
  50. h & graphics;
  51. h & icon;
  52. h & iconIndex;
  53. h & battlefield;
  54. h & impassableHexes;
  55. }
  56. };
  57. class DLL_LINKAGE BattleFieldService : public EntityServiceT<BattleField, BattleFieldInfo>
  58. {
  59. public:
  60. };
  61. class BattleFieldHandler : public CHandlerBase<BattleField, BattleFieldInfo, BattleFieldInfo, BattleFieldService>
  62. {
  63. public:
  64. virtual BattleFieldInfo * loadFromJson(
  65. const std::string & scope,
  66. const JsonNode & json,
  67. const std::string & identifier,
  68. size_t index) override;
  69. virtual const std::vector<std::string> & getTypeNames() const override;
  70. virtual std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  71. virtual std::vector<bool> getDefaultAllowed() const override;
  72. template <typename Handler> void serialize(Handler & h, const int version)
  73. {
  74. h & objects;
  75. }
  76. };
  77. VCMI_LIB_NAMESPACE_END