| 366 | |
| 367 | |
| 368 | bool cPieceGenerator::TryPlacePieceAtConnector( |
| 369 | const cPlacedPiece & a_ParentPiece, |
| 370 | const cPiece::cConnector & a_Connector, |
| 371 | cPlacedPieces & a_OutPieces, |
| 372 | cPieceGenerator::cFreeConnectors & a_OutConnectors |
| 373 | ) |
| 374 | { |
| 375 | // Translation of direction - direction -> number of CCW rotations needed: |
| 376 | // You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite) |
| 377 | static const int DirectionRotationTable[6][6] = |
| 378 | { |
| 379 | /* YM, YP, ZM, ZP, XM, XP */ |
| 380 | /* YM */ { 0, 0, 0, 0, 0, 0}, |
| 381 | /* YP */ { 0, 0, 0, 0, 0, 0}, |
| 382 | /* ZM */ { 0, 0, 2, 0, 1, 3}, |
| 383 | /* ZP */ { 0, 0, 0, 2, 3, 1}, |
| 384 | /* XM */ { 0, 0, 3, 1, 2, 0}, |
| 385 | /* XP */ { 0, 0, 1, 3, 0, 2}, |
| 386 | }; |
| 387 | |
| 388 | // Get a list of available connections: |
| 389 | const int * RotTable = DirectionRotationTable[a_Connector.m_Direction]; |
| 390 | cConnections Connections; |
| 391 | cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type); |
| 392 | Connections.reserve(AvailablePieces.size()); |
| 393 | Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector |
| 394 | AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction); |
| 395 | |
| 396 | /* |
| 397 | // DEBUG: |
| 398 | printf("Placing piece at connector pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str()); |
| 399 | //*/ |
| 400 | |
| 401 | for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) |
| 402 | { |
| 403 | cPiece::cConnectors Connectors = (*itrP)->GetConnectors(); |
| 404 | for (cPiece::cConnectors::iterator itrC = Connectors.begin(), endC = Connectors.end(); itrC != endC; ++itrC) |
| 405 | { |
| 406 | if (itrC->m_Type != a_Connector.m_Type) |
| 407 | { |
| 408 | continue; |
| 409 | } |
| 410 | // This is a same-type connector, find out how to rotate to it: |
| 411 | int NumCCWRotations = RotTable[itrC->m_Direction]; |
| 412 | if (!(*itrP)->CanRotateCCW(NumCCWRotations)) |
| 413 | { |
| 414 | // Doesn't support this rotation |
| 415 | continue; |
| 416 | } |
| 417 | if (!CheckConnection(a_Connector, ConnPos, **itrP, *itrC, NumCCWRotations, a_OutPieces)) |
| 418 | { |
| 419 | // Doesn't fit in this rotation |
| 420 | continue; |
| 421 | } |
| 422 | Connections.push_back(cConnection(**itrP, *itrC, NumCCWRotations)); |
| 423 | } // for itrC - Connectors[] |
| 424 | } // for itrP - AvailablePieces[] |
| 425 | if (Connections.empty()) |
nothing calls this directly
no test coverage detected