AObjectTypeHandler.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * AObjectTypeHandler.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 "RandomMapInfo.h"
  12. #include "SObjectSounds.h"
  13. #include "../JsonNode.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class ObjectTemplate;
  16. class CGObjectInstance;
  17. class CRandomGenerator;
  18. class IObjectInfo;
  19. /// Class responsible for creation of objects of specific type & subtype
  20. class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
  21. {
  22. friend class CObjectClassesHandler;
  23. RandomMapInfo rmgInfo;
  24. JsonNode base; /// describes base template
  25. std::vector<std::shared_ptr<const ObjectTemplate>> templates;
  26. SObjectSounds sounds;
  27. std::optional<si32> aiValue;
  28. BattleField battlefield;
  29. std::string modScope;
  30. std::string typeName;
  31. std::string subTypeName;
  32. si32 type;
  33. si32 subtype;
  34. bool blockVisit;
  35. bool removable;
  36. protected:
  37. void preInitObject(CGObjectInstance * obj) const;
  38. virtual bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const;
  39. /// initialization for classes that inherit this one
  40. virtual void initTypeData(const JsonNode & input);
  41. public:
  42. virtual ~AObjectTypeHandler() = default;
  43. si32 getIndex() const;
  44. si32 getSubIndex() const;
  45. std::string getTypeName() const;
  46. std::string getSubTypeName() const;
  47. /// loads generic data from Json structure and passes it towards type-specific constructors
  48. void init(const JsonNode & input);
  49. /// returns full form of identifier of this object in form of modName:objectName
  50. std::string getJsonKey() const;
  51. /// Returns object-specific name, if set
  52. SObjectSounds getSounds() const;
  53. void addTemplate(const std::shared_ptr<const ObjectTemplate> & templ);
  54. void addTemplate(JsonNode config);
  55. void clearTemplates();
  56. /// returns all templates matching parameters
  57. std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates() const;
  58. std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates(const TerrainId terrainType) const;
  59. /// returns preferred template for this object, if present (e.g. one of 3 possible templates for town - village, fort and castle)
  60. /// note that appearance will not be changed - this must be done separately (either by assignment or via pack from server)
  61. std::shared_ptr<const ObjectTemplate> getOverride(TerrainId terrainType, const CGObjectInstance * object) const;
  62. BattleField getBattlefield() const;
  63. const RandomMapInfo & getRMGInfo();
  64. std::optional<si32> getAiValue() const;
  65. /// returns true if this class provides custom text ID's instead of generic per-object name
  66. virtual bool hasNameTextID() const;
  67. /// returns base prefix for all translatable strings of this object
  68. std::string getBaseTextID() const;
  69. /// returns object's name in form of translatable text ID
  70. virtual std::string getNameTextID() const;
  71. /// returns object's name in form of human-readable text
  72. std::string getNameTranslated() const;
  73. virtual bool isStaticObject();
  74. virtual void afterLoadFinalization();
  75. /// Creates object and set up core properties (like ID/subID). Object is NOT initialized
  76. /// to allow creating objects before game start (e.g. map loading)
  77. virtual CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const = 0;
  78. /// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
  79. /// This should set remaining properties, including randomized or depending on map
  80. virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0;
  81. /// Returns object configuration, if available. Otherwise returns NULL
  82. virtual std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const;
  83. };
  84. VCMI_LIB_NAMESPACE_END