AObjectTypeHandler.h 3.7 KB

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