mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Random map generator refactoring (#762)
random map generator refactoring and improvements
This commit is contained in:
committed by
Andrii Danylchenko
parent
804f1bf3f2
commit
4bd0ff680a
@@ -16,36 +16,15 @@
|
||||
#include "../int3.h"
|
||||
#include "CRmgTemplate.h"
|
||||
|
||||
class CMap;
|
||||
class CRmgTemplate;
|
||||
class CRmgTemplateZone;
|
||||
class CMapGenOptions;
|
||||
class CTerrainViewPatternConfig;
|
||||
class CMapEditManager;
|
||||
class JsonNode;
|
||||
class CMapGenerator;
|
||||
class CTileInfo;
|
||||
class RmgMap;
|
||||
class CMap;
|
||||
class Zone;
|
||||
|
||||
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
|
||||
{
|
||||
@@ -57,7 +36,6 @@ public:
|
||||
std::vector<CTreasureInfo> waterTreasure;
|
||||
int shipyardGuard;
|
||||
int mineExtraResources;
|
||||
std::map<Res::ERes, int> mineValues;
|
||||
int minGuardStrength;
|
||||
std::string defaultRoadType;
|
||||
int treasureValueLimit;
|
||||
@@ -68,84 +46,44 @@ public:
|
||||
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();
|
||||
void findZonesForQuestArts();
|
||||
void foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
||||
void foreachDirectNeighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
||||
void foreachDiagonalNeighbour(const int3& pos, std::function<void(int3& pos)> foo);
|
||||
|
||||
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;
|
||||
bool isRoad(const int3 &tile) const;
|
||||
|
||||
void setOccupied(const int3 &tile, ETileType::ETileType state);
|
||||
void setRoad(const int3 &tile, const std::string & roadType);
|
||||
|
||||
CTileInfo getTile(const int3 & tile) const;
|
||||
bool isAllowedSpell(SpellID sid) const;
|
||||
|
||||
float getNearestObjectDistance(const int3 &tile) const;
|
||||
void setNearestObjectDistance(int3 &tile, float value);
|
||||
|
||||
int getNextMonlithIndex();
|
||||
int getPrisonsRemaning() const;
|
||||
void decreasePrisonsRemaining();
|
||||
std::vector<ArtifactID> getQuestArtsRemaning() const;
|
||||
const 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;
|
||||
Zone * getZoneWater() const;
|
||||
void createWaterTreasures();
|
||||
void prepareWaterTiles();
|
||||
|
||||
TRmgTemplateZoneId getZoneID(const int3& tile) const;
|
||||
void setZoneID(const int3& tile, TRmgTemplateZoneId zid);
|
||||
int getRandomSeed() const;
|
||||
|
||||
void dump(bool zoneId);
|
||||
|
||||
private:
|
||||
int randomSeed;
|
||||
CMapGenOptions& mapGenOptions;
|
||||
Config config;
|
||||
std::unique_ptr<RmgMap> map;
|
||||
|
||||
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]
|
||||
//std::pair<Zones::key_type, Zones::mapped_type> zoneWater;
|
||||
|
||||
int prisonsRemaining;
|
||||
//int questArtsRemaining;
|
||||
int monolithIndex;
|
||||
std::vector<ArtifactID> questArtifacts;
|
||||
void checkIsOnMap(const int3 &tile) const; //throws
|
||||
|
||||
/// Generation methods
|
||||
void loadConfig();
|
||||
@@ -156,10 +94,7 @@ private:
|
||||
void initQuestArtsRemaining();
|
||||
void addPlayerInfo();
|
||||
void addHeaderInfo();
|
||||
void initTiles();
|
||||
void genZones();
|
||||
void fillZones();
|
||||
void createObstaclesCommon1();
|
||||
void createObstaclesCommon2();
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user