/* * Copy a -1 terminated (in the type field) shop_buy_data * array list. */ void copy_type_list(struct shop_buy_data **tlist, struct shop_buy_data *flist) { int num_items, i; if (*tlist) free_type_list(tlist); /* * Count number of entries. */ for (i = 0; BUY_TYPE(flist[i]) != -1; i++); num_items = i + 1; /* * Make space for entries. */ CREATE(*tlist, struct shop_buy_data, num_items); /* * Copy entries over. */ for (i = 0; i < num_items; i++) { (*tlist)[i].type = flist[i].type; if (BUY_WORD(flist[i])) BUY_WORD((*tlist)[i]) = str_dup(BUY_WORD(flist[i])); } }
int end_read_list(struct shop_buy_data * list, int len, int error) { if (error) { sprintf(buf, "Raise MAX_SHOP_OBJ constant in shop.h to %d", len + error); log("%s", buf); } BUY_WORD(list[len]) = 0; BUY_TYPE(list[len++]) = NOTHING; return (len); }
int add_to_list(struct shop_buy_data * list, int type, int *len, int *val) { if (*val >= 0) { if (*len < MAX_SHOP_OBJ) { if (type == LIST_PRODUCE) *val = real_object(*val); if (*val >= 0) { BUY_TYPE(list[*len]) = *val; BUY_WORD(list[(*len)++]) = 0; } else *val = 0; return (FALSE); } else return (TRUE); } return (FALSE); }
void boot_the_shops(FILE * shop_f, char *filename, int rec_count) { char *buf, buf2[150]; int temp, count, new_format = 0; struct shop_buy_data list[MAX_SHOP_OBJ + 1]; int done = 0; sprintf(buf2, "beginning of shop file %s", filename); while (!done) { buf = fread_string(shop_f, buf2); if (*buf == '#') { /* New shop */ sscanf(buf, "#%d\n", &temp); sprintf(buf2, "shop #%d in shop file %s", temp, filename); FREE(buf); /* Plug memory leak! */ if (!top_shop) CREATE(shop_index, struct shop_data, rec_count); SHOP_NUM(top_shop) = temp; temp = read_list(shop_f, list, new_format, MAX_PROD, LIST_PRODUCE); CREATE(shop_index[top_shop].producing, int, temp); for (count = 0; count < temp; count++) SHOP_PRODUCT(top_shop, count) = BUY_TYPE(list[count]); read_line(shop_f, "%f", &SHOP_BUYPROFIT(top_shop)); read_line(shop_f, "%f", &SHOP_SELLPROFIT(top_shop)); temp = read_type_list(shop_f, list, new_format, MAX_TRADE); CREATE(shop_index[top_shop].type, struct shop_buy_data, temp); for (count = 0; count < temp; count++) { SHOP_BUYTYPE(top_shop, count) = (byte) BUY_TYPE(list[count]); SHOP_BUYWORD(top_shop, count) = BUY_WORD(list[count]); } shop_index[top_shop].no_such_item1 = fread_string(shop_f, buf2); shop_index[top_shop].no_such_item2 = fread_string(shop_f, buf2); shop_index[top_shop].do_not_buy = fread_string(shop_f, buf2); shop_index[top_shop].missing_cash1 = fread_string(shop_f, buf2); shop_index[top_shop].missing_cash2 = fread_string(shop_f, buf2); shop_index[top_shop].message_buy = fread_string(shop_f, buf2); shop_index[top_shop].message_sell = fread_string(shop_f, buf2); read_line(shop_f, "%d", &SHOP_BROKE_TEMPER(top_shop)); read_line(shop_f, "%d", &SHOP_BITVECTOR(top_shop)); read_line(shop_f, "%d", &SHOP_KEEPER(top_shop)); SHOP_KEEPER(top_shop) = real_mobile(SHOP_KEEPER(top_shop)); read_line(shop_f, "%d", &SHOP_TRADE_WITH(top_shop)); temp = read_list(shop_f, list, new_format, 1, LIST_ROOM); CREATE(shop_index[top_shop].in_room, int, temp); for (count = 0; count < temp; count++) SHOP_ROOM(top_shop, count) = BUY_TYPE(list[count]); read_line(shop_f, "%d", &SHOP_OPEN1(top_shop)); read_line(shop_f, "%d", &SHOP_CLOSE1(top_shop)); read_line(shop_f, "%d", &SHOP_OPEN2(top_shop)); read_line(shop_f, "%d", &SHOP_CLOSE2(top_shop)); SHOP_BANK(top_shop) = 0; SHOP_SORT(top_shop) = 0; SHOP_FUNC(top_shop) = 0; top_shop++; } else { if (*buf == '$') /* EOF */
void sedit_parse(struct descriptor_data *d, char *arg) { int i; if (OLC_MODE(d) > SEDIT_NUMERICAL_RESPONSE) { if (!isdigit(arg[0]) && ((*arg == '-') && (!isdigit(arg[1])))) { write_to_output(d, "Field must be numerical, try again : "); return; } } switch (OLC_MODE(d)) { /*-------------------------------------------------------------------*/ case SEDIT_CONFIRM_SAVESTRING: switch (*arg) { case 'y': case 'Y': sedit_save_internally(d); mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, "OLC: %s edits shop %d", GET_NAME(d->character), OLC_NUM(d)); if (CONFIG_OLC_SAVE) { sedit_save_to_disk(real_zone_by_thing(OLC_NUM(d))); write_to_output(d, "Shop saved to disk.\r\n"); } else write_to_output(d, "Shop saved to memory.\r\n"); cleanup_olc(d, CLEANUP_STRUCTS); return; case 'n': case 'N': cleanup_olc(d, CLEANUP_ALL); return; default: write_to_output(d, "Invalid choice!\r\nDo you wish to save your changes? : "); return; } break; /*-------------------------------------------------------------------*/ case SEDIT_MAIN_MENU: i = 0; switch (*arg) { case 'q': case 'Q': if (OLC_VAL(d)) { /* Anything been changed? */ write_to_output(d, "Do you wish to save your changes? : "); OLC_MODE(d) = SEDIT_CONFIRM_SAVESTRING; } else cleanup_olc(d, CLEANUP_ALL); return; case '0': OLC_MODE(d) = SEDIT_KEEPER; write_to_output(d, "Enter vnum number of shop keeper : "); return; case '1': OLC_MODE(d) = SEDIT_OPEN1; i++; break; case '2': OLC_MODE(d) = SEDIT_CLOSE1; i++; break; case '3': OLC_MODE(d) = SEDIT_OPEN2; i++; break; case '4': OLC_MODE(d) = SEDIT_CLOSE2; i++; break; case '5': OLC_MODE(d) = SEDIT_BUY_PROFIT; i++; break; case '6': OLC_MODE(d) = SEDIT_SELL_PROFIT; i++; break; case '7': OLC_MODE(d) = SEDIT_NOITEM1; i--; break; case '8': OLC_MODE(d) = SEDIT_NOITEM2; i--; break; case '9': OLC_MODE(d) = SEDIT_NOCASH1; i--; break; case 'a': case 'A': OLC_MODE(d) = SEDIT_NOCASH2; i--; break; case 'b': case 'B': OLC_MODE(d) = SEDIT_NOBUY; i--; break; case 'c': case 'C': OLC_MODE(d) = SEDIT_BUY; i--; break; case 'd': case 'D': OLC_MODE(d) = SEDIT_SELL; i--; break; case 'e': case 'E': sedit_no_trade_menu(d); return; case 'f': case 'F': sedit_shop_flags_menu(d); return; case 'r': case 'R': sedit_rooms_menu(d); return; case 'p': case 'P': sedit_products_menu(d); return; case 't': case 'T': sedit_namelist_menu(d); return; default: sedit_disp_menu(d); return; } if (i == 0) break; else if (i == 1) write_to_output(d, "\r\nEnter new value : "); else if (i == -1) write_to_output(d, "\r\nEnter new text :\r\n] "); else write_to_output(d, "Oops...\r\n"); return; /*-------------------------------------------------------------------*/ case SEDIT_NAMELIST_MENU: switch (*arg) { case 'a': case 'A': sedit_types_menu(d); return; case 'd': case 'D': write_to_output(d, "\r\nDelete which entry? : "); OLC_MODE(d) = SEDIT_DELETE_TYPE; return; case 'q': case 'Q': break; } break; /*-------------------------------------------------------------------*/ case SEDIT_PRODUCTS_MENU: switch (*arg) { case 'a': case 'A': write_to_output(d, "\r\nEnter new product vnum number : "); OLC_MODE(d) = SEDIT_NEW_PRODUCT; return; case 'd': case 'D': write_to_output(d, "\r\nDelete which product? : "); OLC_MODE(d) = SEDIT_DELETE_PRODUCT; return; case 'q': case 'Q': break; } break; /*-------------------------------------------------------------------*/ case SEDIT_ROOMS_MENU: switch (*arg) { case 'a': case 'A': write_to_output(d, "\r\nEnter new room vnum number : "); OLC_MODE(d) = SEDIT_NEW_ROOM; return; case 'c': case 'C': sedit_compact_rooms_menu(d); return; case 'l': case 'L': sedit_rooms_menu(d); return; case 'd': case 'D': write_to_output(d, "\r\nDelete which room? : "); OLC_MODE(d) = SEDIT_DELETE_ROOM; return; case 'q': case 'Q': break; } break; /*-------------------------------------------------------------------*/ /* * String edits. */ case SEDIT_NOITEM1: if (genolc_checkstring(d, arg)) modify_string(&S_NOITEM1(OLC_SHOP(d)), arg); break; case SEDIT_NOITEM2: if (genolc_checkstring(d, arg)) modify_string(&S_NOITEM2(OLC_SHOP(d)), arg); break; case SEDIT_NOCASH1: if (genolc_checkstring(d, arg)) modify_string(&S_NOCASH1(OLC_SHOP(d)), arg); break; case SEDIT_NOCASH2: if (genolc_checkstring(d, arg)) modify_string(&S_NOCASH2(OLC_SHOP(d)), arg); break; case SEDIT_NOBUY: if (genolc_checkstring(d, arg)) modify_string(&S_NOBUY(OLC_SHOP(d)), arg); break; case SEDIT_BUY: if (genolc_checkstring(d, arg)) modify_string(&S_BUY(OLC_SHOP(d)), arg); break; case SEDIT_SELL: if (genolc_checkstring(d, arg)) modify_string(&S_SELL(OLC_SHOP(d)), arg); break; case SEDIT_NAMELIST: if (genolc_checkstring(d, arg)) { struct shop_buy_data new_entry; BUY_TYPE(new_entry) = OLC_VAL(d); BUY_WORD(new_entry) = strdup(arg); add_to_type_list(&(S_NAMELISTS(OLC_SHOP(d))), &new_entry); } sedit_namelist_menu(d); return; /*-------------------------------------------------------------------*/ /* * Numerical responses. */ case SEDIT_KEEPER: i = atoi(arg); if ((i = atoi(arg)) != -1) if ((i = real_mobile(i)) == NOBODY) { write_to_output(d, "That mobile does not exist, try again : "); return; } S_KEEPER(OLC_SHOP(d)) = i; if (i == -1) break; /* * Fiddle with special procs. */ S_FUNC(OLC_SHOP(d)) = mob_index[i].func != shop_keeper ? mob_index[i].func : NULL; mob_index[i].func = shop_keeper; break; case SEDIT_OPEN1: S_OPEN1(OLC_SHOP(d)) = LIMIT(atoi(arg), 0, 28); break; case SEDIT_OPEN2: S_OPEN2(OLC_SHOP(d)) = LIMIT(atoi(arg), 0, 28); break; case SEDIT_CLOSE1: S_CLOSE1(OLC_SHOP(d)) = LIMIT(atoi(arg), 0, 28); break; case SEDIT_CLOSE2: S_CLOSE2(OLC_SHOP(d)) = LIMIT(atoi(arg), 0, 28); break; case SEDIT_BUY_PROFIT: sscanf(arg, "%f", &S_BUYPROFIT(OLC_SHOP(d))); break; case SEDIT_SELL_PROFIT: sscanf(arg, "%f", &S_SELLPROFIT(OLC_SHOP(d))); break; case SEDIT_TYPE_MENU: OLC_VAL(d) = LIMIT(atoi(arg), 0, NUM_ITEM_TYPES - 1); write_to_output(d, "Enter namelist (return for none) :-\r\n] "); OLC_MODE(d) = SEDIT_NAMELIST; return; case SEDIT_DELETE_TYPE: remove_from_type_list(&(S_NAMELISTS(OLC_SHOP(d))), atoi(arg)); sedit_namelist_menu(d); return; case SEDIT_NEW_PRODUCT: if ((i = atoi(arg)) != -1) if ((i = real_object(i)) == NOTHING) { write_to_output(d, "That object does not exist, try again : "); return; } if (i > 0) add_to_int_list(&(S_PRODUCTS(OLC_SHOP(d))), i); sedit_products_menu(d); return; case SEDIT_DELETE_PRODUCT: remove_from_int_list(&(S_PRODUCTS(OLC_SHOP(d))), atoi(arg)); sedit_products_menu(d); return; case SEDIT_NEW_ROOM: if ((i = atoi(arg)) != -1) if ((i = real_room(i)) == NOWHERE) { write_to_output(d, "That room does not exist, try again : "); return; } if (i >= 0) add_to_int_list(&(S_ROOMS(OLC_SHOP(d))), atoi(arg)); sedit_rooms_menu(d); return; case SEDIT_DELETE_ROOM: remove_from_int_list(&(S_ROOMS(OLC_SHOP(d))), atoi(arg)); sedit_rooms_menu(d); return; case SEDIT_SHOP_FLAGS: if ((i = LIMIT(atoi(arg), 0, NUM_SHOP_FLAGS)) > 0) { TOGGLE_BIT(S_BITVECTOR(OLC_SHOP(d)), 1 << (i - 1)); sedit_shop_flags_menu(d); return; } break; case SEDIT_NOTRADE: if ((i = LIMIT(atoi(arg), 0, NUM_TRADERS)) > 0) { TOGGLE_BIT(S_NOTRADE(OLC_SHOP(d)), 1 << (i - 1)); sedit_no_trade_menu(d); return; } break; /*-------------------------------------------------------------------*/ default: /* * We should never get here. */ cleanup_olc(d, CLEANUP_ALL); mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: sedit_parse(): Reached default case!"); write_to_output(d, "Oops...\r\n"); break; } /*-------------------------------------------------------------------*/ /* * END OF CASE * If we get here, we have probably changed something, and now want to * return to main menu. Use OLC_VAL as a 'has changed' flag. */ OLC_VAL(d) = 1; sedit_disp_menu(d); }