CModHandler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include "Filesystem/CResourceLoader.h"
  3. #include "VCMI_Lib.h"
  4. #include "CCreatureHandler.h"
  5. #include "CArtHandler.h"
  6. #include "CTownHandler.h"
  7. /*
  8. * CModHandler.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. class CModHandler;
  17. class CModIndentifier;
  18. class CModInfo;
  19. class JsonNode;
  20. /// class that stores all object identifiers strings and maps them to numeric ID's
  21. /// if possible, objects ID's should be in format <type>.<name>, camelCase e.g. "creature.grandElf"
  22. class CIdentifierStorage
  23. {
  24. std::map<std::string, si32 > registeredObjects;
  25. std::map<std::string, std::vector<boost::function<void(si32)> > > missingObjects;
  26. public:
  27. /// request identifier for specific object name. If ID is not yet resolved callback will be queued
  28. /// and will be called later
  29. void requestIdentifier(std::string name, const boost::function<void(si32)> & callback);
  30. /// registers new object, calls all associated callbacks
  31. void registerObject(std::string name, si32 identifier);
  32. /// called at the very end of loading to check for any missing ID's
  33. void finalize() const;
  34. };
  35. typedef std::string TModID;
  36. class DLL_LINKAGE CModInfo
  37. {
  38. public:
  39. /// identifier, identical to name of folder with mod
  40. std::string identifier;
  41. /// human-readable strings
  42. std::string name;
  43. std::string description;
  44. /// priority in which this mod should be loaded
  45. /// may be somewhat ignored to load required mods first or overriden by user
  46. double loadPriority;
  47. /// TODO: list of mods that should be loaded before this one
  48. std::set <TModID> requirements;
  49. // mod configuration (mod.json). (no need to store it right now)
  50. // std::shared_ptr<JsonNode> config; //TODO: unique_ptr can't be serialized
  51. template <typename Handler> void serialize(Handler &h, const int version)
  52. {
  53. h & name & requirements;
  54. }
  55. };
  56. class DLL_LINKAGE CModHandler
  57. {
  58. std::map <TModID, CModInfo> allMods;
  59. std::vector <TModID> activeMods;//active mods, in order in which they were loaded
  60. void loadConfigFromFile (std::string name);
  61. public:
  62. CIdentifierStorage identifiers;
  63. /// receives list of available mods and trying to load mod.json from all of them
  64. void initialize(std::vector<std::string> availableMods);
  65. /// returns list of mods that should be active with order in which they shoud be loaded
  66. std::vector<std::string> getActiveMods();
  67. /// load content from all available mods
  68. void loadActiveMods();
  69. /// actions that should be triggered on map restart
  70. /// TODO: merge into appropriate handlers?
  71. void reload();
  72. struct DLL_LINKAGE hardcodedFeatures
  73. {
  74. int CREEP_SIZE; // neutral stacks won't grow beyond this number
  75. int WEEKLY_GROWTH; //percent
  76. int NEUTRAL_STACK_EXP;
  77. int MAX_BUILDING_PER_TURN;
  78. bool DWELLINGS_ACCUMULATE_CREATURES;
  79. bool ALL_CREATURES_GET_DOUBLE_MONTHS;
  80. template <typename Handler> void serialize(Handler &h, const int version)
  81. {
  82. h & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP;
  83. h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS;
  84. }
  85. } settings;
  86. struct DLL_LINKAGE gameModules
  87. {
  88. bool STACK_EXP;
  89. bool STACK_ARTIFACT;
  90. bool COMMANDERS;
  91. bool MITHRIL;
  92. template <typename Handler> void serialize(Handler &h, const int version)
  93. {
  94. h & STACK_EXP & STACK_ARTIFACT & COMMANDERS & MITHRIL;
  95. }
  96. } modules;
  97. CModHandler();
  98. template <typename Handler> void serialize(Handler &h, const int version)
  99. {
  100. h & allMods & activeMods & settings & modules;
  101. }
  102. };