MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CopyGroup

Function CopyGroup

editor/Group.cpp:238–359  ·  view source on GitHub ↗

Copy the given list of rooms to a group Parameters: nrooms - the number of rooms in list roomnums - pointer to list of room numbers attachroom, attachface - where group attaches when pasted Returns: pointer to group

Source from the content-addressed store, hash-verified

236// attachroom, attachface - where group attaches when pasted
237// Returns: pointer to group
238group *CopyGroup(int nrooms, int *roomnums, int attachroom, int attachface) {
239 group *g;
240 int r;
241 int room_xlate[MAX_ROOMS];
242 int n_objects = 0, n_triggers = 0, n_doors = 0;
243
244 // Allocate group & room arrays
245 g = (group *)mem_malloc(sizeof(*g));
246 ASSERT(g != NULL);
247 g->nrooms = nrooms;
248 g->rooms = (room *)mem_malloc(sizeof(*g->rooms) * nrooms);
249 ASSERT(g->rooms != NULL);
250
251 // Initialize xlate list
252 for (r = 0; r < MAX_ROOMS; r++)
253 room_xlate[r] = -1;
254
255 // Copy the rooms & build xlate list. Count objects while we're at it
256 for (r = 0; r < nrooms; r++) {
257
258 CopyRoom(&g->rooms[r], &Rooms[roomnums[r]]);
259 room_xlate[roomnums[r]] = r;
260
261 for (int o = Rooms[roomnums[r]].objects; o != -1; o = Objects[o].next)
262 if ((Objects[o].type != OBJ_VIEWER) && (Objects[o].type != OBJ_CAMERA) && (Objects[o].type != OBJ_PLAYER)) {
263 n_objects++;
264 if (Objects[o].type == OBJ_DOOR)
265 n_doors++;
266 }
267 }
268
269 // Add portals for rooms in the group
270 for (r = 0; r < nrooms; r++)
271 for (int p = 0; p < Rooms[roomnums[r]].num_portals; p++) {
272 portal *pp = &Rooms[roomnums[r]].portals[p];
273 if ((pp->croom != -1) && IsRoomSelected(pp->croom)) {
274
275 // link the two rooms
276 if (r < room_xlate[pp->croom]) // only link lower to higher, so we don't double link
277 LinkRoomsSimple(g->rooms, r, pp->portal_face, room_xlate[pp->croom],
278 Rooms[pp->croom].portals[pp->cportal].portal_face);
279
280 // Copy the portal flags
281 int new_portal_num = g->rooms[r].faces[pp->portal_face].portal_num;
282 g->rooms[r].portals[new_portal_num].flags = pp->flags;
283 }
284 }
285
286 // Fill in attach fields
287 g->attachroom = room_xlate[attachroom];
288 g->attachface = attachface;
289
290 // Copy objects
291 g->nobjects = n_objects;
292 g->ndoors = n_doors;
293 if (n_objects == 0)
294 g->objects = NULL;
295 else {

Callers 1

CopySelectedRoomsFunction · 0.85

Calls 2

CopyRoomFunction · 0.85
IsRoomSelectedFunction · 0.85

Tested by

no test coverage detected