summaryrefslogtreecommitdiffstats
path: root/src/Generating/PieceGenerator.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-05-27 22:05:50 +0200
committermadmaxoft <github@xoft.cz>2014-05-27 22:05:50 +0200
commitff99373237178e9f7da02f51581f9a83d0e624d9 (patch)
treee5214df93dfbeb166d8b65ccb094175285c0068b /src/Generating/PieceGenerator.cpp
parentBiome generators: biome lists can contain spaces. (diff)
downloadcuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar.gz
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar.bz2
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar.lz
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar.xz
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.tar.zst
cuberite-ff99373237178e9f7da02f51581f9a83d0e624d9.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/PieceGenerator.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index 1880a20d5..5de231f75 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -362,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: