File: edoors.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (129 lines) | stat: -rw-r--r-- 3,617 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Descent 3
 * Copyright (C) 2024 Parallax Software
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Edoors.cpp

#ifndef NEWEDITOR
#include "d3edit.h"
#else
#include "globals.h"
#define texdlg_texture GetCurrentTexture()
#endif

#include "polymodel.h"
#include "erooms.h"
#include "room.h"
#include "door.h"
#include "hroom.h"

#include "pserror.h"

void PlaceDoor(room *baseroomp, int baseface, int placed_door) {
  poly_model *po = GetPolymodelPointer(GetDoorImage(placed_door));
  int i, t;
  int num_faces = 0, num_verts = 0;
  int got_shell = 0, got_front = 0;
  bsp_info *front_sm, *shell_sm;
  room *rp;
  int front_face_index;
  int front_remap_points[30];

  for (i = 0; i < po->n_models; i++) {
    bsp_info *sm = &po->submodel[i];
    if (sm->flags & SOF_SHELL) {
      got_shell = 1;
      num_verts += sm->nverts;
      num_faces += sm->num_faces;
      shell_sm = &po->submodel[i];
    }
    if (sm->flags & SOF_FRONTFACE) {
      got_front = 1;
      num_verts += sm->nverts;
      num_faces++;
      front_sm = &po->submodel[i];
    }
  }

  if (!got_shell || !got_front) {
    Int3(); // This door is improperly specified in 3dsmax
    return;
  }

  rp = CreateNewRoom(num_verts, num_faces, 1);

  ASSERT(rp != NULL);

  // Create the actual room walls
  int index = 0;
  for (i = 0; i < shell_sm->nverts; i++, index++) {
    rp->verts[index] = shell_sm->verts[i];
  }
  for (i = 0; i < front_sm->nverts; i++, index++) {
    rp->verts[index] = front_sm->verts[i];
  }

  index = 0;

  for (i = 0; i < shell_sm->num_faces; i++, index++) {
    InitRoomFace(&rp->faces[index], shell_sm->faces[i].nverts);

    ASSERT(rp->faces[index].face_verts);
    ASSERT(rp->faces[index].face_uvls);

    rp->faces[index].tmap = D3EditState.texdlg_texture;

    for (t = 0; t < rp->faces[index].num_verts; t++)
      rp->faces[index].face_verts[t] = shell_sm->faces[i].vertnums[t];
  }

  ASSERT(front_sm->num_faces == 1);

  front_face_index = index;
  InitRoomFace(&rp->faces[index], front_sm->faces[0].nverts);
  rp->faces[index].tmap = D3EditState.texdlg_texture;

  // Now find the points on the front face that are the same as the shell
  for (i = 0; i < front_sm->nverts; i++)
    front_remap_points[i] = -1;

  vector diff_vec = front_sm->offset - shell_sm->offset;

  for (i = 0; i < shell_sm->nverts; i++)
    for (t = 0; t < front_sm->nverts; t++) {
      vector testvec = front_sm->verts[t] + diff_vec;

      if ((PointsAreSame(&shell_sm->verts[i], &testvec)))
        front_remap_points[t] = i;
    }

  for (i = 0; i < front_sm->nverts; i++)
    ASSERT(front_remap_points[i] != -1);

  for (t = 0; t < rp->faces[index].num_verts; t++)
    rp->faces[index].face_verts[t] = front_remap_points[front_sm->faces[0].vertnums[t]];

  // Reset some values

  if (!ResetRoomFaceNormals(rp))
    Int3(); // Get Matt

  AssignDefaultUVsToRoom(rp);

  // Now use to the attach room code to actually place this door's room
  PlaceRoom(baseroomp, baseface, rp - Rooms, front_face_index, placed_door);
}