CModHandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. typedef si32 artID;
  20. typedef si32 creID;
  21. class DLL_LINKAGE CModIdentifier
  22. {
  23. //TODO? are simple integer identifiers enough?
  24. int id;
  25. public:
  26. // int operator ()() {return 0;};
  27. bool operator < (CModIdentifier rhs) const {return true;}; //for map
  28. template <typename Handler> void serialize(Handler &h, const int version)
  29. {
  30. h & id;
  31. }
  32. };
  33. class DLL_LINKAGE CModInfo
  34. {
  35. public:
  36. std::vector <CModIdentifier> requirements;
  37. std::vector <ResourceID> usedFiles;
  38. //TODO: config options?
  39. //items added by this mod
  40. std::vector <artID> artifacts;
  41. std::vector <creID> creatures;
  42. //TODO: some additional scripts?
  43. template <typename Handler> void serialize(Handler &h, const int version)
  44. {
  45. h & requirements & artifacts & creatures;
  46. //h & usedFiles; //TODO: make seralizable?
  47. }
  48. };
  49. class DLL_LINKAGE CModHandler
  50. {
  51. public:
  52. std::string currentConfig; //save settings in this file
  53. //list of all possible objects in game, including inactive mods or not allowed
  54. std::vector <ConstTransitivePtr<CCreature> > creatures;
  55. std::vector <ConstTransitivePtr<CArtifact> > artifacts;
  56. std::map <CModIdentifier, CModInfo> allMods;
  57. std::set <CModIdentifier> activeMods;
  58. //create unique object indentifier
  59. artID addNewArtifact (CArtifact * art);
  60. creID addNewCreature (CCreature * cre);
  61. void loadConfigFromFile (std::string name);
  62. void saveConfigToFile (std::string name);
  63. CCreature * loadCreature (const JsonNode &node);
  64. void recreateAdvMapDefs();
  65. void recreateHandlers();
  66. struct DLL_LINKAGE hardcodedFeatures
  67. {
  68. int CREEP_SIZE; // neutral stacks won't grow beyond this number
  69. int WEEKLY_GROWTH; //percent
  70. int NEUTRAL_STACK_EXP;
  71. int MAX_BUILDING_PER_TURN;
  72. bool DWELLINGS_ACCUMULATE_CREATURES;
  73. bool ALL_CREATURES_GET_DOUBLE_MONTHS;
  74. template <typename Handler> void serialize(Handler &h, const int version)
  75. {
  76. h & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP;
  77. h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS;
  78. }
  79. } settings;
  80. struct DLL_LINKAGE gameModules
  81. {
  82. bool STACK_EXP;
  83. bool STACK_ARTIFACT;
  84. bool COMMANDERS;
  85. bool MITHRIL;
  86. template <typename Handler> void serialize(Handler &h, const int version)
  87. {
  88. h & STACK_EXP & STACK_ARTIFACT & COMMANDERS & MITHRIL;
  89. }
  90. } modules;
  91. CModHandler();
  92. ~CModHandler();
  93. template <typename Handler> void serialize(Handler &h, const int version)
  94. {
  95. h & currentConfig;
  96. h & creatures & artifacts;
  97. h & allMods & activeMods & settings & modules;
  98. }
  99. };