static void quest_weapon_enchant(struct creature *ch, struct obj_data *obj, int lvl) { int i; for (i = MAX_OBJ_AFFECT - 1; i >= 0; i--) { if (obj->affected[i].location == APPLY_HITROLL || obj->affected[i].location == APPLY_DAMROLL) { obj->affected[i].location = APPLY_NONE; obj->affected[i].modifier = 0; } else if (i < MAX_OBJ_AFFECT - 2 && obj->affected[i].location) { obj->affected[i + 2].location = obj->affected[i].location; obj->affected[i + 2].modifier = obj->affected[i].modifier; } } obj->affected[0].location = APPLY_HITROLL; obj->affected[0].modifier = MAX(2, number(2, 4)) + (lvl >= 50) + (lvl >= 56) + (lvl >= 60) + (lvl >= 67); obj->affected[1].location = APPLY_DAMROLL; obj->affected[1].modifier = MAX(2, number(2, 4)) + (lvl >= 50) + (lvl >= 56) + (lvl >= 60) + (lvl >= 67); if (IS_GOOD(ch)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_ANTI_EVIL); act("$p glows a bright blue.", false, ch, obj, NULL, TO_CHAR); } else if (IS_EVIL(ch)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_ANTI_GOOD); act("$p glows a bright red.", false, ch, obj, NULL, TO_CHAR); } else { act("$p glows a bright yellow.", false, ch, obj, NULL, TO_CHAR); } SET_BIT(GET_OBJ_EXTRA(obj), ITEM_MAGIC | ITEM_GLOW); }
struct obj_data *Obj_from_store(struct obj_file_elem object, int *location) { struct obj_data *obj; int j; *location = 0; if (real_object(object.item_number) != NOTHING) { obj = read_object(object.item_number, VIRTUAL); #if USE_AUTOEQ *location = object.location; #endif GET_OBJ_VAL(obj, 0) = object.value[0]; GET_OBJ_VAL(obj, 1) = object.value[1]; GET_OBJ_VAL(obj, 2) = object.value[2]; GET_OBJ_VAL(obj, 3) = object.value[3]; GET_OBJ_EXTRA(obj) = object.extra_flags; GET_OBJ_WEIGHT(obj) = object.weight; GET_OBJ_TIMER(obj) = object.timer; obj->obj_flags.bitvector = object.bitvector; for (j = 0; j < MAX_OBJ_AFFECT; j++) obj->affected[j] = object.affected[j]; return (obj); } else return (NULL); }
struct obj_data * Obj_from_store(struct obj_file_elem object, int *locate) { struct obj_data *obj; int j; if (real_object(object.item_number) > -1) { obj = read_object(object.item_number, VNUMBER); *locate = (int) object.locate; GET_OBJ_VAL(obj, 0) = object.value[0]; GET_OBJ_VAL(obj, 1) = object.value[1]; GET_OBJ_VAL(obj, 2) = object.value[2]; GET_OBJ_VAL(obj, 3) = object.value[3]; GET_OBJ_VAL(obj, 4) = object.value[4]; GET_OBJ_VAL(obj, 5) = object.value[5]; GET_OBJ_VAL(obj, 6) = object.value[6]; GET_OBJ_VAL(obj, 7) = object.value[7]; GET_OBJ_VAL(obj, 8) = object.value[8]; GET_OBJ_VAL(obj, 9) = object.value[9]; GET_OBJ_EXTRA(obj) = object.extra_flags; GET_OBJ_WEIGHT(obj) = object.weight; GET_OBJ_TIMER(obj) = object.timer; obj->obj_flags.bitvector = object.bitvector; for (j = 0; j < MAX_OBJ_AFFECT; j++) obj->affected[j] = object.affected[j]; return obj; } else return NULL; }
int Obj_to_store_from(struct obj_data * obj, FILE * fl, int locate) { int j; struct obj_file_elem object; object.item_number = GET_OBJ_VNUM(obj); object.locate = (sh_int) locate; /* where worn or inventory? */ object.value[0] = GET_OBJ_VAL(obj, 0); object.value[1] = GET_OBJ_VAL(obj, 1); object.value[2] = GET_OBJ_VAL(obj, 2); object.value[3] = GET_OBJ_VAL(obj, 3); object.value[4] = GET_OBJ_VAL(obj, 4); object.value[5] = GET_OBJ_VAL(obj, 5); object.value[6] = GET_OBJ_VAL(obj, 6); object.value[7] = GET_OBJ_VAL(obj, 7); object.value[8] = GET_OBJ_VAL(obj, 8); object.value[9] = GET_OBJ_VAL(obj, 9); object.extra_flags = GET_OBJ_EXTRA(obj); object.weight = GET_OBJ_WEIGHT(obj); object.timer = GET_OBJ_TIMER(obj); object.bitvector = obj->obj_flags.bitvector; for (j = 0; j < MAX_OBJ_AFFECT; j++) object.affected[j] = obj->affected[j]; if (fwrite(&object, sizeof(struct obj_file_elem), 1, fl) < 1) { perror("Error writing object in Obj_to_store"); return 0; } return 1; }
void make_corpse(struct char_data * ch) { struct obj_data *corpse, *o; struct obj_data *money; int i; corpse = create_obj(); corpse->item_number = NOTHING; IN_ROOM(corpse) = NOWHERE; corpse->name = str_dup("corpse"); sprintf(buf2, "The corpse of %s is lying here.", GET_NAME(ch)); corpse->description = str_dup(buf2); sprintf(buf2, "the corpse of %s", GET_NAME(ch)); corpse->short_description = str_dup(buf2); GET_OBJ_TYPE(corpse) = ITEM_CONTAINER; GET_OBJ_WEAR(corpse) = ITEM_WEAR_TAKE; GET_OBJ_EXTRA(corpse) = ITEM_NODONATE; GET_OBJ_VAL(corpse, 0) = 0; /* You can't store stuff in a corpse */ GET_OBJ_VAL(corpse, 3) = 1; /* corpse identifier */ GET_OBJ_WEIGHT(corpse) = GET_WEIGHT(ch) + IS_CARRYING_W(ch); GET_OBJ_RENT(corpse) = 100000; if (IS_NPC(ch)) GET_OBJ_TIMER(corpse) = max_npc_corpse_time; else GET_OBJ_TIMER(corpse) = max_pc_corpse_time; /* transfer character's inventory to the corpse */ corpse->contains = ch->carrying; for (o = corpse->contains; o != NULL; o = o->next_content) o->in_obj = corpse; object_list_new_owner(corpse, NULL); /* transfer character's equipment to the corpse */ for (i = 0; i < NUM_WEARS; i++) if (GET_EQ(ch, i)) { remove_otrigger(GET_EQ(ch, i), ch); obj_to_obj(unequip_char(ch, i), corpse); } /* transfer gold */ if (GET_GOLD(ch) > 0) { /* following 'if' clause added to fix gold duplication loophole */ if (IS_NPC(ch) || (!IS_NPC(ch) && ch->desc)) { money = create_money(GET_GOLD(ch)); obj_to_obj(money, corpse); } GET_GOLD(ch) = 0; } ch->carrying = NULL; IS_CARRYING_N(ch) = 0; IS_CARRYING_W(ch) = 0; obj_to_room(corpse, IN_ROOM(ch)); }
static void quest_armor_enchant(struct creature *ch, struct obj_data *obj, int lvl) { int i; for (i = 0; i < MAX_OBJ_AFFECT - 1; i++) { if (obj->affected[i].location == APPLY_AC || obj->affected[i].location == APPLY_SAVING_BREATH || obj->affected[i].location == APPLY_SAVING_SPELL || obj->affected[i].location == APPLY_SAVING_PARA) { obj->affected[i].location = APPLY_NONE; obj->affected[i].modifier = 0; } } obj->affected[0].location = APPLY_AC; obj->affected[0].modifier = -(lvl / 8) - 5; obj->affected[1].location = APPLY_SAVING_PARA; obj->affected[1].modifier = -(4 + (lvl >= 53)); obj->affected[2].location = APPLY_SAVING_BREATH; obj->affected[2].modifier = -(4 + (lvl >= 53)); obj->affected[3].location = APPLY_SAVING_SPELL; obj->affected[3].modifier = -(4 + (lvl >= 53)); if (IS_GOOD(ch)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_ANTI_EVIL); act("$p glows a bright blue.", false, ch, obj, NULL, TO_CHAR); } else if (IS_EVIL(ch)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_ANTI_GOOD); act("$p glows a bright red.", false, ch, obj, NULL, TO_CHAR); } else { act("$p glows a bright yellow.", false, ch, obj, NULL, TO_CHAR); } SET_BIT(GET_OBJ_EXTRA(obj), ITEM_MAGIC | ITEM_GLOW); }
int carrying_quest_item(CharData *ch) { ObjData *obj, *objnext = NULL; for( obj = ch->carrying; obj; obj = objnext ) { objnext = obj->next_content; if ( IS_SET_AR(GET_OBJ_EXTRA(obj), ITEM_ARENA) ) { return 1; } } // for // No quest item, returning 0: return 0; }
/* * Object extra flags. */ void oedit_disp_extra_menu(struct descriptor_data *d) { char bits[MAX_STRING_LENGTH]; int counter, columns = 0; get_char_colors(d->character); clear_screen(d); for (counter = 0; counter < NUM_ITEM_FLAGS; counter++) { write_to_output(d, "%s%2d%s) %-20.20s %s", grn, counter + 1, nrm, extra_bits[counter], !(++columns % 2) ? "\r\n" : ""); } sprintbit(GET_OBJ_EXTRA(OLC_OBJ(d)), extra_bits, bits, sizeof(bits)); write_to_output(d, "\r\nObject flags: %s%s%s\r\n" "Enter object extra flag (0 to quit) : ", cyn, bits, nrm); }
void mag_alter_objs(int level, struct char_data *ch, struct obj_data *obj, int spellnum, int savetype) { const char *to_char = NULL, *to_room = NULL; if (obj == NULL) return; switch (spellnum) { case SPELL_BLESS: if (!OBJ_FLAGGED(obj, ITEM_BLESS) && (GET_OBJ_WEIGHT(obj) <= 5 * GET_LEVEL(ch))) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_BLESS); to_char = "$p glows briefly."; } break; case SPELL_CURSE: if (!OBJ_FLAGGED(obj, ITEM_NODROP)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_NODROP); if (GET_OBJ_TYPE(obj) == ITEM_WEAPON) GET_OBJ_VAL(obj, 2)--; to_char = "$p briefly glows red."; } break; case SPELL_INVISIBLE: if (!OBJ_FLAGGED(obj, ITEM_NOINVIS | ITEM_INVISIBLE)) { SET_BIT(GET_OBJ_EXTRA(obj), ITEM_INVISIBLE); to_char = "$p vanishes."; } break; case SPELL_POISON: if (((GET_OBJ_TYPE(obj) == ITEM_DRINKCON) || (GET_OBJ_TYPE(obj) == ITEM_FOUNTAIN) || (GET_OBJ_TYPE(obj) == ITEM_FOOD)) && !GET_OBJ_VAL(obj, 3)) { GET_OBJ_VAL(obj, 3) = 1; to_char = "$p steams briefly."; } break; case SPELL_REMOVE_CURSE: if (OBJ_FLAGGED(obj, ITEM_NODROP)) { REMOVE_BIT(GET_OBJ_EXTRA(obj), ITEM_NODROP); if (GET_OBJ_TYPE(obj) == ITEM_WEAPON) GET_OBJ_VAL(obj, 2)++; to_char = "$p briefly glows blue."; } break; case SPELL_REMOVE_POISON: if (((GET_OBJ_TYPE(obj) == ITEM_DRINKCON) || (GET_OBJ_TYPE(obj) == ITEM_FOUNTAIN) || (GET_OBJ_TYPE(obj) == ITEM_FOOD)) && GET_OBJ_VAL(obj, 3)) { GET_OBJ_VAL(obj, 3) = 0; to_char = "$p steams briefly."; } break; } if (to_char == NULL) send_to_char(ch, "%s", NOEFFECT); else act(to_char, TRUE, ch, obj, 0, TO_CHAR); if (to_room != NULL) act(to_room, TRUE, ch, obj, 0, TO_ROOM); else if (to_char != NULL) act(to_char, TRUE, ch, obj, 0, TO_ROOM); }
void make_corpse(struct char_data *ch) { char buf2[MAX_NAME_LENGTH + 64]; struct obj_data *corpse, *o; struct obj_data *money; int i; corpse = create_obj(); corpse->item_number = NOTHING; IN_ROOM(corpse) = NOWHERE; corpse->name = strdup("corpse"); snprintf(buf2, sizeof(buf2), "The corpse of %s is lying here.", GET_NAME(ch)); corpse->description = strdup(buf2); snprintf(buf2, sizeof(buf2), "the corpse of %s", GET_NAME(ch)); corpse->short_description = strdup(buf2); GET_OBJ_TYPE(corpse) = ITEM_CONTAINER; GET_OBJ_WEAR(corpse) = ITEM_WEAR_TAKE; GET_OBJ_EXTRA(corpse) = ITEM_NODONATE; GET_OBJ_VAL(corpse, 0) = 0; /* You can't store stuff in a corpse */ GET_OBJ_VAL(corpse, 3) = 1; /* corpse identifier */ GET_OBJ_WEIGHT(corpse) = GET_WEIGHT(ch) + IS_CARRYING_W(ch); GET_OBJ_RENT(corpse) = 100000; if (IS_NPC(ch)) GET_OBJ_TIMER(corpse) = max_npc_corpse_time; else GET_OBJ_TIMER(corpse) = max_pc_corpse_time; /* transfer character's inventory to the corpse */ corpse->contains = ch->carrying; for (o = corpse->contains; o != NULL; o = o->next_content) o->in_obj = corpse; object_list_new_owner(corpse, NULL); /* transfer character's equipment to the corpse */ for (i = 0; i < NUM_WEARS; i++) if (GET_EQ(ch, i)) obj_to_obj(unequip_char(ch, i), corpse); /* transfer gold */ if (GET_GOLD(ch) > 0) { /* * following 'if' clause added to fix gold duplication loophole * The above line apparently refers to the old "partially log in, * kill the game character, then finish login sequence" duping * bug. The duplication has been fixed (knock on wood) but the * test below shall live on, for a while. -gg 3/3/2002 */ if (IS_NPC(ch) || ch->desc) { money = create_money(GET_GOLD(ch)); obj_to_obj(money, corpse); } GET_GOLD(ch) = 0; } ch->carrying = NULL; IS_CARRYING_N(ch) = 0; IS_CARRYING_W(ch) = 0; obj_to_room(corpse, IN_ROOM(ch)); }
void mag_affect_obj(struct char_data *caster, struct obj_data *object, struct spell_info_type *sinfo, int level) { int i, j; if (object) { for (i = 0; i < NUM_MODIFY; i++) { switch (sinfo->obj_aff[i].location) { case OBJ_EXTRA: if (strcmp(sinfo->command, "darkness") == 0) { REMOVE_BIT(GET_OBJ_EXTRA(object), sinfo->spell_obj_bit); break; } if (!sinfo->spell_obj_bit) SET_BIT(GET_OBJ_EXTRA(object), sinfo->obj_aff[i].location); else SET_BIT(GET_OBJ_EXTRA(object), sinfo->spell_obj_bit); break; case OBJ_VALUE_0: if (strcmp(sinfo->command, "enchant shield") == 0) { if (GET_OBJ_WEAR(object) == ITEM_WEAR_SHIELD) { GET_OBJ_VAL(object, 0) += number((level / 20), sinfo->obj_aff[i].modifier); } } else { GET_OBJ_VAL(object, 0) += sinfo->obj_aff[i].modifier; } break; case OBJ_VALUE_1: GET_OBJ_VAL(object, 1) += sinfo->obj_aff[i].modifier; break; case OBJ_VALUE_2: GET_OBJ_VAL(object, 2) += sinfo->obj_aff[i].modifier; break; case OBJ_VALUE_3: GET_OBJ_VAL(object, 3) += sinfo->obj_aff[i].modifier; break; case OBJ_VALUE_4: GET_OBJ_VAL(object, 4) += sinfo->obj_aff[i].modifier; break; case OBJ_DAMROLL: if (strcmp(sinfo->command, "enchant weapon") == 0) { for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_DAMROLL; object->affected[0].modifier = number((level / 33), sinfo->obj_aff[i].modifier); } } break; case OBJ_HITROLL: if (strcmp(sinfo->command, "enchant weapon") == 0) { for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_HITROLL; object->affected[0].modifier = number((level / 33), sinfo->obj_aff[i].modifier); } } break; case OBJ_SAVING_PARA: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_SAVING_PARA; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_SAVING_ROD: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_SAVING_ROD; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_SAVING_PETRI: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_SAVING_PETRI; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_SAVING_BREATH: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_SAVING_BREATH; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_SAVING_SPELL: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_SAVING_SPELL; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_MAX_HIT: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_MAX_HIT; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_MAX_MANA: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_MAX_MANA; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_MAX_MOVE: for (j = 0; j < MAX_OBJ_AFFECT; j++) if (object->affected[j].location != APPLY_NONE) break; if (j == MAX_OBJ_AFFECT) { object->affected[0].location = APPLY_MAX_MOVE; object->affected[0].modifier = sinfo->obj_aff[i].modifier; } break; case OBJ_RES_LIGHT: GET_OBJ_RESIST(object, DAM_LIGHT) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_DARK: GET_OBJ_RESIST(object, DAM_DARK) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_FIRE: GET_OBJ_RESIST(object, DAM_FIRE) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_COLD: GET_OBJ_RESIST(object, DAM_COLD) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_ACID: GET_OBJ_RESIST(object, DAM_ACID) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_POISON: GET_OBJ_RESIST(object, DAM_POISON) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_DISEASE: GET_OBJ_RESIST(object, DAM_DISEASE) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_CHARM: GET_OBJ_RESIST(object, DAM_CHARM) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_SLEEP: GET_OBJ_RESIST(object, DAM_SLEEP) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_SLASH: GET_OBJ_RESIST(object, DAM_SLASH) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_PIERCE: GET_OBJ_RESIST(object, DAM_PIERCE) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_BLUDGEON: GET_OBJ_RESIST(object, DAM_BLUDGEON) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_NWEAP: GET_OBJ_RESIST(object, DAM_NWEAP) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_MWEAP: GET_OBJ_RESIST(object, DAM_MWEAP) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_MAGIC: GET_OBJ_RESIST(object, DAM_MAGIC) += sinfo->obj_aff[i].modifier; break; case OBJ_RES_ELECTRICITY: GET_OBJ_RESIST(object, DAM_ELECTRICITY) += sinfo->obj_aff[i].modifier; break; case OBJ_TIMER: GET_OBJ_TIMER(object) += (sinfo->obj_aff[i].modifier * level); break; } } } }
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; }
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; }
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); } } }
/** * formerly obj_from_store * * @param FILE *fl The open item file. * @param obj_vnum vnum The vnum of the item being loaded, or NOTHING for non-prototyped item. * @param int *location A place to bind the current WEAR_x position of the item; also used to track container contents. * @param char_data *notify Optional: A person to notify if an item is updated (NULL for none). * @return obj_data* The loaded item, or NULL if it's not available. */ obj_data *Obj_load_from_file(FILE *fl, obj_vnum vnum, int *location, char_data *notify) { void scale_item_to_level(obj_data *obj, int level); char line[MAX_INPUT_LENGTH], error[MAX_STRING_LENGTH], s_in[MAX_INPUT_LENGTH]; obj_data *proto = obj_proto(vnum); struct extra_descr_data *ex; obj_data *obj, *new; bool end = FALSE; int length, i_in[3]; int l_in; bool seek_end = FALSE; // up-front *location = 0; // load based on vnum or, if NOTHING, create anonymous object if (proto) { obj = read_object(vnum, FALSE); } else { // what we do here depends on input ... if the vnum was real, but no proto, it's a deleted obj if (vnum == NOTHING) { obj = create_obj(); } else { obj = NULL; seek_end = TRUE; // signal it to skip obj data } } // default to version 0 if (obj) { OBJ_VERSION(obj) = 0; } // for fread_string sprintf(error, "Obj_load_from_file %d", vnum); // for more readable if/else chain #define OBJ_FILE_TAG(src, tag, len) (!strn_cmp((src), (tag), ((len) = strlen(tag)))) while (!end) { if (!get_line(fl, line)) { log("SYSERR: Unexpected end of obj file in Obj_load_from_file"); exit(1); } if (OBJ_FILE_TAG(line, "End", length)) { end = TRUE; } else if (seek_end) { // are we looking for the end of the object? ignore this line // WARNING: don't put any ifs that require "obj" above seek_end; obj is not guaranteed continue; } else if (OBJ_FILE_TAG(line, "Version:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { OBJ_VERSION(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Location:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0]) == 1) { *location = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Keywords:", length)) { if (GET_OBJ_KEYWORDS(obj) && (!proto || GET_OBJ_KEYWORDS(obj) != GET_OBJ_KEYWORDS(proto))) { free(GET_OBJ_KEYWORDS(obj)); } GET_OBJ_KEYWORDS(obj) = fread_string(fl, error); } else if (OBJ_FILE_TAG(line, "Short-desc:", length)) { if (GET_OBJ_SHORT_DESC(obj) && (!proto || GET_OBJ_SHORT_DESC(obj) != GET_OBJ_SHORT_DESC(proto))) { free(GET_OBJ_SHORT_DESC(obj)); } GET_OBJ_SHORT_DESC(obj) = fread_string(fl, error); } else if (OBJ_FILE_TAG(line, "Long-desc:", length)) { if (GET_OBJ_LONG_DESC(obj) && (!proto || GET_OBJ_LONG_DESC(obj) != GET_OBJ_LONG_DESC(proto))) { free(GET_OBJ_LONG_DESC(obj)); } GET_OBJ_LONG_DESC(obj) = fread_string(fl, error); } else if (OBJ_FILE_TAG(line, "Action-desc:", length)) { if (GET_OBJ_ACTION_DESC(obj) && (!proto || GET_OBJ_ACTION_DESC(obj) != GET_OBJ_ACTION_DESC(proto))) { free(GET_OBJ_ACTION_DESC(obj)); } GET_OBJ_ACTION_DESC(obj) = fread_string(fl, error); } else if (OBJ_FILE_TAG(line, "Extra-desc:", length)) { if (proto && obj->ex_description == proto->ex_description) { obj->ex_description = NULL; } CREATE(ex, struct extra_descr_data, 1); ex->next = obj->ex_description; obj->ex_description = ex; ex->keyword = fread_string(fl, error); ex->description = fread_string(fl, error); } else if (OBJ_FILE_TAG(line, "Val-0:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_VAL(obj, 0) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Val-1:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_VAL(obj, 1) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Val-2:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_VAL(obj, 2) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Type:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_TYPE(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Wear:", length)) { if (sscanf(line + length + 1, "%s", s_in)) { GET_OBJ_WEAR(obj) = asciiflag_conv(s_in); } } else if (OBJ_FILE_TAG(line, "Flags:", length)) { if (sscanf(line + length + 1, "%s", s_in)) { GET_OBJ_EXTRA(obj) = asciiflag_conv(s_in); } } else if (OBJ_FILE_TAG(line, "Affects:", length)) { if (sscanf(line + length + 1, "%s", s_in)) { obj->obj_flags.bitvector = asciiflag_conv(s_in); } } else if (OBJ_FILE_TAG(line, "Timer:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_TIMER(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Current-scale:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_CURRENT_SCALE_LEVEL(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Min-scale:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_MIN_SCALE_LEVEL(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Max-scale:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_MAX_SCALE_LEVEL(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Material:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_OBJ_MATERIAL(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Last-empire:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { obj->last_empire_id = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Last-owner:", length)) { if (sscanf(line + length + 1, "%d", &l_in)) { obj->last_owner_id = l_in; } } else if (OBJ_FILE_TAG(line, "Stolen-timer:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { obj->stolen_timer = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Autostore-timer:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { GET_AUTOSTORE_TIMER(obj) = i_in[0]; } } else if (OBJ_FILE_TAG(line, "Apply:", length)) { if (sscanf(line + length + 1, "%d %d %d", &i_in[0], &i_in[1], &i_in[2])) { obj->affected[i_in[0]].location = i_in[1]; obj->affected[i_in[0]].modifier = i_in[2]; } } else if (OBJ_FILE_TAG(line, "Bound-to:", length)) { if (sscanf(line + length + 1, "%d", &i_in[0])) { struct obj_binding *bind; CREATE(bind, struct obj_binding, 1); bind->idnum = i_in[0]; bind->next = OBJ_BOUND_TO(obj); OBJ_BOUND_TO(obj) = bind; } } else if (OBJ_FILE_TAG(line, "Trigger:", length)) {
/* 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 Obj_to_store(struct obj_data * obj, int objnum, int obj_pos, FILE * fl) { void olc_print_bitvectors(FILE *f, long bitvector, long max); int j; fprintf(fl, "-obj_begin-\n"); fprintf(fl, "-obj_number- %d\n", GET_OBJ_VNUM(obj)); fprintf(fl, "-obj_tnum- %d\n", objnum); fprintf(fl, "-obj_pos- %d\n", obj_pos); if (GET_OBJ_VAL(obj, 0)) { fprintf(fl, "-obj_value0- %d\n", GET_OBJ_VAL(obj, 0)); } if (GET_OBJ_VAL(obj, 1)) { fprintf(fl, "-obj_value1- %d\n", GET_OBJ_VAL(obj, 1)); } if (GET_OBJ_VAL(obj, 2)) { fprintf(fl, "-obj_value2- %d\n", GET_OBJ_VAL(obj, 2)); } if (GET_OBJ_VAL(obj, 3)) { fprintf(fl, "-obj_value3- %d\n", GET_OBJ_VAL(obj, 3)); } if (GET_OBJ_VAL(obj, 4)) { fprintf(fl, "-obj_value4- %d\n", GET_OBJ_VAL(obj, 4)); } if (GET_OBJ_TIMER(obj)) { fprintf(fl, "-obj_timer- %d\n", GET_OBJ_TIMER(obj)); } if (GET_OBJ_EXTRA(obj)) { fprintf(fl, "-obj_extra_flags- "); olc_print_bitvectors(fl, GET_OBJ_EXTRA(obj), NUM_ITEM_FLAGS); fprintf(fl, "\n"); } if (GET_OBJ_BITV(obj)) { fprintf(fl, "-obj_bitvector- "); olc_print_bitvectors(fl, GET_OBJ_BITV(obj), NUM_AFF_FLAGS); fprintf(fl, "\n"); } if (GET_OBJ_BITV2(obj)) { fprintf(fl, "-obj_bitvector- "); olc_print_bitvectors(fl, GET_OBJ_BITV2(obj), NUM_AFF2_FLAGS); fprintf(fl, "\n"); } for (j = 0; j < MAX_OBJ_AFFECT; j++) { if (obj->affected[j].location) { fprintf(fl, "-obj_affect_loc- %d\n", obj->affected[j].location); fprintf(fl, "-obj_affect_mod- %d\n", obj->affected[j].modifier); } } switch (GET_OBJ_TYPE(obj)) { case ITEM_SPELLBOOK: if (GET_OBJ_SPELLLIST(obj)) { for (j = 0; j < GET_OBJ_VAL(obj, 0); j++) { if (GET_OBJ_SPELLLISTNUM(obj, j)) { fprintf(fl, "-obj_spellbook_entry- %s\n", spells[find_skill_num_def(GET_OBJ_SPELLLISTNUM(obj, j))].command); } } } break; case ITEM_POTION: case ITEM_SCROLL: if (GET_OBJ_VAL(obj, 1)) { fprintf(fl, "-obj_spell1- %s\n", spells[find_skill_num_def(GET_OBJ_VAL(obj, 1))].command); } if (GET_OBJ_VAL(obj, 2)) { fprintf(fl, "-obj_spell2- %s\n", spells[find_skill_num_def(GET_OBJ_VAL(obj, 2))].command); } if (GET_OBJ_VAL(obj, 3)) { fprintf(fl, "-obj_spell3- %s\n", spells[find_skill_num_def(GET_OBJ_VAL(obj, 3))].command); } break; case ITEM_WAND: case ITEM_STAFF: if (GET_OBJ_VAL(obj, 1)) { fprintf(fl, "-obj_spell1- %s\n", spells[find_skill_num_def(GET_OBJ_VAL(obj, 1))].command); } break; } fprintf(fl, "-obj_end-\n"); }
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 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 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; }
int evaluate_expression(struct obj_data * obj, char *expr) { struct stack_data ops, vals; char *ptr, *end, name[200]; int temp, index; if (!expr) return TRUE; if (!isalpha(*expr)) return TRUE; ops.len = vals.len = 0; ptr = expr; while (*ptr) { if (isspace(*ptr)) ptr++; else { if ((temp = find_oper_num(*ptr)) == NOTHING) { end = ptr; while (*ptr && !isspace(*ptr) && (find_oper_num(*ptr) == NOTHING)) ptr++; strncpy(name, end, ptr - end); name[ptr - end] = 0; for (index = 0; *extra_bits[index] != '\n'; index++) if (!str_cmp(name, extra_bits[index])) { push(&vals, IS_SET_AR(GET_OBJ_EXTRA(obj), index)); break; } if (*extra_bits[index] == '\n') push(&vals, isname(name, obj->name)); } else { if (temp != OPER_OPEN_PAREN) while (top(&ops) > temp) evaluate_operation(&ops, &vals); if (temp == OPER_CLOSE_PAREN) { if ((temp = pop(&ops)) != OPER_OPEN_PAREN) { log("Illegal parenthesis in shop keyword expression"); return (FALSE); } } else push(&ops, temp); ptr++; } } } while (top(&ops) != NOTHING) evaluate_operation(&ops, &vals); temp = pop(&vals); if (top(&vals) != NOTHING) { log("Extra operands left on shop keyword expression stack"); return (FALSE); } return (temp); }
/* * 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; }
/* * 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; }
/* return values: 0 - successful load, keep char in rent room. 1 - load failure or load of crash items -- put char in temple. 2 - rented equipment lost (no $) */ int Crash_load(struct char_data * ch) { void Crash_save(struct char_data * ch, int type); FILE *fl; char fname[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH]; char input[MAX_INPUT_LENGTH + 1]; char tag[MAX_INPUT_LENGTH + 1]; char tag_arguments[MAX_INPUT_LENGTH + 1]; int val; struct obj_data *tmpobj = NULL; struct obj_data *tmpobj2; struct obj_data *next_obj; int found_begin = 0; int affect_counter = 0; int found; char *p; struct corpse_obj_save *crash_load_stack = NULL; struct corpse_obj_save *temp_stack = NULL; struct corpse_obj_save *temp_stack_next = NULL; int chg; int ovnum = 0; int j; if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) { return 1; } if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ sprintf(buf1, "SYSERR: READING OBJECT FILE %s (5)", fname); perror(buf1); send_to_char("\r\n********************* NOTICE *********************\r\n" "There was a problem loading your objects from disk.\r\n" "Contact a God for assistance.\r\n", ch); } sprintf(buf, "%s entering game with no equipment.", GET_NAME(ch)); mudlog(buf, 'R', COM_IMMORT, TRUE); plog(buf, ch, 0); return 1; } while (get_line(fl, input)) { parse_pline(input, tag, tag_arguments); while ((p = strrchr(tag_arguments, '\n')) != NULL) { *p = '\0'; } val = atoi(tag_arguments); switch (tag[4]) { case 'a': case 'A': if (strcasecmp(tag, "obj_affect_loc") == 0 && affect_counter < MAX_OBJ_AFFECT) { tmpobj->affected[affect_counter].location = val; } else if (strcasecmp(tag, "obj_affect_mod") == 0 && affect_counter < MAX_OBJ_AFFECT) { tmpobj->affected[affect_counter].modifier = val; affect_counter++; } else { sprintf(buf, "Unknown Rent-File Tag: %s", tag); stderr_log(buf); } break; case 'b': case 'B': if (strcasecmp(tag, "obj_begin") == 0) { if (found_begin) { send_to_char("\r\n********************* NOTICE *********************\r\n" "There was a problem loading your objects from disk.\r\n" "Contact a God for assistance.\r\n", ch); return 1; } found_begin = 1; } else if (strcasecmp(tag, "obj_bitvector") == 0) { GET_OBJ_BITV(tmpobj) = asciiflag_conv(tag_arguments); } else if (strcasecmp(tag, "obj_bitvector2") == 0) { GET_OBJ_BITV2(tmpobj) = asciiflag_conv(tag_arguments); } else { sprintf(buf, "Unknown Rent-File Tag: %s", tag); stderr_log(buf); } break; case 'e': case 'E': if (strcasecmp(tag, "obj_extra_flags") == 0) { GET_OBJ_EXTRA(tmpobj) = asciiflag_conv(tag_arguments); } else if (strcasecmp(tag, "obj_end") == 0) { if (ovnum >= 0) { if (!found_begin) { send_to_char("\r\n********************* NOTICE *********************\r\n" "There was a problem loading your objects from disk.\r\n" "Contact a God for assistance.\r\n", ch); return 1; } found_begin = 0; affect_counter = 0; CREATE(crash_load_stack, struct corpse_obj_save, 1); crash_load_stack->level = 0; crash_load_stack->prev = NULL; for (tmpobj2 = ch->carrying, found = 0; tmpobj2 && !found; tmpobj2 = next_obj) { next_obj = tmpobj2->next_content; if (tmpobj2->objnum == tmpobj->inobj) { obj_to_obj(tmpobj, tmpobj2); found = 1; } if (tmpobj2->contains) { crash_load_stack->next_obj = next_obj; CREATE(temp_stack, struct corpse_obj_save, 1); temp_stack->level = crash_load_stack->level + 1; temp_stack->prev = crash_load_stack; crash_load_stack = temp_stack; next_obj = tmpobj2->contains; if (tmpobj2 == next_obj) { /* infinite loop */ next_obj = NULL; continue; } } else if (next_obj == NULL && crash_load_stack->level > 0) { temp_stack = crash_load_stack; crash_load_stack = crash_load_stack->prev; FREE(temp_stack); next_obj = crash_load_stack->next_obj; } } for (temp_stack = crash_load_stack; temp_stack; temp_stack = temp_stack_next) { temp_stack_next = temp_stack->prev; FREE(temp_stack); } if (!found) { obj_to_char(tmpobj, ch); } } else { extract_obj(tmpobj); found_begin = 0; affect_counter = 0; ovnum = 0; } } else {