CTownHandler.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * CTownHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <vcmi/FactionService.h>
  12. #include "CFaction.h"
  13. #include "../../IHandlerBase.h"
  14. #include "../../bonuses/Bonus.h"
  15. #include "../../constants/EntityIdentifiers.h"
  16. #include "../../json/JsonNode.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class CBuilding;
  19. class CTown;
  20. class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFaction, FactionService>
  21. {
  22. JsonNode buildingsLibrary;
  23. struct BuildingRequirementsHelper
  24. {
  25. JsonNode json;
  26. CBuilding * building;
  27. CTown * town;
  28. };
  29. std::map<CTown *, JsonNode> warMachinesToLoad;
  30. std::vector<BuildingRequirementsHelper> requirementsToLoad;
  31. std::vector<BuildingRequirementsHelper> overriddenBidsToLoad; //list of buildings, which bonuses should be overridden.
  32. static const TPropagatorPtr & emptyPropagator();
  33. void initializeRequirements();
  34. void initializeOverridden();
  35. void initializeWarMachines();
  36. /// loads CBuilding's into town
  37. void loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad) const;
  38. void loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source);
  39. void loadBuildings(CTown * town, const JsonNode & source);
  40. /// loads CStructure's into town
  41. void loadStructure(CTown & town, const std::string & stringID, const JsonNode & source) const;
  42. void loadStructures(CTown & town, const JsonNode & source) const;
  43. /// loads town hall vector (hallSlots)
  44. void loadTownHall(CTown & town, const JsonNode & source) const;
  45. void loadSiegeScreen(CTown & town, const JsonNode & source) const;
  46. void loadClientData(CTown & town, const JsonNode & source) const;
  47. void loadTown(CTown * town, const JsonNode & source);
  48. void loadPuzzle(CFaction & faction, const JsonNode & source) const;
  49. void loadRandomFaction();
  50. public:
  51. CTown * randomTown;
  52. CFaction * randomFaction;
  53. CTownHandler();
  54. ~CTownHandler();
  55. std::vector<JsonNode> loadLegacyData() override;
  56. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  57. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  58. void loadCustom() override;
  59. void afterLoadFinalization() override;
  60. void beforeValidate(JsonNode & object) override;
  61. std::set<FactionID> getDefaultAllowed() const;
  62. std::set<FactionID> getAllowedFactions(bool withTown = true) const;
  63. static void loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building);
  64. protected:
  65. const std::vector<std::string> & getTypeNames() const override;
  66. std::shared_ptr<CFaction> loadFromJson(const std::string & scope, const JsonNode & data, const std::string & identifier, size_t index) override;
  67. };
  68. VCMI_LIB_NAMESPACE_END