/* * Free all the notice character strings in a shop structure. */ void free_shop_strings(struct shop_data *shop) { if (S_NOITEM1(shop)) { free(S_NOITEM1(shop)); S_NOITEM1(shop) = NULL; } if (S_NOITEM2(shop)) { free(S_NOITEM2(shop)); S_NOITEM2(shop) = NULL; } if (S_NOCASH1(shop)) { free(S_NOCASH1(shop)); S_NOCASH1(shop) = NULL; } if (S_NOCASH2(shop)) { free(S_NOCASH2(shop)); S_NOCASH2(shop) = NULL; } if (S_NOBUY(shop)) { free(S_NOBUY(shop)); S_NOBUY(shop) = NULL; } if (S_BUY(shop)) { free(S_BUY(shop)); S_BUY(shop) = NULL; } if (S_SELL(shop)) { free(S_SELL(shop)); S_SELL(shop) = NULL; } }
static void sedit_setup_new(struct descriptor_data *d) { struct shop_data *shop; /* Allocate a scratch shop structure. */ CREATE(shop, struct shop_data, 1); /* Fill in some default values. */ S_KEEPER(shop) = NOBODY; S_CLOSE1(shop) = 28; S_BUYPROFIT(shop) = 1.0; S_SELLPROFIT(shop) = 1.0; S_NOTRADE(shop) = 0; /* Add a spice of default strings. */ S_NOITEM1(shop) = strdup("%s Sorry, I don't stock that item."); S_NOITEM2(shop) = strdup("%s You don't seem to have that."); S_NOCASH1(shop) = strdup("%s I can't afford that!"); S_NOCASH2(shop) = strdup("%s You are too poor!"); S_NOBUY(shop) = strdup("%s I don't trade in such items."); S_BUY(shop) = strdup("%s That'll be %d coins, thanks."); S_SELL(shop) = strdup("%s I'll give you %d coins for that."); /* Stir the lists lightly. */ CREATE(S_PRODUCTS(shop), obj_vnum, 1); S_PRODUCT(shop, 0) = NOTHING; CREATE(S_ROOMS(shop), room_rnum, 1); S_ROOM(shop, 0) = NOWHERE; CREATE(S_NAMELISTS(shop), struct shop_buy_data, 1); S_BUYTYPE(shop, 0) = NOTHING; /* Presto! A shop. */ OLC_SHOP(d) = shop; }
void copy_shop(struct shop_data *tshop, struct shop_data *fshop) { /* * Copy basic information over. */ S_NUM(tshop) = S_NUM(fshop); S_KEEPER(tshop) = S_KEEPER(fshop); S_OPEN1(tshop) = S_OPEN1(fshop); S_CLOSE1(tshop) = S_CLOSE1(fshop); S_OPEN2(tshop) = S_OPEN2(fshop); S_CLOSE2(tshop) = S_CLOSE2(fshop); S_BANK(tshop) = S_BANK(fshop); S_BROKE_TEMPER(tshop) = S_BROKE_TEMPER(fshop); S_BITVECTOR(tshop) = S_BITVECTOR(fshop); S_NOTRADE(tshop) = S_NOTRADE(fshop); S_SORT(tshop) = S_SORT(fshop); S_BUYPROFIT(tshop) = S_BUYPROFIT(fshop); S_SELLPROFIT(tshop) = S_SELLPROFIT(fshop); S_FUNC(tshop) = S_FUNC(fshop); /* * Copy lists over. */ copy_list(&(S_ROOMS(tshop)), S_ROOMS(fshop)); copy_list(&(S_PRODUCTS(tshop)), S_PRODUCTS(fshop)); copy_type_list(&(tshop->type), fshop->type); /* * Copy notification strings over. */ free_shop_strings(tshop); S_NOITEM1(tshop) = str_dup(S_NOITEM1(fshop)); S_NOITEM2(tshop) = str_dup(S_NOITEM2(fshop)); S_NOCASH1(tshop) = str_dup(S_NOCASH1(fshop)); S_NOCASH2(tshop) = str_dup(S_NOCASH2(fshop)); S_NOBUY(tshop) = str_dup(S_NOBUY(fshop)); S_BUY(tshop) = str_dup(S_BUY(fshop)); S_SELL(tshop) = str_dup(S_SELL(fshop)); S_PROPRIETARIO(tshop) = S_PROPRIETARIO(fshop); S_CLAN(tshop) = S_CLAN(fshop); S_VALORE(tshop) = S_VALORE(fshop); S_VALORE1(tshop) = S_VALORE1(fshop); S_VALORE2(tshop) = S_VALORE2(fshop); S_VALORE3(tshop) = S_VALORE3(fshop); S_VALORE4(tshop) = S_VALORE4(fshop); S_VALORE5(tshop) = S_VALORE5(fshop); }
/* Display main menu. */ static void sedit_disp_menu(struct descriptor_data *d) { char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; struct shop_data *shop; shop = OLC_SHOP(d); get_char_colors(d->character); clear_screen(d); sprintbit(S_NOTRADE(shop), trade_letters, buf1, sizeof(buf1)); sprintbit(S_BITVECTOR(shop), shop_bits, buf2, sizeof(buf2)); write_to_output(d, "-- Shop Number : [%s%d%s]\r\n" "%s0%s) Keeper : [%s%d%s] %s%s\r\n" "%s1%s) Open 1 : %s%4d%s %s2%s) Close 1 : %s%4d\r\n" "%s3%s) Open 2 : %s%4d%s %s4%s) Close 2 : %s%4d\r\n" "%s5%s) Sell rate : %s%1.2f%s %s6%s) Buy rate : %s%1.2f\r\n" "%s7%s) Keeper no item : %s%s\r\n" "%s8%s) Player no item : %s%s\r\n" "%s9%s) Keeper no cash : %s%s\r\n" "%sA%s) Player no cash : %s%s\r\n" "%sB%s) Keeper no buy : %s%s\r\n" "%sC%s) Buy success : %s%s\r\n" "%sD%s) Sell success : %s%s\r\n" "%sE%s) No Trade With : %s%s\r\n" "%sF%s) Shop flags : %s%s\r\n" "%sR%s) Rooms Menu\r\n" "%sP%s) Products Menu\r\n" "%sT%s) Accept Types Menu\r\n" "%sW%s) Copy Shop\r\n" "%sQ%s) Quit\r\n" "Enter Choice : ", cyn, OLC_NUM(d), nrm, grn, nrm, cyn, S_KEEPER(shop) == NOBODY ? -1 : mob_index[S_KEEPER(shop)].vnum, nrm, yel, S_KEEPER(shop) == NOBODY ? "None" : mob_proto[S_KEEPER(shop)].player.short_descr, grn, nrm, cyn, S_OPEN1(shop), nrm, grn, nrm, cyn, S_CLOSE1(shop), grn, nrm, cyn, S_OPEN2(shop), nrm, grn, nrm, cyn, S_CLOSE2(shop), grn, nrm, cyn, S_BUYPROFIT(shop), nrm, grn, nrm, cyn, S_SELLPROFIT(shop), grn, nrm, yel, S_NOITEM1(shop), grn, nrm, yel, S_NOITEM2(shop), grn, nrm, yel, S_NOCASH1(shop), grn, nrm, yel, S_NOCASH2(shop), grn, nrm, yel, S_NOBUY(shop), grn, nrm, yel, S_BUY(shop), grn, nrm, yel, S_SELL(shop), grn, nrm, cyn, buf1, grn, nrm, cyn, buf2, grn, nrm, grn, nrm, grn, nrm, grn, nrm, grn, nrm ); OLC_MODE(d) = SEDIT_MAIN_MENU; }
void sedit_setup_new(struct descriptor_data *d) { struct shop_data *shop; /* * Allocate a scratch shop structure. */ CREATE(shop, struct shop_data, 1); /* * Fill in some default values. */ S_KEEPER(shop) = -1; S_CLOSE1(shop) = 28; S_BUYPROFIT(shop) = 1.0; S_SELLPROFIT(shop) = 1.0; S_PROPRIETARIO(shop) = 0; S_CLAN(shop) = -1; S_VALORE(shop) = 0; S_VALORE1(shop) = -1; S_VALORE2(shop) = -1; S_VALORE3(shop) = -1; S_VALORE4(shop) = -1; S_VALORE5(shop) = -1; /* * Add a spice of default strings. */ S_NOITEM1(shop) = str_dup("%s Mi dispiace, non ho quell'oggetto in assortimento."); S_NOITEM2(shop) = str_dup("%s Non sembra che tu lo abbia."); S_NOCASH1(shop) = str_dup("%s Non me lo posso permettere!"); S_NOCASH2(shop) = str_dup("%s Sei troppo povero!"); S_NOBUY(shop) = str_dup("%s Non tratto quel genere di cose."); S_BUY(shop) = str_dup("%s Sono %d monete, grazie."); S_SELL(shop) = str_dup("%s Ti potrei dare %d monete per quello."); /* * Stir the lists lightly. */ CREATE(S_PRODUCTS(shop), int, 1); S_PRODUCT(shop, 0) = -1; CREATE(S_ROOMS(shop), int, 1); S_ROOM(shop, 0) = -1; CREATE(S_NAMELISTS(shop), struct shop_buy_data, 1); S_BUYTYPE(shop, 0) = -1; /* * Presto! A shop. */ OLC_SHOP(d) = shop; sedit_disp_menu(d); }
int save_shops(zone_rnum zone_num) { int i, j, rshop, vzone, top; FILE *shop_file; char fname[64]; struct shop_data *shop; if (zone_num < 0 || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_mobiles: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } vzone = zone_table[zone_num].number; top = zone_table[zone_num].top; sprintf(fname, "%s/%d.new", SHP_PREFIX, vzone); if (!(shop_file = fopen(fname, "w"))) { mudlog("SYSERR: OLC: Cannot open shop file!", BRF, LVL_GOD, TRUE); return FALSE; } else if (fprintf(shop_file, "CircleMUD v3.0 Shop File~\n") < 0) { mudlog("SYSERR: OLC: Cannot write to shop file!", BRF, LVL_GOD, TRUE); fclose(shop_file); return FALSE; } /* * Search database for shops in this zone. */ for (i = vzone * 100; i <= top; i++) { if ((rshop = real_shop(i)) != -1) { fprintf(shop_file, "#%d~\n", i); shop = shop_index + rshop; /* * Save the products. */ for (j = 0; S_PRODUCT(shop, j) != -1; j++) fprintf(shop_file, "%d\n", obj_index[S_PRODUCT(shop, j)].vnum); /* * Save the rates. */ fprintf(shop_file, "-1\n%1.2f\n%1.2f\n", S_BUYPROFIT(shop), S_SELLPROFIT(shop)); /* * Save the buy types and namelists. */ j = -1; do { j++; fprintf(shop_file, "%d%s\n", S_BUYTYPE(shop, j), S_BUYWORD(shop, j) ? S_BUYWORD(shop, j) : ""); } while (S_BUYTYPE(shop, j) != -1); /* * Save messages'n'stuff. * Added some small'n'silly defaults as sanity checks. */ fprintf(shop_file, "%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n" "%d\n%ld\n%d\n%d\n", S_NOITEM1(shop) ? S_NOITEM1(shop) : "%s Ke?!", S_NOITEM2(shop) ? S_NOITEM2(shop) : "%s Ke?!", S_NOBUY(shop) ? S_NOBUY(shop) : "%s Ke?!", S_NOCASH1(shop) ? S_NOCASH1(shop) : "%s Ke?!", S_NOCASH2(shop) ? S_NOCASH2(shop) : "%s Ke?!", S_BUY(shop) ? S_BUY(shop) : "%s Ke?! %d?", S_SELL(shop) ? S_SELL(shop) : "%s Ke?! %d?", S_BROKE_TEMPER(shop), S_BITVECTOR(shop), mob_index[S_KEEPER(shop)].vnum, S_NOTRADE(shop) ); /* * Save the rooms. */ j = -1; do { j++; fprintf(shop_file, "%d\n", S_ROOM(shop, j)); } while (S_ROOM(shop, j) != -1); /* * Save open/closing times */ fprintf(shop_file, "%d\n%d\n%d\n%d\n", S_OPEN1(shop), S_CLOSE1(shop), S_OPEN2(shop), S_CLOSE2(shop)); } } fprintf(shop_file, "$~\n"); fclose(shop_file); sprintf(buf2, "%s/%d.shp", SHP_PREFIX, vzone); remove(buf2); rename(fname, buf2); remove_from_save_list(vzone, SL_SHP); return TRUE; }
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); }