summaryrefslogtreecommitdiffstats
path: root/src/Generating/VillageGen.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-05-25 23:50:16 +0200
committermadmaxoft <github@xoft.cz>2014-05-25 23:50:16 +0200
commit1a742a2b52d32bd22cd57b4d462bee312717e010 (patch)
tree65657eb46ac05e24b101a14f45a9d124212322cd /src/Generating/VillageGen.cpp
parentAdded Japanese village prefabs. (diff)
downloadcuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar.gz
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar.bz2
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar.lz
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar.xz
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.tar.zst
cuberite-1a742a2b52d32bd22cd57b4d462bee312717e010.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/VillageGen.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp
index 62822c33b..cb1f4fe0d 100644
--- a/src/Generating/VillageGen.cpp
+++ b/src/Generating/VillageGen.cpp
@@ -127,10 +127,23 @@ public:
m_HeightGen(a_HeightGen),
m_RoadBlock(a_RoadBlock)
{
+ // Generate the pieces for this village; don't care about the Y coord:
cBFSPieceGenerator pg(*this, a_Seed);
- // Generate the pieces at very negative Y coords, so that we can later test
- // Piece has negative Y coord -> hasn't been height-adjusted yet
- pg.PlacePieces(a_OriginX, -1000, a_OriginZ, a_MaxRoadDepth + 1, m_Pieces);
+ pg.PlacePieces(a_OriginX, 0, a_OriginZ, a_MaxRoadDepth + 1, m_Pieces);
+ if (m_Pieces.empty())
+ {
+ return;
+ }
+
+ // If the central piece should be moved to ground, move it, and
+ // check all of its dependents and move those that are strictly connector-driven based on its new Y coord:
+ if (((cPrefab &)m_Pieces[0]->GetPiece()).ShouldMoveToGround())
+ {
+ int OrigPosY = m_Pieces[0]->GetCoords().y;
+ PlacePieceOnGround(*m_Pieces[0]);
+ int NewPosY = m_Pieces[0]->GetCoords().y;
+ MoveAllDescendants(m_Pieces, 0, NewPosY - OrigPosY);
+ }
}
protected:
@@ -179,7 +192,7 @@ protected:
DrawRoad(a_Chunk, **itr, HeightMap);
continue;
}
- if ((*itr)->GetCoords().y < 0)
+ if (Prefab.ShouldMoveToGround() && !(*itr)->HasBeenMovedToGround())
{
PlacePieceOnGround(**itr);
}
@@ -201,7 +214,7 @@ protected:
cChunkDef::HeightMap HeightMap;
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, HeightMap);
int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
- a_Piece.GetCoords().y += TerrainHeight - FirstConnector.m_Pos.y + 1;
+ a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
}
@@ -232,11 +245,13 @@ protected:
return m_Prefabs.GetPiecesWithConnector(a_ConnectorType);
}
+
virtual cPieces GetStartingPieces(void)
{
return m_Prefabs.GetStartingPieces();
}
+
virtual int GetPieceWeight(
const cPlacedPiece & a_PlacedPiece,
const cPiece::cConnector & a_ExistingConnector,
@@ -258,15 +273,35 @@ protected:
return m_Prefabs.GetPieceWeight(a_PlacedPiece, a_ExistingConnector, a_NewPiece);
}
+
virtual void PiecePlaced(const cPiece & a_Piece) override
{
m_Prefabs.PiecePlaced(a_Piece);
}
+
virtual void Reset(void) override
{
m_Prefabs.Reset();
}
+
+
+ void MoveAllDescendants(cPlacedPieces & a_PlacedPieces, size_t a_Pivot, int a_HeightDifference)
+ {
+ size_t num = a_PlacedPieces.size();
+ cPlacedPiece * Pivot = a_PlacedPieces[a_Pivot];
+ for (size_t i = a_Pivot + 1; i < num; i++)
+ {
+ if (
+ (a_PlacedPieces[i]->GetParent() == Pivot) && // It is a direct dependant of the pivot
+ !((const cPrefab &)a_PlacedPieces[i]->GetPiece()).ShouldMoveToGround() // It attaches strictly by connectors
+ )
+ {
+ a_PlacedPieces[i]->MoveToGroundBy(a_HeightDifference);
+ MoveAllDescendants(a_PlacedPieces, i, a_HeightDifference);
+ }
+ } // for i - a_PlacedPieces[]
+ }
} ;