summaryrefslogtreecommitdiffstats
path: root/src/Generating/PrefabStructure.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-12-03 13:07:23 +0100
committerMattes D <github@xoft.cz>2015-12-03 13:07:23 +0100
commit3fb356648453169758a9f5649f0ed4c5925d911f (patch)
tree57c90ff51aaeac4b1c2e05538a9f486da0a19f28 /src/Generating/PrefabStructure.cpp
parentMerge pull request #2696 from Gargaj/breeding (diff)
parentChanged Nether defaults to use PieceStructures. (diff)
downloadcuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar.gz
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar.bz2
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar.lz
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar.xz
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.tar.zst
cuberite-3fb356648453169758a9f5649f0ed4c5925d911f.zip
Diffstat (limited to 'src/Generating/PrefabStructure.cpp')
-rw-r--r--src/Generating/PrefabStructure.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/Generating/PrefabStructure.cpp b/src/Generating/PrefabStructure.cpp
new file mode 100644
index 000000000..3ebbe8143
--- /dev/null
+++ b/src/Generating/PrefabStructure.cpp
@@ -0,0 +1,74 @@
+
+// PrefabStructure.cpp
+
+// Implements the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab instances
+
+#include "Globals.h"
+#include "PrefabStructure.h"
+#include "Prefab.h"
+
+
+
+
+
+cPrefabStructure::cPrefabStructure(
+ int a_GridX, int a_GridZ,
+ int a_OriginX, int a_OriginZ,
+ cPlacedPieces & a_Pieces,
+ cTerrainHeightGenPtr a_HeightGen
+):
+ Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
+ m_Pieces(a_Pieces),
+ m_HeightGen(a_HeightGen)
+{
+}
+
+
+
+
+
+cPrefabStructure::~cPrefabStructure()
+{
+ cPieceGenerator::FreePieces(m_Pieces);
+}
+
+
+
+
+
+void cPrefabStructure::DrawIntoChunk(cChunkDesc & a_Chunk)
+{
+ // Iterate over all items
+ // Each intersecting prefab is placed on ground, if requested, then drawn
+ for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
+ {
+ const cPrefab & Prefab = static_cast<const cPrefab &>((*itr)->GetPiece());
+ if (Prefab.ShouldMoveToGround() && !(*itr)->HasBeenMovedToGround())
+ {
+ PlacePieceOnGround(**itr);
+ }
+ Prefab.Draw(a_Chunk, *itr);
+ } // for itr - m_PlacedPieces[]
+}
+
+
+
+
+
+void cPrefabStructure::PlacePieceOnGround(cPlacedPiece & a_Piece)
+{
+ cPiece::cConnector FirstConnector = a_Piece.GetRotatedConnector(0);
+ int ChunkX, ChunkZ;
+ int BlockX = FirstConnector.m_Pos.x;
+ int BlockZ = FirstConnector.m_Pos.z;
+ int BlockY;
+ cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
+ cChunkDef::HeightMap HeightMap;
+ m_HeightGen->GenHeightMap(ChunkX, ChunkZ, HeightMap);
+ int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
+ a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
+}
+
+
+
+