/* * Adding artifacts to the history list is trickier than other operations. * This is a wrapper function that gets some of the logic out of places * where it really doesn't belong. Call this to add an artifact to the history * list or make the history entry visible--history_add_artifact will make that * determination depending on what object_is_known returns for the artifact. */ bool history_add_artifact(byte a_idx, bool known, bool found) { object_type object_type_body; object_type *o_ptr = &object_type_body; char o_name[80]; char buf[80]; u16b type; /* Make fake artifact for description purposes */ object_wipe(o_ptr); make_fake_artifact(o_ptr, a_idx); object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_BASE | ODESC_SPOIL); strnfmt(buf, sizeof(buf), (found)?"Found %s":"Missed %s", o_name); /* Known objects gets different treatment */ if (known) { /* Try revealing any existing artifact, otherwise log it */ if (history_is_artifact_logged(a_idx)) history_know_artifact(a_idx); else history_add(buf, HISTORY_ARTIFACT_KNOWN, a_idx); } else { if (!history_is_artifact_logged(a_idx)) { type = HISTORY_ARTIFACT_UNKNOWN | (found ? 0 : HISTORY_ARTIFACT_LOST); history_add(buf, type, a_idx); } else { return FALSE; } } return TRUE; }
/* * Show artifact lore */ static void desc_art_fake(int a_idx) { object_type *o_ptr; object_type object_type_body = { 0 }; char header[120]; textblock *tb; region area = { 0, 0, 0, 0 }; o_ptr = find_artifact(&a_info[a_idx]); /* If it's been lost, make a fake artifact for it */ if (!o_ptr) { o_ptr = &object_type_body; make_fake_artifact(o_ptr, &a_info[a_idx]); o_ptr->ident |= IDENT_NAME; /* Check the history entry, to see if it was fully known before it * was lost */ if (history_is_artifact_known(o_ptr->artifact)) object_notice_everything(o_ptr); } /* Hack -- Handle stuff */ handle_stuff(p_ptr); tb = object_info(o_ptr, OINFO_NONE); object_desc(header, sizeof(header), o_ptr, ODESC_PREFIX | ODESC_FULL); textui_textblock_show(tb, area, format("%^s", header)); textblock_free(tb); #if 0 /* XXX This should be in object_info */ if (lost) text_out("\nThis artifact has been lost."); #endif }
/* * Show artifact lore */ static void desc_art_fake(int a_idx) { object_type *o_ptr; object_type object_type_body = { 0 }; char header[120]; textblock *tb; region area = { 0, 0, 0, 0 }; o_ptr = find_artifact(a_idx); /* If it's been lost, make a fake artifact for it */ if (!o_ptr) { o_ptr = &object_type_body; make_fake_artifact(o_ptr, a_idx); /* Check the history entry, to see if it was fully known * before it was lost */ if (history_is_artifact_known(a_idx)) { o_ptr->ident |= IDENT_KNOWN; } } /* Hack -- Handle stuff */ handle_stuff(); tb = object_info(o_ptr, OINFO_NONE); object_desc(header, sizeof(header), o_ptr, ODESC_PREFIX | ODESC_FULL); textui_textblock_show(tb, area, format("%^s", header)); textblock_free(tb); }
/* * Create a spoiler file for artifacts */ static void spoil_artifact(const char *fname) { int i, j; object_type *i_ptr; object_type object_type_body; char buf[1024]; /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname); fh = file_open(buf, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fh) { msg("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fh; /* Dump the header */ spoiler_underline(format("Artifact Spoilers for %s", buildid), '='); /* List the artifacts by tval */ for (i = 0; group_artifact[i].tval; i++) { /* Write out the group title */ if (group_artifact[i].name) { spoiler_blanklines(2); spoiler_underline(group_artifact[i].name, '='); spoiler_blanklines(1); } /* Now search through all of the artifacts */ for (j = 1; j < z_info->a_max; ++j) { artifact_type *a_ptr = &a_info[j]; char buf[80]; /* We only want objects in the current group */ if (a_ptr->tval != group_artifact[i].tval) continue; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Attempt to "forge" the artifact */ if (!make_fake_artifact(i_ptr, a_ptr)) continue; /* Grab artifact name */ object_desc(buf, sizeof(buf), i_ptr, ODESC_PREFIX | ODESC_COMBAT | ODESC_EXTRA | ODESC_SPOIL); /* Print name and underline */ spoiler_underline(buf, '-'); /* Write out the artifact description to the spoiler file */ object_info_spoil(fh, i_ptr, 80); /* * Determine the minimum and maximum depths an * artifact can appear, its rarity, its weight, and * its power rating. */ text_out("\nMin Level %u, Max Level %u, Generation chance %u, Power %d, %d.%d lbs\n", a_ptr->alloc_min, a_ptr->alloc_max, a_ptr->alloc_prob, object_power(i_ptr, FALSE, NULL, TRUE), (a_ptr->weight / 10), (a_ptr->weight % 10)); /* Terminate the entry */ spoiler_blanklines(2); } } /* Check for errors */ if (!file_close(fh)) { msg("Cannot close spoiler file."); return; } /* Message */ msg("Successfully created a spoiler file."); }
/* * Dump the object information a format easily parsed by a spreadsheet. * * Original function by -EB- (probably), revisions by -LM- & JG. */ void write_a_info_txt(void) { int i, j, bc; int dlen; char buf[1024]; int fd; FILE *fff = NULL; cptr desc; artifact_type *a_ptr; /* We allow 75 characters on the line (plus 2) */ u16b line_length = 75; /* Build the filename */ path_build(buf, 1024, ANGBAND_DIR_EDIT, "a_output.txt"); /* Check for existing file */ fd = fd_open(buf, O_RDONLY); /* Existing file */ if (fd >= 0) { char out_val[160]; /* Close the file */ fd_close(fd); /* Build query */ sprintf(out_val, "Replace existing file %s? ", buf); /* Ask */ if (get_check(out_val)) fd = -1; } /* Open the non-existing file */ if (fd < 0) fff = my_fopen(buf, "w"); /* No output file - fail */ if (!fff) return; /* Write a note */ fprintf(fff, "# File: a_info.txt (autogenerated)\n\n"); /* Read and print out all the objects */ for (i = 0; i < z_info->art_norm_max; i++) { int counter = 1; char o_name[80]; object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Get the object */ a_ptr = &a_info[i]; /* Ignore unused objects */ if (!strlen(a_ptr->name)) { fprintf(fff, "## empty space (available for artifact) ##\n\n"); continue; } /* Perform any translations */ /* Write New/Number/Name */ fprintf(fff, "N:%d:%s\n", i, a_ptr->name); /* Write the complete name of the artifact*/ make_fake_artifact(i_ptr, i); /*identify it*/ /* Identify it */ object_aware(i_ptr); object_known(i_ptr); i_ptr->ident |= (IDENT_MENTAL); /* Get a description to dump */ object_desc(o_name, sizeof(o_name), i_ptr, TRUE, 0); /*dump the long name*/ fprintf(fff, "desc:%d: # %s\n", i, o_name); /* Write I: line */ fprintf(fff, "I:%d:%d:%d:%d\n", i, a_ptr->tval, a_ptr->sval, a_ptr->pval); /* Write W: line */ fprintf(fff, "W:%d:%d:%d:%d:%d\n", i, a_ptr->a_level, a_ptr->a_rarity, a_ptr->weight, a_ptr->cost); /* Write P: line */ fprintf(fff, "P:%d:%d:%d:d:%d:%d:%d:%d\n", i, a_ptr->ac, a_ptr->dd, a_ptr->ds, a_ptr->to_h, a_ptr->to_d, a_ptr->to_a); /* Get the flags, store flag text in a format easily parsed by a * database, but pretty much illegible to a person. */ dump_flags(fff, a_ptr->a_flags1, 1, i); dump_flags(fff, a_ptr->a_flags2, 2, i); dump_flags(fff, a_ptr->a_flags3, 3, i); dump_flags(fff, a_ptr->a_native, 4, i); /* Write the A line */ fprintf(fff, "A:%d:%d:%d:%d\n", i, a_ptr->activation, a_ptr->time, a_ptr->randtime); /* Acquire the description */ desc = a_text + a_ptr->text; dlen = strlen(desc); if (dlen < 1) { /* Space between entries */ fprintf(fff, "\n\n\n"); continue; } /* Write Description */ for (j = 0; j < dlen;) { char buf[160], *t; /* Initialize */ t = buf; bc = 0; /* Build this line */ while (TRUE) { /* Insert this character, count it */ *t++ = desc[j++]; /* Oops. Line is too long. */ if (bc++ >= line_length) { /* Parse backwards until we find a space */ while (!my_isspace(desc[j-1]) && (bc-- > 40)) { j--; t--; } /* Time to end this line */ *t++ = '\0'; break; } /* All done */ if (j >= dlen) { /* Time to end this line */ *t++ = '\0'; break; } } /* Done with this line; write it */ fprintf(fff, "D-%d:%d:%s\n", counter, i, buf); counter++; } /* * Print out empty lines, so all objects have * an equal number of lines * makes parsing and combining the description easier */ for (; counter <+ 12; counter++) { fprintf(fff, "D-%d:%d\n", counter, i); } /* Space between entries */ fprintf(fff, "\n\n\n"); } /* Done */ fclose(fff); }
/*used to check the power of artifacts. Currently unused*/ void dump_artifact_power(void) { int i; char buf[1024]; int fd; FILE *fff = NULL; artifact_type *a_ptr; /* Build the filename */ path_build(buf, 1024, ANGBAND_DIR_EDIT, "power.txt"); /* Check for existing file */ fd = fd_open(buf, O_RDONLY); /* Existing file */ if (fd >= 0) { char out_val[160]; /* Close the file */ fd_close(fd); /* Build query */ sprintf(out_val, "Replace existing file %s? ", buf); /* Ask */ if (get_check(out_val)) fd = -1; } /* Open the non-existing file */ if (fd < 0) fff = my_fopen(buf, "w"); /* No output file - fail */ if (!fff) return; /* Write a note */ fprintf(fff, "# File: artifact_power.txt (autogenerated)\n\n"); /* Read and print out all the objects */ for (i = 1; i < z_info->art_norm_max; i++) { s32b power; char o_name[80]; object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Get the object */ a_ptr = &a_info[i]; /* Ignore unused objects */ if (!strlen(a_ptr->name)) { fprintf(fff, "## empty space (available for artifact) ##\n\n"); continue; } /* Write the complete name of the artifact*/ make_fake_artifact(i_ptr, i); /* Identify it */ object_aware(i_ptr); object_known(i_ptr); i_ptr->ident |= (IDENT_MENTAL); /* Get a description to dump */ object_desc(o_name, sizeof(o_name), i_ptr, TRUE, 0); power = artifact_power(i); /*dump the information*/ fprintf(fff, "%9d is the power of %55s, tval is %6d \n", power, o_name, a_ptr->tval); } /* Done */ fclose(fff); }
/** * Create a spoiler file for artifacts */ static void spoil_artifact(const char *fname) { int i, j; char buf[1024]; /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname); fh = file_open(buf, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fh) { msg("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fh; /* Dump the header */ spoiler_underline(format("Artifact Spoilers for %s", buildid), '='); text_out("\n Randart seed is %u\n", seed_randart); /* List the artifacts by tval */ for (i = 0; group_artifact[i].tval; i++) { /* Write out the group title */ if (group_artifact[i].name) { spoiler_blanklines(2); spoiler_underline(group_artifact[i].name, '='); spoiler_blanklines(1); } /* Now search through all of the artifacts */ for (j = 1; j < z_info->a_max; ++j) { struct artifact *art = &a_info[j]; char buf2[80]; char *temp; struct object *obj, *known_obj; /* We only want objects in the current group */ if (art->tval != group_artifact[i].tval) continue; /* Get local object */ obj = object_new(); known_obj = object_new(); /* Attempt to "forge" the artifact */ if (!make_fake_artifact(obj, art)) { object_delete(&known_obj); object_delete(&obj); continue; } /* Grab artifact name */ object_copy(known_obj, obj); obj->known = known_obj; object_desc(buf2, sizeof(buf2), obj, ODESC_PREFIX | ODESC_COMBAT | ODESC_EXTRA | ODESC_SPOIL); /* Print name and underline */ spoiler_underline(buf2, '-'); /* Temporarily blank the artifact flavour text - spoilers spoil the mechanics, not the atmosphere. */ temp = obj->artifact->text; obj->artifact->text = NULL; /* Write out the artifact description to the spoiler file */ object_info_spoil(fh, obj, 80); /* Put back the flavour */ obj->artifact->text = temp; /* * Determine the minimum and maximum depths an * artifact can appear, its rarity, its weight, and * its power rating. */ text_out("\nMin Level %u, Max Level %u, Generation chance %u, Power %d, %d.%d lbs\n", art->alloc_min, art->alloc_max, art->alloc_prob, object_power(obj, false, NULL), (art->weight / 10), (art->weight % 10)); if (OPT(birth_randarts)) text_out("%s.\n", art->text); /* Terminate the entry */ spoiler_blanklines(2); object_delete(&known_obj); object_delete(&obj); } } /* Check for errors */ if (!file_close(fh)) { msg("Cannot close spoiler file."); return; } /* Message */ msg("Successfully created a spoiler file."); }
/* * Create a spoiler file for artifacts */ static void spoil_artifact(void) { int i, j; object_type forge; object_type *q_ptr; const bool old_spoil_art = spoil_art; const bool old_spoil_base = spoil_base; const bool old_cheat_item = cheat_item; /* Use full spoilers, but no cheating. */ spoil_art = spoil_base = TRUE; cheat_item = FALSE; /* Dump the header */ print_header(); /* List the artifacts by tval */ for (i = 0; group_artifact[i].idx; i++) { /* Write out the group title */ if (group_artifact[i].str) { spoiler_blanklines(2); spoiler_underline(group_artifact[i].str); spoiler_blanklines(1); } /* Now search through all of the artifacts */ for (j = 1; j < MAX_A_IDX; ++j) { artifact_type *a_ptr = &a_info[j]; /* We only want objects in the current group */ if (k_info[a_ptr->k_idx].tval != group_artifact[i].idx) continue; /* Get local object */ q_ptr = &forge; /* Wipe the object */ object_wipe(q_ptr); /* Attempt to "forge" the artifact */ if (!make_fake_artifact(q_ptr, j)) continue; /* Know most things about the object. */ object_known(q_ptr); my_fprintf(fff, "%v\n", object_desc_f3, q_ptr, OD_ART | OD_SHOP, 1); /* Describe the artifact in a relatively brief way. */ identify_fully_file(q_ptr, fff, TRUE); /* Provide some allocation data. */ fprintf(fff, " Level %d", a_ptr->level); if (a_ptr->level2 && a_ptr->level2 != a_ptr->level) { fprintf(fff, "/%d", a_ptr->level2); } fprintf(fff, ", Rarity %d, %d.%d lbs, %ld Gold\n", a_ptr->rarity, a_ptr->weight/10, a_ptr->weight%10, a_ptr->cost); } } /* Reset spoilers. */ spoil_art = old_spoil_art; spoil_base = old_spoil_base; cheat_item = old_cheat_item; }
/* * Create a spoiler file for artifacts */ static void spoil_artifact(cptr fname) { int i, j; object_type *i_ptr; object_type object_type_body; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Dump the header */ print_header("Artifact"); /* List the artifacts by tval */ for (i = 0; group_artifact[i].tval; i++) { /* Write out the group title */ if (group_artifact[i].name) { spoiler_blanklines(2); spoiler_underline(group_artifact[i].name); spoiler_blanklines(1); } /* Now search through all of the artifacts */ for (j = 0; j < z_info->a_max; ++j) { artifact_type *a_ptr = &a_info[j]; /* We only want objects in the current group */ if (a_ptr->tval != group_artifact[i].tval) continue; /* Get local object */ i_ptr = &object_type_body; /* Attempt to create the artifact */ if (!make_fake_artifact(i_ptr, j)) continue; /* Get this artifact */ a_ptr = &a_info[i_ptr->artifact_index]; /* Write a description of the artifact */ object_desc_store(buf, sizeof(buf), i_ptr, TRUE, 1); x_fprintf(fff, encoding, buf); fprintf(fff, "\n"); /* Write pval, flag, and activation information */ dump_obj_attrib(fff, i_ptr, 2); /* Write level, rarity, and weight */ if (use_metric) fprintf(fff, " Level %u, Rarity %u, %d.%d kgs, " "%ld Gold", a_ptr->level, a_ptr->rarity, make_metric(a_ptr->weight) / 10, make_metric(a_ptr->weight) % 10, a_ptr->cost); else fprintf(fff, " Level %u, Rarity %u, %d.%d lbs, " "%ld Gold", a_ptr->level, a_ptr->rarity, a_ptr->weight / 10, a_ptr->weight % 10, (long)a_ptr->cost); /* Insert a spacer line */ fprintf(fff, "\n\n"); } } /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }