/* * Copy strings over so bad things don't happen. We do not free the * existing strings here because copy_room() did a shallow copy previously * and we'd be freeing the very strings we're copying. If this function * is used elsewhere, be sure to free_room_strings() the 'dest' room first. */ int copy_room_strings(struct room_data *dest, struct room_data *source) { int i; if (dest == NULL || source == NULL) { log("SYSERR: GenOLC: copy_room_strings: NULL values passed."); return FALSE; } dest->description = strdup(source->description ? source->description : "<NULL>"); dest->name = strdup(source->name ? source->name : "<NULL>"); for (i = 0; i < NUM_OF_DIRS; i++) { if (!R_EXIT(source, i)) continue; CREATE(R_EXIT(dest, i), struct room_direction_data, 1); *R_EXIT(dest, i) = *R_EXIT(source, i); if (R_EXIT(source, i)->general_description) R_EXIT(dest, i)->general_description = strdup(R_EXIT(source, i)->general_description); if (R_EXIT(source, i)->keyword) R_EXIT(dest, i)->keyword = strdup(R_EXIT(source, i)->keyword); } if (source->ex_description) copy_ex_descriptions(&dest->ex_description, source->ex_description); return TRUE; }
/* * Idea by: Cris Jacobin <*****@*****.**> */ room_rnum duplicate_room(room_vnum dest_vnum, room_rnum orig) { int new_rnum, znum; struct room_data nroom; #if CIRCLE_UNSIGNED_INDEX if (orig == NOWHERE || orig > top_of_world) { #else if (orig < 0 || orig > top_of_world) { #endif log("SYSERR: GenOLC: copy_room: Given bad original real room."); return NOWHERE; } else if ((znum = real_zone_by_thing(dest_vnum)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: No such destination zone."); return NOWHERE; } /* * add_room will make its own copies of strings. */ if ((new_rnum = add_room(&nroom)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: Problem adding room."); return NOWHERE; } nroom = world[new_rnum]; nroom.number = dest_vnum; nroom.zone = znum; /* So the people and objects aren't in two places at once... */ nroom.contents = NULL; nroom.people = NULL; return new_rnum; } /* -------------------------------------------------------------------------- */ /* * Copy strings over so bad things don't happen. We do not free the * existing strings here because copy_room() did a shallow copy previously * and we'd be freeing the very strings we're copying. If this function * is used elsewhere, be sure to free_room_strings() the 'dest' room first. */ int copy_room_strings(struct room_data *dest, struct room_data *source) { int i; if (dest == NULL || source == NULL) { log("SYSERR: GenOLC: copy_room_strings: NULL values passed."); return FALSE; } dest->description = str_udup(source->description); dest->name = str_udup(source->name); for (i = 0; i < NUM_OF_DIRS; i++) { if (!R_EXIT(source, i)) continue; CREATE(R_EXIT(dest, i), struct room_direction_data, 1); *R_EXIT(dest, i) = *R_EXIT(source, i); if (R_EXIT(source, i)->general_description) R_EXIT(dest, i)->general_description = strdup(R_EXIT(source, i)->general_description); if (R_EXIT(source, i)->keyword) R_EXIT(dest, i)->keyword = strdup(R_EXIT(source, i)->keyword); } if (source->ex_description) copy_ex_descriptions(&dest->ex_description, source->ex_description); return TRUE; }
int save_rooms(zone_rnum rzone) { int i; int dflag = 0; struct room_data *room; FILE *sf; char buf[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; if (rzone == NOWHERE || rzone > top_of_zone_table) { log("SYSERR: GenOLC: save_rooms: Invalid zone number %d passed! (0-%d)", rzone, top_of_zone_table); return FALSE; } log("GenOLC: save_rooms: Saving rooms in zone #%d (%d-%d).", zone_table[rzone].number, genolc_zone_bottom(rzone), zone_table[rzone].top); sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number); if (!(sf = fopen(buf, "w"))) { perror("SYSERR: save_rooms"); return FALSE; } for (i = genolc_zone_bottom(rzone); i <= zone_table[rzone].top; i++) { int rnum; if ((rnum = real_room(i)) != NOWHERE) { int j; room = (world + rnum); /* * Copy the description and strip off trailing newlines. */ strcpy(buf, room->description ? room->description : "Empty room."); strip_cr(buf); /* * Save the numeric and string section of the file. */ sprintasciilong(buf2, room->room_flags); fprintf(sf, "#%d\n" "%s%c\n" "%s%c\n" "%d %s %d %d %d %d %d\n", room->number, room->name ? room->name : "Untitled", STRING_TERMINATOR, buf, STRING_TERMINATOR, zone_table[room->zone].number, buf2, room->sector_type, room->size, room->nat_light, room->min_level, room->max_level ); /* * Now you write out the exits for the room. */ for (j = 0; j < NUM_OF_DIRS; j++) { if (R_EXIT(room, j)) { if (R_EXIT(room, j)->general_description) { strcpy(buf, R_EXIT(room, j)->general_description); strip_cr(buf); } else *buf = '\0'; /* * Figure out door flag. */ if (IS_SET(R_EXIT(room, j)->exit_info, EX_ISDOOR)) { dflag = 1; if (IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF) && !IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN)) dflag = 2; if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) && !IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 3; if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) && IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 4; } else if (!IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN)) dflag = 0; if (R_EXIT(room, j)->keyword) strcpy(buf1, R_EXIT(room, j)->keyword); 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, R_EXIT(room, j)->to_room != -1 ? 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) { strcpy(buf, xdesc->description); strip_cr(buf); fprintf(sf, "E\n" "%s~\n" "%s~\n", xdesc->keyword, buf); } } if (room->pain_message) { fprintf(sf, "P\n" "%s~\n" "%d~\n" "%d~\n", room->pain_message, room->pain_damage, room->pain_rate ); } if (room->nomagic_message_room && room->nomagic_message_caster ) { fprintf(sf, "N\n" "%s~\n" "%s~\n", room->nomagic_message_caster, room->nomagic_message_room ); } if (room->min_level_message || room->max_level_message ) { fprintf(sf, "F\n" "%s~\n" "%s~\n", room->min_level_message, room->max_level_message ); } fprintf(sf, "S\n"); script_save_to_disk(sf, room, WLD_TRIGGER); } } /* * Write the final line and close it. */ fprintf(sf, "$~\n"); fclose(sf); /* New file we just made. */ sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number); /* Old file we're replacing. */ sprintf(buf2, "%s/%d.wld", WLD_PREFIX, zone_table[rzone].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[rzone].number, SL_WLD); return TRUE; }
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; }