VCMI_Lib.h 4.4 KB

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