2013-01-06 22:30:12 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2014-05-22 17:27:13 +03:00
|
|
|
#include "../GameConstants.h"
|
2013-01-06 22:30:12 +03:00
|
|
|
#include "../CRandomGenerator.h"
|
2014-05-22 20:25:17 +03:00
|
|
|
#include "CMapGenOptions.h"
|
2014-05-22 17:27:13 +03:00
|
|
|
#include "../int3.h"
|
2018-03-05 16:05:17 +02:00
|
|
|
#include "CRmgTemplate.h"
|
2013-01-06 22:30:12 +03:00
|
|
|
|
|
|
|
class CMap;
|
2014-05-22 20:25:17 +03:00
|
|
|
class CRmgTemplate;
|
|
|
|
class CRmgTemplateZone;
|
|
|
|
class CMapGenOptions;
|
2014-05-22 17:27:13 +03:00
|
|
|
class CTerrainViewPatternConfig;
|
2013-01-06 22:30:12 +03:00
|
|
|
class CMapEditManager;
|
2014-05-22 17:27:13 +03:00
|
|
|
class JsonNode;
|
|
|
|
class CMapGenerator;
|
2014-05-30 17:50:06 +03:00
|
|
|
class CTileInfo;
|
2014-05-22 17:27:13 +03:00
|
|
|
|
2014-05-30 17:50:06 +03:00
|
|
|
typedef std::vector<JsonNode> JsonVector;
|
2014-05-24 19:39:58 +03:00
|
|
|
|
2017-10-29 17:23:30 +02:00
|
|
|
class rmgException : public std::exception
|
2014-05-23 18:12:31 +03:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-14 21:52:05 +03:00
|
|
|
/// The map generator creates a map randomly.
|
|
|
|
class DLL_LINKAGE CMapGenerator
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
|
|
|
public:
|
2022-06-05 08:02:58 +02:00
|
|
|
struct Config
|
|
|
|
{
|
2022-06-20 16:39:50 +02:00
|
|
|
std::vector<Terrain> terrainUndergroundAllowed;
|
|
|
|
std::vector<Terrain> terrainGroundProhibit;
|
2022-06-05 08:02:58 +02:00
|
|
|
std::vector<CTreasureInfo> waterTreasure;
|
|
|
|
int shipyardGuard;
|
|
|
|
int mineExtraResources;
|
|
|
|
std::map<Res::ERes, int> mineValues;
|
|
|
|
int minGuardStrength;
|
2022-06-20 16:39:50 +02:00
|
|
|
std::string defaultRoadType;
|
2022-06-05 08:02:58 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
using Zones = std::map<TRmgTemplateZoneId, std::shared_ptr<CRmgTemplateZone>>;
|
|
|
|
|
2022-05-28 15:03:50 +02:00
|
|
|
explicit CMapGenerator(CMapGenOptions& mapGenOptions, int RandomSeed = std::time(nullptr));
|
2015-12-29 04:43:33 +02:00
|
|
|
~CMapGenerator(); // required due to std::unique_ptr
|
2022-05-28 15:03:50 +02:00
|
|
|
|
2022-06-05 08:02:58 +02:00
|
|
|
const Config & getConfig() const;
|
|
|
|
|
2022-05-28 15:03:50 +02:00
|
|
|
mutable std::unique_ptr<CMap> map;
|
2014-05-22 20:25:17 +03:00
|
|
|
CRandomGenerator rand;
|
2022-05-28 15:03:50 +02:00
|
|
|
|
|
|
|
CMapEditManager* getEditManager() const;
|
|
|
|
const CMapGenOptions& getMapGenOptions() const;
|
|
|
|
|
|
|
|
std::unique_ptr<CMap> generate();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
Zones & getZones();
|
2016-08-13 19:48:44 +02:00
|
|
|
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);
|
2022-05-28 15:03:50 +02:00
|
|
|
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;
|
2014-07-04 00:11:24 +03:00
|
|
|
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
|
|
|
|
2014-05-31 15:11:20 +03:00
|
|
|
void setOccupied(const int3 &tile, ETileType::ETileType state);
|
2022-06-20 16:39:50 +02:00
|
|
|
void setRoad(const int3 &tile, const std::string & roadType);
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2014-05-31 15:11:20 +03: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);
|
2014-06-01 13:02:43 +03:00
|
|
|
|
|
|
|
int getNextMonlithIndex();
|
2014-07-25 11:44:17 +03:00
|
|
|
int getPrisonsRemaning() const;
|
|
|
|
void decreasePrisonsRemaining();
|
2015-02-28 23:37:04 +02:00
|
|
|
std::vector<ArtifactID> getQuestArtsRemaning() const;
|
|
|
|
void banQuestArt(ArtifactID id);
|
2014-07-25 11:44:17 +03:00
|
|
|
|
2014-07-07 17:20:48 +03:00
|
|
|
void registerZone (TFaction faction);
|
|
|
|
ui32 getZoneCount(TFaction faction);
|
|
|
|
ui32 getTotalZoneCount() const;
|
2022-05-31 11:25:39 +02:00
|
|
|
|
|
|
|
Zones::value_type getZoneWater() const;
|
|
|
|
void createWaterTreasures();
|
|
|
|
void prepareWaterTiles();
|
2014-05-30 17:50:06 +03:00
|
|
|
|
2016-08-09 10:12:13 +02:00
|
|
|
TRmgTemplateZoneId getZoneID(const int3& tile) const;
|
|
|
|
void setZoneID(const int3& tile, TRmgTemplateZoneId zid);
|
2022-05-31 11:25:39 +02:00
|
|
|
|
|
|
|
void dump(bool zoneId);
|
2016-08-09 10:12:13 +02:00
|
|
|
|
2013-01-06 22:30:12 +03:00
|
|
|
private:
|
2022-05-28 15:03:50 +02:00
|
|
|
int randomSeed;
|
|
|
|
CMapGenOptions& mapGenOptions;
|
2022-06-05 08:02:58 +02:00
|
|
|
Config config;
|
2022-05-28 15:03:50 +02:00
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
std::vector<rmg::ZoneConnection> connectionsLeft;
|
2018-03-09 20:11:20 +02:00
|
|
|
Zones zones;
|
2014-07-07 17:20:48 +03:00
|
|
|
std::map<TFaction, ui32> zonesPerFaction;
|
|
|
|
ui32 zonesTotal; //zones that have their main town only
|
2022-05-31 11:25:39 +02:00
|
|
|
|
|
|
|
std::pair<Zones::key_type, Zones::mapped_type> zoneWater;
|
2014-05-22 17:27:13 +03:00
|
|
|
|
2014-05-30 17:50:06 +03:00
|
|
|
CTileInfo*** tiles;
|
2016-08-09 10:12:13 +02:00
|
|
|
boost::multi_array<TRmgTemplateZoneId, 3> zoneColouring; //[z][x][y]
|
2014-05-30 17:50:06 +03:00
|
|
|
|
2014-07-25 11:44:17 +03:00
|
|
|
int prisonsRemaining;
|
2015-03-30 23:55:37 +02:00
|
|
|
//int questArtsRemaining;
|
2014-06-01 13:02:43 +03:00
|
|
|
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
|
2014-06-01 13:02:43 +03:00
|
|
|
|
2013-04-14 22:24:31 +03:00
|
|
|
/// Generation methods
|
2022-06-05 08:02:58 +02:00
|
|
|
void loadConfig();
|
|
|
|
|
2013-04-14 22:24:31 +03:00
|
|
|
std::string getMapDescription() const;
|
2014-07-25 11:44:17 +03:00
|
|
|
|
|
|
|
void initPrisonsRemaining();
|
2015-02-28 22:14:45 +02:00
|
|
|
void initQuestArtsRemaining();
|
2013-04-14 22:24:31 +03:00
|
|
|
void addPlayerInfo();
|
|
|
|
void addHeaderInfo();
|
2014-05-30 17:50:06 +03:00
|
|
|
void initTiles();
|
2014-05-22 17:27:13 +03:00
|
|
|
void genZones();
|
|
|
|
void fillZones();
|
2015-03-28 23:03:38 +02:00
|
|
|
void createObstaclesCommon1();
|
|
|
|
void createObstaclesCommon2();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-31 15:11:20 +03:00
|
|
|
};
|