VCMI_Lib.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 onlyEssential, bool extractArchives = false);
  94. #if SCRIPTING_ENABLED
  95. void scriptsLoaded();
  96. #endif
  97. template <typename Handler> void serialize(Handler &h, const int version)
  98. {
  99. #if SCRIPTING_ENABLED
  100. h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
  101. if(!h.saving)
  102. {
  103. scriptsLoaded();
  104. }
  105. #endif
  106. h & heroh;
  107. h & arth;
  108. h & creh;
  109. h & townh;
  110. h & objh;
  111. h & objtypeh;
  112. h & spellh;
  113. h & skillh;
  114. h & battlefieldsHandler;
  115. h & obstacleHandler;
  116. h & roadTypeHandler;
  117. h & riverTypeHandler;
  118. h & terrainTypeHandler;
  119. if(!h.saving)
  120. {
  121. //modh will be changed and modh->content will be empty after deserialization
  122. auto content = getContent();
  123. h & modh;
  124. setContent(content);
  125. }
  126. else
  127. h & modh;
  128. h & IS_AI_ENABLED;
  129. h & bth;
  130. if(!h.saving)
  131. {
  132. callWhenDeserializing();
  133. }
  134. }
  135. };
  136. extern DLL_LINKAGE LibClasses * VLC;
  137. DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential = false, bool extractArchives = false);
  138. DLL_LINKAGE void loadDLLClasses(bool onlyEssential = false);
  139. VCMI_LIB_NAMESPACE_END