TreasurePlacer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * TreasurePlacer.cpp, 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 "Zone.h"
  12. #include "../mapObjects/ObjectTemplate.h"
  13. class CGObjectInstance;
  14. class ObjectManager;
  15. class RmgMap;
  16. class CMapGenerator;
  17. struct ObjectInfo
  18. {
  19. std::shared_ptr<const ObjectTemplate> templ;
  20. ui32 value = 0;
  21. ui16 probability = 0;
  22. ui32 maxPerZone = -1;
  23. //ui32 maxPerMap; //unused
  24. std::function<CGObjectInstance *()> generateObject;
  25. void setTemplate(si32 type, si32 subtype, TTerrainId terrain);
  26. ObjectInfo();
  27. bool operator==(const ObjectInfo& oi) const { return (templ == oi.templ); }
  28. };
  29. class TreasurePlacer: public Modificator
  30. {
  31. public:
  32. MODIFICATOR(TreasurePlacer);
  33. void process() override;
  34. void init() override;
  35. char dump(const int3 &) override;
  36. void createTreasures(ObjectManager & manager);
  37. void setQuestArtZone(Zone * otherZone);
  38. void addAllPossibleObjects(); //add objects, including zone-specific, to possibleObjects
  39. protected:
  40. bool isGuardNeededForTreasure(int value);
  41. ObjectInfo * getRandomObject(ui32 desiredValue, ui32 currentValue, ui32 maxValue, bool allowLargeObjects);
  42. std::vector<ObjectInfo*> prepareTreasurePile(const CTreasureInfo & treasureInfo);
  43. rmg::Object constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement = false);
  44. protected:
  45. std::vector<ObjectInfo> possibleObjects;
  46. int minGuardedValue = 0;
  47. rmg::Area treasureArea;
  48. rmg::Area treasureBlockArea;
  49. rmg::Area guards;
  50. Zone * questArtZone = nullptr; //artifacts required for Seer Huts will be placed here - or not if null
  51. };