AObjectTypeHandler.h 4.1 KB

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