AObjectTypeHandler.h 3.9 KB

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