VCMI_Lib.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * VCMI_Lib.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 <vcmi/Services.h>
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CConsoleHandler;
  14. class CArtHandler;
  15. class CHeroHandler;
  16. class CCreatureHandler;
  17. class CSpellHandler;
  18. class CSkillHandler;
  19. class CBuildingHandler;
  20. class CObjectHandler;
  21. class CObjectClassesHandler;
  22. class CTownHandler;
  23. class CGeneralTextHandler;
  24. class CModHandler;
  25. class CContentHandler;
  26. class BattleFieldHandler;
  27. class IBonusTypeHandler;
  28. class CBonusTypeHandler;
  29. class TerrainTypeHandler;
  30. class RoadTypeHandler;
  31. class RiverTypeHandler;
  32. class ObstacleHandler;
  33. class CTerrainViewPatternConfig;
  34. class CRmgTemplateStorage;
  35. class IHandlerBase;
  36. #if SCRIPTING_ENABLED
  37. namespace scripting
  38. {
  39. class ScriptHandler;
  40. }
  41. #endif
  42. /// Loads and constructs several handlers
  43. class DLL_LINKAGE LibClasses : public Services
  44. {
  45. CBonusTypeHandler * bth;
  46. void callWhenDeserializing(); //should be called only by serialize !!!
  47. void makeNull(); //sets all handler pointers to null
  48. std::shared_ptr<CContentHandler> getContent() const;
  49. void setContent(std::shared_ptr<CContentHandler> content);
  50. public:
  51. bool IS_AI_ENABLED; //unused?
  52. const ArtifactService * artifacts() const override;
  53. const CreatureService * creatures() const override;
  54. const FactionService * factions() const override;
  55. const HeroClassService * heroClasses() const override;
  56. const HeroTypeService * heroTypes() const override;
  57. #if SCRIPTING_ENABLED
  58. const scripting::Service * scripts() const override;
  59. #endif
  60. const spells::Service * spells() const override;
  61. const SkillService * skills() const override;
  62. const BattleFieldService * battlefields() const override;
  63. const ObstacleService * obstacles() const override;
  64. void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
  65. const spells::effects::Registry * spellEffects() const override;
  66. spells::effects::Registry * spellEffects() override;
  67. const IBonusTypeHandler * getBth() const; //deprecated
  68. CArtHandler * arth;
  69. CHeroHandler * heroh;
  70. CCreatureHandler * creh;
  71. CSpellHandler * spellh;
  72. CSkillHandler * skillh;
  73. CObjectHandler * objh;
  74. CObjectClassesHandler * objtypeh;
  75. CTownHandler * townh;
  76. CGeneralTextHandler * generaltexth;
  77. CModHandler * modh;
  78. TerrainTypeHandler * terrainTypeHandler;
  79. RoadTypeHandler * roadTypeHandler;
  80. RiverTypeHandler * riverTypeHandler;
  81. CTerrainViewPatternConfig * terviewh;
  82. CRmgTemplateStorage * tplh;
  83. BattleFieldHandler * battlefieldsHandler;
  84. ObstacleHandler * obstacleHandler;
  85. #if SCRIPTING_ENABLED
  86. scripting::ScriptHandler * scriptHandler;
  87. #endif
  88. LibClasses(); //c-tor, loads .lods and NULLs handlers
  89. ~LibClasses();
  90. void init(bool onlyEssential); //uses standard config file
  91. void clear(); //deletes all handlers and its data
  92. // basic initialization. should be called before init(). Can also extract original H3 archives
  93. void loadFilesystem(bool extractArchives);
  94. void loadModFilesystem(bool onlyEssential);
  95. #if SCRIPTING_ENABLED
  96. void scriptsLoaded();
  97. #endif
  98. template <typename Handler> void serialize(Handler &h, const int version)
  99. {
  100. #if SCRIPTING_ENABLED
  101. h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
  102. if(!h.saving)
  103. {
  104. scriptsLoaded();
  105. }
  106. #endif
  107. h & heroh;
  108. h & arth;
  109. h & creh;
  110. h & townh;
  111. h & objh;
  112. h & objtypeh;
  113. h & spellh;
  114. h & skillh;
  115. h & battlefieldsHandler;
  116. h & obstacleHandler;
  117. h & roadTypeHandler;
  118. h & riverTypeHandler;
  119. h & terrainTypeHandler;
  120. if(!h.saving)
  121. {
  122. //modh will be changed and modh->content will be empty after deserialization
  123. auto content = getContent();
  124. h & modh;
  125. setContent(content);
  126. }
  127. else
  128. h & modh;
  129. h & IS_AI_ENABLED;
  130. h & bth;
  131. if(!h.saving)
  132. {
  133. callWhenDeserializing();
  134. }
  135. }
  136. };
  137. extern DLL_LINKAGE LibClasses * VLC;
  138. DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential = false, bool extractArchives = false);
  139. DLL_LINKAGE void loadDLLClasses(bool onlyEssential = false);
  140. VCMI_LIB_NAMESPACE_END