BattleFieldHandler.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * BattleFieldHandler.cpp, 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. #include "StdInc.h"
  11. #include <vcmi/Entity.h>
  12. #include "BattleFieldHandler.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
  15. {
  16. assert(identifier.find(':') == std::string::npos);
  17. auto * info = new BattleFieldInfo(BattleField(index), identifier);
  18. info->graphics = json["graphics"].String();
  19. info->icon = json["icon"].String();
  20. info->name = json["name"].String();
  21. for(const auto & b : json["bonuses"].Vector())
  22. {
  23. auto bonus = JsonUtils::parseBonus(b);
  24. bonus->source = BonusSource::TERRAIN_OVERLAY;
  25. bonus->sid = info->getIndex();
  26. bonus->duration = BonusDuration::ONE_BATTLE;
  27. info->bonuses.push_back(bonus);
  28. }
  29. info->isSpecial = json["isSpecial"].Bool();
  30. for(auto node : json["impassableHexes"].Vector())
  31. info->impassableHexes.emplace_back(node.Integer());
  32. return info;
  33. }
  34. std::vector<JsonNode> BattleFieldHandler::loadLegacyData()
  35. {
  36. return std::vector<JsonNode>();
  37. }
  38. const std::vector<std::string> & BattleFieldHandler::getTypeNames() const
  39. {
  40. static const std::vector<std::string> types = std::vector<std::string> { "battlefield" };
  41. return types;
  42. }
  43. std::vector<bool> BattleFieldHandler::getDefaultAllowed() const
  44. {
  45. return std::vector<bool>();
  46. }
  47. int32_t BattleFieldInfo::getIndex() const
  48. {
  49. return battlefield.getNum();
  50. }
  51. int32_t BattleFieldInfo::getIconIndex() const
  52. {
  53. return iconIndex;
  54. }
  55. std::string BattleFieldInfo::getJsonKey() const
  56. {
  57. return identifier;
  58. }
  59. std::string BattleFieldInfo::getNameTextID() const
  60. {
  61. return name;
  62. }
  63. std::string BattleFieldInfo::getNameTranslated() const
  64. {
  65. return name; // TODO?
  66. }
  67. void BattleFieldInfo::registerIcons(const IconRegistar & cb) const
  68. {
  69. //cb(getIconIndex(), "BATTLEFIELD", icon);
  70. }
  71. BattleField BattleFieldInfo::getId() const
  72. {
  73. return battlefield;
  74. }
  75. VCMI_LIB_NAMESPACE_END