CModHandler.h 3.5 KB

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