/* * CRmgTemplateZone.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #pragma once #include "../GameConstants.h" #include "CMapGenerator.h" #include "float3.h" #include "../int3.h" #include "../ResourceSet.h" //for TResource (?) #include "../mapObjects/ObjectTemplate.h" #include //A* class CMapGenerator; class CTileInfo; class int3; class CGObjectInstance; class ObjectTemplate; class CRmgTemplateZoneConnection; namespace ETemplateZoneType { enum ETemplateZoneType { PLAYER_START, CPU_START, TREASURE, JUNCTION }; } namespace EObjectPlacingResult { enum EObjectPlacingResult { SUCCESS, CANNOT_FIT, SEALED_OFF }; } class DLL_LINKAGE CTileInfo { public: CTileInfo(); float getNearestObjectDistance() const; void setNearestObjectDistance(float value); bool isBlocked() const; bool shouldBeBlocked() const; bool isPossible() const; bool isFree() const; bool isUsed() const; bool isRoad() const; void setOccupied(ETileType::ETileType value); ETerrainType getTerrainType() const; ETileType::ETileType getTileType() const; void setTerrainType(ETerrainType value); void setRoadType(ERoadType::ERoadType value); private: float nearestObjectDistance; ETileType::ETileType occupied; ETerrainType terrain; ERoadType::ERoadType roadType; }; class DLL_LINKAGE CTreasureInfo { public: ui32 min; ui32 max; ui16 density; }; struct DLL_LINKAGE ObjectInfo { ObjectTemplate templ; ui32 value; ui16 probability; ui32 maxPerZone; //ui32 maxPerMap; //unused std::function generateObject; void setTemplate (si32 type, si32 subtype, ETerrainType terrain); ObjectInfo(); bool operator==(const ObjectInfo& oi) const { return (templ == oi.templ); } }; struct DLL_LINKAGE CTreasurePileInfo { std::set visitableFromBottomPositions; //can be visited only from bottom or side std::set visitableFromTopPositions; //they can be visited from any direction std::set blockedPositions; std::set occupiedPositions; //blocked + visitable int3 nextTreasurePos; }; /// The CRmgTemplateZone describes a zone in a template. class DLL_LINKAGE CRmgTemplateZone { public: class DLL_LINKAGE CTownInfo { public: CTownInfo(); int getTownCount() const; /// Default: 0 void setTownCount(int value); int getCastleCount() const; /// Default: 0 void setCastleCount(int value); int getTownDensity() const; /// Default: 0 void setTownDensity(int value); int getCastleDensity() const; /// Default: 0 void setCastleDensity(int value); private: int townCount, castleCount, townDensity, castleDensity; }; CRmgTemplateZone(); void setGenPtr(CMapGenerator * Gen); TRmgTemplateZoneId getId() const; /// Default: 0 void setId(TRmgTemplateZoneId value); ETemplateZoneType::ETemplateZoneType getType() const; /// Default: ETemplateZoneType::PLAYER_START void setType(ETemplateZoneType::ETemplateZoneType value); int getSize() const; /// Default: 1 void setSize(int value); boost::optional getOwner() const; void setOwner(boost::optional value); const CTownInfo & getPlayerTowns() const; void setPlayerTowns(const CTownInfo & value); const CTownInfo & getNeutralTowns() const; void setNeutralTowns(const CTownInfo & value); bool getTownsAreSameType() const; /// Default: false void setTownsAreSameType(bool value); const std::set & getTownTypes() const; /// Default: all void setTownTypes(const std::set & value); void setMonsterTypes(const std::set & value); std::set getDefaultTownTypes() const; bool getMatchTerrainToTown() const; /// Default: true void setMatchTerrainToTown(bool value); const std::set & getTerrainTypes() const; /// Default: all void setTerrainTypes(const std::set & value); std::set getDefaultTerrainTypes() const; void setMinesAmount (TResource res, ui16 amount); std::map getMinesInfo() const; void setMonsterStrength (EMonsterStrength::EMonsterStrength val); float3 getCenter() const; void setCenter(const float3 &f); int3 getPos() const; void setPos(const int3 &pos); bool isAccessibleFromAnywhere(ObjectTemplate &appearance, int3 &tile) const; int3 getAccessibleOffset(ObjectTemplate &appearance, int3 &tile) const; void addTile (const int3 &pos); void initFreeTiles (); std::set getTileInfo() const; std::set getPossibleTiles() const; void discardDistantTiles (float distance); void clearTiles(); void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0); void addCloseObject(CGObjectInstance * obj, si32 guardStrength = 0); void addToConnectLater(const int3& src); bool addMonster(int3 &pos, si32 strength, bool clearSurroundingTiles = true, bool zoneGuard = false); bool createTreasurePile(int3 &pos, float minDistance, const CTreasureInfo& treasureInfo); bool fill (); bool placeMines (); void initTownType (); void paintZoneTerrain (ETerrainType terrainType); void randomizeTownType(); //helper function void initTerrainType (); void createBorder(); void fractalize(); void connectLater(); EObjectPlacingResult::EObjectPlacingResult tryToPlaceObjectAndConnectToPath(CGObjectInstance *obj, int3 &pos); //return true if the position cna be connected bool createRequiredObjects(); void createTreasures(); void createObstacles1(); void createObstacles2(); bool crunchPath(const int3 &src, const int3 &dst, bool onlyStraight, std::set* clearedTiles = nullptr); bool connectPath(const int3& src, bool onlyStraight); bool connectWithCenter(const int3& src, bool onlyStraight); void updateDistances(const int3 & pos); std::vector getAccessibleOffsets (const CGObjectInstance* object); bool areAllTilesAvailable(CGObjectInstance* obj, int3& tile, std::set& tilesBlockedByObject) const; void addConnection(TRmgTemplateZoneId otherZone); void setQuestArtZone(CRmgTemplateZone * otherZone); std::vector getConnections() const; void addTreasureInfo(CTreasureInfo & info); std::vector getTreasureInfo(); std::set* getFreePaths(); ObjectInfo getRandomObject (CTreasurePileInfo &info, ui32 desiredValue, ui32 maxValue, ui32 currentValue); void placeSubterraneanGate(int3 pos, si32 guardStrength); void placeObject(CGObjectInstance* object, const int3 &pos, bool updateDistance = true); bool guardObject(CGObjectInstance* object, si32 str, bool zoneGuard = false, bool addToFreePaths = false); void placeAndGuardObject(CGObjectInstance* object, const int3 &pos, si32 str, bool zoneGuard = false); void addRoadNode(const int3 & node); void connectRoads(); //fills "roads" according to "roadNodes" //A* priority queue typedef std::pair TDistance; struct NodeComparer { bool operator()(const TDistance & lhs, const TDistance & rhs) const { return (rhs.second < lhs.second); } }; boost::heap::priority_queue> createPiorityQueue(); private: CMapGenerator * gen; //template info TRmgTemplateZoneId id; ETemplateZoneType::ETemplateZoneType type; int size; boost::optional owner; CTownInfo playerTowns, neutralTowns; bool townsAreSameType; std::set townTypes; std::set monsterTypes; bool matchTerrainToTown; std::set terrainTypes; std::map mines; //obligatory mines to spawn in this zone si32 townType; ETerrainType terrainType; CRmgTemplateZone * questArtZone; //artifacts required for Seer Huts will be placed here - or not if null EMonsterStrength::EMonsterStrength zoneMonsterStrength; std::vector treasureInfo; std::vector possibleObjects; int minGuardedValue; //content info std::vector> requiredObjects; std::vector> closeObjects; std::vector objects; //placement info int3 pos; float3 center; std::set tileinfo; //irregular area assined to zone std::set possibleTiles; //optimization purposes for treasure generation std::vector connections; //list of adjacent zones std::set freePaths; //core paths of free tiles that all other objects will be linked to std::set roadNodes; //tiles to be connected with roads std::set roads; //all tiles with roads std::set tilesToConnectLater; //will be connected after paths are fractalized bool createRoad(const int3 &src, const int3 &dst); void drawRoads(); //actually updates tiles bool pointIsIn(int x, int y); void addAllPossibleObjects (); //add objects, including zone-specific, to possibleObjects bool findPlaceForObject(CGObjectInstance* obj, si32 min_dist, int3 &pos); bool findPlaceForTreasurePile(float min_dist, int3 &pos, int value); bool canObstacleBePlacedHere(ObjectTemplate &temp, int3 &pos); void setTemplateForObject(CGObjectInstance* obj); void checkAndPlaceObject(CGObjectInstance* object, const int3 &pos); };