int add_shop(struct shop_data *nshp) { shop_rnum rshop; int found = 0; zone_rnum rznum = real_zone_by_thing(S_NUM(nshp)); /* * The shop already exists, just update it. */ if ((rshop = real_shop(S_NUM(nshp))) != NOWHERE) { free_shop_strings(&shop_index[rshop]); copy_shop(&shop_index[rshop], nshp); if (rznum != NOWHERE) add_to_save_list(zone_table[rznum].number, SL_SHP); else mudlog("SYSERR: GenOLC: Cannot determine shop zone.", BRF, LVL_BUILDER, TRUE); return rshop; } top_shop++; RECREATE(shop_index, struct shop_data, top_shop + 1); for (rshop = top_shop; rshop > 0; rshop--) { if (nshp->vnum > SHOP_NUM(rshop - 1)) { found = rshop; /* Make a "nofree" variant and remove these later. */ shop_index[rshop].in_room = NULL; shop_index[rshop].producing = NULL; shop_index[rshop].type = NULL; copy_shop(&shop_index[rshop], nshp); break; } shop_index[rshop] = shop_index[rshop - 1]; } if (!found) { /* Make a "nofree" variant and remove these later. */ shop_index[rshop].in_room = NULL; shop_index[rshop].producing = NULL; shop_index[rshop].type = NULL; copy_shop(&shop_index[0], nshp); } if (rznum != NOWHERE) add_to_save_list(zone_table[rznum].number, SL_SHP); else mudlog("SYSERR: GenOLC: Cannot determine shop zone.", BRF, LVL_BUILDER, TRUE); return rshop; }
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; }
/* The GARGANTUAN event handler */ 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; } case SEDIT_MAIN_MENU: i = 0; switch (*arg) { case 'w': case 'W': write_to_output(d, "Copy what shop? "); OLC_MODE(d) = SEDIT_COPY; return; 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_shop_string(&S_NOITEM1(OLC_SHOP(d)), arg); break; case SEDIT_NOITEM2: if (genolc_checkstring(d, arg)) modify_shop_string(&S_NOITEM2(OLC_SHOP(d)), arg); break; case SEDIT_NOCASH1: if (genolc_checkstring(d, arg)) modify_shop_string(&S_NOCASH1(OLC_SHOP(d)), arg); break; case SEDIT_NOCASH2: if (genolc_checkstring(d, arg)) modify_shop_string(&S_NOCASH2(OLC_SHOP(d)), arg); break; case SEDIT_NOBUY: if (genolc_checkstring(d, arg)) modify_shop_string(&S_NOBUY(OLC_SHOP(d)), arg); break; case SEDIT_BUY: if (genolc_checkstring(d, arg)) modify_shop_string(&S_BUY(OLC_SHOP(d)), arg); break; case SEDIT_SELL: if (genolc_checkstring(d, arg)) modify_shop_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_shop_to_type_list(&(S_NAMELISTS(OLC_SHOP(d))), &new_entry); } sedit_namelist_menu(d); return; /* Numerical responses. */ case SEDIT_KEEPER: 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_shop_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_shop_to_int_list(&(S_PRODUCTS(OLC_SHOP(d))), i); sedit_products_menu(d); return; case SEDIT_DELETE_PRODUCT: remove_shop_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_shop_to_int_list(&(S_ROOMS(OLC_SHOP(d))), atoi(arg)); sedit_rooms_menu(d); return; case SEDIT_DELETE_ROOM: remove_shop_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; case SEDIT_COPY: if ((i = real_shop(atoi(arg))) != NOWHERE) { sedit_setup_existing(d, i); } else write_to_output(d, "That shop does not exist.\r\n"); 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; } /* 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); }