BattleFieldHandler.h 2.2 KB

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