Combine the two rooms. base_rp stays, att_rp goes away Returns true if combine sucessful, false if can't join
| 2715 | // Combine the two rooms. base_rp stays, att_rp goes away |
| 2716 | // Returns true if combine sucessful, false if can't join |
| 2717 | bool CombineRooms(room *base_rp, room *att_rp) { |
| 2718 | int i; |
| 2719 | face *fp; |
| 2720 | bool connected = 0, rendered_portals = 0; |
| 2721 | |
| 2722 | // Make sure these rooms share a portal |
| 2723 | for (i = 0; i < base_rp->num_portals; i++) { |
| 2724 | if (base_rp->portals[i].croom == ROOMNUM(att_rp)) { |
| 2725 | connected = 1; |
| 2726 | if ((base_rp->faces[base_rp->portals[i].portal_face].flags & FF_HAS_TRIGGER) || |
| 2727 | (att_rp->faces[att_rp->portals[base_rp->portals[i].cportal].portal_face].flags & FF_HAS_TRIGGER)) { |
| 2728 | OutrageMessageBox("Cannot combine rooms: a portal connecting them has a trigger."); |
| 2729 | return 0; |
| 2730 | } |
| 2731 | if ((base_rp->portals[i].flags & PF_RENDER_FACES) || |
| 2732 | (att_rp->portals[base_rp->portals[i].cportal].flags & PF_RENDER_FACES)) { |
| 2733 | rendered_portals = 1; |
| 2734 | } |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | if (!connected) { |
| 2739 | OutrageMessageBox("Cannot combine rooms: the rooms are not connected."); |
| 2740 | return 0; |
| 2741 | } |
| 2742 | |
| 2743 | if (rendered_portals) { |
| 2744 | if (OutrageMessageBox( |
| 2745 | MBOX_YESNO, |
| 2746 | "One or more of the portals connecting these rooms has the Render Faces flag set. " |
| 2747 | "The rendered face will remain in the room after combine.\n\nDo you still want to combine?") != IDYES) |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | // Check for doors |
| 2752 | if (base_rp->doorway_data || att_rp->doorway_data) { |
| 2753 | OutrageMessageBox("Cannot combine rooms: one room is a door."); |
| 2754 | return 0; |
| 2755 | } |
| 2756 | |
| 2757 | // Allocate new verts & faces |
| 2758 | int first_new_vert = RoomAddVertices(base_rp, att_rp->num_verts); |
| 2759 | int first_new_face = RoomAddFaces(base_rp, att_rp->num_faces); |
| 2760 | |
| 2761 | // Copy verts to base room |
| 2762 | for (i = 0; i < att_rp->num_verts; i++) |
| 2763 | base_rp->verts[first_new_vert + i] = att_rp->verts[i]; |
| 2764 | |
| 2765 | // Copy faces to base room |
| 2766 | for (i = 0, fp = &base_rp->faces[first_new_face]; i < att_rp->num_faces; fp++, i++) { |
| 2767 | |
| 2768 | // Copy the face |
| 2769 | CopyFace(fp, &att_rp->faces[i]); |
| 2770 | fp->flags = att_rp->faces[i].flags; |
| 2771 | |
| 2772 | // Update the vertices |
| 2773 | for (int v = 0; v < fp->num_verts; v++) |
| 2774 | fp->face_verts[v] += first_new_vert; |
no test coverage detected