diff options
author | madmaxoft <github@xoft.cz> | 2014-06-14 12:06:48 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-06-14 12:06:48 +0200 |
commit | f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b (patch) | |
tree | d2f3e35f37821e93d92143db2055bcedeaf57142 /src/Generating/PieceGenerator.cpp | |
parent | Player.h: Moved doxy-comments to Entity.h (diff) | |
parent | Fixed a repeater issue (diff) | |
download | cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar.gz cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar.bz2 cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar.lz cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar.xz cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.tar.zst cuberite-f8f7748a09b936cc888c0c4a1f0ae9e9e444ba5b.zip |
Diffstat (limited to 'src/Generating/PieceGenerator.cpp')
-rw-r--r-- | src/Generating/PieceGenerator.cpp | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index ce19c1c95..5de231f75 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -286,7 +286,8 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece m_Parent(a_Parent), m_Piece(&a_Piece), m_Coords(a_Coords), - m_NumCCWRotations(a_NumCCWRotations) + m_NumCCWRotations(a_NumCCWRotations), + m_HasBeenMovedToGround(false) { m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1); m_HitBox = a_Piece.RotateMoveHitBox(a_NumCCWRotations, a_Coords.x, a_Coords.y, a_Coords.z); @@ -297,6 +298,36 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece +cPiece::cConnector cPlacedPiece::GetRotatedConnector(size_t a_Index) const +{ + cPiece::cConnectors Connectors = m_Piece->GetConnectors(); + ASSERT(Connectors.size() >= a_Index); + return m_Piece->RotateMoveConnector(Connectors[a_Index], m_NumCCWRotations, m_Coords.x, m_Coords.y, m_Coords.z); +} + + + + + +cPiece::cConnector cPlacedPiece::GetRotatedConnector(const cPiece::cConnector & a_Connector) const +{ + return m_Piece->RotateMoveConnector(a_Connector, m_NumCCWRotations, m_Coords.x, m_Coords.y, m_Coords.z); +} + + + + + +void cPlacedPiece::MoveToGroundBy(int a_OffsetY) +{ + m_Coords.y += a_OffsetY; + m_HasBeenMovedToGround = true; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPieceGenerator: @@ -331,7 +362,31 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i // Choose a random one of the starting pieces: cPieces StartingPieces = m_PiecePool.GetStartingPieces(); - cPiece * StartingPiece = StartingPieces[rnd % StartingPieces.size()]; + int Total = 0; + for (cPieces::const_iterator itr = StartingPieces.begin(), end = StartingPieces.end(); itr != end; ++itr) + { + Total += m_PiecePool.GetStartingPieceWeight(**itr); + } + cPiece * StartingPiece; + if (Total > 0) + { + int Chosen = rnd % Total; + StartingPiece = StartingPieces.front(); + for (cPieces::const_iterator itr = StartingPieces.begin(), end = StartingPieces.end(); itr != end; ++itr) + { + Chosen -= m_PiecePool.GetStartingPieceWeight(**itr); + if (Chosen <= 0) + { + StartingPiece = *itr; + break; + } + } + } + else + { + // All pieces returned zero weight, but we need one to start. Choose with equal chance: + StartingPiece = StartingPieces[rnd % StartingPieces.size()]; + } rnd = rnd >> 16; // Choose a random supported rotation: |