Attach an already-placed room
| 699 | |
| 700 | // Attach an already-placed room |
| 701 | void AttachRoom() { |
| 702 | vector basecenter, attcenter; |
| 703 | room *baseroomp, *attroomp, *newroomp; |
| 704 | int baseface, attface; |
| 705 | |
| 706 | ASSERT(Placed_room != -1); |
| 707 | |
| 708 | // Set some vars |
| 709 | baseroomp = Placed_baseroomp; |
| 710 | baseface = Placed_baseface; |
| 711 | attroomp = &Rooms[Placed_room]; |
| 712 | attface = Placed_room_face; |
| 713 | attcenter = Placed_room_origin; |
| 714 | basecenter = Placed_room_attachpoint; |
| 715 | |
| 716 | // Get the new room |
| 717 | newroomp = CreateNewRoom(attroomp->num_verts, attroomp->num_faces, 0); |
| 718 | if (newroomp == NULL) { |
| 719 | OutrageMessageBox("Cannot attach room: No free rooms."); |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | // Rotate verts, copying into new room |
| 724 | for (int i = 0; i < attroomp->num_verts; i++) |
| 725 | newroomp->verts[i] = ((attroomp->verts[i] - attcenter) * Placed_room_rotmat) + basecenter; |
| 726 | |
| 727 | // Copy faces to new room |
| 728 | for (i = 0; i < attroomp->num_faces; i++) { |
| 729 | CopyFace(&newroomp->faces[i], &attroomp->faces[i]); |
| 730 | #ifdef NEWEDITOR |
| 731 | LevelTexIncrementTexture(attroomp->faces[i].tmap); |
| 732 | #endif |
| 733 | } |
| 734 | |
| 735 | // Recompute normals for the faces |
| 736 | if (!ResetRoomFaceNormals(newroomp)) |
| 737 | Int3(); // Get Matt |
| 738 | |
| 739 | // Copy other values for this room |
| 740 | newroomp->flags = attroomp->flags; |
| 741 | newroomp->num_portals = 0; |
| 742 | |
| 743 | // Check for terrain or mine room |
| 744 | if (baseroomp == NULL) { // a terrain room |
| 745 | |
| 746 | // Flag this as an external room |
| 747 | newroomp->flags |= RF_EXTERNAL; |
| 748 | |
| 749 | // Delete the attach face, which should now be facing the ground |
| 750 | DeleteRoomFace(newroomp, attface); |
| 751 | } else { // a mine room |
| 752 | |
| 753 | // Clip the connecting faces against each other |
| 754 | if (!ClipFacePair(newroomp, attface, baseroomp, baseface)) { |
| 755 | OutrageMessageBox("Error making portal -- faces probably don't overlap."); |
| 756 | FreeRoom(newroomp); |
| 757 | return; |
| 758 | } |
no test coverage detected