CModHandler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. //Check if identifier can be valid (camelCase, point as separator)
  24. void checkIdentifier(std::string & ID);
  25. public:
  26. /// request identifier for specific object name. If ID is not yet resolved callback will be queued
  27. /// and will be called later
  28. void requestIdentifier(std::string name, const boost::function<void(si32)> & callback);
  29. /// registers new object, calls all associated callbacks
  30. void registerObject(std::string name, si32 identifier);
  31. /// called at the very end of loading to check for any missing ID's
  32. void finalize() const;
  33. };
  34. typedef std::string TModID;
  35. class DLL_LINKAGE CModInfo
  36. {
  37. public:
  38. /// identifier, identical to name of folder with mod
  39. std::string identifier;
  40. /// human-readable strings
  41. std::string name;
  42. std::string description;
  43. /// priority in which this mod should be loaded
  44. /// may be somewhat ignored to load required mods first or overriden by user
  45. double loadPriority;
  46. /// TODO: list of mods that should be loaded before this one
  47. std::set <TModID> requirements;
  48. // mod configuration (mod.json). (no need to store it right now)
  49. // std::shared_ptr<JsonNode> config; //TODO: unique_ptr can't be serialized
  50. template <typename Handler> void serialize(Handler &h, const int version)
  51. {
  52. h & name & requirements;
  53. }
  54. };
  55. class DLL_LINKAGE CModHandler
  56. {
  57. std::map <TModID, CModInfo> allMods;
  58. std::vector <TModID> activeMods;//active mods, in order in which they were loaded
  59. void loadConfigFromFile (std::string name);
  60. public:
  61. CIdentifierStorage identifiers;
  62. /// receives list of available mods and trying to load mod.json from all of them
  63. void initialize(std::vector<std::string> availableMods);
  64. /// returns list of mods that should be active with order in which they shoud be loaded
  65. std::vector<std::string> getActiveMods();
  66. /// load content from all available mods
  67. void loadActiveMods();
  68. /// actions that should be triggered on map restart
  69. /// TODO: merge into appropriate handlers?
  70. void reload();
  71. struct DLL_LINKAGE hardcodedFeatures
  72. {
  73. int CREEP_SIZE; // neutral stacks won't grow beyond this number
  74. int WEEKLY_GROWTH; //percent
  75. int NEUTRAL_STACK_EXP;
  76. int MAX_BUILDING_PER_TURN;
  77. bool DWELLINGS_ACCUMULATE_CREATURES;
  78. bool ALL_CREATURES_GET_DOUBLE_MONTHS;
  79. template <typename Handler> void serialize(Handler &h, const int version)
  80. {
  81. h & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP;
  82. h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS;
  83. }
  84. } settings;
  85. struct DLL_LINKAGE gameModules
  86. {
  87. bool STACK_EXP;
  88. bool STACK_ARTIFACT;
  89. bool COMMANDERS;
  90. bool MITHRIL;
  91. template <typename Handler> void serialize(Handler &h, const int version)
  92. {
  93. h & STACK_EXP & STACK_ARTIFACT & COMMANDERS & MITHRIL;
  94. }
  95. } modules;
  96. CModHandler();
  97. template <typename Handler> void serialize(Handler &h, const int version)
  98. {
  99. h & allMods & activeMods & settings & modules;
  100. }
  101. };