| 325 | |
| 326 | |
| 327 | cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors) |
| 328 | { |
| 329 | m_PiecePool.Reset(); |
| 330 | int rnd = m_Noise.IntNoise3DInt(a_BlockX, a_BlockY, a_BlockZ) / 7; |
| 331 | |
| 332 | // Choose a random one of the starting pieces: |
| 333 | cPieces StartingPieces = m_PiecePool.GetStartingPieces(); |
| 334 | cPiece * StartingPiece = StartingPieces[rnd % StartingPieces.size()]; |
| 335 | rnd = rnd >> 16; |
| 336 | |
| 337 | // Choose a random supported rotation: |
| 338 | int Rotations[4] = {0}; |
| 339 | int NumRotations = 1; |
| 340 | for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++) |
| 341 | { |
| 342 | if (StartingPiece->CanRotateCCW(i)) |
| 343 | { |
| 344 | Rotations[NumRotations] = i; |
| 345 | NumRotations += 1; |
| 346 | } |
| 347 | } |
| 348 | int Rotation = Rotations[rnd % NumRotations]; |
| 349 | |
| 350 | cPlacedPiece * res = new cPlacedPiece(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation); |
| 351 | |
| 352 | // Place the piece's connectors into a_OutConnectors: |
| 353 | const cPiece::cConnectors & Conn = StartingPiece->GetConnectors(); |
| 354 | for (cPiece::cConnectors::const_iterator itr = Conn.begin(), end = Conn.end(); itr != end; ++itr) |
| 355 | { |
| 356 | a_OutConnectors.push_back( |
| 357 | cFreeConnector(res, StartingPiece->RotateMoveConnector(*itr, Rotation, a_BlockX, a_BlockY, a_BlockZ)) |
| 358 | ); |
| 359 | } |
| 360 | |
| 361 | return res; |
| 362 | } |
| 363 | |
| 364 | |
| 365 |
nothing calls this directly
no test coverage detected