int copy_room(struct room_data *to, struct room_data *from) { free_room_strings(to); *to = *from; copy_room_strings(to, from); /* Don't put people and objects in two locations. Am thinking this shouldn't be done here... */ from->people = NULL; from->contents = NULL; return TRUE; }
/* * This function will copy the strings so be sure you free your own * copies of the description, title, and such. */ room_rnum add_room(struct room_data *room) { struct char_data *tch; struct obj_data *tobj; int i, j, found = FALSE; if (room == NULL) return NOWHERE; if ((i = real_room(room->number)) != NOWHERE) { tch = world[i].people; tobj = world[i].contents; copy_room(&world[i], room); world[i].people = tch; world[i].contents = tobj; add_to_save_list(zone_table[room->zone].number, SL_WLD); log("GenOLC: add_room: Updated existing room #%d.", room->number); return i; } RECREATE(world, struct room_data, top_of_world + 2); top_of_world++; for (i = top_of_world; i > 0; i--) { if (room->number > world[i - 1].number) { world[i] = *room; copy_room_strings(&world[i], room); found = i; break; } else { /* Copy the room over now. */ world[i] = world[i - 1]; /* People in this room must have their in_rooms moved up one. */ for (tch = world[i].people; tch; tch = tch->next_in_room) IN_ROOM(tch) += (IN_ROOM(tch) != NOWHERE); /* Move objects too. */ for (tobj = world[i].contents; tobj; tobj = tobj->next_content) IN_ROOM(tobj) += (IN_ROOM(tobj) != NOWHERE); } } if (!found) { world[0] = *room; /* Last place, in front. */ copy_room_strings(&world[0], room); } log("GenOLC: add_room: Added room %d at index #%d.", room->number, found); /* found is equal to the array index where we added the room. */ /* * Find what zone that room was in so we can update the loading table. */ for (i = room->zone; i <= top_of_zone_table; i++) for (j = 0; ZCMD(i, j).command != 'S'; j++) switch (ZCMD(i, j).command) { case 'M': case 'O': case 'T': case 'V': ZCMD(i, j).arg3 += (ZCMD(i, j).arg3 >= found); break; case 'D': case 'R': ZCMD(i, j).arg1 += (ZCMD(i, j).arg1 >= found); case 'G': case 'P': case 'E': case '*': /* Known zone entries we don't care about. */ break; default: mudlog(BRF, LVL_DEITY, TRUE, "SYSERR: GenOLC: add_room: Unknown zone entry found!"); } /* * Update the loadroom table. Adds 1 or 0. */ r_mortal_start_room += (r_mortal_start_room >= found); r_immort_start_room += (r_immort_start_room >= found); r_frozen_start_room += (r_frozen_start_room >= found); r_newbie_start_room += (r_newbie_start_room >= found); r_sorin_start_room += (r_sorin_start_room >= found); /* * Update world exits & triggers. */ for (i = top_of_world; i >= 0; i--) { /* exits */ for (j = 0; j < NUM_OF_DIRS; j++) if (W_EXIT(i, j)) W_EXIT(i, j)->to_room += (W_EXIT(i, j)->to_room >= found); /* TRIGGERS */ if(SCRIPT(&world[i])) { extract_script(SCRIPT(&world[i])); SCRIPT(&world[i]) = NULL; } assign_triggers(&world[i], WLD_TRIGGER); } add_to_save_list(zone_table[room->zone].number, SL_WLD); /* * Return what array entry we placed the new room in. */ return found; }
int save_rooms(zone_rnum zone_num) { int i; struct room_data *room; FILE *sf; char filename[128]; char buf[MAX_STRING_LENGTH], buf1[MAX_STRING_LENGTH]; char rbuf1[MAX_STRING_LENGTH], rbuf2[MAX_STRING_LENGTH]; char rbuf3[MAX_STRING_LENGTH], rbuf4[MAX_STRING_LENGTH]; #if CIRCLE_UNSIGNED_INDEX if (zone_num == NOWHERE || zone_num > top_of_zone_table) { #else if (zone_num < 0 || zone_num > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_rooms: Invalid zone number %d passed! (0-%d)", zone_num, top_of_zone_table); return FALSE; } log("GenOLC: save_rooms: Saving rooms in zone #%d (%d-%d).", zone_table[zone_num].number, genolc_zone_bottom(zone_num), zone_table[zone_num].top); snprintf(filename, sizeof(filename), "%s%d.new", WLD_PREFIX, zone_table[zone_num].number); if (!(sf = fopen(filename, "w"))) { perror("SYSERR: save_rooms"); return FALSE; } for (i = genolc_zone_bottom(zone_num); i <= zone_table[zone_num].top; i++) { room_rnum rnum; if ((rnum = real_room(i)) != NOWHERE) { int j; room = (world + rnum); /* * Copy the description and strip off trailing newlines. */ strncpy(buf, room->description ? room->description : "Empty room.", sizeof(buf)-1 ); strip_cr(buf); /* * Save the numeric and string section of the file. */ sprintascii(rbuf1, room->room_flags[0]); sprintascii(rbuf2, room->room_flags[1]); sprintascii(rbuf3, room->room_flags[2]); sprintascii(rbuf4, room->room_flags[3]); fprintf(sf, "#%d\n" "%s%c\n" "%s%c\n" "%d %s %s %s %s %d\n", room->number, room->name ? room->name : "Untitled", STRING_TERMINATOR, buf, STRING_TERMINATOR, zone_table[room->zone].number, rbuf1, rbuf2, rbuf3, rbuf4, room->sector_type ); /* * Now you write out the exits for the room. */ for (j = 0; j < NUM_OF_DIRS; j++) { if (R_EXIT(room, j)) { int dflag; if (R_EXIT(room, j)->general_description) { strncpy(buf, R_EXIT(room, j)->general_description, sizeof(buf)-1); strip_cr(buf); } else *buf = '\0'; /* * Figure out door flag. */ if (IS_SET(R_EXIT(room, j)->exit_info, EX_ISDOOR)) { if (IS_SET(R_EXIT(room, j)->exit_info, EX_SECRET) && IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 4; else if (IS_SET(R_EXIT(room, j)->exit_info, EX_SECRET)) dflag = 3; else if (IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 2; else dflag = 1; } else dflag = 0; if (R_EXIT(room, j)->keyword) strncpy(buf1, R_EXIT(room, j)->keyword, sizeof(buf1)-1 ); else *buf1 = '\0'; /* * Now write the exit to the file. */ fprintf(sf, "D%d\n" "%s~\n" "%s~\n" "%d %d %d\n", j, buf, buf1, dflag, R_EXIT(room, j)->key != NOTHING ? R_EXIT(room, j)->key : -1, R_EXIT(room, j)->to_room != NOWHERE ? world[R_EXIT(room, j)->to_room].number : -1); } } if (room->ex_description) { struct extra_descr_data *xdesc; for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) { strncpy(buf, xdesc->description, sizeof(buf)); strip_cr(buf); fprintf(sf, "E\n" "%s~\n" "%s~\n", xdesc->keyword, buf); } } fprintf(sf, "S\n"); script_save_to_disk(sf, room, WLD_TRIGGER); } } /* * Write the final line and close it. */ fprintf(sf, "$~\n"); fclose(sf); /* Old file we're replacing. */ snprintf(buf, sizeof(buf), "%s%d.wld", WLD_PREFIX, zone_table[zone_num].number); remove(buf); rename(filename, buf); if (in_save_list(zone_table[zone_num].number, SL_WLD)) { remove_from_save_list(zone_table[zone_num].number, SL_WLD); create_world_index(zone_table[zone_num].number, "wld"); log("GenOLC: save_rooms: Saving rooms '%s'", buf); } return TRUE; } int copy_room(struct room_data *to, struct room_data *from) { free_room_strings(to); *to = *from; copy_room_strings(to, from); /* Don't put people and objects in two locations. Am thinking this shouldn't be done here... */ from->people = NULL; from->contents = NULL; return TRUE; }