CModHandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "Filesystem/CResourceLoader.h"
  3. #include "VCMI_Lib.h"
  4. #include "CCreatureHandler.h"
  5. #include "CArtHandler.h"
  6. /*
  7. * CModHandler.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. class CModHandler;
  16. class CModIndentifier;
  17. class CModInfo;
  18. typedef si32 artID;
  19. typedef si32 creID;
  20. class DLL_LINKAGE CModIdentifier
  21. {
  22. //TODO? are simple integer identifiers enough?
  23. int id;
  24. public:
  25. // int operator ()() {return 0;};
  26. bool operator < (CModIdentifier rhs) const {return true;}; //for map
  27. template <typename Handler> void serialize(Handler &h, const int version)
  28. {
  29. h & id;
  30. }
  31. };
  32. class DLL_LINKAGE CModInfo
  33. {
  34. public:
  35. std::vector <CModIdentifier> requirements;
  36. std::vector <ResourceID> usedFiles;
  37. //TODO: config options?
  38. //items added by this mod
  39. std::vector <artID> artifacts;
  40. std::vector <creID> creatures;
  41. //TODO: some additional scripts?
  42. template <typename Handler> void serialize(Handler &h, const int version)
  43. {
  44. h & requirements & artifacts & creatures;
  45. //h & usedFiles; //TODO: make seralizable?
  46. }
  47. };
  48. class DLL_LINKAGE CModHandler
  49. {
  50. public:
  51. std::string currentConfig; //save settings in this file
  52. //list of all possible objects in game, including inactive mods or not allowed
  53. std::vector <ConstTransitivePtr<CCreature> > creatures;
  54. std::vector <ConstTransitivePtr<CArtifact> > artifacts;
  55. std::map <CModIdentifier, CModInfo> allMods;
  56. std::set <CModIdentifier> activeMods;
  57. //create unique object indentifier
  58. artID addNewArtifact (CArtifact * art);
  59. creID addNewCreature (CCreature * cre);
  60. void loadConfigFromFile (std::string name);
  61. void saveConfigToFile (std::string name);
  62. CCreature * loadCreature (const JsonNode &node); //TODO: handler collections now use ModHandler vector index. Should they be aligned according to mods actually used??
  63. void recreateHandlers();
  64. struct DLL_LINKAGE hardcodedFeatures
  65. {
  66. int CREEP_SIZE; // neutral stacks won't grow beyond this number
  67. int WEEKLY_GROWTH; //percent
  68. int NEUTRAL_STACK_EXP;
  69. bool DWELLINGS_ACCUMULATE_CREATURES;
  70. bool ALL_CREATURES_GET_DOUBLE_MONTHS;
  71. template <typename Handler> void serialize(Handler &h, const int version)
  72. {
  73. h & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP;
  74. h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS;
  75. }
  76. } settings;
  77. struct DLL_LINKAGE gameModules
  78. {
  79. bool STACK_EXP;
  80. bool STACK_ARTIFACT;
  81. bool COMMANDERS;
  82. bool MITHRIL;
  83. template <typename Handler> void serialize(Handler &h, const int version)
  84. {
  85. h & STACK_EXP & STACK_ARTIFACT & COMMANDERS & MITHRIL;
  86. }
  87. } modules;
  88. CModHandler();
  89. ~CModHandler();
  90. template <typename Handler> void serialize(Handler &h, const int version)
  91. {
  92. h & currentConfig;
  93. h & creatures & artifacts;
  94. h & allMods & activeMods & settings & modules;
  95. }
  96. };