CTownHandler.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val) const;
  41. std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype) const;
  42. std::shared_ptr<Bonus> createBonus(CBuilding * build, BonusType type, int val, BonusSubtypeID subtype, const TPropagatorPtr & prop) const;
  43. /// loads CStructure's into town
  44. void loadStructure(CTown & town, const std::string & stringID, const JsonNode & source) const;
  45. void loadStructures(CTown & town, const JsonNode & source) const;
  46. /// loads town hall vector (hallSlots)
  47. void loadTownHall(CTown & town, const JsonNode & source) const;
  48. void loadSiegeScreen(CTown & town, const JsonNode & source) const;
  49. void loadClientData(CTown & town, const JsonNode & source) const;
  50. void loadTown(CTown * town, const JsonNode & source);
  51. void loadPuzzle(CFaction & faction, const JsonNode & source) const;
  52. void loadRandomFaction();
  53. public:
  54. CTown * randomTown;
  55. CFaction * randomFaction;
  56. CTownHandler();
  57. ~CTownHandler();
  58. std::vector<JsonNode> loadLegacyData() override;
  59. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  60. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  61. void loadCustom() override;
  62. void afterLoadFinalization() override;
  63. void beforeValidate(JsonNode & object) override;
  64. std::set<FactionID> getDefaultAllowed() const;
  65. std::set<FactionID> getAllowedFactions(bool withTown = true) const;
  66. static void loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building);
  67. protected:
  68. const std::vector<std::string> & getTypeNames() const override;
  69. std::shared_ptr<CFaction> loadFromJson(const std::string & scope, const JsonNode & data, const std::string & identifier, size_t index) override;
  70. };
  71. VCMI_LIB_NAMESPACE_END