VCMI_Lib.h 3.5 KB

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