2013-08-17 15:46:48 +03:00
/*
* 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"
2014-05-22 20:25:17 +03:00
# include "CMapGenerator.h"
2014-05-24 13:42:06 +03:00
# include "float3.h"
2014-05-30 17:50:06 +03:00
# include "../int3.h"
2014-06-14 21:05:19 +03:00
# include "../ResourceSet.h" //for TResource (?)
2014-07-08 21:13:51 +03:00
# include "../mapObjects/ObjectTemplate.h"
2014-05-22 20:25:17 +03:00
2014-05-30 17:50:06 +03:00
class CMapGenerator ;
class CTileInfo ;
class int3 ;
class CGObjectInstance ;
2014-06-28 10:46:32 +03:00
class ObjectTemplate ;
2016-08-13 19:48:44 +02:00
class CRmgTemplateZoneConnection ;
2013-08-17 15:46:48 +03:00
namespace ETemplateZoneType
{
2014-05-30 17:50:06 +03:00
enum ETemplateZoneType
{
PLAYER_START ,
CPU_START ,
TREASURE ,
JUNCTION
} ;
}
2016-07-12 11:42:03 +02:00
namespace EObjectPlacingResult
{
enum EObjectPlacingResult
{
SUCCESS ,
CANNOT_FIT ,
SEALED_OFF
} ;
}
2014-05-30 17:50:06 +03:00
class DLL_LINKAGE CTileInfo
2013-08-17 15:46:48 +03:00
{
2014-05-30 17:50:06 +03:00
public :
CTileInfo ( ) ;
2014-07-25 18:10:16 +03:00
float getNearestObjectDistance ( ) const ;
void setNearestObjectDistance ( float value ) ;
2014-05-30 17:50:06 +03:00
bool isBlocked ( ) const ;
bool shouldBeBlocked ( ) const ;
bool isPossible ( ) const ;
bool isFree ( ) const ;
2014-07-04 00:11:24 +03:00
bool isUsed ( ) const ;
2016-02-15 12:34:37 +02:00
bool isRoad ( ) const ;
2014-05-30 17:50:06 +03:00
void setOccupied ( ETileType : : ETileType value ) ;
ETerrainType getTerrainType ( ) const ;
2015-01-16 10:40:11 +02:00
ETileType : : ETileType getTileType ( ) const ;
2014-05-30 17:50:06 +03:00
void setTerrainType ( ETerrainType value ) ;
2016-02-15 12:34:37 +02:00
2015-01-03 05:59:51 +02:00
void setRoadType ( ERoadType : : ERoadType value ) ;
2014-05-30 17:50:06 +03:00
private :
2014-07-25 18:10:16 +03:00
float nearestObjectDistance ;
2014-05-30 17:50:06 +03:00
ETileType : : ETileType occupied ;
ETerrainType terrain ;
2015-01-03 05:59:51 +02:00
ERoadType : : ERoadType roadType ;
2013-08-17 15:46:48 +03:00
} ;
2014-06-04 16:16:23 +03:00
class DLL_LINKAGE CTreasureInfo
{
public :
ui32 min ;
ui32 max ;
ui16 density ;
} ;
2014-06-04 20:08:04 +03:00
struct DLL_LINKAGE ObjectInfo
{
2014-07-08 21:13:51 +03:00
ObjectTemplate templ ;
2014-06-04 20:08:04 +03:00
ui32 value ;
ui16 probability ;
2014-07-15 23:33:51 +03:00
ui32 maxPerZone ;
ui32 maxPerMap ;
2014-06-04 20:08:04 +03:00
std : : function < CGObjectInstance * ( ) > generateObject ;
2014-07-08 21:13:51 +03:00
void setTemplate ( si32 type , si32 subtype , ETerrainType terrain ) ;
2014-07-15 23:33:51 +03:00
bool operator = = ( const ObjectInfo & oi ) const { return ( templ = = oi . templ ) ; }
2014-07-08 21:13:51 +03:00
} ;
struct DLL_LINKAGE CTreasurePileInfo
{
2014-07-09 10:22:50 +03:00
std : : set < int3 > visitableFromBottomPositions ; //can be visited only from bottom or side
2014-07-08 21:13:51 +03:00
std : : set < int3 > visitableFromTopPositions ; //they can be visited from any direction
2014-07-09 10:22:50 +03:00
std : : set < int3 > blockedPositions ;
std : : set < int3 > occupiedPositions ; //blocked + visitable
2014-07-08 21:13:51 +03:00
int3 nextTreasurePos ;
2014-06-04 20:08:04 +03:00
} ;
2013-08-17 15:46:48 +03:00
/// 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 ( ) ;
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 < int > getOwner ( ) const ;
void setOwner ( boost : : optional < int > 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 < TFaction > & getTownTypes ( ) const ; /// Default: all
void setTownTypes ( const std : : set < TFaction > & value ) ;
2014-10-30 14:03:53 +02:00
void setMonsterTypes ( const std : : set < TFaction > & value ) ;
2013-08-17 15:46:48 +03:00
std : : set < TFaction > getDefaultTownTypes ( ) const ;
bool getMatchTerrainToTown ( ) const ; /// Default: true
void setMatchTerrainToTown ( bool value ) ;
const std : : set < ETerrainType > & getTerrainTypes ( ) const ; /// Default: all
void setTerrainTypes ( const std : : set < ETerrainType > & value ) ;
std : : set < ETerrainType > getDefaultTerrainTypes ( ) const ;
2014-06-14 21:05:19 +03:00
void setMinesAmount ( TResource res , ui16 amount ) ;
std : : map < TResource , ui16 > getMinesInfo ( ) const ;
2014-06-15 12:08:06 +03:00
void setMonsterStrength ( EMonsterStrength : : EMonsterStrength val ) ;
2014-05-24 13:42:06 +03:00
float3 getCenter ( ) const ;
2014-05-30 17:50:06 +03:00
void setCenter ( const float3 & f ) ;
int3 getPos ( ) const ;
2014-05-25 12:02:15 +03:00
void setPos ( const int3 & pos ) ;
2016-07-10 10:11:29 +02:00
bool isAccessibleFromAnywhere ( CMapGenerator * gen , ObjectTemplate & appearance , int3 & tile ) const ;
int3 getAccessibleOffset ( CMapGenerator * gen , ObjectTemplate & appearance , int3 & tile ) const ;
2014-05-24 13:42:06 +03:00
2014-05-25 12:02:15 +03:00
void addTile ( const int3 & pos ) ;
2014-07-24 20:16:49 +03:00
void initFreeTiles ( CMapGenerator * gen ) ;
2016-08-13 19:48:44 +02:00
std : : set < int3 > getTileInfo ( ) const ;
std : : set < int3 > getPossibleTiles ( ) const ;
2014-07-07 19:01:15 +03:00
void discardDistantTiles ( CMapGenerator * gen , float distance ) ;
2015-01-16 20:28:27 +02:00
void clearTiles ( ) ;
2014-05-31 11:56:14 +03:00
2014-06-01 17:31:15 +03:00
void addRequiredObject ( CGObjectInstance * obj , si32 guardStrength = 0 ) ;
2014-12-20 23:13:10 +02:00
void addCloseObject ( CGObjectInstance * obj , si32 guardStrength = 0 ) ;
2015-06-04 09:02:56 +02:00
void addToConnectLater ( const int3 & src ) ;
2014-07-15 15:38:05 +03:00
bool addMonster ( CMapGenerator * gen , int3 & pos , si32 strength , bool clearSurroundingTiles = true , bool zoneGuard = false ) ;
2014-12-20 15:01:48 +02:00
bool createTreasurePile ( CMapGenerator * gen , int3 & pos , float minDistance , const CTreasureInfo & treasureInfo ) ;
2014-06-14 21:05:19 +03:00
bool fill ( CMapGenerator * gen ) ;
bool placeMines ( CMapGenerator * gen ) ;
2014-06-14 18:14:59 +03:00
void initTownType ( CMapGenerator * gen ) ;
2014-07-03 18:24:28 +03:00
void paintZoneTerrain ( CMapGenerator * gen , ETerrainType terrainType ) ;
2015-06-02 09:30:56 +02:00
void randomizeTownType ( CMapGenerator * gen ) ; //helper function
2014-06-14 18:14:59 +03:00
void initTerrainType ( CMapGenerator * gen ) ;
2014-05-30 22:23:41 +03:00
void createBorder ( CMapGenerator * gen ) ;
2014-06-12 22:10:43 +03:00
void fractalize ( CMapGenerator * gen ) ;
2015-06-04 09:02:56 +02:00
void connectLater ( CMapGenerator * gen ) ;
2016-07-12 11:42:03 +02:00
EObjectPlacingResult : : EObjectPlacingResult tryToPlaceObjectAndConnectToPath ( CMapGenerator * gen , CGObjectInstance * obj , int3 & pos ) ; //return true if the position cna be connected
2014-06-15 09:48:46 +03:00
bool createRequiredObjects ( CMapGenerator * gen ) ;
void createTreasures ( CMapGenerator * gen ) ;
2015-03-28 23:03:38 +02:00
void createObstacles1 ( CMapGenerator * gen ) ;
void createObstacles2 ( CMapGenerator * gen ) ;
2015-06-02 16:40:32 +02:00
bool crunchPath ( CMapGenerator * gen , const int3 & src , const int3 & dst , bool onlyStraight , std : : set < int3 > * clearedTiles = nullptr ) ;
bool connectPath ( CMapGenerator * gen , const int3 & src , bool onlyStraight ) ;
2015-06-04 09:02:56 +02:00
bool connectWithCenter ( CMapGenerator * gen , const int3 & src , bool onlyStraight ) ;
2016-02-15 12:34:37 +02:00
2014-06-15 20:56:58 +03:00
std : : vector < int3 > getAccessibleOffsets ( CMapGenerator * gen , CGObjectInstance * object ) ;
2016-08-15 21:37:38 +02:00
bool areAllTilesAvailable ( CMapGenerator * gen , CGObjectInstance * obj , int3 & tile , std : : set < int3 > & tilesBlockedByObject ) const ;
2013-08-17 15:46:48 +03:00
2014-05-24 13:42:06 +03:00
void addConnection ( TRmgTemplateZoneId otherZone ) ;
2015-03-01 11:20:49 +02:00
void setQuestArtZone ( CRmgTemplateZone * otherZone ) ;
2014-05-24 13:42:06 +03:00
std : : vector < TRmgTemplateZoneId > getConnections ( ) const ;
2014-06-04 16:16:23 +03:00
void addTreasureInfo ( CTreasureInfo & info ) ;
std : : vector < CTreasureInfo > getTreasureInfo ( ) ;
2014-06-18 10:57:36 +03:00
std : : set < int3 > * getFreePaths ( ) ;
2014-05-24 13:42:06 +03:00
2014-09-22 14:36:55 +03:00
ObjectInfo getRandomObject ( CMapGenerator * gen , CTreasurePileInfo & info , ui32 desiredValue , ui32 maxValue , ui32 currentValue ) ;
2014-06-04 20:08:04 +03:00
2015-06-04 09:02:56 +02:00
void placeSubterraneanGate ( CMapGenerator * gen , int3 pos , si32 guardStrength ) ;
void placeObject ( CMapGenerator * gen , CGObjectInstance * object , const int3 & pos , bool updateDistance = true ) ;
bool guardObject ( CMapGenerator * gen , CGObjectInstance * object , si32 str , bool zoneGuard = false , bool addToFreePaths = false ) ;
2014-07-15 15:38:05 +03:00
void placeAndGuardObject ( CMapGenerator * gen , CGObjectInstance * object , const int3 & pos , si32 str , bool zoneGuard = false ) ;
2015-01-18 15:19:00 +02:00
void addRoadNode ( const int3 & node ) ;
2015-05-25 16:37:57 +02:00
void connectRoads ( CMapGenerator * gen ) ; //fills "roads" according to "roadNodes"
2014-07-03 18:24:28 +03:00
2013-08-17 15:46:48 +03:00
private :
2014-05-24 13:42:06 +03:00
//template info
2013-08-17 15:46:48 +03:00
TRmgTemplateZoneId id ;
ETemplateZoneType : : ETemplateZoneType type ;
int size ;
boost : : optional < int > owner ;
CTownInfo playerTowns , neutralTowns ;
bool townsAreSameType ;
std : : set < TFaction > townTypes ;
2014-10-30 14:03:53 +02:00
std : : set < TFaction > monsterTypes ;
2013-08-17 15:46:48 +03:00
bool matchTerrainToTown ;
std : : set < ETerrainType > terrainTypes ;
2014-06-14 21:05:19 +03:00
std : : map < TResource , ui16 > mines ; //obligatory mines to spawn in this zone
2014-06-14 18:14:59 +03:00
si32 townType ;
ETerrainType terrainType ;
2015-03-01 11:20:49 +02:00
CRmgTemplateZone * questArtZone ; //artifacts required for Seer Huts will be placed here - or not if null
2014-05-22 20:25:17 +03:00
2014-06-15 12:08:06 +03:00
EMonsterStrength : : EMonsterStrength zoneMonsterStrength ;
2014-06-04 16:16:23 +03:00
std : : vector < CTreasureInfo > treasureInfo ;
2014-06-04 20:08:04 +03:00
std : : vector < ObjectInfo > possibleObjects ;
2014-12-26 17:17:39 +02:00
int minGuardedValue ;
2014-06-04 16:16:23 +03:00
2014-05-24 13:42:06 +03:00
//content info
2014-06-01 17:31:15 +03:00
std : : vector < std : : pair < CGObjectInstance * , ui32 > > requiredObjects ;
2014-12-20 23:13:10 +02:00
std : : vector < std : : pair < CGObjectInstance * , ui32 > > closeObjects ;
2014-05-22 20:25:17 +03:00
std : : vector < CGObjectInstance * > objects ;
2014-05-24 13:42:06 +03:00
//placement info
int3 pos ;
float3 center ;
2014-05-30 22:23:41 +03:00
std : : set < int3 > tileinfo ; //irregular area assined to zone
2014-07-24 20:16:49 +03:00
std : : set < int3 > possibleTiles ; //optimization purposes for treasure generation
2014-05-24 13:42:06 +03:00
std : : vector < TRmgTemplateZoneId > connections ; //list of adjacent zones
2014-06-18 10:57:36 +03:00
std : : set < int3 > freePaths ; //core paths of free tiles that all other objects will be linked to
2016-02-15 12:34:37 +02:00
2015-01-18 15:19:00 +02:00
std : : set < int3 > roadNodes ; //tiles to be connected with roads
std : : set < int3 > roads ; //all tiles with roads
2015-06-04 09:02:56 +02:00
std : : set < int3 > tilesToConnectLater ; //will be connected after paths are fractalized
2016-02-15 12:34:37 +02:00
2015-05-25 16:37:57 +02:00
bool createRoad ( CMapGenerator * gen , const int3 & src , const int3 & dst ) ;
void drawRoads ( CMapGenerator * gen ) ; //actually updates tiles
2014-05-24 13:42:06 +03:00
2014-05-22 20:25:17 +03:00
bool pointIsIn ( int x , int y ) ;
2014-06-04 20:08:04 +03:00
void addAllPossibleObjects ( CMapGenerator * gen ) ; //add objects, including zone-specific, to possibleObjects
2014-05-22 20:25:17 +03:00
bool findPlaceForObject ( CMapGenerator * gen , CGObjectInstance * obj , si32 min_dist , int3 & pos ) ;
2014-12-26 17:17:39 +02:00
bool findPlaceForTreasurePile ( CMapGenerator * gen , float min_dist , int3 & pos , int value ) ;
2014-06-28 10:46:32 +03:00
bool canObstacleBePlacedHere ( CMapGenerator * gen , ObjectTemplate & temp , int3 & pos ) ;
2014-12-20 23:13:10 +02:00
void setTemplateForObject ( CMapGenerator * gen , CGObjectInstance * obj ) ;
2014-05-23 18:12:31 +03:00
void checkAndPlaceObject ( CMapGenerator * gen , CGObjectInstance * object , const int3 & pos ) ;
2013-08-17 15:46:48 +03:00
} ;