TreasurePlacer.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGObjectInstance;
  15. class ObjectManager;
  16. class RmgMap;
  17. class CMapGenerator;
  18. struct ObjectInfo
  19. {
  20. std::shared_ptr<const ObjectTemplate> templ;
  21. ui32 value = 0;
  22. ui16 probability = 0;
  23. ui32 maxPerZone = 1;
  24. //ui32 maxPerMap; //unused
  25. std::function<CGObjectInstance *()> generateObject;
  26. void setTemplate(si32 type, si32 subtype, TerrainId terrain);
  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 addObjectToRandomPool(const ObjectInfo& oi);
  39. void addAllPossibleObjects(); //add objects, including zone-specific, to possibleObjects
  40. size_t getPossibleObjectsSize() const;
  41. protected:
  42. bool isGuardNeededForTreasure(int value);
  43. ObjectInfo * getRandomObject(ui32 desiredValue, ui32 currentValue, ui32 maxValue, bool allowLargeObjects);
  44. std::vector<ObjectInfo*> prepareTreasurePile(const CTreasureInfo & treasureInfo);
  45. rmg::Object constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement = false);
  46. protected:
  47. std::vector<ObjectInfo> possibleObjects;
  48. int minGuardedValue = 0;
  49. rmg::Area treasureArea;
  50. rmg::Area treasureBlockArea;
  51. rmg::Area guards;
  52. Zone * questArtZone = nullptr; //artifacts required for Seer Huts will be placed here - or not if null
  53. };
  54. VCMI_LIB_NAMESPACE_END