1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00
vcmi/lib/rmg/CMapGenerator.h

166 lines
4.3 KiB
C
Raw Normal View History

/*
* CMapGenerator.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 "../CRandomGenerator.h"
#include "CMapGenOptions.h"
#include "../int3.h"
#include "CRmgTemplate.h"
class CMap;
class CRmgTemplate;
class CRmgTemplateZone;
class CMapGenOptions;
class CTerrainViewPatternConfig;
class CMapEditManager;
class JsonNode;
class CMapGenerator;
class CTileInfo;
typedef std::vector<JsonNode> JsonVector;
class rmgException : public std::exception
{
std::string msg;
public:
explicit rmgException(const std::string& _Message) : msg(_Message)
{
}
virtual ~rmgException() throw ()
{
};
const char *what() const throw () override
{
return msg.c_str();
}
};
/// The map generator creates a map randomly.
class DLL_LINKAGE CMapGenerator
{
public:
struct Config
{
std::vector<Terrain> terrainUndergroundAllowed;
std::vector<Terrain> terrainGroundProhibit;
std::vector<CTreasureInfo> waterTreasure;
int shipyardGuard;
int mineExtraResources;
std::map<Res::ERes, int> mineValues;
int minGuardStrength;
std::string defaultRoadType;
int treasureValueLimit;
std::vector<int> prisonExperience, prisonValues;
std::vector<int> scrollValues;
int pandoraMultiplierGold, pandoraMultiplierExperience, pandoraMultiplierSpells, pandoraSpellSchool, pandoraSpell60;
std::vector<int> pandoraCreatureValues;
std::vector<int> questValues, questRewardValues;
};
using Zones = std::map<TRmgTemplateZoneId, std::shared_ptr<CRmgTemplateZone>>;
explicit CMapGenerator(CMapGenOptions& mapGenOptions, int RandomSeed = std::time(nullptr));
~CMapGenerator(); // required due to std::unique_ptr
const Config & getConfig() const;
mutable std::unique_ptr<CMap> map;
CRandomGenerator rand;
CMapEditManager* getEditManager() const;
const CMapGenOptions& getMapGenOptions() const;
std::unique_ptr<CMap> generate();
Zones & getZones();
void createDirectConnections();
void createConnections2();
2015-03-01 11:20:49 +02:00
void findZonesForQuestArts();
2014-05-30 22:23:41 +03:00
void foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo);
2015-01-03 08:20:52 +02:00
void foreachDirectNeighbour(const int3 &pos, std::function<void(int3& pos)> foo);
void foreachDiagonalNeighbour(const int3& pos, std::function<void(int3& pos)> foo);
2014-05-24 13:42:06 +03:00
2014-05-30 22:23:41 +03:00
bool isBlocked(const int3 &tile) const;
bool shouldBeBlocked(const int3 &tile) const;
bool isPossible(const int3 &tile) const;
bool isFree(const int3 &tile) const;
bool isUsed(const int3 &tile) const;
2015-01-18 15:19:00 +02:00
bool isRoad(const int3 &tile) const;
2016-02-15 12:34:37 +02:00
void setOccupied(const int3 &tile, ETileType::ETileType state);
void setRoad(const int3 &tile, const std::string & roadType);
2016-02-15 12:34:37 +02:00
CTileInfo getTile(const int3 & tile) const;
2015-08-12 16:40:08 +02:00
bool isAllowedSpell(SpellID sid) const;
2014-05-30 22:23:41 +03:00
2016-02-15 12:34:37 +02:00
float getNearestObjectDistance(const int3 &tile) const;
2014-07-25 18:10:16 +03:00
void setNearestObjectDistance(int3 &tile, float value);
int getNextMonlithIndex();
int getPrisonsRemaning() const;
void decreasePrisonsRemaining();
2015-02-28 23:37:04 +02:00
std::vector<ArtifactID> getQuestArtsRemaning() const;
void banQuestArt(ArtifactID id);
void registerZone (TFaction faction);
ui32 getZoneCount(TFaction faction);
ui32 getTotalZoneCount() const;
Zones::value_type getZoneWater() const;
void createWaterTreasures();
void prepareWaterTiles();
TRmgTemplateZoneId getZoneID(const int3& tile) const;
void setZoneID(const int3& tile, TRmgTemplateZoneId zid);
void dump(bool zoneId);
private:
int randomSeed;
CMapGenOptions& mapGenOptions;
Config config;
std::vector<rmg::ZoneConnection> connectionsLeft;
Zones zones;
std::map<TFaction, ui32> zonesPerFaction;
ui32 zonesTotal; //zones that have their main town only
std::pair<Zones::key_type, Zones::mapped_type> zoneWater;
CTileInfo*** tiles;
boost::multi_array<TRmgTemplateZoneId, 3> zoneColouring; //[z][x][y]
int prisonsRemaining;
2015-03-30 23:55:37 +02:00
//int questArtsRemaining;
int monolithIndex;
2015-02-28 23:37:04 +02:00
std::vector<ArtifactID> questArtifacts;
2015-01-18 15:19:00 +02:00
void checkIsOnMap(const int3 &tile) const; //throws
/// Generation methods
void loadConfig();
std::string getMapDescription() const;
void initPrisonsRemaining();
void initQuestArtsRemaining();
void addPlayerInfo();
void addHeaderInfo();
void initTiles();
void genZones();
void fillZones();
2015-03-28 23:03:38 +02:00
void createObstaclesCommon1();
void createObstaclesCommon2();
};