Attach the already-placed group
| 464 | |
| 465 | // Attach the already-placed group |
| 466 | void AttachGroup() { |
| 467 | vector basecenter, attcenter; |
| 468 | room *baseroomp, *attroomp; |
| 469 | int baseface, attface; |
| 470 | int room_xlate[MAX_ROOMS]; |
| 471 | int r; |
| 472 | |
| 473 | ASSERT(Placed_group != NULL); |
| 474 | |
| 475 | // Set some vars |
| 476 | baseroomp = Placed_baseroomp; |
| 477 | baseface = Placed_baseface; |
| 478 | attroomp = &Placed_group->rooms[Placed_group->attachroom]; |
| 479 | attface = Placed_group->attachface; |
| 480 | attcenter = Placed_room_origin; |
| 481 | basecenter = Placed_room_attachpoint; |
| 482 | |
| 483 | // Copy the rooms into the main room list, build the xlate table, and rotate the verts |
| 484 | for (r = 0; r < Placed_group->nrooms; r++) { |
| 485 | int roomnum; |
| 486 | room *newroomp; |
| 487 | |
| 488 | // Get a new room & copy into it |
| 489 | roomnum = GetFreeRoom(0); |
| 490 | if (roomnum == -1) { |
| 491 | OutrageMessageBox("Cannot attach group: Not enough free rooms."); |
| 492 | for (int t = 0; t < r; t++) // delete the rooms we just created |
| 493 | DeleteRoomFromMine(&Rooms[room_xlate[t]]); |
| 494 | return; |
| 495 | } |
| 496 | newroomp = &Rooms[roomnum]; |
| 497 | CopyRoom(newroomp, &Placed_group->rooms[r]); |
| 498 | room_xlate[r] = roomnum; |
| 499 | |
| 500 | // Rotate verts in the new rooms |
| 501 | for (int i = 0; i < newroomp->num_verts; i++) |
| 502 | newroomp->verts[i] = ((newroomp->verts[i] - attcenter) * Placed_room_rotmat) + basecenter; |
| 503 | |
| 504 | // Recompute normals for the faces |
| 505 | if (!ResetRoomFaceNormals(newroomp)) |
| 506 | Int3(); // Get Matt |
| 507 | } |
| 508 | |
| 509 | // Add portals for new rooms |
| 510 | for (r = 0; r < Placed_group->nrooms; r++) |
| 511 | for (int p = 0; p < Placed_group->rooms[r].num_portals; p++) { |
| 512 | portal *pp = &Placed_group->rooms[r].portals[p]; |
| 513 | if (r < pp->croom) // only link lower to higher, so we don't double link |
| 514 | LinkRoomsSimple(Rooms, room_xlate[r], pp->portal_face, room_xlate[pp->croom], |
| 515 | Placed_group->rooms[pp->croom].portals[pp->cportal].portal_face); |
| 516 | |
| 517 | // Copy the portal flags |
| 518 | int new_portal_num = Rooms[room_xlate[r]].faces[pp->portal_face].portal_num; |
| 519 | Rooms[room_xlate[r]].portals[new_portal_num].flags = pp->flags; |
| 520 | } |
| 521 | |
| 522 | // Get pointer to the placed attachroom |
| 523 | room *newroomp = &Rooms[room_xlate[Placed_group->attachroom]]; |
no test coverage detected