void zedit_setup(struct descriptor_data *d, int room_num) { struct zone_data *zone; int subcmd = 0, count = 0, cmd_room = -1; /* * Allocate one scratch zone structure. */ CREATE(zone, struct zone_data, 1); /* * Copy all the zone header information over. */ zone->name = str_dup(zone_table[OLC_ZNUM(d)].name); zone->lifespan = zone_table[OLC_ZNUM(d)].lifespan; zone->top = zone_table[OLC_ZNUM(d)].top; zone->reset_mode = zone_table[OLC_ZNUM(d)].reset_mode; /* * The remaining fields are used as a 'has been modified' flag */ zone->number = 0; /* Header information has changed. */ zone->age = 0; /* The commands have changed. */ /* * Start the reset command list with a terminator. */ CREATE(zone->cmd, struct reset_com, 1); zone->cmd[0].command = 'S'; /* * Add all entries in zone_table that relate to this room. */ while (ZCMD(OLC_ZNUM(d), subcmd).command != 'S') { switch (ZCMD(OLC_ZNUM(d), subcmd).command) { case 'M': case 'O': cmd_room = ZCMD(OLC_ZNUM(d), subcmd).arg3; break; case 'D': case 'R': cmd_room = ZCMD(OLC_ZNUM(d), subcmd).arg1; break; default: break; } if (cmd_room == room_num) { add_cmd_to_list(&(zone->cmd), &ZCMD(OLC_ZNUM(d), subcmd), count); count++; } subcmd++; } OLC_ZONE(d) = zone; /* * Display main menu. */ zedit_disp_menu(d); }
int delete_mobile(mob_rnum refpt) { struct char_data *live_mob; int vnum, counter, zone, cmd_no; if (refpt < 0 || refpt > top_of_mobt) { log("SYSERR: GenOLC: delete_mobile: Invalid rnum %d.", refpt); return FALSE; } vnum = mob_index[refpt].vnum; add_to_save_list(zone_table[real_zone_by_thing(vnum)].number, SL_MOB); extract_mobile_all(vnum); free_mobile_strings(&mob_proto[refpt]); for (counter = refpt; counter < top_of_mobt; counter++) { mob_index[counter] = mob_index[counter + 1]; mob_proto[counter] = mob_proto[counter + 1]; mob_proto[counter].nr--; } top_of_mobt--; RECREATE(mob_index, struct index_data, top_of_mobt + 1); RECREATE(mob_proto, struct char_data, top_of_mobt + 1); /* * Update live mobile rnums. */ for (live_mob = character_list; live_mob; live_mob = live_mob->next) GET_MOB_RNUM(live_mob) -= (GET_MOB_RNUM(live_mob) >= refpt); /* * Update zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) if (ZCMD(zone, cmd_no).command == 'M') ZCMD(zone, cmd_no).arg1 -= (ZCMD(zone, cmd_no).arg1 >= refpt); /* * Update shop keepers. */ if (shop_index) for (counter = 0; counter <= top_shop - top_shop_offset; counter++) SHOP_KEEPER(counter) -= (SHOP_KEEPER(counter) >= refpt); return TRUE; }
/* * Adjust the internal values of other objects as if something was inserted at the given array index. * Might also be useful to make 'holes' in the array for some reason. */ int adjust_objects(obj_rnum refpt) { int shop, i, zone, cmd_no; struct obj_data *obj; if (refpt < 0 || refpt >= top_of_objt) return refpt; /* * Renumber live objects. */ for (obj = object_list; obj; obj = obj->next) GET_OBJ_RNUM(obj) += (GET_OBJ_RNUM(obj) >= refpt); /* * Renumber zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) { for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) { switch (ZCMD(zone, cmd_no).command) { case 'P': ZCMD(zone, cmd_no).arg3 += (ZCMD(zone, cmd_no).arg3 >= refpt); /* * No break here - drop into next case. */ case 'O': case 'G': case 'E': ZCMD(zone, cmd_no).arg1 += (ZCMD(zone, cmd_no).arg1 >= refpt); break; case 'R': ZCMD(zone, cmd_no).arg2 += (ZCMD(zone, cmd_no).arg2 >= refpt); break; } } } /* * Renumber notice boards. */ for (i = 0; i < NUM_OF_BOARDS; i++) BOARD_RNUM(i) += (BOARD_RNUM(i) >= refpt); /* * Renumber shop produce. */ for (shop = 0; shop <= top_shop; shop++) for (i = 0; SHOP_PRODUCT(shop, i) != NOTHING; i++) SHOP_PRODUCT(shop, i) += (SHOP_PRODUCT(shop, i) >= refpt); return refpt; }
/* * Adjust the internal values of other objects as if something was inserted at the given array index. * Might also be useful to make 'holes' in the array for some reason. */ obj_rnum adjust_objects(obj_rnum refpt) { int shop, i, zone, cmd_no; struct obj_data *obj; #if CIRCLE_UNSIGNED_INDEX if (refpt == NOTHING || refpt > top_of_objt) #else if (refpt < 0 || refpt > top_of_objt) #endif return NOTHING; /* * Renumber live objects. */ for (obj = object_list; obj; obj = obj->next) GET_OBJ_RNUM(obj) += (GET_OBJ_RNUM(obj) >= refpt); /* * Renumber zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) { for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) { switch (ZCMD(zone, cmd_no).command) { case 'P': ZCMD(zone, cmd_no).arg3 += (ZCMD(zone, cmd_no).arg3 >= refpt); /* * No break here - drop into next case. */ case 'O': case 'G': case 'E': ZCMD(zone, cmd_no).arg1 += (ZCMD(zone, cmd_no).arg1 >= refpt); break; case 'R': ZCMD(zone, cmd_no).arg2 += (ZCMD(zone, cmd_no).arg2 >= refpt); break; } } } /* * Renumber shop produce. */ for (shop = 0; shop <= top_shop - top_shop_offset; shop++) for (i = 0; SHOP_PRODUCT(shop, i) != NOTHING; i++) SHOP_PRODUCT(shop, i) += (SHOP_PRODUCT(shop, i) >= refpt); return refpt; }
int add_mobile(struct char_data *mob, mob_vnum vnum) { int rnum, i, found = FALSE, shop, cmd_no; zone_rnum zone; struct char_data *live_mob; if ((rnum = real_mobile(vnum)) != NOBODY) { /* Copy over the mobile and free() the old strings. */ copy_mobile(&mob_proto[rnum], mob); /* Now re-point all existing mobile strings to here. */ for (live_mob = character_list; live_mob; live_mob = live_mob->next) if (rnum == live_mob->nr) update_mobile_strings(live_mob, &mob_proto[rnum]); add_to_save_list(zone_table[real_zone_by_thing(vnum)].number, SL_MOB); log("GenOLC: add_mobile: Updated existing mobile #%d.", vnum); return TRUE; } RECREATE(mob_proto, struct char_data, top_of_mobt + 2); RECREATE(mob_index, struct index_data, top_of_mobt + 2); top_of_mobt++; for (i = top_of_mobt; i > 0; i--) { if (vnum > mob_index[i - 1].vnum) { mob_proto[i] = *mob; mob_proto[i].nr = i; copy_mobile_strings(mob_proto + i, mob); mob_index[i].vnum = vnum; mob_index[i].number = 0; mob_index[i].func = 0; found = i; break; } mob_index[i] = mob_index[i - 1]; mob_proto[i] = mob_proto[i - 1]; mob_proto[i].nr++; } if (!found) { mob_proto[0] = *mob; mob_proto[0].nr = 0; copy_mobile_strings(&mob_proto[0], mob); mob_index[0].vnum = vnum; mob_index[0].number = 0; mob_index[0].func = 0; } log("GenOLC: add_mobile: Added mobile %d at index #%d.", vnum, found); #if CONFIG_GENOLC_MOBPROG GET_MPROG(OLC_MOB(d)) = OLC_MPROGL(d); GET_MPROG_TYPE(OLC_MOB(d)) = (OLC_MPROGL(d) ? OLC_MPROGL(d)->type : 0); while (OLC_MPROGL(d)) { GET_MPROG_TYPE(OLC_MOB(d)) |= OLC_MPROGL(d)->type; OLC_MPROGL(d) = OLC_MPROGL(d)->next; } #endif /* * Update live mobile rnums. */ for (live_mob = character_list; live_mob; live_mob = live_mob->next) GET_MOB_RNUM(live_mob) += (GET_MOB_RNUM(live_mob) >= found); /* * Update zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) if (ZCMD(zone, cmd_no).command == 'M') ZCMD(zone, cmd_no).arg1 += (ZCMD(zone, cmd_no).arg1 >= found); /* * Update shop keepers. */ if (shop_index) for (shop = 0; shop <= top_shop - top_shop_offset; shop++) SHOP_KEEPER(shop) += (SHOP_KEEPER(shop) >= found); add_to_save_list(zone_table[real_zone_by_thing(vnum)].number, SL_MOB); return found; }
/* * Save all the zone_table for this zone to disk. This function now * writes simple comments in the form of (<name>) to each record. A * header for each field is also there. */ int save_zone(zone_rnum zone_num) { int subcmd, arg1 = -1, arg2 = -1, arg3 = -1; char fname[128], oldname[128]; const char *comment = NULL; FILE *zfile; #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_zone: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } snprintf(fname, sizeof(fname), "%s/%d.new", ZON_PREFIX, zone_table[zone_num].number); if (!(zfile = fopen(fname, "w"))) { mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: save_zones: Can't write zone %d.", zone_table[zone_num].number); return FALSE; } /* * Print zone header to file */ fprintf(zfile, "#%d\n" "%s~\n" "%s~\n" "%d %d %d %d\n", zone_table[zone_num].number, (zone_table[zone_num].builders && *zone_table[zone_num].builders) ? zone_table[zone_num].builders : "None.", (zone_table[zone_num].name && *zone_table[zone_num].name) ? zone_table[zone_num].name : "undefined", genolc_zone_bottom(zone_num), zone_table[zone_num].top, zone_table[zone_num].lifespan, zone_table[zone_num].reset_mode ); /* * Handy Quick Reference Chart for Zone Values. * * Field #1 Field #3 Field #4 Field #5 * ------------------------------------------------- * M (Mobile) Mob-Vnum Wld-Max Room-Vnum * O (Object) Obj-Vnum Wld-Max Room-Vnum * G (Give) Obj-Vnum Wld-Max Unused * E (Equip) Obj-Vnum Wld-Max EQ-Position * P (Put) Obj-Vnum Wld-Max Target-Obj-Vnum * D (Door) Room-Vnum Door-Dir Door-State * R (Remove) Room-Vnum Obj-Vnum Unused * T (Trigger) Trig-type Trig-Vnum Room-Vnum * V (var) Trig-type Context Room-Vnum Varname Value * ------------------------------------------------- */ for (subcmd = 0; ZCMD(zone_num, subcmd).command != 'S'; subcmd++) { switch (ZCMD(zone_num, subcmd).command) { case 'M': arg1 = mob_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = world[ZCMD(zone_num, subcmd).arg3].number; comment = mob_proto[ZCMD(zone_num, subcmd).arg1].player.short_descr; break; case 'O': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = world[ZCMD(zone_num, subcmd).arg3].number; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'G': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = -1; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'E': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = ZCMD(zone_num, subcmd).arg3; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'P': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = obj_index[ZCMD(zone_num, subcmd).arg3].vnum; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'D': arg1 = world[ZCMD(zone_num, subcmd).arg1].number; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = ZCMD(zone_num, subcmd).arg3; comment = world[ZCMD(zone_num, subcmd).arg1].name; break; case 'R': arg1 = world[ZCMD(zone_num, subcmd).arg1].number; arg2 = obj_index[ZCMD(zone_num, subcmd).arg2].vnum; comment = obj_proto[ZCMD(zone_num, subcmd).arg2].short_description; arg3 = -1; break; case 'T': arg1 = ZCMD(zone_num, subcmd).arg1; /* trigger type */ arg2 = trig_index[ZCMD(zone_num, subcmd).arg2]->vnum; /* trigger vnum */ arg3 = world[ZCMD(zone_num, subcmd).arg3].number; /* room num */ comment = GET_TRIG_NAME(trig_index[real_trigger(arg2)]->proto); break; case 'V': arg1 = ZCMD(zone_num, subcmd).arg1; /* trigger type */ arg2 = ZCMD(zone_num, subcmd).arg2; /* context */ arg3 = world[ZCMD(zone_num, subcmd).arg3].number; break; case '*': /* * Invalid commands are replaced with '*' - Ignore them. */ continue; default: mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: z_save_to_disk(): Unknown cmd '%c' - NOT saving", ZCMD(zone_num, subcmd).command); continue; } if (ZCMD(zone_num, subcmd).command != 'V') fprintf(zfile, "%c %d %d %d %d \t(%s)\n", ZCMD(zone_num, subcmd).command, ZCMD(zone_num, subcmd).if_flag, arg1, arg2, arg3, comment); else fprintf(zfile, "%c %d %d %d %d %s %s\n", ZCMD(zone_num, subcmd).command, ZCMD(zone_num, subcmd).if_flag, arg1, arg2, arg3, ZCMD(zone_num, subcmd).sarg1, ZCMD(zone_num, subcmd).sarg2); } fputs("S\n$\n", zfile); fclose(zfile); snprintf(oldname, sizeof(oldname), "%s/%d.zon", ZON_PREFIX, zone_table[zone_num].number); remove(oldname); rename(fname, oldname); if (in_save_list(zone_table[zone_num].number, SL_ZON)) remove_from_save_list(zone_table[zone_num].number, SL_ZON); return TRUE; } /*-------------------------------------------------------------------*/ /* * Some common code to count the number of comands in the list. */ int count_commands(struct reset_com *list) { int count = 0; while (list[count].command != 'S') count++; return count; }
/************************************************************************\ ** Description : ** ** Removes a room from memory, updates the world list, and moves ** ** all of the objects, mobiles, and players to the void. ** ** ** ** Return Value: ** ** TRUE if successful...otherwise, FALSE. ** ** ** ** Parameters : ** ** rnum : The real number of the room requested to delete. ** \************************************************************************/ int remove_room_from_memory(room_rnum rnum) { struct char_data *tch; struct obj_data *obj; struct room_data *room; int i, j; if (rnum <= 0 || rnum > top_of_world) return FALSE; room = &world[rnum]; add_to_save_list(zone_table[room->zone].number, SL_WLD); log("GenOLC: delete_room: Deleting room #%d (%s).", room->number, room->name); /* * Dump the contents of this room into the void. We could also just * exract the people, mobs, and objects here. */ for (obj = world[rnum].contents; obj; obj = obj->next_content) { obj_from_room(obj); obj_to_room(obj, 0); } for (tch = world[rnum].people; tch; tch = tch->next_in_room) { char_from_room(tch); char_to_room(tch, 0); } free_room(room); /* * Change any exit going to this room to go to the void. This way, * the builders know when they type show errors. */ for (i = top_of_world; i >= 0; i--) for (j = 0; j < NUM_OF_DIRS; j++) if (W_EXIT(i, j) == NULL) continue; else if (W_EXIT(i, j)->to_room > rnum) W_EXIT(i, j)->to_room--; else if (W_EXIT(i, j)->to_room == rnum) W_EXIT(i, j)->to_room = 0; /* * Find what zone the room was in so we can update the loading table. */ for (i = 0; i <= top_of_zone_table; i++) for (j = 0; ZCMD(i, j).command != 'S'; j++) switch (ZCMD(i, j).command) { case 'M': case 'O': if (ZCMD(i, j).arg3 == rnum) ZCMD(i, j).command = '*'; /* Cancel Command */ else if (ZCMD(i, j).arg3 > rnum) ZCMD(i, j).arg3--; break; case 'D': case 'R': if (ZCMD(i, j).arg1 == rnum) ZCMD(i, j).command = '*'; /* Cancel Command */ else if (ZCMD(i, j).arg1 > rnum) ZCMD(i, j).arg1--; break; case 'G': case 'P': case 'E': case '*': /* Known zone entries we don't use here. */ break; default: mudlog(BRF, LVL_GOD, TRUE, "SYSERR: GenOLC: delete_room: Unknown zone entry found!"); } /* * Now we actually move the rooms down. */ for (i = rnum; i < top_of_world; i++) { world[i] = world[i + 1]; for (tch = world[i].people; tch; tch = tch->next_in_room) IN_ROOM(tch) -= (IN_ROOM(tch) != NOWHERE); /* Redundant Check? */ for (obj = world[i].contents; obj; obj = obj->next_content) IN_ROOM(obj) -= (IN_ROOM(obj) != NOWHERE); } top_of_world--; RECREATE(world, struct room_data, top_of_world + 1); return (TRUE); }
/* * Save all the zone_table for this zone to disk. This function now * writes simple comments in the form of (<name>) to each record. A * header for each field is also there. */ int save_zone(zone_rnum zone_num) { int subcmd, arg1 = -1, arg2 = -1, arg3 = -1, arg4 = 100; char fname[64]; const char *comment = NULL; FILE *zfile; if (zone_num < 0 || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_zone: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } sprintf(fname, "%s/%d.new", ZON_PREFIX, zone_table[zone_num].number); if (!(zfile = fopen(fname, "w"))) { sprintf(buf, "SYSERR: OLC: save_zones: Can't write zone %d.", zone_table[zone_num].number); mudlog(buf, BRF, LVL_BUILDER, TRUE); return FALSE; } /* * Print zone header to file */ fprintf(zfile, "#%d\n" "%s~\n" "%d %d %d\n", zone_table[zone_num].number, (zone_table[zone_num].name && *zone_table[zone_num].name) ? zone_table[zone_num].name : "undefined", zone_table[zone_num].top, zone_table[zone_num].lifespan, zone_table[zone_num].reset_mode ); /* * Handy Quick Reference Chart for Zone Values. * * Field #1 Field #3 Field #4 Field #5 * ------------------------------------------------- * M (Mobile) Mob-Vnum Wld-Max Room-Vnum PERCENT * O (Object) Obj-Vnum Wld-Max Room-Vnum PERCENT * G (Give) Obj-Vnum Wld-Max Unused PERCENT * E (Equip) Obj-Vnum Wld-Max EQ-Position PERCENT * P (Put) Obj-Vnum Wld-Max Target-Obj-Vnum * D (Door) Room-Vnum Door-Dir Door-State * R (Remove) Room-Vnum Obj-Vnum Unused * ------------------------------------------------- */ for (subcmd = 0; ZCMD(zone_num, subcmd).command != 'S'; subcmd++) { switch (ZCMD(zone_num, subcmd).command) { case 'M': arg1 = mob_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = world[ZCMD(zone_num, subcmd).arg3].number; arg4 = ZCMD(zone_num, subcmd).arg4; comment = mob_proto[ZCMD(zone_num, subcmd).arg1].player.short_descr; break; case 'O': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = world[ZCMD(zone_num, subcmd).arg3].number; arg4 = ZCMD(zone_num, subcmd).arg4; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'G': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = -1; arg4 = ZCMD(zone_num, subcmd).arg4; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'E': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = ZCMD(zone_num, subcmd).arg3; arg4 = ZCMD(zone_num, subcmd).arg4; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'P': arg1 = obj_index[ZCMD(zone_num, subcmd).arg1].vnum; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = obj_index[ZCMD(zone_num, subcmd).arg3].vnum; comment = obj_proto[ZCMD(zone_num, subcmd).arg1].short_description; break; case 'D': arg1 = world[ZCMD(zone_num, subcmd).arg1].number; arg2 = ZCMD(zone_num, subcmd).arg2; arg3 = ZCMD(zone_num, subcmd).arg3; comment = world[ZCMD(zone_num, subcmd).arg1].name; break; case 'R': arg1 = world[ZCMD(zone_num, subcmd).arg1].number; arg2 = obj_index[ZCMD(zone_num, subcmd).arg2].vnum; comment = obj_proto[ZCMD(zone_num, subcmd).arg2].short_description; arg3 = -1; break; case '*': /* * Invalid commands are replaced with '*' - Ignore them. */ continue; default: sprintf(buf, "SYSERR: OLC: z_save_to_disk(): Unknown cmd '%c' - NOT saving", ZCMD(zone_num, subcmd).command); mudlog(buf, BRF, LVL_BUILDER, TRUE); continue; } fprintf(zfile, "%c %d %d %d %d %d \t(%s)\n", ZCMD(zone_num, subcmd).command, ZCMD(zone_num, subcmd).if_flag, arg1, arg2, arg3, arg4, comment); } fputs("S\n$\n", zfile); fclose(zfile); sprintf(buf2, "%s/%d.zon", ZON_PREFIX, zone_table[zone_num].number); remove(buf2); rename(fname, buf2); remove_from_save_list(zone_table[zone_num].number, SL_ZON); 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 delete_room(room_rnum rnum) { int i, j; struct char_data *ppl, *next_ppl; struct obj_data *obj, *next_obj; struct room_data *room; if (rnum <= 0 || rnum > top_of_world) /* Can't delete void yet. */ return FALSE; room = &world[rnum]; add_to_save_list(zone_table[room->zone].number, SL_WLD); /* This is something you might want to read about in the logs. */ log("GenOLC: delete_room: Deleting room #%d (%s).", room->number, room->name); if (r_mortal_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting mortal start room!"); r_mortal_start_room = 0; /* The Void */ } if (r_immort_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting immortal start room!"); r_immort_start_room = 0; /* The Void */ } if (r_newbie_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting newbie start room!"); r_newbie_start_room = 0; /* The Void */ } if (r_sorin_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting sorin start room!"); r_sorin_start_room = 0; /* The Void */ } if (r_frozen_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting frozen start room!"); r_frozen_start_room = 0; /* The Void */ } /* * Dump the contents of this room into the Void. We could also just * extract the people, mobs, and objects here. */ for (obj = world[rnum].contents; obj; obj = next_obj) { next_obj = obj->next_content; obj_from_room(obj); obj_to_room(obj, 0); } for (ppl = world[rnum].people; ppl; ppl = next_ppl) { next_ppl = ppl->next_in_room; char_from_room(ppl); char_to_room(ppl, 0); } free_room_strings(room); /* * Change any exit going to this room to go the void. * Also fix all the exits pointing to rooms above this. */ for (i = top_of_world; i >= 0; i--) for (j = 0; j < NUM_OF_DIRS; j++) if (W_EXIT(i, j) == NULL) continue; else if (W_EXIT(i, j)->to_room > rnum) W_EXIT(i, j)->to_room--; else if (W_EXIT(i, j)->to_room == rnum) W_EXIT(i, j)->to_room = 0; /* Some may argue -1. */ /* * Find what zone that room was in so we can update the loading table. */ for (i = 0; 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': if (ZCMD(i, j).arg3 == rnum) ZCMD(i, j).command = '*'; /* Cancel command. */ else if (ZCMD(i, j).arg3 > rnum) ZCMD(i, j).arg3--; break; case 'D': case 'R': if (ZCMD(i, j).arg1 == rnum) ZCMD(i, j).command = '*'; /* Cancel command. */ else if (ZCMD(i, j).arg1 > rnum) ZCMD(i, j).arg1--; case 'G': case 'P': case 'E': case '*': /* Known zone entries we don't care about. */ break; default: mudlog(BRF, LVL_DEITY, TRUE, "SYSERR: GenOLC: delete_room: Unknown zone entry found!"); } /* * Now we actually move the rooms down. */ for (i = rnum; i < top_of_world; i++) { world[i] = world[i + 1]; for (ppl = world[i].people; ppl; ppl = ppl->next_in_room) IN_ROOM(ppl) -= (IN_ROOM(ppl) != NOWHERE); /* Redundant check? */ for (obj = world[i].contents; obj; obj = obj->next_content) IN_ROOM(obj) -= (IN_ROOM(obj) != NOWHERE); /* Redundant check? */ } top_of_world--; RECREATE(world, struct room_data, top_of_world + 1); return TRUE; }
int delete_object(obj_rnum rnum) { obj_rnum i; zone_rnum zrnum; struct obj_data *obj, *tmp, *next_tmp; int shop, j, zone, cmd_no; if (rnum == NOTHING || rnum > top_of_objt) return NOTHING; obj = &obj_proto[rnum]; zrnum = real_zone_by_thing(GET_OBJ_VNUM(obj)); /* This is something you might want to read about in the logs. */ log("GenOLC: delete_object: Deleting object #%d (%s).", GET_OBJ_VNUM(obj), obj->short_description); for (tmp = object_list; tmp; tmp = next_tmp) { next_tmp = tmp->next; if (tmp->item_number != obj->item_number) continue; /* extract_obj() will just axe contents. */ if (tmp->contains) { struct obj_data *this_content, *next_content; for (this_content = tmp->contains; this_content; this_content = next_content) { next_content = this_content->next_content; if (IN_ROOM(tmp)) { /* Transfer stuff from object to room. */ obj_from_obj(this_content); obj_to_room(this_content, IN_ROOM(tmp)); } else if (tmp->worn_by || tmp->carried_by) { /* Transfer stuff from object to person inventory. */ obj_from_char(this_content); obj_to_char(this_content, tmp->carried_by); } else if (tmp->in_obj) { /* Transfer stuff from object to containing object. */ obj_from_obj(this_content); obj_to_obj(this_content, tmp->in_obj); } } } /* Remove from object_list, etc. - handles weightchanges, and similar. */ extract_obj(tmp); } /* Make sure all are removed. */ assert(obj_index[rnum].number == 0); /* Adjust rnums of all other objects. */ for (tmp = object_list; tmp; tmp = tmp->next) { GET_OBJ_RNUM(tmp) -= (GET_OBJ_RNUM(tmp) > rnum); } for (i = rnum; i < top_of_objt; i++) { obj_index[i] = obj_index[i + 1]; obj_proto[i] = obj_proto[i + 1]; obj_proto[i].item_number = i; } top_of_objt--; RECREATE(obj_index, struct index_data, top_of_objt + 1); RECREATE(obj_proto, struct obj_data, top_of_objt + 1); /* Renumber notice boards. */ for (j = 0; j < NUM_OF_BOARDS; j++) BOARD_RNUM(j) -= (BOARD_RNUM(j) > rnum); /* Renumber shop produce. */ for (shop = 0; shop <= top_shop; shop++) for (j = 0; SHOP_PRODUCT(shop, j) != NOTHING; j++) SHOP_PRODUCT(shop, j) -= (SHOP_PRODUCT(shop, j) > rnum); /* Renumber zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) { for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) { switch (ZCMD(zone, cmd_no).command) { case 'P': if (ZCMD(zone, cmd_no).arg3 == rnum) { delete_command(&zone_table[zone], cmd_no); } else ZCMD(zone, cmd_no).arg3 -= (ZCMD(zone, cmd_no).arg3 > rnum); break; case 'O': case 'G': case 'E': if (ZCMD(zone, cmd_no).arg1 == rnum) { delete_command(&zone_table[zone], cmd_no); } else ZCMD(zone, cmd_no).arg1 -= (ZCMD(zone, cmd_no).arg1 > rnum); break; case 'R': if (ZCMD(zone, cmd_no).arg2 == rnum) { delete_command(&zone_table[zone], cmd_no); } else ZCMD(zone, cmd_no).arg2 -= (ZCMD(zone, cmd_no).arg2 > rnum); break; } } } save_objects(zrnum); return rnum; }
int delete_mobile(mob_rnum refpt) { struct char_data *live_mob; struct char_data *proto; int counter, cmd_no; mob_vnum vnum; zone_rnum zone; #if CIRCLE_UNSIGNED_INDEX if (refpt == NOBODY || refpt > top_of_mobt) { #else if (refpt < 0 || refpt > top_of_mobt) { #endif log("SYSERR: GenOLC: delete_mobile: Invalid rnum %d.", refpt); return NOBODY; } vnum = mob_index[refpt].vnum; proto = &mob_proto[refpt]; extract_mobile_all(vnum); extract_char(proto); for (counter = refpt; counter < top_of_mobt; counter++) { mob_index[counter] = mob_index[counter + 1]; mob_proto[counter] = mob_proto[counter + 1]; mob_proto[counter].nr--; } top_of_mobt--; RECREATE(mob_index, struct index_data, top_of_mobt + 1); RECREATE(mob_proto, struct char_data, top_of_mobt + 1); /* Update live mobile rnums. */ for (live_mob = character_list; live_mob; live_mob = live_mob->next) GET_MOB_RNUM(live_mob) -= (GET_MOB_RNUM(live_mob) >= refpt); /* Update zone table. */ for (zone = 0; zone <= top_of_zone_table; zone++) for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) if (ZCMD(zone, cmd_no).command == 'M'){ if (ZCMD(zone, cmd_no).arg1 == refpt) { delete_zone_command(&zone_table[zone], cmd_no); } else ZCMD(zone, cmd_no).arg1 -= (ZCMD(zone, cmd_no).arg1 > refpt); } /* Update shop keepers. */ if (shop_index) for (counter = 0; counter <= top_shop; counter++) SHOP_KEEPER(counter) -= (SHOP_KEEPER(counter) >= refpt); save_mobiles(real_zone_by_thing(vnum)); return refpt; } int copy_mobile_strings(struct char_data *t, struct char_data *f) { if (f->player.name) t->player.name = strdup(f->player.name); if (f->player.title) t->player.title = strdup(f->player.title); if (f->player.short_descr) t->player.short_descr = strdup(f->player.short_descr); if (f->player.long_descr) t->player.long_descr = strdup(f->player.long_descr); if (f->player.description) t->player.description = strdup(f->player.description); return TRUE; } int update_mobile_strings(struct char_data *t, struct char_data *f) { if (f->player.name) t->player.name = f->player.name; if (f->player.title) t->player.title = f->player.title; if (f->player.short_descr) t->player.short_descr = f->player.short_descr; if (f->player.long_descr) t->player.long_descr = f->player.long_descr; if (f->player.description) t->player.description = f->player.description; return TRUE; } int free_mobile_strings(struct char_data *mob) { if (mob->player.name) free(mob->player.name); if (mob->player.title) free(mob->player.title); if (mob->player.short_descr) free(mob->player.short_descr); if (mob->player.long_descr) free(mob->player.long_descr); if (mob->player.description) free(mob->player.description); return TRUE; } /* Free a mobile structure that has been edited. Take care of existing mobiles * and their mob_proto! */ int free_mobile(struct char_data *mob) { mob_rnum i; if (mob == NULL) return FALSE; /* Non-prototyped mobile. Also known as new mobiles. */ if ((i = GET_MOB_RNUM(mob)) == NOBODY) { free_mobile_strings(mob); /* free script proto list */ free_proto_script(mob, MOB_TRIGGER); } else { /* Prototyped mobile. */ if (mob->player.name && mob->player.name != mob_proto[i].player.name) free(mob->player.name); if (mob->player.title && mob->player.title != mob_proto[i].player.title) free(mob->player.title); if (mob->player.short_descr && mob->player.short_descr != mob_proto[i].player.short_descr) free(mob->player.short_descr); if (mob->player.long_descr && mob->player.long_descr != mob_proto[i].player.long_descr) free(mob->player.long_descr); if (mob->player.description && mob->player.description != mob_proto[i].player.description) free(mob->player.description); /* free script proto list if it's not the prototype */ if (mob->proto_script && mob->proto_script != mob_proto[i].proto_script) free_proto_script(mob, MOB_TRIGGER); } while (mob->affected) affect_remove(mob, mob->affected); /* free any assigned scripts */ if (SCRIPT(mob)) extract_script(mob, MOB_TRIGGER); free(mob); return TRUE; }
int delete_room(room_rnum rnum) { room_rnum i; int j; struct char_data *ppl, *next_ppl; struct obj_data *obj, *next_obj; struct room_data *room; if (rnum <= 0 || rnum > top_of_world) /* Can't delete void yet. */ return FALSE; room = &world[rnum]; add_to_save_list(zone_table[room->zone].number, SL_WLD); /* remove from realnum lookup tree */ htree_del(room_htree, room->number); /* This is something you might want to read about in the logs. */ log("GenOLC: delete_room: Deleting room #%d (%s).", room->number, room->name); if (r_mortal_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting mortal start room!"); r_mortal_start_room = 0; /* The Void */ } if (r_immort_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting immortal start room!"); r_immort_start_room = 0; /* The Void */ } if (r_frozen_start_room == rnum) { log("WARNING: GenOLC: delete_room: Deleting frozen start room!"); r_frozen_start_room = 0; /* The Void */ } /* * Dump the contents of this room into the Void. We could also just * extract the people, mobs, and objects here. */ for (obj = world[rnum].contents; obj; obj = next_obj) { next_obj = obj->next_content; obj_from_room(obj); obj_to_room(obj, 0); } for (ppl = world[rnum].people; ppl; ppl = next_ppl) { next_ppl = ppl->next_in_room; char_from_room(ppl); char_to_room(ppl, 0); } free_room_strings(room); if (SCRIPT(room)) extract_script(room, WLD_TRIGGER); free_proto_script(room, WLD_TRIGGER); /* * Change any exit going to this room to go the void. * Also fix all the exits pointing to rooms above this. */ i = top_of_world + 1; do { i--; for (j = 0; j < NUM_OF_DIRS; j++) if (W_EXIT(i, j) == NULL) continue; else if (W_EXIT(i, j)->to_room > rnum) W_EXIT(i, j)->to_room -= (W_EXIT(i, j)->to_room != NOWHERE); /* with unsigned NOWHERE > any rnum */ else if (W_EXIT(i, j)->to_room == rnum) { if ((!W_EXIT(i, j)->keyword || !*W_EXIT(i, j)->keyword) && (!W_EXIT(i, j)->general_description || !*W_EXIT(i, j)->general_description)) { /* no description, remove exit completely */ if (W_EXIT(i, j)->keyword) free(W_EXIT(i, j)->keyword); if (W_EXIT(i, j)->general_description) free(W_EXIT(i, j)->general_description); free(W_EXIT(i, j)); W_EXIT(i, j) = NULL; } else { /* description is set, just point to nowhere */ W_EXIT(i, j)->to_room = NOWHERE; } } } while (i > 0); /* * Find what zone that room was in so we can update the loading table. */ for (i = 0; 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': if (ZCMD(i, j).arg3 == rnum) ZCMD(i, j).command = '*'; /* Cancel command. */ else if (ZCMD(i, j).arg3 > rnum) ZCMD(i, j).arg3 -= (ZCMD(i, j).arg3 != NOWHERE); /* with unsigned NOWHERE > any rnum */ break; case 'D': case 'R': if (ZCMD(i, j).arg1 == rnum) ZCMD(i, j).command = '*'; /* Cancel command. */ else if (ZCMD(i, j).arg1 > rnum) ZCMD(i, j).arg1 -= (ZCMD(i, j).arg1 != NOWHERE); /* with unsigned NOWHERE > any rnum */ case 'G': case 'P': case 'E': case '*': /* Known zone entries we don't care about. */ break; default: mudlog(BRF, LVL_GOD, TRUE, "SYSERR: GenOLC: delete_room: Unknown zone entry found!"); } /* * Remove this room from all shop lists. */ { extern int top_shop; for (i = 0;i < top_shop;i++) { for (j = 0;SHOP_ROOM(i, j) != NOWHERE;j++) { if (SHOP_ROOM(i, j) == world[rnum].number) SHOP_ROOM(i, j) = 0; /* set to the void */ } } } /* * Now we actually move the rooms down. */ for (i = rnum; i < top_of_world; i++) { world[i] = world[i + 1]; update_wait_events(&world[i], &world[i+1]); for (ppl = world[i].people; ppl; ppl = ppl->next_in_room) IN_ROOM(ppl) -= (IN_ROOM(ppl) != NOWHERE); /* Redundant check? */ for (obj = world[i].contents; obj; obj = obj->next_content) IN_ROOM(obj) -= (IN_ROOM(obj) != NOWHERE); /* Redundant check? */ } top_of_world--; RECREATE(world, struct room_data, top_of_world + 1); return TRUE; }