struct obj_data * roll_joint(struct obj_data *tobac, struct obj_data *paper) { struct obj_data *obj; struct extra_descr_data *new_descr; char buf[200]; if (!tobac || !paper) { errlog(" Attempt to roll_joint with NULL tobac or paper."); return NULL; } obj = make_object(); obj->shared = null_obj_shared; CREATE(new_descr, struct extra_descr_data, 1); snprintf(buf, sizeof(buf), "cig cigarette joint %s", fname(tobac->aliases)); obj->aliases = strdup(buf); snprintf(buf, sizeof(buf), "a %s cigarette", fname(tobac->aliases)); obj->name = strdup(buf); snprintf_cat(buf, sizeof(buf), " has been dropped here.", sizeof(buf), "It looks like a %s cigarette, waiting to be smoked.", fname(tobac->aliases)); new_descr->description = strdup(buf); new_descr->next = NULL; obj->ex_description = new_descr; GET_OBJ_TYPE(obj) = ITEM_CIGARETTE; GET_OBJ_VAL(obj, 0) = 3 + (GET_OBJ_WEIGHT(tobac) * 3); GET_OBJ_VAL(obj, 1) = GET_OBJ_VAL(tobac, 2); GET_OBJ_VAL(obj, 2) = SMOKE_TYPE(tobac); GET_OBJ_WEAR(obj) = ITEM_WEAR_TAKE + ITEM_WEAR_HOLD; GET_OBJ_COST(obj) = GET_OBJ_COST(tobac); return obj; }
int same_obj(struct obj_data * obj1, struct obj_data * obj2) { int index; if (!obj1 || !obj2) return (obj1 == obj2); if (GET_OBJ_RNUM(obj1) != GET_OBJ_RNUM(obj2)) return (FALSE); if (GET_OBJ_COST(obj1) != GET_OBJ_COST(obj2)) return (FALSE); if (GET_OBJ_EXTRA_AR(obj1, 0) != GET_OBJ_EXTRA_AR(obj2, 0) || GET_OBJ_EXTRA_AR(obj1, 1) != GET_OBJ_EXTRA_AR(obj2, 1) || GET_OBJ_EXTRA_AR(obj1, 2) != GET_OBJ_EXTRA_AR(obj2, 2) || GET_OBJ_EXTRA_AR(obj1, 3) != GET_OBJ_EXTRA_AR(obj2, 3)) return (FALSE); for (index = 0; index < MAX_OBJ_AFFECT; index++) if ((obj1->affected[index].location != obj2->affected[index].location) || (obj1->affected[index].modifier != obj2->affected[index].modifier)) return (FALSE); return (TRUE); }
struct obj_data * findCostliestObj(struct creature *ch) { struct obj_data *cur_obj, *result; if (GET_LEVEL(ch) >= LVL_AMBASSADOR) return NULL; result = NULL; cur_obj = ch->carrying; while (cur_obj) { if (cur_obj && (!result || GET_OBJ_COST(result) < GET_OBJ_COST(cur_obj))) result = cur_obj; if (cur_obj->contains) cur_obj = cur_obj->contains; // descend into obj else if (!cur_obj->next_content && cur_obj->in_obj) cur_obj = cur_obj->in_obj->next_content; // ascend out of obj else cur_obj = cur_obj->next_content; // go to next obj } return result; }
/* * This is when the player buys something from the keeper. */ int buy_price(struct char_data *ch, struct obj_data *obj, int shop_nr) { int price = (int) (GET_OBJ_COST(obj) * SHOP_BUYPROFIT(shop_nr)); if (GET_CHA(ch)) price -= price*(GET_CHA(ch)*.005); return (MAX(MAX(price, 1), GET_OBJ_COST(obj))); }
/* * This is when the player sells something to the keeper. */ int sell_price(struct char_data * ch, struct obj_data * obj, int shop_nr) { int bprice = 0; int price = (int) (GET_OBJ_COST(obj) * SHOP_SELLPROFIT(shop_nr)); if (GET_CHA(ch)) price += price*(GET_CHA(ch)*.005); if ( (bprice = buy_price(ch, obj, shop_nr)) < price) price = bprice; return (MIN(MAX(1,price), GET_OBJ_COST(obj))); }
struct obj_data * get_purchase_obj(struct char_data * ch, char *arg, struct char_data * keeper, int shop_nr, int msg) { char buf[MAX_STRING_LENGTH], name[MAX_INPUT_LENGTH]; struct obj_data *obj; one_argument(arg, name); do { if (*name == '#') obj = get_hash_obj_vis(ch, name, keeper->carrying); else obj = get_slide_obj_vis(ch, name, keeper->carrying); if (!obj) { if (msg) { sprintf(buf, shop_index[shop_nr].no_such_item1, GET_NAME(ch)); do_tell(keeper, buf, cmd_tell, 0); } return (0); } if (GET_OBJ_COST(obj) <= 0) { extract_obj(obj); obj = 0; } } while (!obj); return (obj); }
/* Used by James the Butler and the Cleaning Lady */ int is_trash(struct obj_data * i) { if (IS_SET(i->obj_flags.wear_flags, ITEM_WEAR_TAKE) && ((GET_OBJ_TYPE(i) == ITEM_DRINKCON) || (GET_OBJ_COST(i) <= 10))) return TRUE; else return FALSE; }
/* Routine to check if an object is trash. Used by James the Butler and the * Cleaning Lady. */ int is_trash(struct obj_data *i) { if (!OBJWEAR_FLAGGED(i, ITEM_WEAR_TAKE)) return (FALSE); if (GET_OBJ_TYPE(i) == ITEM_DRINKCON || GET_OBJ_COST(i) <= 10) return (TRUE); return (FALSE); }
struct obj_data *create_money(int amount) { struct obj_data *obj; struct extra_descr_data *new_descr; char buf[200]; int y; if (amount <= 0) { log("SYSERR: Try to create negative or 0 money. (%d)", amount); return (NULL); } obj = create_obj(); CREATE(new_descr, struct extra_descr_data, 1); if (amount == 1) { obj->name = strdup("coin gold"); obj->short_description = strdup("a gold coin"); obj->description = strdup("One miserable gold coin is lying here."); new_descr->keyword = strdup("coin gold"); new_descr->description = strdup("It's just one miserable little gold coin."); } else { obj->name = strdup("coins gold"); obj->short_description = strdup(money_desc(amount)); snprintf(buf, sizeof(buf), "%s is lying here.", money_desc(amount)); obj->description = strdup(CAP(buf)); new_descr->keyword = strdup("coins gold"); if (amount < 10) snprintf(buf, sizeof(buf), "There are %d coins.", amount); else if (amount < 100) snprintf(buf, sizeof(buf), "There are about %d coins.", 10 * (amount / 10)); else if (amount < 1000) snprintf(buf, sizeof(buf), "It looks to be about %d coins.", 100 * (amount / 100)); else if (amount < 100000) snprintf(buf, sizeof(buf), "You guess there are, maybe, %d coins.", 1000 * ((amount / 1000) + rand_number(0, (amount / 1000)))); else strcpy(buf, "There are a LOT of coins."); /* strcpy: OK (is < 200) */ new_descr->description = strdup(buf); } new_descr->next = NULL; obj->ex_description = new_descr; GET_OBJ_TYPE(obj) = ITEM_MONEY; for(y = 0; y < TW_ARRAY_MAX; y++) obj->obj_flags.wear_flags[y] = 0; SET_BIT_AR(GET_OBJ_WEAR(obj), ITEM_WEAR_TAKE); GET_OBJ_VAL(obj, 0) = amount; GET_OBJ_COST(obj) = amount; obj->item_number = NOTHING; return (obj); }
void postmaster_receive_mail (struct char_data *ch, struct char_data *mailman, int cmd, char *arg) { char buf[256]; struct obj_data *obj; if (!has_mail (GET_IDNUM (ch))) { sprintf (buf, "$n tells you, 'Sorry, you don't have any mail waiting.'"); act (buf, FALSE, mailman, 0, ch, TO_VICT); return; } while (has_mail (GET_IDNUM (ch))) { obj = create_obj (); obj->item_number = NOTHING; obj->name = str_dup ("mail paper letter"); obj->short_description = str_dup ("a piece of mail"); obj->description = str_dup ("Someone has left a piece of mail here."); GET_OBJ_TYPE (obj) = ITEM_NOTE; GET_OBJ_WEAR (obj) = ITEM_WEAR_TAKE | ITEM_WEAR_HOLD; GET_OBJ_WEIGHT (obj) = 1; GET_OBJ_COST (obj) = 30; GET_OBJ_RENT (obj) = 10; obj->action_description = read_delete (GET_IDNUM (ch)); if (obj->action_description == NULL) obj->action_description = str_dup ("Mail system error - please report. Error #11.\r\n"); obj_to_char (obj, ch); act ("$n gives you a piece of mail.", FALSE, mailman, 0, ch, TO_VICT); act ("$N gives $n a piece of mail.", FALSE, ch, 0, mailman, TO_ROOM); } }
int trade_with(struct obj_data * item, int shop_nr) { int counter; if (GET_OBJ_COST(item) < 1) return (OBJECT_NOTOK); if (IS_OBJ_STAT(item, ITEM_NOSELL)) return (OBJECT_NOTOK); for (counter = 0; SHOP_BUYTYPE(shop_nr, counter) != NOTHING; counter++) if (SHOP_BUYTYPE(shop_nr, counter) == GET_OBJ_TYPE(item)) { if ((GET_OBJ_VAL(item, 2) == 0) && ((GET_OBJ_TYPE(item) == ITEM_WAND) || (GET_OBJ_TYPE(item) == ITEM_STAFF))) return (OBJECT_DEAD); else if (evaluate_expression(item, SHOP_BUYWORD(shop_nr, counter))) return (OBJECT_OK); } return (OBJECT_NOTOK); }
/* * Display main menu. */ void oedit_disp_menu(struct descriptor_data *d) { char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; struct obj_data *obj; obj = OLC_OBJ(d); get_char_colors(d->character); clear_screen(d); /* * Build buffers for first part of menu. */ sprinttype(GET_OBJ_TYPE(obj), item_types, buf1, sizeof(buf1)); sprintbit(GET_OBJ_EXTRA(obj), extra_bits, buf2, sizeof(buf2)); /* * Build first half of menu. */ write_to_output(d, "-- Item number : [%s%d%s]\r\n" "%s1%s) Namelist : %s%s\r\n" "%s2%s) S-Desc : %s%s\r\n" "%s3%s) L-Desc :-\r\n%s%s\r\n" "%s4%s) A-Desc :-\r\n%s%s" "%s5%s) Type : %s%s\r\n" "%s6%s) Extra flags : %s%s\r\n", cyn, OLC_NUM(d), nrm, grn, nrm, yel, (obj->name && *obj->name) ? obj->name : "undefined", grn, nrm, yel, (obj->short_description && *obj->short_description) ? obj->short_description : "undefined", grn, nrm, yel, (obj->description && *obj->description) ? obj->description : "undefined", grn, nrm, yel, (obj->action_description && *obj->action_description) ? obj->action_description : "<not set>\r\n", grn, nrm, cyn, buf1, grn, nrm, cyn, buf2 ); /* * Send first half. */ /* * Build second half of menu. */ sprintbit(GET_OBJ_WEAR(obj), wear_bits, buf1, sizeof(buf1)); sprintbit(GET_OBJ_PERM(obj), affected_bits, buf2, sizeof(buf2)); write_to_output(d, "%s7%s) Wear flags : %s%s\r\n" "%s8%s) Weight : %s%d\r\n" "%s9%s) Cost : %s%d\r\n" "%sA%s) Cost/Day : %s%d\r\n" "%sB%s) Timer : %s%d\r\n" "%sC%s) Values : %s%d %d %d %d\r\n" "%sD%s) Applies menu\r\n" "%sE%s) Extra descriptions menu\r\n" "%sM%s) Min Level : %s%d\r\n" "%sP%s) Perm Affects: %s%s\r\n" "%sS%s) Script : %s%s\r\n" "%sQ%s) Quit\r\n" "Enter choice : ", grn, nrm, cyn, buf1, grn, nrm, cyn, GET_OBJ_WEIGHT(obj), grn, nrm, cyn, GET_OBJ_COST(obj), grn, nrm, cyn, GET_OBJ_RENT(obj), grn, nrm, cyn, GET_OBJ_TIMER(obj), grn, nrm, cyn, GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), grn, nrm, grn, nrm, grn, nrm, cyn, GET_OBJ_LEVEL(obj), grn, nrm, cyn, buf2, grn, nrm, cyn, OLC_SCRIPT(d) ? "Set." : "Not Set.", grn, nrm ); OLC_MODE(d) = OEDIT_MAIN_MENU; }
int save_objects(zone_rnum zone_num) { char fname[128], buf[MAX_STRING_LENGTH]; char ebuf1[MAX_STRING_LENGTH], ebuf2[MAX_STRING_LENGTH]; char ebuf3[MAX_STRING_LENGTH], ebuf4[MAX_STRING_LENGTH]; char wbuf1[MAX_STRING_LENGTH], wbuf2[MAX_STRING_LENGTH]; char wbuf3[MAX_STRING_LENGTH], wbuf4[MAX_STRING_LENGTH]; char pbuf1[MAX_STRING_LENGTH], pbuf2[MAX_STRING_LENGTH]; char pbuf3[MAX_STRING_LENGTH], pbuf4[MAX_STRING_LENGTH]; int counter, counter2, realcounter; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; #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_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } snprintf(fname, sizeof(fname), "%s%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(fname, "w+"))) { mudlog(BRF, LVL_IMMORT, TRUE, "SYSERR: OLC: Cannot open objects file %s!", fname); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = genolc_zone_bottom(zone_num); counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) != NOTHING) { if ((obj = &obj_proto[realcounter])->action_description) { strncpy(buf, obj->action_description, sizeof(buf) - 1); strip_cr(buf); } else *buf = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : "undefined", (obj->short_description && *obj->short_description) ? obj->short_description : "undefined", (obj->description && *obj->description) ? obj->description : "undefined", buf); sprintascii(ebuf1, GET_OBJ_EXTRA(obj)[0]); sprintascii(ebuf2, GET_OBJ_EXTRA(obj)[1]); sprintascii(ebuf3, GET_OBJ_EXTRA(obj)[2]); sprintascii(ebuf4, GET_OBJ_EXTRA(obj)[3]); sprintascii(wbuf1, GET_OBJ_WEAR(obj)[0]); sprintascii(wbuf2, GET_OBJ_WEAR(obj)[1]); sprintascii(wbuf3, GET_OBJ_WEAR(obj)[2]); sprintascii(wbuf4, GET_OBJ_WEAR(obj)[3]); sprintascii(pbuf1, GET_OBJ_PERM(obj)[0]); sprintascii(pbuf2, GET_OBJ_PERM(obj)[1]); sprintascii(pbuf3, GET_OBJ_PERM(obj)[2]); sprintascii(pbuf4, GET_OBJ_PERM(obj)[3]); fprintf(fp, "%d %s %s %s %s %s %s %s %s %s %s %s %s\n" "%d %d %d %d\n" "%d %d %d %d\n", GET_OBJ_TYPE(obj), ebuf1, ebuf2, ebuf3, ebuf4, wbuf1, wbuf2, wbuf3, wbuf4, pbuf1, pbuf2, pbuf3, pbuf4, GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj) ); /* * Do we have script(s) attached ? */ script_save_to_disk(fp, obj, OBJ_TRIGGER); /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog(BRF, LVL_IMMORT, TRUE, "SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!"); continue; } strncpy(buf, ex_desc->description, sizeof(buf) - 1); strip_cr(buf); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); snprintf(buf, sizeof(buf), "%s%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf); rename(fname, buf); if (in_save_list(zone_table[zone_num].number, SL_OBJ)) { remove_from_save_list(zone_table[zone_num].number, SL_OBJ); create_world_index(zone_table[zone_num].number, "obj"); log("GenOLC: save_objects: Saving objects '%s'", buf); } return TRUE; } /* * Free all, unconditionally. */ void free_object_strings(struct obj_data *obj) { #if 0 /* Debugging, do not enable. */ extern struct obj_data *object_list; struct obj_data *t; int i = 0; for (t = object_list; t; t = t->next) { if (t == obj) { i++; continue; } assert(obj->name != t->name); assert(obj->description != t->description); assert(obj->short_description != t->short_description); assert(obj->action_description != t->action_description); assert(obj->ex_description != t->ex_description); } assert(i <= 1); #endif if (obj->name) free(obj->name); if (obj->description) free(obj->description); if (obj->short_description) free(obj->short_description); if (obj->action_description) free(obj->action_description); if (obj->ex_description) free_ex_descriptions(obj->ex_description); } /* * For object instances that are not the prototype. */ void free_object_strings_proto(struct obj_data *obj) { int robj_num = GET_OBJ_RNUM(obj); if (obj->name && obj->name != obj_proto[robj_num].name) free(obj->name); if (obj->description && obj->description != obj_proto[robj_num].description) free(obj->description); if (obj->short_description && obj->short_description != obj_proto[robj_num].short_description) free(obj->short_description); if (obj->action_description && obj->action_description != obj_proto[robj_num].action_description) free(obj->action_description); if (obj->ex_description) { struct extra_descr_data *thised, *plist, *next_one; /* O(horrible) */ int ok_key, ok_desc, ok_item; for (thised = obj->ex_description; thised; thised = next_one) { next_one = thised->next; for (ok_item = ok_key = ok_desc = 1, plist = obj_proto[robj_num].ex_description; plist; plist = plist->next) { if (plist->keyword == thised->keyword) ok_key = 0; if (plist->description == thised->description) ok_desc = 0; if (plist == thised) ok_item = 0; } if (thised->keyword && ok_key) free(thised->keyword); if (thised->description && ok_desc) free(thised->description); if (ok_item) free(thised); } } }
int save_objects(zone_rnum zone_num) { int counter, counter2, realcounter; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; if (zone_num < 0 || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } sprintf(buf, "%s/%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(buf, "w+"))) { mudlog("SYSERR: OLC: Cannot open objects file!", BRF, LVL_IMMORT, TRUE); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = zone_table[zone_num].number * 100; counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) >= 0) { if ((obj = &obj_proto[realcounter])->action_description) { buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, obj->action_description, MAX_STRING_LENGTH - 1); strip_cr(buf1); } else *buf1 = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n" "%d %d %d %ld\n" "%d %d %d %d\n" "%d %d %d %d\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : "undefined", (obj->short_description && *obj->short_description) ? obj->short_description : "undefined", (obj->description && *obj->description) ? obj->description : "undefined", buf1, GET_OBJ_TYPE(obj), GET_OBJ_EXTRA(obj), GET_OBJ_WEAR(obj), GET_OBJ_PERM(obj), GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj)); script_save_to_disk(fp, obj, OBJ_TRIGGER); /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog("SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!", BRF, LVL_IMMORT, TRUE); continue; } buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, ex_desc->description, MAX_STRING_LENGTH - 1); strip_cr(buf1); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); /* And now the spec-proc */ if (obj_index[realcounter].func != NULL) fprintf(fp, "S\n%s\n", obj_procs[get_spec_name(obj_procs, obj_index[realcounter].func)].name); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); sprintf(buf2, "%s/%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[zone_num].number, SL_OBJ); return TRUE; }
void do_obj_report (struct char_data *ch) { struct obj_data *obj, *key; int i=0, j=0, found=0; FILE *reportfile; if (!(reportfile = fopen("report.obj", "w"))) { mlog("SYSERR: Object report file unavailable."); send_to_char ("Report.obj could not be generated.\r\n",ch); return; } sprintf(buf, "OBJECTS\n-------\n"); for (i=0; i<top_of_objt;i++) { obj=read_object(i, REAL); sprintf(buf+strlen(buf), "[%5d] %s\nSpec Proc: ", GET_OBJ_VNUM(obj), obj->short_description); if (obj_index[GET_OBJ_RNUM(obj)].func!=NULL) get_spec_name(GET_OBJ_RNUM(obj), buf2,'o'); else sprintf(buf2, "none"); sprintf(buf+strlen(buf), "%s Aliases: %s\n", buf2, GET_OBJ_NAME(obj)); sprinttype(GET_OBJ_TYPE(obj), item_types, buf2, sizeof(buf2)); sprintf (buf+strlen(buf),"Type: %s Worn on: ",buf2); sprintbit(obj->obj_flags.wear_flags, wear_bits, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), "%s\n", buf2); sprintf(buf+strlen(buf), "Weight: %d, Value: %d, Cost/day: %d, Timer: %d\n", GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_TIMER(obj)); sprintbit(obj->obj_flags.bitvector, affected_bits, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), "Affects player: %s\n",buf2); sprintbit(obj->obj_flags.bitvector, affected_bits, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), "Extra bits: %s\n",buf2); switch (GET_OBJ_TYPE(obj)) { case ITEM_LIGHT: if (GET_OBJ_VAL(obj, 2) == -1) strcpy(buf, "Hours left: Infinite\n"); else sprintf(buf+strlen(buf), "Hours left: [%d]\n", GET_OBJ_VAL(obj, 2)); break; case ITEM_SCROLL: case ITEM_POTION: sprintf(buf+strlen(buf), "Spells: (Level %d) %s, %s, %s\n", GET_OBJ_VAL(obj, 0), skill_name(GET_OBJ_VAL(obj, 1)), skill_name(GET_OBJ_VAL(obj, 2)), skill_name(GET_OBJ_VAL(obj, 3))); break; case ITEM_WAND: case ITEM_STAFF: sprintf(buf+strlen(buf), "Spell: %s at level %d, %d (of %d) charges remaining\n", skill_name(GET_OBJ_VAL(obj, 3)), GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 1)); break; case ITEM_WEAPON: sprintf(buf+strlen(buf), "Ave. Dam: %d, Message type: %d\n", get_weapon_dam(obj), GET_OBJ_VAL(obj, 3)); break; case ITEM_ARMOR: sprintf(buf+strlen(buf), "Passive Defense: [%d]\n", GET_OBJ_VAL(obj, 0)); sprintf(buf+strlen(buf), "Damage Reduction: [%d]\n", GET_OBJ_VAL(obj, 1)); break; case ITEM_TRAP: sprintf(buf+strlen(buf), "Spell: %d, - Hitpoints: %d\n", GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1)); break; case ITEM_CONTAINER: sprintbit(GET_OBJ_VAL(obj, 1), container_bits, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), "Weight capacity: %d, Lock Type: %s, Key Num: %d ", GET_OBJ_VAL(obj, 0), buf2, GET_OBJ_VAL(obj, 2)); if (GET_OBJ_VAL(obj, 2) > 0) { key=read_object(GET_OBJ_VAL(obj,2), VIRTUAL); if (key) { sprintf(buf+strlen(buf), "(%s)", GET_OBJ_NAME(key)); extract_obj(key); } else sprintf(buf+strlen(buf), "(Error: Key does not exist!)"); } sprintf(buf+strlen(buf), "\n"); break; case ITEM_DRINKCON: case ITEM_FOUNTAIN: sprinttype(GET_OBJ_VAL(obj, 2), drinks, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), "Capacity: %d, Contains: %d, Poisoned: %s, Liquid: %s\n", GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), YESNO(GET_OBJ_VAL(obj, 3)),buf2); break; case ITEM_FOOD: sprintf(buf+strlen(buf), "Makes full: %d, Poisoned: %s\n", GET_OBJ_VAL(obj, 0),YESNO(GET_OBJ_VAL(obj, 3))); break; case ITEM_MONEY: sprintf(buf, "Coins: %d\n", GET_OBJ_VAL(obj, 0)); break; case ITEM_PORTAL: sprintf(buf, "To room: %d\n", GET_OBJ_VAL(obj, 0)); break; default: sprintf(buf+strlen(buf), "Values 0-3: [%d] [%d] [%d] [%d]\n", GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3)); break; } found = 0; sprintf(buf+strlen(buf), "Affects on player stats:\n"); for (j = 0; j < MAX_OBJ_AFFECT; j++) if (obj->affected[j].modifier) { sprinttype(obj->affected[j].location, apply_types, buf2, sizeof(buf2)); sprintf(buf+strlen(buf), " %+d to %s\n",obj->affected[j].modifier, buf2); found=1; } if (!found) sprintf(buf+strlen(buf)," None\n"); sprintf(buf+strlen(buf), "\n--------\n"); extract_obj(obj); fprintf(reportfile, buf); buf[0]='\0'; }/*for i=0...*/ fclose (reportfile); send_to_char ("report.obj printed\r\n",ch); }
struct obj_data *create_money(struct money_data amount) { struct obj_data *obj; struct extra_descr_data *new_descr; char buf[200]; int coins; if ( money_to_copper(amount) <= 0) { log("SYSERR: Try to create negative or 0 money."); return NULL; } obj = create_obj(); CREATE(new_descr, struct extra_descr_data, 1); coins = amount.platinum + amount.steel + amount.gold + amount.copper; if (coins == 1) { obj->name = str_dup("one coin"); obj->short_description = str_dup("a coin"); obj->description = str_dup("One miserable coin is lying here."); new_descr->keyword = str_dup("coin"); new_descr->description = str_dup("It's just one miserable little coin."); } else { obj->name = str_dup("coins"); obj->short_description = str_dup(money_desc(coins)); sprintf(buf, "%s is lying here.", money_desc(coins)); obj->description = str_dup(CAP(buf)); new_descr->keyword = str_dup("coins"); if (coins < 10) { sprintf(buf, "There are %d coins.", coins); new_descr->description = str_dup(buf); } else if (coins < 100) { sprintf(buf, "There are about %d coins.", 10 * (coins / 10)); new_descr->description = str_dup(buf); } else if (coins < 1000) { sprintf(buf, "It looks to be about %d coins.", 100 * (coins / 100)); new_descr->description = str_dup(buf); } else if (coins < 100000) { sprintf(buf, "You guess there are, maybe, %d coins.", 1000 * ((coins / 1000) + number(0, (coins / 1000)))); new_descr->description = str_dup(buf); } else new_descr->description = str_dup("There are a LOT of coins."); } new_descr->next = NULL; obj->ex_description = new_descr; GET_OBJ_TYPE(obj) = ITEM_MONEY; GET_OBJ_WEAR(obj) = ITEM_WEAR_TAKE; GET_OBJ_VAL(obj, 0) = amount.platinum; GET_OBJ_VAL(obj, 1) = amount.steel; GET_OBJ_VAL(obj, 2) = amount.gold; GET_OBJ_VAL(obj, 3) = amount.copper; GET_OBJ_COST(obj) = money_to_copper(amount); obj->item_number = NOTHING; return obj; }
void oedit_parse(struct descriptor_data *d, char *arg) { int number, max_val, min_val; char *oldtext = NULL; struct board_info *tmp; struct obj_data *obj; obj_rnum robj; switch (OLC_MODE(d)) { case OEDIT_CONFIRM_SAVESTRING: switch (*arg) { case 'y': case 'Y': oedit_save_internally(d); mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, "OLC: %s edits obj %d", GET_NAME(d->character), OLC_NUM(d)); if (CONFIG_OLC_SAVE) { oedit_save_to_disk(real_zone_by_thing(OLC_NUM(d))); write_to_output(d, "Object saved to disk.\r\n"); } else write_to_output(d, "Object saved to memory.\r\n"); if (GET_OBJ_TYPE(OLC_OBJ(d)) == ITEM_BOARD) { if ((tmp=locate_board(GET_OBJ_VNUM(OLC_OBJ(d)))) != NULL) { save_board(tmp); } else { tmp = create_new_board(GET_OBJ_VNUM(OLC_OBJ(d))); BOARD_NEXT(tmp) = bboards; bboards = tmp; } } /* Fall through. */ case 'n': case 'N': cleanup_olc(d, CLEANUP_ALL); return; case 'a': /* abort quit */ case 'A': oedit_disp_menu(d); return; default: write_to_output(d, "Invalid choice!\r\n"); write_to_output(d, "Do you wish to save your changes? : \r\n"); return; } case OEDIT_MAIN_MENU: /* * Throw us out to whichever edit mode based on user input. */ switch (*arg) { case 'q': case 'Q': if (STATE(d) != CON_IEDIT) { if (OLC_VAL(d)) { /* Something has been modified. */ write_to_output(d, "Do you wish to save your changes? : "); OLC_MODE(d) = OEDIT_CONFIRM_SAVESTRING; } else cleanup_olc(d, CLEANUP_ALL); } else { send_to_char(d->character, "\r\nCommitting iedit changes.\r\n"); obj = OLC_IOBJ(d); *obj = *(OLC_OBJ(d)); GET_ID(obj) = max_obj_id++; /* find_obj helper */ add_to_lookup_table(GET_ID(obj), (void *)obj); if (GET_OBJ_VNUM(obj) != NOTHING) { /* remove any old scripts */ if (SCRIPT(obj)) { extract_script(obj, OBJ_TRIGGER); SCRIPT(obj) = NULL; } free_proto_script(obj, OBJ_TRIGGER); robj = real_object(GET_OBJ_VNUM(obj)); copy_proto_script(&obj_proto[robj], obj, OBJ_TRIGGER); assign_triggers(obj, OBJ_TRIGGER); } SET_BIT_AR(GET_OBJ_EXTRA(obj), ITEM_UNIQUE_SAVE); /* Xap - ought to save the old pointer, free after assignment I suppose */ mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, "OLC: %s iedit a unique #%d", GET_NAME(d->character), GET_OBJ_VNUM(obj)); if (d->character) { REMOVE_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING); STATE(d) = CON_PLAYING; act("$n stops using OLC.", TRUE, d->character, 0, 0, TO_ROOM); } free(d->olc); d->olc = NULL; } return; case '1': write_to_output(d, "Enter namelist : "); OLC_MODE(d) = OEDIT_EDIT_NAMELIST; break; case '2': write_to_output(d, "Enter short desc : "); OLC_MODE(d) = OEDIT_SHORTDESC; break; case '3': write_to_output(d, "Enter long desc :-\r\n| "); OLC_MODE(d) = OEDIT_LONGDESC; break; case '4': OLC_MODE(d) = OEDIT_ACTDESC; send_editor_help(d); write_to_output(d, "Enter action description:\r\n\r\n"); if (OLC_OBJ(d)->action_description) { write_to_output(d, "%s", OLC_OBJ(d)->action_description); oldtext = strdup(OLC_OBJ(d)->action_description); } string_write(d, &OLC_OBJ(d)->action_description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; break; case '5': oedit_disp_type_menu(d); OLC_MODE(d) = OEDIT_TYPE; break; case '6': oedit_disp_extra_menu(d); OLC_MODE(d) = OEDIT_EXTRAS; break; case '7': oedit_disp_wear_menu(d); OLC_MODE(d) = OEDIT_WEAR; break; case '8': write_to_output(d, "Enter weight : "); OLC_MODE(d) = OEDIT_WEIGHT; break; case '9': write_to_output(d, "Enter cost : "); OLC_MODE(d) = OEDIT_COST; break; case 'a': case 'A': write_to_output(d, "Enter cost per day : "); OLC_MODE(d) = OEDIT_COSTPERDAY; break; case 'b': case 'B': write_to_output(d, "Enter timer : "); OLC_MODE(d) = OEDIT_TIMER; break; case 'c': case 'C': /* * Clear any old values */ GET_OBJ_VAL(OLC_OBJ(d), 0) = 0; GET_OBJ_VAL(OLC_OBJ(d), 1) = 0; GET_OBJ_VAL(OLC_OBJ(d), 2) = 0; GET_OBJ_VAL(OLC_OBJ(d), 3) = 0; OLC_VAL(d) = 1; oedit_disp_val1_menu(d); break; case 'd': case 'D': oedit_disp_prompt_apply_menu(d); break; case 'e': case 'E': /* * If extra descriptions don't exist. */ if (OLC_OBJ(d)->ex_description == NULL) { CREATE(OLC_OBJ(d)->ex_description, struct extra_descr_data, 1); OLC_OBJ(d)->ex_description->next = NULL; } OLC_DESC(d) = OLC_OBJ(d)->ex_description; oedit_disp_extradesc_menu(d); break; case 'm': case 'M': write_to_output(d, "Enter new minimum level: "); OLC_MODE(d) = OEDIT_LEVEL; break; case 'p': case 'P': oedit_disp_perm_menu(d); OLC_MODE(d) = OEDIT_PERM; break; case 's': case 'S': if (STATE(d) != CON_IEDIT) { OLC_SCRIPT_EDIT_MODE(d) = SCRIPT_MAIN_MENU; dg_script_menu(d); } else { write_to_output(d, "\r\nScripts cannot be modified on individual objects.\r\nEnter choice : "); } return; default: oedit_disp_menu(d); break; } return; /* * end of OEDIT_MAIN_MENU */ case OLC_SCRIPT_EDIT: if (dg_script_edit_parse(d, arg)) return; break; case OEDIT_EDIT_NAMELIST: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->name) free(OLC_OBJ(d)->name); OLC_OBJ(d)->name = str_udup(arg); break; case OEDIT_SHORTDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->short_description) free(OLC_OBJ(d)->short_description); OLC_OBJ(d)->short_description = str_udup(arg); break; case OEDIT_LONGDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->description) free(OLC_OBJ(d)->description); OLC_OBJ(d)->description = str_udup(arg); break; case OEDIT_TYPE: number = atoi(arg); if ((number < 1) || (number >= NUM_ITEM_TYPES)) { write_to_output(d, "Invalid choice, try again : "); return; } else GET_OBJ_TYPE(OLC_OBJ(d)) = number; /* what's the boundschecking worth if we don't do this ? -- Welcor */ GET_OBJ_VAL(OLC_OBJ(d), 0) = GET_OBJ_VAL(OLC_OBJ(d), 1) = GET_OBJ_VAL(OLC_OBJ(d), 2) = GET_OBJ_VAL(OLC_OBJ(d), 3) = 0; break; case OEDIT_EXTRAS: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_FLAGS)) { oedit_disp_extra_menu(d); return; } else if (number == 0) break; else { TOGGLE_BIT_AR(GET_OBJ_EXTRA(OLC_OBJ(d)), number - 1); oedit_disp_extra_menu(d); return; } case OEDIT_WEAR: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_WEARS)) { write_to_output(d, "That's not a valid choice!\r\n"); oedit_disp_wear_menu(d); return; } else if (number == 0) /* Quit. */ break; else { TOGGLE_BIT_AR(GET_OBJ_WEAR(OLC_OBJ(d)), (number - 1)); oedit_disp_wear_menu(d); return; } case OEDIT_WEIGHT: GET_OBJ_WEIGHT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_WEIGHT); break; case OEDIT_COST: GET_OBJ_COST(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_COST); break; case OEDIT_COSTPERDAY: GET_OBJ_RENT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_RENT); break; case OEDIT_TIMER: switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_PORTAL: GET_OBJ_TIMER(OLC_OBJ(d)) = LIMIT(atoi(arg), -1, MAX_OBJ_TIMER); break; default: GET_OBJ_TIMER(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_TIMER); break; } break; case OEDIT_LEVEL: GET_OBJ_LEVEL(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, LVL_IMPL); break; case OEDIT_PERM: if ((number = atoi(arg)) == 0) break; if (number > 0 && number <= NUM_AFF_FLAGS) { /* Setting AFF_CHARM on objects like this is dangerous. */ if (number != AFF_CHARM) { TOGGLE_BIT_AR(GET_OBJ_PERM(OLC_OBJ(d)), number); } } oedit_disp_perm_menu(d); return; case OEDIT_VALUE_1: /* * Lucky, I don't need to check any of these for out of range values. * Hmm, I'm not so sure - Rv */ switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_WEAPON: GET_OBJ_VAL(OLC_OBJ(d), 0) = MIN(MAX(atoi(arg), -50), 50); break; case ITEM_CONTAINER: GET_OBJ_VAL(OLC_OBJ(d), 0) = LIMIT(atoi(arg), -1, MAX_CONTAINER_SIZE); break; default: GET_OBJ_VAL(OLC_OBJ(d), 0) = atoi(arg); } /* * proceed to menu 2 */ oedit_disp_val2_menu(d); return; case OEDIT_VALUE_2: /* * Here, I do need to check for out of range values. */ number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) GET_OBJ_VAL(OLC_OBJ(d), 1) = -1; else GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, NUM_SPELLS-1); oedit_disp_val3_menu(d); break; case ITEM_CONTAINER: case ITEM_VEHICLE: case ITEM_HATCH: case ITEM_WINDOW: case ITEM_PORTAL: /* * Needs some special handling since we are dealing with flag values * here. */ if (number < 0 || number > 4) oedit_disp_container_flags_menu(d); else if (number != 0) { TOGGLE_BIT(GET_OBJ_VAL(OLC_OBJ(d), 1), 1 << (number - 1)); OLC_VAL(d) = 1; oedit_disp_val2_menu(d); } else oedit_disp_val3_menu(d); break; case ITEM_WEAPON: GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, MAX_WEAPON_NDICE); oedit_disp_val3_menu(d); break; default: GET_OBJ_VAL(OLC_OBJ(d), 1) = number; oedit_disp_val3_menu(d); } return; case OEDIT_VALUE_3: number = atoi(arg); /* * Quick'n'easy error checking. */ switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) { GET_OBJ_VAL(OLC_OBJ(d), 2) = -1; oedit_disp_val4_menu(d); return; } min_val = 1; max_val = NUM_SPELLS - 1; break; case ITEM_WEAPON: min_val = 1; max_val = MAX_WEAPON_SDICE; break; case ITEM_WAND: case ITEM_STAFF: min_val = 0; max_val = 20; break; case ITEM_DRINKCON: case ITEM_FOUNTAIN: min_val = 0; max_val = NUM_LIQ_TYPES - 1; break; case ITEM_KEY: min_val = 0; max_val = 32099; break; default: min_val = -32000; max_val = 32000; } GET_OBJ_VAL(OLC_OBJ(d), 2) = LIMIT(number, min_val, max_val); oedit_disp_val4_menu(d); return; case OEDIT_VALUE_4: number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) { GET_OBJ_VAL(OLC_OBJ(d), 3) = -1; oedit_disp_menu(d); return; } min_val = 1; max_val = NUM_SPELLS - 1; break; case ITEM_WAND: case ITEM_STAFF: min_val = 1; max_val = NUM_SPELLS - 1; break; case ITEM_WEAPON: min_val = 0; max_val = NUM_ATTACK_TYPES - 1; break; default: min_val = -32000; max_val = 32000; break; } GET_OBJ_VAL(OLC_OBJ(d), 3) = LIMIT(number, min_val, max_val); break; case OEDIT_PROMPT_APPLY: if ((number = atoi(arg)) == 0) break; else if (number < 0 || number > MAX_OBJ_AFFECT) { oedit_disp_prompt_apply_menu(d); return; } OLC_VAL(d) = number - 1; OLC_MODE(d) = OEDIT_APPLY; oedit_disp_apply_menu(d); return; case OEDIT_APPLY: if ((number = atoi(arg)) == 0) { OLC_OBJ(d)->affected[OLC_VAL(d)].location = 0; OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = 0; oedit_disp_prompt_apply_menu(d); } else if (number < 0 || number >= NUM_APPLIES) oedit_disp_apply_menu(d); else { int counter; /* add in check here if already applied.. deny builders another */ if (GET_LEVEL(d->character) < LVL_IMPL) { for (counter = 0; counter < MAX_OBJ_AFFECT; counter++) { if (OLC_OBJ(d)->affected[counter].location == number) { write_to_output(d, "Object already has that apply."); return; } } } OLC_OBJ(d)->affected[OLC_VAL(d)].location = number; write_to_output(d, "Modifier : "); OLC_MODE(d) = OEDIT_APPLYMOD; } return; case OEDIT_APPLYMOD: OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = atoi(arg); oedit_disp_prompt_apply_menu(d); return; case OEDIT_EXTRADESC_KEY: if (genolc_checkstring(d, arg)) { if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); OLC_DESC(d)->keyword = str_udup(arg); } oedit_disp_extradesc_menu(d); return; case OEDIT_EXTRADESC_MENU: switch ((number = atoi(arg))) { case 0: if (!OLC_DESC(d)->keyword || !OLC_DESC(d)->description) { struct extra_descr_data *temp; if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); if (OLC_DESC(d)->description) free(OLC_DESC(d)->description); /* * Clean up pointers */ REMOVE_FROM_LIST(OLC_DESC(d), OLC_OBJ(d)->ex_description, next); free(OLC_DESC(d)); OLC_DESC(d) = NULL; } break; case 1: OLC_MODE(d) = OEDIT_EXTRADESC_KEY; write_to_output(d, "Enter keywords, separated by spaces :-\r\n| "); return; case 2: OLC_MODE(d) = OEDIT_EXTRADESC_DESCRIPTION; send_editor_help(d); write_to_output(d, "Enter the extra description:\r\n\r\n"); if (OLC_DESC(d)->description) { write_to_output(d, "%s", OLC_DESC(d)->description); oldtext = strdup(OLC_DESC(d)->description); } string_write(d, &OLC_DESC(d)->description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; return; case 3: /* * Only go to the next description if this one is finished. */ if (OLC_DESC(d)->keyword && OLC_DESC(d)->description) { struct extra_descr_data *new_extra; if (OLC_DESC(d)->next) OLC_DESC(d) = OLC_DESC(d)->next; else { /* Make new extra description and attach at end. */ CREATE(new_extra, struct extra_descr_data, 1); OLC_DESC(d)->next = new_extra; OLC_DESC(d) = OLC_DESC(d)->next; } } /* * No break - drop into default case. */ default: oedit_disp_extradesc_menu(d); return; } break; default: mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: Reached default case in oedit_parse()!"); write_to_output(d, "Oops...\r\n"); break; }
void mobile_activity(void) { struct char_data *ch, *next_ch, *vict; struct obj_data *obj, *best_obj; int door, found, max; memory_rec *names; for (ch = character_list; ch; ch = next_ch) { next_ch = ch->next; if (!IS_MOB(ch)) continue; /* Examine call for special procedure */ if (MOB_FLAGGED(ch, MOB_SPEC) && !no_specials) { if (mob_index[GET_MOB_RNUM(ch)].func == NULL) { log("SYSERR: %s (#%d): Attempting to call non-existing mob function.", GET_NAME(ch), GET_MOB_VNUM(ch)); REMOVE_BIT_AR(MOB_FLAGS(ch), MOB_SPEC); } else { char actbuf[MAX_INPUT_LENGTH] = ""; if ((mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, actbuf)) continue; /* go to next char */ } } /* If the mob has no specproc, do the default actions */ if (FIGHTING(ch) || !AWAKE(ch)) continue; /* hunt a victim, if applicable */ hunt_victim(ch); /* Scavenger (picking up objects) */ if (MOB_FLAGGED(ch, MOB_SCAVENGER)) if (world[IN_ROOM(ch)].contents && !rand_number(0, 10)) { max = 1; best_obj = NULL; for (obj = world[IN_ROOM(ch)].contents; obj; obj = obj->next_content) if (CAN_GET_OBJ(ch, obj) && GET_OBJ_COST(obj) > max) { best_obj = obj; max = GET_OBJ_COST(obj); } if (best_obj != NULL) { obj_from_room(best_obj); obj_to_char(best_obj, ch); act("$n gets $p.", FALSE, ch, best_obj, 0, TO_ROOM); } } /* Mob Movement */ if (!MOB_FLAGGED(ch, MOB_SENTINEL) && (GET_POS(ch) == POS_STANDING) && ((door = rand_number(0, 18)) < DIR_COUNT) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_DEATH) && (!MOB_FLAGGED(ch, MOB_STAY_ZONE) || (world[EXIT(ch, door)->to_room].zone == world[IN_ROOM(ch)].zone))) { /* If the mob is charmed, do not move the mob. */ if (ch->master == NULL) perform_move(ch, door, 1); } /* Aggressive Mobs */ if (!MOB_FLAGGED(ch, MOB_HELPER) && (!AFF_FLAGGED(ch, AFF_BLIND) || !AFF_FLAGGED(ch, AFF_CHARM))) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (IS_NPC(vict) || !CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; if (MOB_FLAGGED(ch, MOB_WIMPY) && AWAKE(vict)) continue; if (MOB_FLAGGED(ch, MOB_AGGRESSIVE ) || (MOB_FLAGGED(ch, MOB_AGGR_EVIL ) && IS_EVIL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_NEUTRAL) && IS_NEUTRAL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_GOOD ) && IS_GOOD(vict))) { /* Can a master successfully control the charmed monster? */ if (aggressive_mob_on_a_leash(ch, ch->master, vict)) continue; hit(ch, vict, TYPE_UNDEFINED); found = TRUE; } } } /* Mob Memory */ if (MOB_FLAGGED(ch, MOB_MEMORY) && MEMORY(ch)) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (IS_NPC(vict) || !CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; for (names = MEMORY(ch); names && !found; names = names->next) { if (names->id != GET_IDNUM(vict)) continue; /* Can a master successfully control the charmed monster? */ if (aggressive_mob_on_a_leash(ch, ch->master, vict)) continue; found = TRUE; act("'Hey! You're the fiend that attacked me!!!', exclaims $n.", FALSE, ch, 0, 0, TO_ROOM); hit(ch, vict, TYPE_UNDEFINED); } } } /* Charmed Mob Rebellion: In order to rebel, there need to be more charmed * monsters than the person can feasibly control at a time. Then the * mobiles have a chance based on the charisma of their leader. * 1-4 = 0, 5-7 = 1, 8-10 = 2, 11-13 = 3, 14-16 = 4, 17-19 = 5, etc. */ if (AFF_FLAGGED(ch, AFF_CHARM) && ch->master && num_followers_charmed(ch->master) > (GET_CHA(ch->master) - 2) / 3) { if (!aggressive_mob_on_a_leash(ch, ch->master, ch->master)) { if (CAN_SEE(ch, ch->master) && !PRF_FLAGGED(ch->master, PRF_NOHASSLE)) hit(ch, ch->master, TYPE_UNDEFINED); stop_follower(ch); } } /* Helper Mobs */ if (MOB_FLAGGED(ch, MOB_HELPER) && (!AFF_FLAGGED(ch, AFF_BLIND) || !AFF_FLAGGED(ch, AFF_CHARM))) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (ch == vict || !IS_NPC(vict) || !FIGHTING(vict)) continue; if (IS_NPC(FIGHTING(vict)) || ch == FIGHTING(vict)) continue; act("$n jumps to the aid of $N!", FALSE, ch, 0, vict, TO_ROOM); hit(ch, FIGHTING(vict), TYPE_UNDEFINED); found = TRUE; } } /* Add new mobile actions here */ } /* end for() */ }
/* main loop (of sorts).. basically interpreter throws all input to here. */ void oedit_parse(struct descriptor_data *d, char *arg) { int number, max_val, min_val; char *oldtext = NULL; switch (OLC_MODE(d)) { case OEDIT_CONFIRM_SAVESTRING: switch (*arg) { case 'y': case 'Y': oedit_save_internally(d); mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, "OLC: %s edits obj %d", GET_NAME(d->character), OLC_NUM(d)); if (CONFIG_OLC_SAVE) { oedit_save_to_disk(real_zone_by_thing(OLC_NUM(d))); write_to_output(d, "Object saved to disk.\r\n"); } else write_to_output(d, "Object saved to memory.\r\n"); cleanup_olc(d, CLEANUP_ALL); return; case 'n': case 'N': /* If not saving, we must free the script_proto list. */ OLC_OBJ(d)->proto_script = OLC_SCRIPT(d); free_proto_script(OLC_OBJ(d), OBJ_TRIGGER); cleanup_olc(d, CLEANUP_ALL); return; case 'a': /* abort quit */ case 'A': oedit_disp_menu(d); return; default: write_to_output(d, "Invalid choice!\r\n"); write_to_output(d, "Do you wish to save your changes? : \r\n"); return; } case OEDIT_MAIN_MENU: /* Throw us out to whichever edit mode based on user input. */ switch (*arg) { case 'q': case 'Q': if (OLC_VAL(d)) { /* Something has been modified. */ write_to_output(d, "Do you wish to save your changes? : "); OLC_MODE(d) = OEDIT_CONFIRM_SAVESTRING; } else cleanup_olc(d, CLEANUP_ALL); return; case '1': write_to_output(d, "Enter keywords : "); OLC_MODE(d) = OEDIT_KEYWORD; break; case '2': write_to_output(d, "Enter short desc : "); OLC_MODE(d) = OEDIT_SHORTDESC; break; case '3': write_to_output(d, "Enter long desc :-\r\n| "); OLC_MODE(d) = OEDIT_LONGDESC; break; case '4': OLC_MODE(d) = OEDIT_ACTDESC; send_editor_help(d); write_to_output(d, "Enter action description:\r\n\r\n"); if (OLC_OBJ(d)->action_description) { write_to_output(d, "%s", OLC_OBJ(d)->action_description); oldtext = strdup(OLC_OBJ(d)->action_description); } string_write(d, &OLC_OBJ(d)->action_description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; break; case '5': oedit_disp_type_menu(d); OLC_MODE(d) = OEDIT_TYPE; break; case '6': oedit_disp_extra_menu(d); OLC_MODE(d) = OEDIT_EXTRAS; break; case '7': oedit_disp_wear_menu(d); OLC_MODE(d) = OEDIT_WEAR; break; case '8': write_to_output(d, "Enter weight : "); OLC_MODE(d) = OEDIT_WEIGHT; break; case '9': write_to_output(d, "Enter cost : "); OLC_MODE(d) = OEDIT_COST; break; case 'a': case 'A': write_to_output(d, "Enter cost per day : "); OLC_MODE(d) = OEDIT_COSTPERDAY; break; case 'b': case 'B': write_to_output(d, "Enter timer : "); OLC_MODE(d) = OEDIT_TIMER; break; case 'c': case 'C': /* Clear any old values */ GET_OBJ_VAL(OLC_OBJ(d), 0) = 0; GET_OBJ_VAL(OLC_OBJ(d), 1) = 0; GET_OBJ_VAL(OLC_OBJ(d), 2) = 0; GET_OBJ_VAL(OLC_OBJ(d), 3) = 0; OLC_VAL(d) = 1; oedit_disp_val1_menu(d); break; case 'd': case 'D': oedit_disp_prompt_apply_menu(d); break; case 'e': case 'E': /* If extra descriptions don't exist. */ if (OLC_OBJ(d)->ex_description == NULL) { CREATE(OLC_OBJ(d)->ex_description, struct extra_descr_data, 1); OLC_OBJ(d)->ex_description->next = NULL; } OLC_DESC(d) = OLC_OBJ(d)->ex_description; oedit_disp_extradesc_menu(d); break; case 'm': case 'M': write_to_output(d, "Enter new minimum level: "); OLC_MODE(d) = OEDIT_LEVEL; break; case 'p': case 'P': oedit_disp_perm_menu(d); OLC_MODE(d) = OEDIT_PERM; break; case 's': case 'S': OLC_SCRIPT_EDIT_MODE(d) = SCRIPT_MAIN_MENU; dg_script_menu(d); return; case 'w': case 'W': write_to_output(d, "Copy what object? "); OLC_MODE(d) = OEDIT_COPY; break; case 'x': case 'X': write_to_output(d, "Are you sure you want to delete this object? "); OLC_MODE(d) = OEDIT_DELETE; break; default: oedit_disp_menu(d); break; } return; /* end of OEDIT_MAIN_MENU */ case OLC_SCRIPT_EDIT: if (dg_script_edit_parse(d, arg)) return; break; case OEDIT_KEYWORD: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->name) free(OLC_OBJ(d)->name); OLC_OBJ(d)->name = str_udup(arg); break; case OEDIT_SHORTDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->short_description) free(OLC_OBJ(d)->short_description); OLC_OBJ(d)->short_description = str_udup(arg); break; case OEDIT_LONGDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->description) free(OLC_OBJ(d)->description); OLC_OBJ(d)->description = str_udup(arg); break; case OEDIT_TYPE: number = atoi(arg); if ((number < 0) || (number >= NUM_ITEM_TYPES)) { write_to_output(d, "Invalid choice, try again : "); return; } else GET_OBJ_TYPE(OLC_OBJ(d)) = number; /* what's the boundschecking worth if we don't do this ? -- Welcor */ GET_OBJ_VAL(OLC_OBJ(d), 0) = GET_OBJ_VAL(OLC_OBJ(d), 1) = GET_OBJ_VAL(OLC_OBJ(d), 2) = GET_OBJ_VAL(OLC_OBJ(d), 3) = 0; break; case OEDIT_EXTRAS: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_FLAGS)) { oedit_disp_extra_menu(d); return; } else if (number == 0) break; else { TOGGLE_BIT_AR(GET_OBJ_EXTRA(OLC_OBJ(d)), (number - 1)); oedit_disp_extra_menu(d); return; } case OEDIT_WEAR: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_WEARS)) { write_to_output(d, "That's not a valid choice!\r\n"); oedit_disp_wear_menu(d); return; } else if (number == 0) /* Quit. */ break; else { TOGGLE_BIT_AR(GET_OBJ_WEAR(OLC_OBJ(d)), (number - 1)); oedit_disp_wear_menu(d); return; } case OEDIT_WEIGHT: GET_OBJ_WEIGHT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_WEIGHT); break; case OEDIT_COST: GET_OBJ_COST(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_COST); break; case OEDIT_COSTPERDAY: GET_OBJ_RENT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_RENT); break; case OEDIT_TIMER: GET_OBJ_TIMER(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_TIMER); break; case OEDIT_LEVEL: GET_OBJ_LEVEL(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, LVL_IMPL); break; case OEDIT_PERM: if ((number = atoi(arg)) == 0) break; if (number > 0 && number <= NUM_AFF_FLAGS) { /* Setting AFF_CHARM on objects like this is dangerous. */ if (number != AFF_CHARM) { TOGGLE_BIT_AR(GET_OBJ_AFFECT(OLC_OBJ(d)), number); } } oedit_disp_perm_menu(d); return; case OEDIT_VALUE_1: number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_FURNITURE: if (number < 0 || number > MAX_PEOPLE) oedit_disp_val1_menu(d); else { GET_OBJ_VAL(OLC_OBJ(d), 0) = number; oedit_disp_val2_menu(d); } break; case ITEM_WEAPON: GET_OBJ_VAL(OLC_OBJ(d), 0) = MIN(MAX(atoi(arg), -50), 50); break; case ITEM_CONTAINER: GET_OBJ_VAL(OLC_OBJ(d), 0) = LIMIT(atoi(arg), -1, MAX_CONTAINER_SIZE); break; default: GET_OBJ_VAL(OLC_OBJ(d), 0) = atoi(arg); } /* proceed to menu 2 */ oedit_disp_val2_menu(d); return; case OEDIT_VALUE_2: /* Here, I do need to check for out of range values. */ number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) GET_OBJ_VAL(OLC_OBJ(d), 1) = -1; else GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, NUM_SPELLS); oedit_disp_val3_menu(d); break; case ITEM_CONTAINER: /* Needs some special handling since we are dealing with flag values here. */ if (number < 0 || number > 4) oedit_disp_container_flags_menu(d); else if (number != 0) { TOGGLE_BIT(GET_OBJ_VAL(OLC_OBJ(d), 1), 1 << (number - 1)); OLC_VAL(d) = 1; oedit_disp_val2_menu(d); } else oedit_disp_val3_menu(d); break; case ITEM_WEAPON: GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, MAX_WEAPON_NDICE); oedit_disp_val3_menu(d); break; default: GET_OBJ_VAL(OLC_OBJ(d), 1) = number; oedit_disp_val3_menu(d); } return; case OEDIT_VALUE_3: number = atoi(arg); /* Quick'n'easy error checking. */ switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) { GET_OBJ_VAL(OLC_OBJ(d), 2) = -1; oedit_disp_val4_menu(d); return; } min_val = 1; max_val = NUM_SPELLS; break; case ITEM_WEAPON: min_val = 1; max_val = MAX_WEAPON_SDICE; break; case ITEM_WAND: case ITEM_STAFF: min_val = 0; max_val = 20; break; case ITEM_DRINKCON: case ITEM_FOUNTAIN: min_val = 0; max_val = NUM_LIQ_TYPES - 1; number--; break; case ITEM_KEY: min_val = 0; max_val = 65099; break; default: min_val = -65000; max_val = 65000; } GET_OBJ_VAL(OLC_OBJ(d), 2) = LIMIT(number, min_val, max_val); oedit_disp_val4_menu(d); return; case OEDIT_VALUE_4: number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number == 0 || number == -1) { GET_OBJ_VAL(OLC_OBJ(d), 3) = -1; oedit_disp_menu(d); return; } min_val = 1; max_val = NUM_SPELLS; break; case ITEM_WAND: case ITEM_STAFF: min_val = 1; max_val = NUM_SPELLS; break; case ITEM_WEAPON: min_val = 0; max_val = NUM_ATTACK_TYPES - 1; break; default: min_val = -65000; max_val = 65000; break; } GET_OBJ_VAL(OLC_OBJ(d), 3) = LIMIT(number, min_val, max_val); break; case OEDIT_PROMPT_APPLY: if ((number = atoi(arg)) == 0) break; else if (number < 0 || number > MAX_OBJ_AFFECT) { oedit_disp_prompt_apply_menu(d); return; } OLC_VAL(d) = number - 1; OLC_MODE(d) = OEDIT_APPLY; oedit_disp_apply_menu(d); return; case OEDIT_APPLY: if (((number = atoi(arg)) == 0) || ((number = atoi(arg)) == 1)) { OLC_OBJ(d)->affected[OLC_VAL(d)].location = 0; OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = 0; oedit_disp_prompt_apply_menu(d); } else if (number < 0 || number > NUM_APPLIES) oedit_disp_apply_menu(d); else { int counter; /* add in check here if already applied.. deny builders another */ if (GET_LEVEL(d->character) < LVL_IMPL) { for (counter = 0; counter < MAX_OBJ_AFFECT; counter++) { if (OLC_OBJ(d)->affected[counter].location == number) { write_to_output(d, "Object already has that apply."); return; } } } OLC_OBJ(d)->affected[OLC_VAL(d)].location = number - 1; write_to_output(d, "Modifier : "); OLC_MODE(d) = OEDIT_APPLYMOD; } return; case OEDIT_APPLYMOD: OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = atoi(arg); oedit_disp_prompt_apply_menu(d); return; case OEDIT_EXTRADESC_KEY: if (genolc_checkstring(d, arg)) { if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); OLC_DESC(d)->keyword = str_udup(arg); } oedit_disp_extradesc_menu(d); return; case OEDIT_EXTRADESC_MENU: switch ((number = atoi(arg))) { case 0: if (!OLC_DESC(d)->keyword || !OLC_DESC(d)->description) { struct extra_descr_data *temp; if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); if (OLC_DESC(d)->description) free(OLC_DESC(d)->description); /* Clean up pointers */ REMOVE_FROM_LIST(OLC_DESC(d), OLC_OBJ(d)->ex_description, next); free(OLC_DESC(d)); OLC_DESC(d) = NULL; } break; case 1: OLC_MODE(d) = OEDIT_EXTRADESC_KEY; write_to_output(d, "Enter keywords, separated by spaces :-\r\n| "); return; case 2: OLC_MODE(d) = OEDIT_EXTRADESC_DESCRIPTION; send_editor_help(d); write_to_output(d, "Enter the extra description:\r\n\r\n"); if (OLC_DESC(d)->description) { write_to_output(d, "%s", OLC_DESC(d)->description); oldtext = strdup(OLC_DESC(d)->description); } string_write(d, &OLC_DESC(d)->description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; return; case 3: /* Only go to the next description if this one is finished. */ if (OLC_DESC(d)->keyword && OLC_DESC(d)->description) { struct extra_descr_data *new_extra; if (OLC_DESC(d)->next) OLC_DESC(d) = OLC_DESC(d)->next; else { /* Make new extra description and attach at end. */ CREATE(new_extra, struct extra_descr_data, 1); OLC_DESC(d)->next = new_extra; OLC_DESC(d) = OLC_DESC(d)->next; } } /* No break - drop into default case. */ default: oedit_disp_extradesc_menu(d); return; } break; case OEDIT_COPY: if ((number = real_object(atoi(arg))) != NOTHING) { oedit_setup_existing(d, number); } else write_to_output(d, "That object does not exist.\r\n"); break; case OEDIT_DELETE: if (*arg == 'y' || *arg == 'Y') { if (delete_object(GET_OBJ_RNUM(OLC_OBJ(d))) != NOTHING) write_to_output(d, "Object deleted.\r\n"); else write_to_output(d, "Couldn't delete the object!\r\n"); cleanup_olc(d, CLEANUP_ALL); } else if (*arg == 'n' || *arg == 'N') { oedit_disp_menu(d); OLC_MODE(d) = OEDIT_MAIN_MENU; } else write_to_output(d, "Please answer 'Y' or 'N': "); return; default: mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: Reached default case in oedit_parse()!"); write_to_output(d, "Oops...\r\n"); break; }
void convert_objs_to_disk(int zone_num) { int counter, counter2, realcounter; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; int tmpmod; sprintf(buf, "%s/%d.obj", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(buf, "w+"))) { return; } /* start running through all objects in this zone */ for (counter = zone_table[zone_num].number * 100; counter <= zone_table[zone_num].top; counter++) { /* write object to disk */ realcounter = real_object(counter); if (realcounter >= 0) { obj = (obj_proto + realcounter); if (obj->action_description) { strcpy(buf1, obj->action_description); strip_string(buf1); } else *buf1 = 0; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n" "%d %d %d\n" "%d %d %d %d %d\n" "%d %d %d\n", GET_OBJ_VNUM(obj), obj->name, obj->short_description, obj->description, buf1, GET_OBJ_TYPE(obj), GET_OBJ_EXTRA(obj), GET_OBJ_WEAR(obj), GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_VAL(obj, 4), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj) /*. GET_OBJ_LEVEL(obj) -- Level flags for objects .*/ ); /* Do we have extra descriptions? */ if (obj->ex_description) { /*. Yep, save them too .*/ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /*. Sanity check to prevent nasty protection faults .*/ if (!*ex_desc->keyword || !*ex_desc->description) { mudlog("SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!", 'G', COM_BUILDER, TRUE); continue; } strcpy(buf1, ex_desc->description); strip_string(buf1); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1); } } /* Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) { if ((obj->affected[counter2].location > 0) && (obj->affected[counter2].location < 7)) tmpmod = obj->affected[counter2].modifier * 5; else tmpmod = obj->affected[counter2].modifier; fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, tmpmod); } } } /* write final line, close */ fprintf(fp, "$~\n"); fclose(fp); }
int Obj_to_store(struct obj_data *obj, FILE *fp, int locate) { int counter2; struct extra_descr_data *ex_desc; char buf1[MAX_STRING_LENGTH +1]; char flags[65]; struct obj_data *temp = NULL; if (GET_OBJ_VNUM(obj) != NOTHING) temp=read_object(GET_OBJ_VNUM(obj), VIRTUAL); else { temp = create_obj(); temp->item_number = -1; } if (obj->action_description) { strcpy(buf1, obj->action_description); strip_string(buf1); } else *buf1 = 0; fprintf(fp, "#%d\n", GET_OBJ_VNUM(obj)); if (locate) fprintf(fp, "Loc : %d\n", locate); if (GET_OBJ_VAL(obj, 0) != GET_OBJ_VAL(temp, 0) || GET_OBJ_VAL(obj, 1) != GET_OBJ_VAL(temp, 1) || GET_OBJ_VAL(obj, 2) != GET_OBJ_VAL(temp, 2) || GET_OBJ_VAL(obj, 3) != GET_OBJ_VAL(temp, 3)) fprintf(fp, "Vals: %d %d %d %d\n", GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3) ); if (GET_OBJ_EXTRA(obj) != GET_OBJ_EXTRA(temp)) { sprintascii(flags, GET_OBJ_EXTRA(obj)); fprintf(fp, "Flag: %s\n", flags); } #define TEST_OBJS(obj1, obj2, field) ((!obj1->field || !obj2->field || \ strcmp(obj1->field, obj2->field))) #define TEST_OBJN(field) (obj->obj_flags.field != temp->obj_flags.field) if (TEST_OBJS(obj, temp, name)) fprintf(fp, "Name: %s\n", obj->name ? obj->name : "Undefined"); if (TEST_OBJS(obj, temp, short_description)) fprintf(fp, "Shrt: %s\n", obj->short_description ? obj->short_description : "Undefined"); /* These two could be a pain on the read... we'll see... */ if (TEST_OBJS(obj, temp, description)) fprintf(fp, "Desc: %s\n", obj->description ? obj->description : "Undefined"); /* Only even try to process this if an action desc exists */ if (obj->action_description || temp->action_description) if (TEST_OBJS(obj, temp, action_description)) fprintf(fp, "ADes:\n%s~\n", buf1); if (TEST_OBJN(type_flag)) fprintf(fp, "Type: %d\n", GET_OBJ_TYPE(obj)); if (TEST_OBJN(weight)) fprintf(fp, "Wght: %d\n", GET_OBJ_WEIGHT(obj)); if (TEST_OBJN(cost)) fprintf(fp, "Cost: %d\n", GET_OBJ_COST(obj)); if (TEST_OBJN(cost_per_day)) fprintf(fp, "Rent: %d\n", GET_OBJ_RENT(obj)); if (TEST_OBJN(bitvector)) { sprintascii(flags, obj->obj_flags.bitvector); fprintf(fp, "Perm: %s\n", flags); } if (TEST_OBJN(wear_flags)) { sprintascii(flags, GET_OBJ_WEAR(obj)); fprintf(fp, "Wear: %s\n", flags); } /* Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier != temp->affected[counter2].modifier) fprintf(fp, "Aff : %d %d %d\n", counter2, obj->affected[counter2].location, obj->affected[counter2].modifier ); /* Do we have extra descriptions? */ if (obj->ex_description || temp->ex_description) { /* To be reimplemented. Need to handle this case in loading as well */ if ((obj->ex_description && temp->ex_description && obj->ex_description != temp->ex_description) || !obj->ex_description || !temp->ex_description) { for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /*. Sanity check to prevent nasty protection faults . */ if (!*ex_desc->keyword || !*ex_desc->description) { continue; } strcpy(buf1, ex_desc->description); strip_string(buf1); fprintf(fp, "EDes:\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1 ); } } } fprintf(fp, "\n"); extract_obj(temp); return 1; }
int Crash_load_objs(struct char_data *ch) { FILE *fl; char fname[MAX_STRING_LENGTH]; char line[256]; int t[10],i,num_of_days; int orig_rent_code; struct obj_data *temp; int locate=0, nr,cost,num_objs=0; struct obj_data *cont_row[MAX_BAG_ROWS]; int rentcode,timed,netcost,gold,account,nitems; if (!get_filename(fname, sizeof(fname), CRASH_FILE, GET_NAME(ch))) return 1; for (i = 0; i < MAX_BAG_ROWS; i++) cont_row[i] = NULL; if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ char buf[MAX_STRING_LENGTH]; sprintf(buf, "SYSERR: READING OBJECT FILE %s (5)", fname); perror(buf); send_to_char(ch, "\r\n********************* NOTICE *********************\r\n" "There was a problem loading your objects from disk.\r\n" "Contact a God for assistance.\r\n"); } mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s entering game with no equipment.", GET_NAME(ch)); return 1; } if (get_line(fl, line)) sscanf(line,"%d %d %d %d %d %d",&rentcode, &timed, &netcost,&gold,&account,&nitems); if (rentcode == RENT_RENTED || rentcode == RENT_TIMEDOUT) { char str[64]; sprintf(str, "%d", SECS_PER_REAL_DAY); num_of_days = (int)((float) (time(0) - timed) / (float)atoi(str)); cost = (int) (netcost * num_of_days); if (cost > GET_GOLD(ch) + GET_BANK_GOLD(ch)) { fclose(fl); mudlog(BRF, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s entering game, rented equipment lost (no $).", GET_NAME(ch)); Crash_crashsave(ch); return 2; } else { GET_BANK_GOLD(ch) -= MAX(cost - GET_GOLD(ch), 0); GET_GOLD(ch) = MAX(GET_GOLD(ch) - cost, 0); save_char(ch); } } switch (orig_rent_code = rentcode) { case RENT_RENTED: mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s un-renting and entering game.", GET_NAME(ch)); break; case RENT_CRASH: mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s retrieving crash-saved items and entering game.", GET_NAME(ch)); break; case RENT_CRYO: mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s un-cryo'ing and entering game.", GET_NAME(ch)); break; case RENT_FORCED: case RENT_TIMEDOUT: mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "%s retrieving force-saved items and entering game.", GET_NAME(ch)); break; default: mudlog(NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE, "WARNING: %s entering game with undefined rent code.", GET_NAME(ch)); break; } temp = NULL; while (get_line(fl, line)) { char tag[6]; int num; /* first, we get the number. Not too hard. */ if(*line == '$' && line[1] == '~') { if (temp) num_objs += handle_obj(temp, ch, locate, cont_row); break; } if (*line == '#') { if (sscanf(line, "#%d", &nr) != 1) { continue; } else { if (temp) num_objs += handle_obj(temp, ch, locate, cont_row); temp = NULL; locate = 0; } /* we have the number, check it, load obj. */ if (nr == NOTHING) { /* then it is unique */ temp = create_obj(); temp->item_number=NOTHING; } else if (nr < 0) { continue; } else { if(nr >= 999999) continue; if(real_object(nr) != NOTHING) { temp=read_object(nr,VIRTUAL); if (!temp) { continue; } } else { log("Nonexistent object %d found in rent file.", nr); continue; } } } tag_argument(line, tag); num = atoi(line); switch(*tag) { case 'A': if (!strcmp(tag, "ADes")) { char error[40]; snprintf(error, sizeof(error)-1, "rent(Ades):%s", temp->name); temp->action_description = fread_string(fl, error); } else if (!strcmp(tag, "Aff ")) { sscanf(line, "%d %d %d", &t[0], &t[1], &t[2]); if (t[0] < MAX_OBJ_AFFECT) { temp->affected[t[0]].location = t[1]; temp->affected[t[0]].modifier = t[2]; } } break; case 'C': if (!strcmp(tag, "Cost")) GET_OBJ_COST(temp) = num; break; case 'D': if (!strcmp(tag, "Desc")) temp->description = strdup(line); break; case 'E': if(!strcmp(tag, "EDes")) { struct extra_descr_data *new_desc; char error[40]; snprintf(error, sizeof(error)-1, "rent(Edes): %s", temp->name); if (temp->item_number != NOTHING && /* Regular object */ temp->ex_description && /* with ex_desc == prototype */ (temp->ex_description == obj_proto[real_object(temp->item_number)].ex_description)) temp->ex_description = NULL; CREATE(new_desc, struct extra_descr_data, 1); new_desc->keyword = fread_string(fl, error); new_desc->description = fread_string(fl, error); new_desc->next = temp->ex_description; temp->ex_description = new_desc; } break; case 'F': if (!strcmp(tag, "Flag")) GET_OBJ_EXTRA(temp) = asciiflag_conv(line); break; case 'L': if(!strcmp(tag, "Loc ")) locate = num; break; case 'N': if (!strcmp(tag, "Name")) temp->name = strdup(line); break; case 'P': if (!strcmp(tag, "Perm")) temp->obj_flags.bitvector = asciiflag_conv(line); break; case 'R': if (!strcmp(tag, "Rent")) GET_OBJ_RENT(temp) = num; break; case 'S': if (!strcmp(tag, "Shrt")) temp->short_description = strdup(line); break; case 'T': if (!strcmp(tag, "Type")) GET_OBJ_TYPE(temp) = num; break; case 'W': if (!strcmp(tag, "Wear")) GET_OBJ_WEAR(temp) = asciiflag_conv(line); else if (!strcmp(tag, "Wght")) GET_OBJ_WEIGHT(temp) = num; break; case 'V': if (!strcmp(tag, "Vals")) { sscanf(line, "%d %d %d %d", &t[0], &t[1], &t[2], &t[3]); for (i = 0; i < 4; i++) GET_OBJ_VAL(temp, i) = t[i]; } break; } } /* Little hoarding check. -gg 3/1/98 */ mudlog(NRM, MAX(LVL_GOD, GET_INVIS_LEV(ch)), TRUE, "%s (level %d) has %d objects (max %d).", GET_NAME(ch), GET_LEVEL(ch), num_objs, max_obj_save); fclose(fl); if ((orig_rent_code == RENT_RENTED) || (orig_rent_code == RENT_CRYO)) return 0; else return 1; }
void oedit_parse(struct descriptor_data *d, char *arg) { int number, max_val, min_val; char *oldtext = NULL; switch (OLC_MODE(d)) { case OEDIT_CONFIRM_SAVESTRING: switch (*arg) { case 'y': case 'Y': write_to_output(d, "Saving object to memory.\r\n"); oedit_save_internally(d); mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, "OLC: %s edits obj %d", GET_NAME(d->character), OLC_NUM(d)); /* Fall through. */ case 'n': case 'N': cleanup_olc(d, CLEANUP_ALL); return; default: write_to_output(d, "Invalid choice!\r\n"); write_to_output(d, "Do you wish to save this object internally?\r\n"); return; } case OEDIT_MAIN_MENU: /* * Throw us out to whichever edit mode based on user input. */ switch (*arg) { case 'q': case 'Q': if (OLC_VAL(d)) { /* Something has been modified. */ write_to_output(d, "Do you wish to save this object internally? : "); OLC_MODE(d) = OEDIT_CONFIRM_SAVESTRING; } else cleanup_olc(d, CLEANUP_ALL); return; case '1': write_to_output(d, "Enter namelist : "); OLC_MODE(d) = OEDIT_EDIT_NAMELIST; break; case '2': write_to_output(d, "Enter short desc : "); OLC_MODE(d) = OEDIT_SHORTDESC; break; case '3': write_to_output(d, "Enter long desc :-\r\n| "); OLC_MODE(d) = OEDIT_LONGDESC; break; case '4': OLC_MODE(d) = OEDIT_ACTDESC; send_editor_help(d); write_to_output(d, "Enter action description:\r\n\r\n"); if (OLC_OBJ(d)->action_description) { write_to_output(d, "%s", OLC_OBJ(d)->action_description); oldtext = strdup(OLC_OBJ(d)->action_description); } string_write(d, &OLC_OBJ(d)->action_description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; break; case '5': oedit_disp_type_menu(d); OLC_MODE(d) = OEDIT_TYPE; break; case '6': oedit_disp_extra_menu(d); OLC_MODE(d) = OEDIT_EXTRAS; break; case '7': oedit_disp_wear_menu(d); OLC_MODE(d) = OEDIT_WEAR; break; case '8': write_to_output(d, "Enter weight : "); OLC_MODE(d) = OEDIT_WEIGHT; break; case '9': write_to_output(d, "Enter cost : "); OLC_MODE(d) = OEDIT_COST; break; case 'a': case 'A': write_to_output(d, "Enter cost per day : "); OLC_MODE(d) = OEDIT_COSTPERDAY; break; case 'b': case 'B': write_to_output(d, "Enter timer : "); OLC_MODE(d) = OEDIT_TIMER; break; case 'c': case 'C': /* * Clear any old values */ GET_OBJ_VAL(OLC_OBJ(d), 0) = 0; GET_OBJ_VAL(OLC_OBJ(d), 1) = 0; GET_OBJ_VAL(OLC_OBJ(d), 2) = 0; GET_OBJ_VAL(OLC_OBJ(d), 3) = 0; oedit_disp_val1_menu(d); break; case 'd': case 'D': oedit_disp_prompt_apply_menu(d); break; case 'e': case 'E': /* * If extra descriptions don't exist. */ if (OLC_OBJ(d)->ex_description == NULL) { CREATE(OLC_OBJ(d)->ex_description, struct extra_descr_data, 1); OLC_OBJ(d)->ex_description->next = NULL; } OLC_DESC(d) = OLC_OBJ(d)->ex_description; oedit_disp_extradesc_menu(d); break; case 'm': case 'M': write_to_output(d, "Enter new minimum level: "); OLC_MODE(d) = OEDIT_LEVEL; break; case 'p': case 'P': oedit_disp_perm_menu(d); OLC_MODE(d) = OEDIT_PERM; break; case 's': case 'S': OLC_SCRIPT_EDIT_MODE(d) = SCRIPT_MAIN_MENU; dg_script_menu(d); return; default: oedit_disp_menu(d); break; } return; /* * end of OEDIT_MAIN_MENU */ case OLC_SCRIPT_EDIT: if (dg_script_edit_parse(d, arg)) return; break; case OEDIT_EDIT_NAMELIST: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->name) free(OLC_OBJ(d)->name); OLC_OBJ(d)->name = str_udup(arg); break; case OEDIT_SHORTDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->short_description) free(OLC_OBJ(d)->short_description); OLC_OBJ(d)->short_description = str_udup(arg); break; case OEDIT_LONGDESC: if (!genolc_checkstring(d, arg)) break; if (OLC_OBJ(d)->description) free(OLC_OBJ(d)->description); OLC_OBJ(d)->description = str_udup(arg); break; case OEDIT_TYPE: number = atoi(arg); if ((number < 1) || (number >= NUM_ITEM_TYPES)) { write_to_output(d, "Invalid choice, try again : "); return; } else GET_OBJ_TYPE(OLC_OBJ(d)) = number; break; case OEDIT_EXTRAS: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_FLAGS)) { oedit_disp_extra_menu(d); return; } else if (number == 0) break; else { TOGGLE_BIT(GET_OBJ_EXTRA(OLC_OBJ(d)), 1 << (number - 1)); oedit_disp_extra_menu(d); return; } case OEDIT_WEAR: number = atoi(arg); if ((number < 0) || (number > NUM_ITEM_WEARS)) { write_to_output(d, "That's not a valid choice!\r\n"); oedit_disp_wear_menu(d); return; } else if (number == 0) /* Quit. */ break; else { TOGGLE_BIT(GET_OBJ_WEAR(OLC_OBJ(d)), 1 << (number - 1)); oedit_disp_wear_menu(d); return; } case OEDIT_WEIGHT: GET_OBJ_WEIGHT(OLC_OBJ(d)) = atoi(arg); break; case OEDIT_COST: GET_OBJ_COST(OLC_OBJ(d)) = atoi(arg); break; case OEDIT_COSTPERDAY: GET_OBJ_RENT(OLC_OBJ(d)) = atoi(arg); break; case OEDIT_TIMER: GET_OBJ_TIMER(OLC_OBJ(d)) = atoi(arg); break; case OEDIT_LEVEL: GET_OBJ_LEVEL(OLC_OBJ(d)) = atoi(arg); break; case OEDIT_PERM: if ((number = atoi(arg)) == 0) break; if (number > 0 && number <= NUM_AFF_FLAGS) TOGGLE_BIT(GET_OBJ_PERM(OLC_OBJ(d)), 1 << (number - 1)); oedit_disp_perm_menu(d); return; case OEDIT_VALUE_1: /* * Lucky, I don't need to check any of these for out of range values. * Hmm, I'm not so sure - Rv */ GET_OBJ_VAL(OLC_OBJ(d), 0) = atoi(arg); /* * proceed to menu 2 */ oedit_disp_val2_menu(d); return; case OEDIT_VALUE_2: /* * Here, I do need to check for out of range values. */ number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: if (number < 0 || number >= NUM_SPELLS) oedit_disp_val2_menu(d); else { GET_OBJ_VAL(OLC_OBJ(d), 1) = number; oedit_disp_val3_menu(d); } break; case ITEM_CONTAINER: /* * Needs some special handling since we are dealing with flag values * here. */ if (number < 0 || number > 4) oedit_disp_container_flags_menu(d); else if (number != 0) { TOGGLE_BIT(GET_OBJ_VAL(OLC_OBJ(d), 1), 1 << (number - 1)); OLC_VAL(d) = 1; oedit_disp_val2_menu(d); } else oedit_disp_val3_menu(d); break; default: GET_OBJ_VAL(OLC_OBJ(d), 1) = number; oedit_disp_val3_menu(d); } return; case OEDIT_VALUE_3: number = atoi(arg); /* * Quick'n'easy error checking. */ switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: min_val = -1; max_val = NUM_SPELLS - 1; break; case ITEM_WEAPON: min_val = 1; max_val = 50; break; case ITEM_WAND: case ITEM_STAFF: min_val = 0; max_val = 20; break; case ITEM_DRINKCON: case ITEM_FOUNTAIN: min_val = 0; max_val = NUM_LIQ_TYPES - 1; break; case ITEM_KEY: min_val = 0; max_val = 32099; break; default: min_val = -32000; max_val = 32000; } GET_OBJ_VAL(OLC_OBJ(d), 2) = LIMIT(number, min_val, max_val); oedit_disp_val4_menu(d); return; case OEDIT_VALUE_4: number = atoi(arg); switch (GET_OBJ_TYPE(OLC_OBJ(d))) { case ITEM_SCROLL: case ITEM_POTION: min_val = -1; max_val = NUM_SPELLS - 1; break; case ITEM_WAND: case ITEM_STAFF: min_val = 1; max_val = NUM_SPELLS - 1; break; case ITEM_WEAPON: min_val = 0; max_val = NUM_ATTACK_TYPES - 1; break; default: min_val = -32000; max_val = 32000; break; } GET_OBJ_VAL(OLC_OBJ(d), 3) = LIMIT(number, min_val, max_val); break; case OEDIT_PROMPT_APPLY: if ((number = atoi(arg)) == 0) break; else if (number < 0 || number > MAX_OBJ_AFFECT) { oedit_disp_prompt_apply_menu(d); return; } OLC_VAL(d) = number - 1; OLC_MODE(d) = OEDIT_APPLY; oedit_disp_apply_menu(d); return; case OEDIT_APPLY: if ((number = atoi(arg)) == 0) { OLC_OBJ(d)->affected[OLC_VAL(d)].location = 0; OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = 0; oedit_disp_prompt_apply_menu(d); } else if (number < 0 || number >= NUM_APPLIES) oedit_disp_apply_menu(d); else { int counter; /* add in check here if already applied.. deny builders another */ if (GET_LEVEL(d->character) < LVL_IMPL) { for (counter = 0; counter < MAX_OBJ_AFFECT; counter++) { if (OLC_OBJ(d)->affected[counter].location == number) { write_to_output(d, "Object already has that apply."); return; } } } OLC_OBJ(d)->affected[OLC_VAL(d)].location = number; write_to_output(d, "Modifier : "); OLC_MODE(d) = OEDIT_APPLYMOD; } return; case OEDIT_APPLYMOD: OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = atoi(arg); oedit_disp_prompt_apply_menu(d); return; case OEDIT_EXTRADESC_KEY: if (genolc_checkstring(d, arg)) { if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); OLC_DESC(d)->keyword = str_udup(arg); } oedit_disp_extradesc_menu(d); return; case OEDIT_EXTRADESC_MENU: switch ((number = atoi(arg))) { case 0: if (!OLC_DESC(d)->keyword || !OLC_DESC(d)->description) { struct extra_descr_data **tmp_desc; if (OLC_DESC(d)->keyword) free(OLC_DESC(d)->keyword); if (OLC_DESC(d)->description) free(OLC_DESC(d)->description); /* * Clean up pointers */ for (tmp_desc = &(OLC_OBJ(d)->ex_description); *tmp_desc; tmp_desc = &((*tmp_desc)->next)) { if (*tmp_desc == OLC_DESC(d)) { *tmp_desc = NULL; break; } } free(OLC_DESC(d)); } break; case 1: OLC_MODE(d) = OEDIT_EXTRADESC_KEY; write_to_output(d, "Enter keywords, separated by spaces :-\r\n| "); return; case 2: OLC_MODE(d) = OEDIT_EXTRADESC_DESCRIPTION; send_editor_help(d); write_to_output(d, "Enter the extra description:\r\n\r\n"); if (OLC_DESC(d)->description) { write_to_output(d, "%s", OLC_DESC(d)->description); oldtext = strdup(OLC_DESC(d)->description); } string_write(d, &OLC_DESC(d)->description, MAX_MESSAGE_LENGTH, 0, oldtext); OLC_VAL(d) = 1; return; case 3: /* * Only go to the next description if this one is finished. */ if (OLC_DESC(d)->keyword && OLC_DESC(d)->description) { struct extra_descr_data *new_extra; if (OLC_DESC(d)->next) OLC_DESC(d) = OLC_DESC(d)->next; else { /* Make new extra description and attach at end. */ CREATE(new_extra, struct extra_descr_data, 1); OLC_DESC(d)->next = new_extra; OLC_DESC(d) = OLC_DESC(d)->next; } } /* * No break - drop into default case. */ default: oedit_disp_extradesc_menu(d); return; } break; default: mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: Reached default case in oedit_parse()!"); write_to_output(d, "Oops...\r\n"); break; }
/* * NOTE: This clobbers all of the global variable strings. Do not * save anything in them around calls to this function. * * buf, buf1, buf2, arg */ int save_objects(zone_rnum zone_num) { char buf[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char buf3[MAX_STRING_LENGTH]; char arg[MAX_STRING_LENGTH]; int counter, counter2, realcounter, i; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; if (zone_num == NOTHING || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } sprintf(buf, "%s/%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(buf, "w+"))) { mudlog(BRF, LVL_SAINT, TRUE, "SYSERR: OLC: Cannot open objects file!"); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = genolc_zone_bottom(zone_num); counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) != NOTHING) { if ((obj = &obj_proto[realcounter])->action_description) { buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, obj->action_description, MAX_STRING_LENGTH - 1); strip_cr(buf1); } else *buf1 = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : STRING_UNDEFINED, (obj->short_description && *obj->short_description) ? obj->short_description : STRING_UNDEFINED, (obj->description && *obj->description) ? obj->description : STRING_UNDEFINED, buf1); sprintasciilong(buf1, GET_OBJ_EXTRA(obj)); sprintasciilong(buf3, GET_OBJ_CLASS(obj)); sprintascii(buf2, GET_OBJ_WEAR(obj)); sprintasciilong(arg, GET_OBJ_PERM(obj)); fprintf(fp, "%d %s %s %s %s\n" "%d %d %d %d %d\n" "%d %d %d %d %d\n", GET_OBJ_TYPE(obj), buf1, buf2, arg, buf3, GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_SIZE(obj), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj), GET_OBJ_MAX_LEVEL(obj) ); /* * Do we have script(s) attached ? */ script_save_to_disk(fp, obj, OBJ_TRIGGER); /* save resists */ for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->resist[i] == 1) fprintf(fp, "R\n%d %d\n",i, obj->resist[i]); } for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->vulnerable[i] == 1) fprintf(fp, "V\n%d %d\n",i, obj->vulnerable[i]); } for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->immune[i] == 1) fprintf(fp, "I\n%d %d\n",i, obj->immune[i]); } /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog(BRF, LVL_SAINT, TRUE, "SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!"); continue; } buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, ex_desc->description, MAX_STRING_LENGTH - 1); strip_cr(buf1); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); sprintf(buf2, "%s/%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[zone_num].number, SL_OBJ); return TRUE; }