mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-05 00:49:09 +02:00
First part of Subterranean Gates rework. Fixes #http://bugs.vcmi.eu/view.php?id=2450
This commit is contained in:
@ -272,19 +272,20 @@ void CMapGenerator::fillZones()
|
|||||||
|
|
||||||
//initialize possible tiles before any object is actually placed
|
//initialize possible tiles before any object is actually placed
|
||||||
for (auto it : zones)
|
for (auto it : zones)
|
||||||
{
|
|
||||||
it.second->initFreeTiles(this);
|
it.second->initFreeTiles(this);
|
||||||
}
|
|
||||||
|
|
||||||
findZonesForQuestArts();
|
findZonesForQuestArts();
|
||||||
createConnections();
|
createDirectConnections(); //direct
|
||||||
//make sure all connections are passable before creating borders
|
//make sure all connections are passable before creating borders
|
||||||
for (auto it : zones)
|
for (auto it : zones)
|
||||||
{
|
it.second->createBorder(this); //once direct connections are done
|
||||||
it.second->createBorder(this);
|
|
||||||
|
createConnections2(); //subterranean gates and monoliths
|
||||||
|
|
||||||
//we need info about all town types to evaluate dwellings and pandoras with creatures properly
|
//we need info about all town types to evaluate dwellings and pandoras with creatures properly
|
||||||
|
for (auto it : zones)
|
||||||
it.second->initTownType(this);
|
it.second->initTownType(this);
|
||||||
}
|
|
||||||
std::vector<CRmgTemplateZone*> treasureZones;
|
std::vector<CRmgTemplateZone*> treasureZones;
|
||||||
for (auto it : zones)
|
for (auto it : zones)
|
||||||
{
|
{
|
||||||
@ -462,7 +463,7 @@ void CMapGenerator::findZonesForQuestArts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMapGenerator::createConnections()
|
void CMapGenerator::createDirectConnections()
|
||||||
{
|
{
|
||||||
for (auto connection : mapGenOptions->getMapTemplate()->getConnections())
|
for (auto connection : mapGenOptions->getMapTemplate()->getConnections())
|
||||||
{
|
{
|
||||||
@ -531,15 +532,38 @@ void CMapGenerator::createConnections()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //create subterranean gates between two zones
|
|
||||||
|
if (!guardPos.valid())
|
||||||
|
connectionsLeft.push_back(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMapGenerator::createConnections2()
|
||||||
|
{
|
||||||
|
for (auto & connection : connectionsLeft)
|
||||||
|
{
|
||||||
|
auto zoneA = connection.getZoneA();
|
||||||
|
auto zoneB = connection.getZoneB();
|
||||||
|
|
||||||
|
auto tileSetA = zoneA->getPossibleTiles(),
|
||||||
|
tileSetB = zoneB->getPossibleTiles();
|
||||||
|
|
||||||
|
std::vector<int3> tilesA(tileSetA.begin(), tileSetA.end()),
|
||||||
|
tilesB(tileSetB.begin(), tileSetB.end());
|
||||||
|
|
||||||
|
int3 guardPos(-1, -1, -1);
|
||||||
|
|
||||||
|
int3 posA = zoneA->getPos();
|
||||||
|
int3 posB = zoneB->getPos();
|
||||||
|
auto zoneAid = zoneA->getId();
|
||||||
|
auto zoneBid = zoneB->getId();
|
||||||
|
|
||||||
|
if (posA.z != posB.z) //try to place subterranean gates
|
||||||
{
|
{
|
||||||
//find common tiles for both zones
|
//find common tiles for both zones
|
||||||
|
|
||||||
std::vector<int3> commonTiles;
|
std::vector<int3> commonTiles;
|
||||||
auto tileSetA = zoneA->getTileInfo(),
|
|
||||||
tileSetB = zoneB->getTileInfo();
|
|
||||||
std::vector<int3> tilesA (tileSetA.begin(), tileSetA.end()),
|
|
||||||
tilesB (tileSetB.begin(), tileSetB.end());
|
|
||||||
boost::sort(tilesA),
|
boost::sort(tilesA),
|
||||||
boost::sort(tilesB);
|
boost::sort(tilesB);
|
||||||
|
|
||||||
@ -576,21 +600,20 @@ void CMapGenerator::createConnections()
|
|||||||
{
|
{
|
||||||
bool withinZone = true;
|
bool withinZone = true;
|
||||||
|
|
||||||
foreach_neighbour (tile, [&withinZone, &tiles, zoneAid, this](int3 &pos)
|
foreach_neighbour(tile, [&withinZone, zoneAid, this](int3 &pos)
|
||||||
{
|
{
|
||||||
if (getZoneID(pos) != zoneAid)
|
if (getZoneID(pos) != zoneAid)
|
||||||
withinZone = false;
|
withinZone = false;
|
||||||
});
|
});
|
||||||
foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles, zoneBid, this](int3 &pos)
|
foreach_neighbour(otherTile, [&withinZone, zoneBid, this](int3 &pos)
|
||||||
{
|
{
|
||||||
if (getZoneID(pos) != zoneBid)
|
if (getZoneID(pos) != zoneBid)
|
||||||
withinZone = false;
|
withinZone = false;
|
||||||
});
|
});
|
||||||
|
if (withinZone)
|
||||||
|
{
|
||||||
//make sure both gates has some free tiles below them
|
//make sure both gates has some free tiles below them
|
||||||
if (zoneA->getAccessibleOffset(this, sgt, tile).valid() && zoneB->getAccessibleOffset(this, sgt, otherTile).valid())
|
if (zoneA->getAccessibleOffset(this, sgt, tile).valid() && zoneB->getAccessibleOffset(this, sgt, otherTile).valid())
|
||||||
{
|
|
||||||
if (withinZone)
|
|
||||||
{
|
{
|
||||||
zoneA->placeSubterraneanGate(this, tile, connection.getGuardStrength());
|
zoneA->placeSubterraneanGate(this, tile, connection.getGuardStrength());
|
||||||
zoneB->placeSubterraneanGate(this, otherTile, connection.getGuardStrength());
|
zoneB->placeSubterraneanGate(this, otherTile, connection.getGuardStrength());
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "CMapGenOptions.h"
|
#include "CMapGenOptions.h"
|
||||||
#include "CRmgTemplateZone.h"
|
#include "CRmgTemplateZone.h"
|
||||||
#include "../int3.h"
|
#include "../int3.h"
|
||||||
|
#include "CRmgTemplate.h" //for CRmgTemplateZoneConnection
|
||||||
|
|
||||||
class CMap;
|
class CMap;
|
||||||
class CRmgTemplate;
|
class CRmgTemplate;
|
||||||
@ -63,7 +64,8 @@ public:
|
|||||||
CMapEditManager * editManager;
|
CMapEditManager * editManager;
|
||||||
|
|
||||||
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> getZones() const;
|
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> getZones() const;
|
||||||
void createConnections();
|
void createDirectConnections();
|
||||||
|
void createConnections2();
|
||||||
void findZonesForQuestArts();
|
void findZonesForQuestArts();
|
||||||
void foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
void foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
||||||
void foreachDirectNeighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
void foreachDirectNeighbour(const int3 &pos, std::function<void(int3& pos)> foo);
|
||||||
@ -98,6 +100,7 @@ public:
|
|||||||
void setZoneID(const int3& tile, TRmgTemplateZoneId zid);
|
void setZoneID(const int3& tile, TRmgTemplateZoneId zid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::list<CRmgTemplateZoneConnection> connectionsLeft;
|
||||||
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
|
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
|
||||||
std::map<TFaction, ui32> zonesPerFaction;
|
std::map<TFaction, ui32> zonesPerFaction;
|
||||||
ui32 zonesTotal; //zones that have their main town only
|
ui32 zonesTotal; //zones that have their main town only
|
||||||
|
@ -392,6 +392,10 @@ std::set<int3> CRmgTemplateZone::getTileInfo () const
|
|||||||
{
|
{
|
||||||
return tileinfo;
|
return tileinfo;
|
||||||
}
|
}
|
||||||
|
std::set<int3> CRmgTemplateZone::getPossibleTiles() const
|
||||||
|
{
|
||||||
|
return possibleTiles;
|
||||||
|
}
|
||||||
|
|
||||||
void CRmgTemplateZone::discardDistantTiles (CMapGenerator* gen, float distance)
|
void CRmgTemplateZone::discardDistantTiles (CMapGenerator* gen, float distance)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@ class CTileInfo;
|
|||||||
class int3;
|
class int3;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class ObjectTemplate;
|
class ObjectTemplate;
|
||||||
|
class CRmgTemplateZoneConnection;
|
||||||
|
|
||||||
namespace ETemplateZoneType
|
namespace ETemplateZoneType
|
||||||
{
|
{
|
||||||
@ -162,6 +163,7 @@ public:
|
|||||||
void addTile (const int3 &pos);
|
void addTile (const int3 &pos);
|
||||||
void initFreeTiles (CMapGenerator* gen);
|
void initFreeTiles (CMapGenerator* gen);
|
||||||
std::set<int3> getTileInfo() const;
|
std::set<int3> getTileInfo() const;
|
||||||
|
std::set<int3> getPossibleTiles() const;
|
||||||
void discardDistantTiles (CMapGenerator* gen, float distance);
|
void discardDistantTiles (CMapGenerator* gen, float distance);
|
||||||
void clearTiles();
|
void clearTiles();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user