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-30 17:50:06 +03:00
|
|
|
#include "CRmgTemplateZone.h"
|
2014-05-22 17:27:13 +03:00
|
|
|
#include "../int3.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
|
|
|
|
2014-05-23 18:12:31 +03:00
|
|
|
class rmgException : 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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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:
|
2014-07-27 14:59:53 +03:00
|
|
|
explicit CMapGenerator();
|
2013-04-14 22:24:31 +03:00
|
|
|
~CMapGenerator(); // required due to unique_ptr
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-07-27 14:59:53 +03:00
|
|
|
std::unique_ptr<CMap> generate(CMapGenOptions * mapGenOptions, int RandomSeed = std::time(nullptr));
|
2014-05-22 17:27:13 +03:00
|
|
|
|
2014-07-27 14:59:53 +03:00
|
|
|
CMapGenOptions * mapGenOptions;
|
2014-05-23 14:23:03 +03:00
|
|
|
std::unique_ptr<CMap> map;
|
2014-05-22 20:25:17 +03:00
|
|
|
CRandomGenerator rand;
|
2014-05-22 17:27:13 +03:00
|
|
|
int randomSeed;
|
|
|
|
CMapEditManager * editManager;
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-24 13:42:06 +03:00
|
|
|
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> getZones() const;
|
2014-06-01 17:31:15 +03:00
|
|
|
void createConnections();
|
2014-05-30 22:23:41 +03:00
|
|
|
void foreach_neighbour(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;
|
2014-05-31 15:11:20 +03:00
|
|
|
void setOccupied(const int3 &tile, ETileType::ETileType state);
|
|
|
|
CTileInfo getTile(const int3 & tile) const;
|
2014-05-30 22:23:41 +03:00
|
|
|
|
2014-07-25 18:10:16 +03:00
|
|
|
float getNearestObjectDistance(const int3 &tile) const;
|
|
|
|
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();
|
|
|
|
|
2014-07-07 17:20:48 +03:00
|
|
|
void registerZone (TFaction faction);
|
|
|
|
ui32 getZoneCount(TFaction faction);
|
|
|
|
ui32 getTotalZoneCount() const;
|
2014-05-30 17:50:06 +03:00
|
|
|
|
2013-01-06 22:30:12 +03:00
|
|
|
private:
|
2014-05-22 20:25:17 +03:00
|
|
|
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
|
2014-07-07 17:20:48 +03:00
|
|
|
std::map<TFaction, ui32> zonesPerFaction;
|
|
|
|
ui32 zonesTotal; //zones that have their main town only
|
2014-05-22 17:27:13 +03:00
|
|
|
|
2014-05-30 17:50:06 +03:00
|
|
|
CTileInfo*** tiles;
|
|
|
|
|
2014-07-25 11:44:17 +03:00
|
|
|
int prisonsRemaining;
|
2014-06-01 13:02:43 +03:00
|
|
|
int monolithIndex;
|
|
|
|
|
2013-04-14 22:24:31 +03:00
|
|
|
/// Generation methods
|
|
|
|
std::string getMapDescription() const;
|
2014-07-25 11:44:17 +03:00
|
|
|
|
|
|
|
void initPrisonsRemaining();
|
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();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-31 15:11:20 +03:00
|
|
|
};
|