2015-11-11 04:32:42 -05:00
|
|
|
|
|
|
|
// 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,
|
2017-02-26 16:49:23 -05:00
|
|
|
cPlacedPieces && a_Pieces,
|
2021-03-08 11:39:43 -05:00
|
|
|
cTerrainHeightGen & a_HeightGen
|
2015-11-11 04:32:42 -05:00
|
|
|
):
|
|
|
|
Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
|
2017-02-26 16:49:23 -05:00
|
|
|
m_Pieces(std::move(a_Pieces)),
|
2021-03-08 11:39:43 -05:00
|
|
|
m_HeightGen(a_HeightGen)
|
2015-11-11 04:32:42 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2017-02-26 16:49:23 -05:00
|
|
|
Prefab.Draw(a_Chunk, itr->get());
|
2015-11-11 04:32:42 -05:00
|
|
|
} // 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;
|
2021-03-08 11:39:43 -05:00
|
|
|
m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap);
|
2015-11-11 04:32:42 -05:00
|
|
|
int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
|
|
|
|
a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
|
|
|
|
}
|