/* * Create the artifact with the specified number */ static void wiz_create_artifact(int a_idx) { object_type *i_ptr; object_type object_type_body; int k_idx; artifact_type *a_ptr = &a_info[a_idx]; /* Ignore "empty" artifacts */ if (!a_ptr->name) return; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Acquire the "kind" index */ k_idx = lookup_kind(a_ptr->tval, a_ptr->sval); /* Oops */ if (!k_idx) return; /* Create the artifact */ object_prep(i_ptr, &k_info[k_idx], a_ptr->alloc_min, RANDOMISE); /* Save the name */ i_ptr->name1 = a_idx; /* Extract the fields */ i_ptr->pval = a_ptr->pval; i_ptr->ac = a_ptr->ac; i_ptr->dd = a_ptr->dd; i_ptr->ds = a_ptr->ds; i_ptr->to_a = a_ptr->to_a; i_ptr->to_h = a_ptr->to_h; i_ptr->to_d = a_ptr->to_d; i_ptr->weight = a_ptr->weight; /* Hack -- extract the "cursed" flags */ if (cursed_p(a_ptr)) { bitflag curse_flags[OF_SIZE]; of_copy(curse_flags, a_ptr->flags); flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END); of_union(i_ptr->flags, curse_flags); } /* Mark that the artifact has been created. */ a_ptr->created = TRUE; /* Mark as cheat */ i_ptr->origin = ORIGIN_CHEAT; /* Drop the artifact from heaven */ drop_near(i_ptr, 0, p_ptr->py, p_ptr->px, TRUE); /* All done */ msg_print("Allocated."); }
/** * Build an "artifact name" and transfer it into a buffer. */ static void get_art_name(char *buf, int a_idx) { int i; object_type localObject; object_type *o_ptr; artifact_type *a_ptr = &a_info[a_idx]; /* Get local object */ o_ptr = &localObject; /* Wipe the object */ object_wipe(o_ptr); /* Acquire the "kind" index */ i = lookup_kind(a_ptr->tval, a_ptr->sval); /* Oops */ if (!i) return; /* Create the base object */ object_prep(o_ptr, i, RANDOMISE); /* Mark it as an artifact */ o_ptr->name1 = a_idx; /* Make it known to us */ o_ptr->ident |= IDENT_KNOWN; /* Create the artifact description */ object_desc(buf, 60, o_ptr, ODESC_SINGULAR | ODESC_SPOIL); }
/* * Read a store */ static errr rd_store(int n) { store_type *st_ptr = &store[n]; int j; byte own, num; /* Read the basic info */ rd_s32b(&st_ptr->store_open); rd_s16b(&st_ptr->insult_cur); rd_byte(&own); rd_byte(&num); rd_s16b(&st_ptr->good_buy); rd_s16b(&st_ptr->bad_buy); /* Paranoia */ if (own >= z_info->b_max) { note("Illegal store owner!"); return (-1); } st_ptr->owner = own; /* Read the items */ for (j = 0; j < num; j++) { object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Accept any valid items */ if (st_ptr->stock_num < STORE_INVEN_MAX) { int k = st_ptr->stock_num++; /* Accept the item */ object_copy(&st_ptr->stock[k], i_ptr); } } /* Success */ return (0); }
/** * Utility function for history_add_artifact(): get artifact name */ static void get_artifact_name(char *buf, size_t len, const struct artifact *artifact) { struct object body = OBJECT_NULL; struct object known_body = OBJECT_NULL; struct object *fake = &body; struct object *known_obj = &known_body; /* Make fake artifact for description purposes */ make_fake_artifact(fake, artifact); fake->known = known_obj; object_copy(known_obj, fake); object_desc(buf, len, fake, ODESC_PREFIX | ODESC_BASE | ODESC_SPOIL); object_wipe(known_obj, false); object_wipe(fake, true); }
/** * 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(struct artifact *artifact, bool known, bool found) { struct object body = { 0 }, known_body = { 0 }; struct object *fake = &body, *known_obj = &known_body; char o_name[80]; char buf[80]; assert(artifact); /* Make fake artifact for description purposes */ make_fake_artifact(fake, artifact); fake->known = known_obj; known_obj->artifact = (struct artifact *) 1; known_obj->kind = fake->kind; object_desc(o_name, sizeof(o_name), fake, ODESC_PREFIX | ODESC_BASE | ODESC_SPOIL); object_wipe(known_obj); object_wipe(fake); 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(artifact)) history_know_artifact(artifact); else history_add(buf, HIST_ARTIFACT_KNOWN, artifact); } else { if (!history_is_artifact_logged(artifact)) { bitflag type[HIST_SIZE]; hist_wipe(type); hist_on(type, HIST_ARTIFACT_UNKNOWN); if (!found) hist_on(type, HIST_ARTIFACT_LOST); history_add_full(type, artifact, player->depth, player->lev, player->total_energy / 100, buf); } else { return false; } } return true; }
/* * Allocate an object * NOTE: this is the only allowed way to create an object */ object_type *new_object() { object_type *o_ptr; MAKE(o_ptr, object_type); flag_init(&o_ptr->flags, 2); object_wipe(o_ptr); return o_ptr; }
/* * Read a store */ static errr rd_store(int town_number, int store_number) { store_type *st_ptr = &town[town_number].store[store_number]; int j; byte num; s16b tmp16s; /* Read the basic info */ rd_s32b(&st_ptr->store_open); rd_s16b(&tmp16s); rd_byte(&st_ptr->owner); rd_byte(&num); rd_s16b(&tmp16s); rd_s16b(&tmp16s); /* Read last visit */ rd_s32b(&st_ptr->last_visit); /* Read the items */ for (j = 0; j < num; j++) { object_type forge; object_type *q_ptr; /* Get local object */ q_ptr = &forge; /* Wipe the object */ object_wipe(q_ptr); /* Read the item */ rd_item(q_ptr); /* Acquire valid items */ if (st_ptr->stock_num < (store_number == STORE_HOME ? (STORE_INVEN_MAX) * 10 : STORE_INVEN_MAX)) { int k = st_ptr->stock_num; if (q_ptr->k_idx != 0) { /* Acquire the item */ object_copy(&st_ptr->stock[k], q_ptr); st_ptr->stock_num++; } } } /* Success */ return (0); }
/* * Helper function which actually removes the inscription */ void uninscribe(object_type *o_ptr) { /* Remove the inscription */ o_ptr->obj_note = 0; /*The object kind has an autoinscription*/ // Sil-y: removed restriction to known items (through 'object_aware') if (!(k_info[o_ptr->k_idx].flags3 & (TR3_INSTA_ART)) && (get_autoinscription_index(o_ptr->k_idx) != -1)) { char tmp_val[160]; char o_name2[80]; /*make a fake object so we can give a proper message*/ object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Create the object */ object_prep(i_ptr, o_ptr->k_idx); /*make it plural*/ i_ptr->number = 2; /*now describe with correct amount*/ object_desc(o_name2, sizeof(o_name2), i_ptr, FALSE, 0); /* Prompt */ strnfmt(tmp_val, sizeof(tmp_val), "Remove automatic inscription for %s? ", o_name2); /* Auto-Inscribe if they want that */ if (get_check(tmp_val)) obliterate_autoinscription(o_ptr->k_idx); } /* Message */ msg_print("Inscription removed."); /* Combine the pack */ p_ptr->notice |= (PN_COMBINE); /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); }
/* * Describe fake object */ static void desc_obj_fake(int k_idx) { object_kind *k_ptr = &k_info[k_idx]; object_type object_type_body; object_type *o_ptr = &object_type_body; char header[120]; textblock *tb; region area = { 0, 0, 0, 0 }; /* Check for known artifacts, display them as artifacts */ if (kf_has(k_ptr->flags_kind, KF_INSTA_ART) && artifact_is_known(get_artifact_from_kind(k_ptr))) { desc_art_fake(get_artifact_from_kind(k_ptr)); return; } /* Update the object recall window */ track_object_kind(k_idx); handle_stuff(p_ptr); /* Wipe the object */ object_wipe(o_ptr); /* Create the artifact */ object_prep(o_ptr, k_idx, EXTREMIFY); /* Hack -- its in the store */ if (k_info[k_idx].aware) o_ptr->ident |= (IDENT_STORE); /* It's fully know */ if (!k_info[k_idx].flavor) object_known(o_ptr); /* Hack -- Handle stuff */ handle_stuff(p_ptr); /* Describe */ tb = object_info(o_ptr, OINFO_DUMMY); object_desc(header, sizeof(header), o_ptr, ODESC_PREFIX | ODESC_FULL | ODESC_CAPITAL); textui_textblock_show(tb, area, format("%s", header)); textblock_free(tb); }
/* * Create the artifact with the specified number */ static void wiz_create_artifact(int a_idx) { object_type *i_ptr; object_type object_type_body; object_kind *kind; artifact_type *a_ptr = &a_info[a_idx]; /* Ignore "empty" artifacts */ if (!a_ptr->name) return; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Acquire the "kind" index */ kind = lookup_kind(a_ptr->tval, a_ptr->sval); if (!kind) return; /* Create the artifact */ object_prep(i_ptr, kind, a_ptr->alloc_min, RANDOMISE); /* Save the name */ i_ptr->artifact = a_ptr; /* Extract the fields */ copy_artifact_data(i_ptr, a_ptr); /* Mark that the artifact has been created. */ a_ptr->created = TRUE; /* Mark as cheat */ i_ptr->origin = ORIGIN_CHEAT; /* Drop the artifact from heaven */ drop_near(cave, i_ptr, 0, p_ptr->py, p_ptr->px, TRUE); /* All done */ msg("Allocated."); /* Redraw map */ p_ptr->redraw |= (PR_MAP | PR_ITEMLIST); handle_stuff(p_ptr); }
/* * Prepare an object based on an object kind. */ void object_prep(object_type *o_ptr, s32b k_idx) { object_kind *k_ptr = &k_info[k_idx]; /* Clear the record */ object_wipe(o_ptr); /* Save the kind index */ o_ptr->k_idx = k_idx; /* Efficiency -- tval/sval */ o_ptr->tval = k_ptr->tval; o_ptr->sval = k_ptr->sval; /* Default number */ o_ptr->number = 1; /* Default weight */ o_ptr->weight = k_ptr->weight; /* Default magic */ o_ptr->to_h = k_ptr->to_h; o_ptr->to_d = k_ptr->to_d; o_ptr->to_a = k_ptr->to_a; /* Default power */ o_ptr->ac = k_ptr->ac; o_ptr->dd = k_ptr->dd; o_ptr->ds = k_ptr->ds; /* Default color */ o_ptr->d_attr = k_ptr->d_attr; o_ptr->x_attr = k_ptr->x_attr; /* Hack -- cursed items are always "cursed" */ if (has_flag(k_ptr, FLAG_CURSED)) o_ptr->ident |= (IDENT_CURSED); /* Hack give a basic exp/exp level to an object that needs it */ if (has_flag(k_ptr, FLAG_LEVELS)) { o_ptr->elevel = (k_ptr->level / 10) + 1; o_ptr->exp = player_exp[o_ptr->elevel - 1]; } /* Grab the basic flags */ flag_add(&o_ptr->flags, &k_ptr->flags); }
/* * Create the artifact with the specified number */ static void wiz_create_artifact(int a_idx) { object_type *i_ptr; object_type object_type_body; int k_idx; artifact_type *a_ptr = &a_info[a_idx]; /* Ignore "empty" artifacts */ if (!a_ptr->name) return; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Acquire the "kind" index */ k_idx = lookup_kind(a_ptr->tval, a_ptr->sval); /* Oops */ if (!k_idx) return; /* Create the artifact */ object_prep(i_ptr, k_idx); /* Save the name */ i_ptr->name1 = a_idx; /* Extract the fields */ i_ptr->pval = a_ptr->pval; i_ptr->ac = a_ptr->ac; i_ptr->dd = a_ptr->dd; i_ptr->ds = a_ptr->ds; i_ptr->to_a = a_ptr->to_a; i_ptr->to_h = a_ptr->to_h; i_ptr->to_d = a_ptr->to_d; i_ptr->weight = a_ptr->weight; /* Drop the artifact from heaven */ drop_near(i_ptr, -1, p_ptr->py, p_ptr->px); /* All done */ msg_print("Allocated."); }
/* * 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; }
void swap_wielding_hands(void) { /* Swap hands wielding sub weapon */ if (is_two_handed()) { char o_name[MAX_NLEN]; object_type *o_ptr = &inventory[INVEN_ARM]; object_type *q_ptr = &inventory[INVEN_WIELD]; object_copy(q_ptr, o_ptr); object_wipe(o_ptr); /* Describe local object */ object_desc(o_name, q_ptr, 0); #ifdef JP msg_format("%sを右手で構えた。", o_name); #else msg_format("You are weilding %s in your right hand.", o_name); #endif p_ptr->redraw |= (PR_EQUIPPY); } }
/* * Examine a grid, return a keypress. * * The "mode" argument contains the "TARGET_LOOK" bit flag, which * indicates that the "space" key should scan through the contents * of the grid, instead of simply returning immediately. This lets * the "look" command get complete information, without making the * "target" command annoying. * * The "info" argument contains the "commands" which should be shown * inside the "[xxx]" text. This string must never be empty, or grids * containing monsters will be displayed with an extra comma. * * Note that if a monster is in the grid, we update both the monster * recall info and the health bar info to track that monster. * * This function correctly handles multiple objects per grid, and objects * and terrain features in the same grid, though the latter never happens. * * This function must handle blindness/hallucination. */ static ui_event_data target_set_interactive_aux(int y, int x, int mode, cptr info, bool list_floor_objects) { s16b this_o_idx, next_o_idx = 0; s16b this_x_idx, next_x_idx = 0; cptr s1, s2, s3; bool floored; u16b feat; ui_event_data query; char out_val[256]; char coords[20]; /* Describe the square location */ coords_desc(coords, sizeof(coords), y, x); /* Repeat forever */ while (1) { int i; char feat_name[80]; /* Terrain suffix for monsters and objects */ char terrain_suffix[200]; /* Temporary array of visible effects */ s16b x_seen[50]; u16b size_x_seen = 0; /* Paranoia */ query.key = ' '; /* Default */ s1 = "You see "; s2 = ""; s3 = "on "; /* The player */ if (cave_m_idx[y][x] < 0) { /* Description */ s1 = "You are "; /* Preposition */ s2 = "on "; } /* Feature (apply "mimic") */ feat = f_info[cave_feat[y][x]].f_mimic; /* Require knowledge about grid, or ability to see grid */ if (!(cave_info[y][x] & (CAVE_MARK)) && !player_can_see_bold(y,x)) { /* Forget feature */ feat = FEAT_NONE; } else { /* Hack -- track the current feature */ feature_kind_track(feat); /* Window stuff */ p_ptr->redraw |= (PR_FEATURE); } /* Pick a prefix */ if (*s2 && (!feat_ff1_match(feat, FF1_MOVE) || !feat_ff1_match(feat, FF1_LOS) || feat_ff1_match(feat, FF1_SHOP | FF1_DOOR) || feat_ff2_match(feat, FF2_SHALLOW | FF2_DEEP) || feat_ff3_match(feat, FF3_NEED_TREE))) { s3 = "in "; } /* Get a default name */ if (feat <= FEAT_NONE) { my_strcpy(feat_name, "an unknown grid", sizeof(feat_name)); } /* Get the real name */ else { feature_desc(feat_name, sizeof (feat_name), feat, TRUE, FALSE); } /* List all effects in the grid */ for (this_x_idx = cave_x_idx[y][x]; this_x_idx; this_x_idx = next_x_idx) { effect_type *x_ptr; /* Get the effect */ x_ptr = &x_list[this_x_idx]; /* Get the next effect */ next_x_idx = x_ptr->next_x_idx; /* Describe it, if not hidden */ if (!(x_ptr->x_flags & (EF1_HIDDEN)) && x_ptr->x_f_idx) { /* Check for available space */ if (size_x_seen < N_ELEMENTS(x_seen)) { x_seen[size_x_seen++] = x_ptr->x_f_idx; } } } /* Prepare the terrain suffix for monsters and objects */ my_strcpy(terrain_suffix, format(" %s%s", s3, feat_name), sizeof(terrain_suffix)); /* Concat the collected effect names */ for (i = 0; i < size_x_seen; i++) { char x_name[80]; /* Obtain an object description */ feature_desc(x_name, sizeof(x_name), x_seen[i], TRUE, TRUE); /* First effect */ if (i == 0) { if ((feat == FEAT_NONE) || !feat_ff1_match(feat, FF1_MOVE) || cave_any_trap_bold(y, x)) { /* Basic info */ my_strcat(terrain_suffix, format(" with %s", x_name), sizeof(terrain_suffix)); } else { /* Basic info */ my_strcat(terrain_suffix, format(" beneath %s", x_name), sizeof(terrain_suffix)); } } /* Basic info */ else if (i < (size_x_seen - 1)) { my_strcat(terrain_suffix, format(", %s", x_name), sizeof(terrain_suffix)); } /* Basic info */ else { my_strcat(terrain_suffix, format(" and %s", x_name), sizeof(terrain_suffix)); } } /* Ignore the terrain suffix if certain things happen */ if ((size_x_seen == 0) && (feat <= FEAT_FLOOR)) { terrain_suffix[0] = '\0'; } /* Hack -- hallucination */ if (p_ptr->timed[TMD_IMAGE]) { cptr name = "something strange"; /* Display a message */ if (p_ptr->wizard) { strnfmt(out_val, sizeof(out_val), "%s%s%s, [%s] %s (%d:%d).", s1, s2, name, info, coords, y, x); } else { strnfmt(out_val, sizeof(out_val), "%s%s%s [%s], %s.", s1, s2, name, info, coords); } prt(out_val, 0, 0); move_cursor_relative(y, x); query = inkey_ex(); /* Stop on everything but "return" */ if ((query.key != '\n') && (query.key != '\r')) break; /* Repeat forever */ continue; } /* Actual monsters */ if (cave_m_idx[y][x] > 0) { monster_type *m_ptr = &mon_list[cave_m_idx[y][x]]; monster_race *r_ptr = &r_info[m_ptr->r_idx]; /* Visible */ if (m_ptr->ml) { bool recall = FALSE; char m_name[80]; if (m_ptr->mimic_k_idx) { /*get the description*/ mimic_desc_object(m_name, sizeof(m_name), m_ptr->mimic_k_idx); } else { /* Get the monster name ("a kobold") */ monster_desc(m_name, sizeof(m_name), m_ptr, 0x08); /* Hack -- track this monster race */ monster_race_track(m_ptr->r_idx); /* Hack -- health bar for this monster */ health_track(cave_m_idx[y][x]); /*Track the feature*/ feature_kind_track(cave_feat[y][x]); /* Window stuff */ p_ptr->redraw |= (PR_FEATURE); /* Hack -- handle stuff */ handle_stuff(); } /* Interact */ while (1) { if (recall) button_add("[CLEAR_RECALL]", 'r'); else button_add("[RECALL]", 'r'); if (cave_o_idx[y][x] > 0)button_add("[VIEW_FLOOR]", 'f'); event_signal(EVENT_MOUSEBUTTONS); /* Recall, but not mimics */ if ((recall) && (!(m_ptr->mimic_k_idx))) { /* Save screen */ screen_save(); /* Recall on screen */ screen_roff(m_ptr->r_idx); /* Hack -- Complete the prompt (again) */ Term_addstr(-1, TERM_WHITE, format(" [r,%s]", info)); /* Command */ query = inkey_ex(); /* Load screen */ screen_load(); } /* Normal */ else { /* Basic info */ strnfmt(out_val, sizeof(out_val), "%s%s%s", s1, s2, m_name); /* Describe the monster, unless a mimic */ if (!(m_ptr->mimic_k_idx)) { char buf[80]; look_mon_desc(buf, sizeof(buf), cave_m_idx[y][x]); /* Monster state, terrain suffix, options */ my_strcat(out_val, format(" (%s)%s [r,%s]", buf, terrain_suffix, info), sizeof(out_val)); } /* Mimics */ else { /* Terrain suffix, options */ my_strcat(out_val, format("%s [I,%s]", terrain_suffix, info), sizeof(out_val)); } /* Wizards want coordinates */ if (p_ptr->wizard) { my_strcat(out_val, format(" (%d:%d)", y, x), sizeof(out_val)); } prt(out_val, 0, 0); /* Place cursor */ move_cursor_relative(y, x); /* Command */ query = inkey_ex(); } button_kill('r'); button_kill('f'); event_signal(EVENT_MOUSEBUTTONS); /* Handle fake object recall */ if (m_ptr->mimic_k_idx) { object_type body; object_type *o_ptr = &body; /* Validate input first */ if (query.key != 'I') break; /* Paranoia */ object_wipe(o_ptr); /* Prepare */ object_prep(o_ptr, m_ptr->mimic_k_idx); /* Fake history */ object_history(o_ptr, ORIGIN_FLOOR, 0); /* Clear prompt. Place cursor */ prt("", 0, 0); /* Show the fake info - EXPERIMENTAL */ object_info_screen(o_ptr); } /* Regular monsters */ else { /* Normal commands */ if (query.key != 'r') break; /* Toggle recall */ recall = !recall; } } /* Stop on everything but "return"/"space", or floor */ if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ') && (query.key != 'f')) break; /* continue with 'f' only if there are floor items....*/ if ((query.key == 'f') && (!cave_o_idx[y][x])) break; /* Sometimes stop at "space" key */ if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; /* Change the intro */ s1 = "It is "; /* Hack -- take account of gender */ if (r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is "; else if (r_ptr->flags1 & (RF1_MALE)) s1 = "He is "; /* Use a preposition */ s2 = "carrying "; /* Scan all objects being carried */ for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) { char o_name[80]; object_type *o_ptr; /* Get the object */ o_ptr = &o_list[this_o_idx]; /* Get the next object */ next_o_idx = o_ptr->next_o_idx; /*Don't let the player see certain objects (used for vault treasure)*/ if ((o_ptr->ident & (IDENT_HIDE_CARRY)) && (!p_ptr->wizard) && (!cheat_peek)) continue; /* Obtain an object description */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Describe the object */ strnfmt(out_val, sizeof(out_val), "%s%s%s [%s]", s1, s2, o_name, info); /* Wizards want coordinates */ if (p_ptr->wizard) { my_strcat(out_val, format(" (%d:%d)", y, x), sizeof(out_val)); } prt(out_val, 0, 0); move_cursor_relative(y, x); query = inkey_ex(); /* Stop on everything but "return"/"space" */ if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; /* Sometimes stop at "space" key */ if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; /* Change the intro */ s2 = "also carrying "; } /* Double break */ if (this_o_idx) break; /* Use a preposition */ s2 = "on "; } } /* Assume not floored */ floored = FALSE; /* Scan all objects in the grid */ if (TRUE) { int floor_list[MAX_FLOOR_STACK]; int floor_num; track_object(-floor_list[0]); handle_stuff(); /* Scan for floor objects */ floor_num = scan_floor(floor_list, MAX_FLOOR_STACK, y, x, 0x02); /* Actual pile */ if (floor_num > 1) { /* Floored */ floored = TRUE; /* Describe */ while (1) { /* Basic info */ strnfmt(out_val, sizeof(out_val), "%s%sa pile of %d objects%s [r,%s]", s1, s2, floor_num, terrain_suffix, info); /* Wizards want coordinates */ if (p_ptr->wizard) { my_strcat(out_val, format(" (%d:%d)", y, x), sizeof(out_val)); } prt(out_val, 0, 0); if (list_floor_objects) { /* Save screen */ screen_save(); /* Display */ show_floor(floor_list, floor_num, (OLIST_WEIGHT | OLIST_GOLD)); } move_cursor_relative(y, x); query = inkey_ex(); if (list_floor_objects) { screen_load(); } /* Display objects */ if (query.key == 'r') { int pos; pos = query.key - 'a'; if (0 <= pos && pos < floor_num) { track_object(-floor_list[pos]); handle_stuff(); } } /* Done */ break; } /* Stop on everything but "return"/"space" */ if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; /* Sometimes stop at "space" key */ if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; /* Change the intro */ s1 = "It is "; /* Preposition */ s2 = "on "; } } /* Scan all objects in the grid */ for (this_o_idx = cave_o_idx[y][x]; this_o_idx; this_o_idx = next_o_idx) { object_type *o_ptr; /* Get the object */ o_ptr = &o_list[this_o_idx]; /* Get the next object */ next_o_idx = o_ptr->next_o_idx; /* Skip objects if floored */ if (floored) continue; /* Describe it */ if (o_ptr->marked) { char o_name[80]; /* Obtain an object description */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Basic info */ strnfmt(out_val, sizeof(out_val), "%s%s%s%s [I,%s]", s1, s2, o_name, terrain_suffix, info); /* Wizards want coordinates */ if (p_ptr->wizard) { my_strcat(out_val, format(" (%d:%d)", y, x), sizeof(out_val)); } /* Show object. Handle object recall */ while (TRUE) { /* Print the prompt */ prt(out_val, 0, 0); /* Move cursor to that location */ move_cursor_relative(y, x); /* Read input key */ query = inkey_ex(); /* No object recall */ if (query.key != 'I') break; /* Object recall. Clear the first line */ prt("", 0, 0); /* Do it */ object_info_screen(o_ptr); } /* Stop on everything but "return"/"space" */ if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; /* Sometimes stop at "space" key */ if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; /* Change the intro */ s1 = "It is "; /* Plurals */ if (o_ptr->number != 1) s1 = "They are "; /* Preposition */ s2 = "on "; } } /* Double break */ if (this_o_idx) break; /* Display terrain */ if (TRUE) { u16b temp_feat; bool enable_recall; bool show_recall = FALSE; char temp_name[80]; /* * Display terrain and effects */ for (i = 0; i <= size_x_seen; i++) { /* Hack - This is the mark for the feature stored in cave_feat */ if (i == size_x_seen) { temp_feat = feat; /* Just copy the feature name */ my_strcpy(temp_name, feat_name, sizeof(temp_name)); } /* Any other value is an effect stored x_list */ else { temp_feat = x_seen[i]; /* Get the effect's name */ feature_desc(temp_name, sizeof(temp_name), temp_feat, TRUE, TRUE); } /* Don't display feature recall if the grid is unknown */ enable_recall = (temp_feat != FEAT_NONE); /* Handle recall */ while (TRUE) { /* Handle recall mode */ if (show_recall && enable_recall) { /* Save screen */ screen_save(); /* Recall feature on screen */ screen_feature_roff(temp_feat); } /* Display a message */ strnfmt(out_val, sizeof(out_val), "%s%s%s [%s%s]%s", s1, s2, temp_name, (enable_recall ? "r,": ""), info, (i < size_x_seen) ? " (more)": ""); /* Wizards want coordinates */ if (p_ptr->wizard) { my_strcat(out_val, format(" (%d:%d)", y, x), sizeof(out_val)); } /*Track this feature*/ feature_kind_track(temp_feat); /* Hack -- handle stuff */ handle_stuff(); prt(out_val, 0, 0); move_cursor_relative(y, x); query = inkey_ex(); /* Load screen if necessary */ if (show_recall && enable_recall) { screen_load(); } /* Stop on everything but the recall command, if enabled */ if (!enable_recall || (query.key != 'r')) break; /* Toggle recall */ show_recall = !show_recall; } /* Stop on everything but "return"/"space" */ if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; } } /* Hack -- handle stuff */ handle_stuff(); /* Stop on everything but "return" */ if ((query.key != '\n') && (query.key != '\r')) break; } /* Keep going */ return (query); }
static int rd_stores(void) { int i; u16b tmp16u; /* Read the stores */ rd_u16b(&tmp16u); for (i = 0; i < tmp16u; i++) { store_type *st_ptr = &store[i]; int j; byte own, num; /* XXX */ strip_bytes(6); /* Read the basic info */ rd_byte(&own); rd_byte(&num); /* XXs */ strip_bytes(4); /* Paranoia */ if (own >= z_info->b_max) { note("Illegal store owner!"); return (-1); } st_ptr->owner = store_ownerbyidx(st_ptr, own); /* Read the items */ for (j = 0; j < num; j++) { object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } i_ptr->ident |= IDENT_STORE; /* Accept any valid items */ if ((st_ptr->stock_num < STORE_INVEN_MAX) && (i_ptr->k_idx)) { int k = st_ptr->stock_num++; /* Accept the item */ object_copy(&st_ptr->stock[k], i_ptr); } } } return 0; }
static int rd_objects(void) { int i; u16b limit; /* Only if the player's alive */ if (p_ptr->is_dead) return 0; /* Read the item count */ rd_u16b(&limit); /* Verify maximum */ if (limit > z_info->o_max) { note(format("Too many (%d) object entries!", limit)); return (-1); } /* Read the dungeon items */ for (i = 1; i < limit; i++) { object_type *i_ptr; object_type object_type_body; s16b o_idx; object_type *o_ptr; /* Get the object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Make an object */ o_idx = o_pop(); /* Paranoia */ if (o_idx != i) { note(format("Cannot place object %d!", i)); return (-1); } /* Get the object */ o_ptr = &o_list[o_idx]; /* Structure Copy */ object_copy(o_ptr, i_ptr); /* Dungeon floor */ if (!i_ptr->held_m_idx) { int x = i_ptr->ix; int y = i_ptr->iy; /* ToDo: Verify coordinates */ /* Link the object to the pile */ o_ptr->next_o_idx = cave_o_idx[y][x]; /* Link the floor to the object */ cave_o_idx[y][x] = o_idx; } } return 0; }
/*! * @brief 検査対象のアイテムを基準とした生成テストを行う / * Try to create an item again. Output some statistics. -Bernd- * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ * @return なし * The statistics are correct now. We acquire a clean grid, and then * repeatedly place an object in this grid, copying it into an item * holder, and then deleting the object. We fiddle with the artifact * counter flags to prevent weirdness. We use the items to collect * statistics on item creation relative to the initial item. */ static void wiz_statistics(object_type *o_ptr) { u32b i, matches, better, worse, other, correct; u32b test_roll = 1000000; char ch; cptr quality; u32b mode; object_type forge; object_type *q_ptr; cptr q = "Rolls: %ld Correct: %ld Matches: %ld Better: %ld Worse: %ld Other: %ld"; cptr p = "Enter number of items to roll: "; char tmp_val[80]; /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */ if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 0; /* Interact */ while (TRUE) { cptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? "; /* Display item */ wiz_display_item(o_ptr); /* Get choices */ if (!get_com(pmt, &ch, FALSE)) break; if (ch == 'n' || ch == 'N') { mode = 0L; quality = "normal"; } else if (ch == 'g' || ch == 'G') { mode = AM_GOOD; quality = "good"; } else if (ch == 'e' || ch == 'E') { mode = AM_GOOD | AM_GREAT; quality = "excellent"; } else { break; } sprintf(tmp_val, "%ld", (long int)test_roll); if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val); test_roll = MAX(1, test_roll); /* Let us know what we are doing */ msg_format("Creating a lot of %s items. Base level = %d.", quality, dun_level); msg_print(NULL); /* Set counters to zero */ correct = matches = better = worse = other = 0; /* Let's rock and roll */ for (i = 0; i <= test_roll; i++) { /* Output every few rolls */ if ((i < 100) || (i % 100 == 0)) { /* Do not wait */ inkey_scan = TRUE; /* Allow interupt */ if (inkey()) { /* Flush */ flush(); /* Stop rolling */ break; } /* Dump the stats */ prt(format(q, i, correct, matches, better, worse, other), 0, 0); Term_fresh(); } /* Get local object */ q_ptr = &forge; /* Wipe the object */ object_wipe(q_ptr); /* Create an object */ make_object(q_ptr, mode); /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */ if (object_is_fixed_artifact(q_ptr)) a_info[q_ptr->name1].cur_num = 0; /* Test for the same tval and sval. */ if ((o_ptr->tval) != (q_ptr->tval)) continue; if ((o_ptr->sval) != (q_ptr->sval)) continue; /* One more correct item */ correct++; /* Check for match */ if ((q_ptr->pval == o_ptr->pval) && (q_ptr->to_a == o_ptr->to_a) && (q_ptr->to_h == o_ptr->to_h) && (q_ptr->to_d == o_ptr->to_d) && (q_ptr->name1 == o_ptr->name1)) { matches++; } /* Check for better */ else if ((q_ptr->pval >= o_ptr->pval) && (q_ptr->to_a >= o_ptr->to_a) && (q_ptr->to_h >= o_ptr->to_h) && (q_ptr->to_d >= o_ptr->to_d)) { better++; } /* Check for worse */ else if ((q_ptr->pval <= o_ptr->pval) && (q_ptr->to_a <= o_ptr->to_a) && (q_ptr->to_h <= o_ptr->to_h) && (q_ptr->to_d <= o_ptr->to_d)) { worse++; } /* Assume different */ else { other++; } } /* Final dump */ msg_format(q, i, correct, matches, better, worse, other); msg_print(NULL); } /* Hack -- Normally only make a single artifact */ if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 1; }
/* * Read the player inventory * * Note that the inventory is "re-sorted" later by "dungeon()". */ static int rd_inventory(void) { int slot = 0; object_type *i_ptr; object_type object_type_body; /* Read until done */ while (1) { u16b n; /* Get the next item index */ rd_u16b(&n); /* Nope, we reached the end */ if (n == 0xFFFF) break; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Hack -- verify item */ if (!i_ptr->k_idx) continue;; /* Verify slot */ if (n >= INVEN_TOTAL) return (-1); /* Wield equipment */ if (n >= INVEN_WIELD) { /* Copy object */ object_copy(&p_ptr->inventory[n], i_ptr); /* Add the weight */ p_ptr->total_weight += (i_ptr->number * i_ptr->weight); /* One more item */ p_ptr->equip_cnt++; } /* Warning -- backpack is full */ else if (p_ptr->inven_cnt == INVEN_PACK) { /* Oops */ note("Too many items in the inventory!"); /* Fail */ return (-1); } /* Carry inventory */ else { /* Get a slot */ n = slot++; /* Copy object */ object_copy(&p_ptr->inventory[n], i_ptr); /* Add the weight */ p_ptr->total_weight += (i_ptr->number * i_ptr->weight); /* One more item */ p_ptr->inven_cnt++; } } /* Success */ return (0); }
/* * Helper function for monster_death - * Drop the monster's normal objects */ static void mon_drop_loot(int m_idx) { monster_type *m_ptr = &mon_list[m_idx]; monster_race *r_ptr = &r_info[m_ptr->r_idx]; int j; bool chest = (r_ptr->flags1 & (RF1_DROP_CHEST)) ? TRUE : FALSE; bool good = (r_ptr->flags1 & (RF1_DROP_GOOD)) ? TRUE : FALSE; bool great = (r_ptr->flags1 & (RF1_DROP_GREAT)) ? TRUE : FALSE; bool do_gold = (!(r_ptr->flags1 & (RF1_ONLY_ITEM))); bool do_item = (!(r_ptr->flags1 & (RF1_ONLY_GOLD))); bool visible = (m_ptr->ml || (r_ptr->flags1 & (RF1_UNIQUE))); int force_coin = get_coin_type(r_ptr); int dump_item = 0; int dump_gold = 0; int number_drops = 0; object_type *i_ptr; object_type object_type_body; /* Average dungeon and monster levels */ s16b set_object_level = object_level = (effective_depth(p_ptr->depth) + r_ptr->level) / 2; /* Determine how much we can drop */ if ((r_ptr->flags1 & (RF1_DROP_60)) && (rand_int(100) < 60)) number_drops++; if ((r_ptr->flags1 & (RF1_DROP_90)) && (rand_int(100) < 90)) number_drops++; if (r_ptr->flags1 & (RF1_DROP_1D2)) number_drops += damroll(1, 2); if (r_ptr->flags1 & (RF1_DROP_2D2)) number_drops += damroll(2, 2); if (r_ptr->flags1 & (RF1_DROP_3D2)) number_drops += damroll(3, 2); if (r_ptr->flags1 & (RF1_DROP_4D2)) number_drops += damroll(4, 2); /* Hack -- handle creeping coins */ coin_type = force_coin; /* Drop some objects */ for (j = 0; j < number_drops; j++) { bool interesting = FALSE; /* Re-set the object level */ object_level = set_object_level; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* work on the "too much junk" problem, large drops sometimes are less items with a "boost". */ if ((randint(750) < (number_drops * number_drops)) && (!(r_ptr->flags1 & (RF1_UNIQUE)))) { interesting = TRUE; number_drops -= 5; object_level += 5; /*Boundry Control*/ if (number_drops < 0) number_drops = 0; if (object_level > MAX_DEPTH) object_level = MAX_DEPTH; } /* Make Gold */ if (do_gold && (!chest) && (!do_item || (rand_int(100) < 50))) { /* Make some gold */ if (!make_gold(i_ptr)) continue; /* Assume seen XXX XXX XXX */ dump_gold++; } /* Make Object */ else { if (chest) { if (!make_object(i_ptr, good, great, DROP_TYPE_CHEST, FALSE)) continue; } /* Make an object */ else if (!make_object(i_ptr, good, great, DROP_TYPE_UNTHEMED, interesting)) continue; /* Remember history */ if (visible) object_history(i_ptr, ORIGIN_DROP_KNOWN, m_ptr->r_idx); else object_history(i_ptr, ORIGIN_DROP_UNKNOWN, 0); /* Assume seen XXX XXX XXX */ dump_item++; } /* Drop it in the dungeon */ drop_near(i_ptr, -1, m_ptr->fy, m_ptr->fx); } /* Re-set the object level */ object_level = set_object_level; /*If marked for a bonus item, create it and drop it */ if (m_ptr->mflag & (MFLAG_BONUS_ITEM)) { bool this_good = good; bool this_great = great; bool this_chest = chest; bool interesting = FALSE; char o_name[80]; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); if (one_in_(50)) this_chest = TRUE; if (one_in_(15)) this_great = TRUE; if (one_in_(5)) this_good = TRUE; if ((!this_good) && (!this_great) && (!this_chest)) { object_level += 5; if (object_level > MAX_DEPTH) object_level = MAX_DEPTH; interesting = TRUE; } if (this_chest) { while (!make_object(i_ptr, TRUE, TRUE, DROP_TYPE_CHEST, FALSE)) continue; } /* Make an object */ else while (!make_object(i_ptr, this_good, this_good, DROP_TYPE_UNTHEMED, interesting)) continue; /* Remember history */ if (visible) object_history(i_ptr, ORIGIN_DROP_KNOWN, m_ptr->r_idx); else object_history(i_ptr, ORIGIN_DROP_UNKNOWN, 0); object_desc(o_name, sizeof(o_name), i_ptr, ODESC_PREFIX | ODESC_FULL); /* Drop it in the dungeon */ drop_near(i_ptr, -1, m_ptr->fy, m_ptr->fx); } /* Reset the object level */ object_level = effective_depth(p_ptr->depth); /* Reset "coin" type */ coin_type = 0; /* Take note of any dropped treasure */ if (visible && (dump_item || dump_gold)) { /* Take notes on treasure */ lore_treasure(m_idx, dump_item, dump_gold); } }
/* * Read the dungeon * * The monsters/objects must be loaded in the same order * that they were stored, since the actual indexes matter. * * Note that the size of the dungeon is now hard-coded to * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another * size will be silently discarded by this routine. * * Note that dungeon objects, including objects held by monsters, are * placed directly into the dungeon, using "object_copy()", which will * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for * objects held by monsters, since it is not saved in the savefile. * * After loading the monsters, the objects being held by monsters are * linked directly into those monsters. */ static errr rd_dungeon(void) { int i, y, x; int by, bx; s16b town; s16b dungeon; s16b depth; s16b py, px; s16b ymax, xmax; byte count; byte tmp8u; u16b tmp16u; u16b limit; /*** Basic info ***/ /* Header info */ rd_s16b(&depth); rd_s16b(&dungeon); rd_s16b(&py); rd_s16b(&px); rd_s16b(&ymax); rd_s16b(&xmax); rd_s16b(&town); rd_u16b(&tmp16u); /* Ignore illegal dungeons */ if (town>=z_info->t_max) { note(format("Ignoring illegal dungeon (%d)", dungeon)); return (0); } /* Ignore illegal dungeons */ if ((depth < 0) || (depth > max_depth(dungeon))) { note(format("Ignoring illegal dungeon depth (%d)", depth)); return (0); } /* Ignore illegal dungeons */ if ((ymax != DUNGEON_HGT) || (xmax != DUNGEON_WID)) { /* XXX XXX XXX */ note(format("Ignoring illegal dungeon size (%d,%d).", ymax, xmax)); return (0); } /* Ignore illegal dungeons */ if ((px < 0) || (px >= DUNGEON_WID) || (py < 0) || (py >= DUNGEON_HGT)) { note(format("Ignoring illegal player location (%d,%d).", py, px)); return (1); } /*** Run length decoding ***/ /* Load the dungeon data */ for (x = y = 0; y < DUNGEON_HGT; ) { /* Grab RLE info */ rd_byte(&count); rd_byte(&tmp8u); /* Apply the RLE info */ for (i = count; i > 0; i--) { /* Extract "info" */ cave_info[y][x] = tmp8u; /* Advance/Wrap */ if (++x >= DUNGEON_WID) { /* Wrap */ x = 0; /* Advance/Wrap */ if (++y >= DUNGEON_HGT) break; } } } /* Hack -- not fully dynamic */ dyna_full = FALSE; /*** Run length decoding ***/ /* Load the dungeon data */ for (x = y = 0; y < DUNGEON_HGT; ) { /* Grab RLE info */ rd_byte(&count); if (variant_save_feats) rd_u16b(&tmp16u); else rd_byte(&tmp8u); /* Apply the RLE info */ for (i = count; i > 0; i--) { /* Save the feat */ if (variant_save_feats) cave_feat[y][x] = tmp16u; else cave_feat[y][x] = tmp8u; /* Check for los flag set*/ if (f_info[cave_feat[y][x]].flags1 & (FF1_LOS)) { cave_info[y][x] &= ~(CAVE_WALL); } /* Handle wall grids */ else { cave_info[y][x] |= (CAVE_WALL); } /* Handle dynamic grids */ if (f_info[cave_feat[y][x]].flags3 & (FF3_DYNAMIC_MASK)) { if (dyna_n < (DYNA_MAX-1)) { dyna_g[dyna_n++] = GRID(y,x); } else { dyna_full = TRUE; dyna_cent_y = 255; dyna_cent_x = 255; } } /* Advance/Wrap */ if (++x >= DUNGEON_WID) { /* Wrap */ x = 0; /* Advance/Wrap */ if (++y >= DUNGEON_HGT) break; } } } /*** Player ***/ /* Fix depth */ if (depth < 1) depth = min_depth(dungeon); /* Fix depth */ if (depth > max_depth(dungeon)) depth = max_depth(dungeon); /* Load depth */ p_ptr->depth = depth; p_ptr->dungeon = dungeon; p_ptr->town = town; /* Place player in dungeon */ if (!player_place(py, px)) { note(format("Cannot place player (%d,%d)!", py, px)); return (-1); } /*** Room descriptions ***/ if (!variant_room_info) { /* Initialize the room table */ for (by = 0; by < MAX_ROOMS_ROW; by++) { for (bx = 0; bx < MAX_ROOMS_COL; bx++) { dun_room[by][bx] = 0; } } /* Initialise 'zeroeth' room description */ room_info[0].flags = 0; } else { for (bx = 0; bx < MAX_ROOMS_ROW; bx++) { for (by = 0; by < MAX_ROOMS_COL; by++) { rd_byte(&dun_room[bx][by]); } } for (i = 1; i < DUN_ROOMS; i++) { int j; rd_byte(&room_info[i].type); rd_byte(&room_info[i].flags); if (room_info[i].type == ROOM_NORMAL) { for (j = 0; j < ROOM_DESC_SECTIONS; j++) { rd_s16b(&room_info[i].section[j]); if (room_info[i].section[j] == -1) break; } } } } /*** Objects ***/ /* Read the item count */ rd_u16b(&limit); /* Verify maximum */ if (limit > z_info->o_max) { note(format("Too many (%d) object entries!", limit)); return (-1); } /* Read the dungeon items */ for (i = 1; i < limit; i++) { object_type *i_ptr; object_type object_type_body; s16b o_idx; object_type *o_ptr; /* Get the object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Make an object */ o_idx = o_pop(); /* Paranoia */ if (o_idx != i) { note(format("Cannot place object %d!", i)); return (-1); } /* Get the object */ o_ptr = &o_list[o_idx]; /* Structure Copy */ object_copy(o_ptr, i_ptr); /* Dungeon floor */ if (!i_ptr->held_m_idx) { int x = i_ptr->ix; int y = i_ptr->iy; /* ToDo: Verify coordinates */ /* Link the object to the pile */ o_ptr->next_o_idx = cave_o_idx[y][x]; /* Link the floor to the object */ cave_o_idx[y][x] = o_idx; } } /*** Monsters ***/ /* Read the monster count */ rd_u16b(&limit); /* Hack -- verify */ if (limit > z_info->m_max) { note(format("Too many (%d) monster entries!", limit)); return (-1); } /* Read the monsters */ for (i = 1; i < limit; i++) { monster_type *n_ptr; monster_type monster_type_body; /* Get local monster */ n_ptr = &monster_type_body; /* Clear the monster */ (void)WIPE(n_ptr, monster_type); /* Read the monster */ rd_monster(n_ptr); /* Place monster in dungeon */ if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i) { note(format("Cannot place monster %d", i)); return (-1); } } /*** Holding ***/ /* Reacquire objects */ for (i = 1; i < o_max; ++i) { object_type *o_ptr; monster_type *m_ptr; /* Get the object */ o_ptr = &o_list[i]; /* Ignore dungeon objects */ if (!o_ptr->held_m_idx) continue; /* Verify monster index */ if (o_ptr->held_m_idx >= z_info->m_max) { note("Invalid monster index"); return (-1); } /* Get the monster */ m_ptr = &m_list[o_ptr->held_m_idx]; /* Link the object to the pile */ o_ptr->next_o_idx = m_ptr->hold_o_idx; /* Link the monster to the object */ m_ptr->hold_o_idx = i; } /*** Success ***/ /* The dungeon is ready */ character_dungeon = TRUE; /* Regenerate town in post 2.9.3 versions */ if (older_than(2, 9, 4) && (p_ptr->depth == 0)) character_dungeon = FALSE; /* Success */ return (0); }
/* * Read the dungeon * * The monsters/objects must be loaded in the same order * that they were stored, since the actual indexes matter. * * Note that the size of the dungeon is now hard-coded to * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another * size will be silently discarded by this routine. * * Note that dungeon objects, including objects held by monsters, are * placed directly into the dungeon, using "object_copy()", which will * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for * objects held by monsters, since it is not saved in the savefile. * * After loading the monsters, the objects being held by monsters are * linked directly into those monsters. */ static errr rd_dungeon(void) { int i, y, x; s16b depth; s16b py, px; byte count; byte tmp8u; u16b tmp16u; u16b limit; /*** Basic info ***/ /* Header info */ rd_s16b(&depth); rd_u16b(&p_ptr->dungeon_type); /* Get dungeon capabilities */ set_dungeon_type(p_ptr->dungeon_type); rd_s16b(&py); rd_s16b(&px); rd_byte(&p_ptr->cur_map_hgt); rd_byte(&p_ptr->cur_map_wid); rd_u16b(&altered_inventory_counter); /* Paranoia */ allow_altered_inventory = FALSE; rd_u16b(&tmp16u); /* Ignore illegal dungeons */ if ((depth < 0) || (depth >= MAX_DEPTH)) { note(format("Ignoring illegal dungeon depth (%d)", depth)); return (0); } /* Ignore illegal dungeons */ if ((p_ptr->cur_map_hgt > MAX_DUNGEON_HGT) || (p_ptr->cur_map_wid > MAX_DUNGEON_WID)) { /* XXX XXX XXX */ note(format("Ignoring illegal dungeon size (%d,%d).", p_ptr->cur_map_hgt, p_ptr->cur_map_wid)); return (0); } /* Ignore illegal dungeons */ if ((px < 0) || (px >= p_ptr->cur_map_wid) || (py < 0) || (py >= p_ptr->cur_map_hgt)) { note(format("Ignoring illegal player location (%d,%d).", py, px)); return (1); } /*** Run length decoding ***/ /* Load the dungeon data */ for (x = y = 0; y < p_ptr->cur_map_hgt; ) { /* Grab RLE info */ rd_byte(&count); rd_byte(&tmp8u); /* Apply the RLE info */ for (i = count; i > 0; i--) { /* Extract "info" */ cave_info[y][x] = tmp8u; /* Advance/Wrap */ if (++x >= p_ptr->cur_map_wid) { /* Wrap */ x = 0; /* Advance/Wrap */ if (++y >= p_ptr->cur_map_hgt) break; } } } /*** Run length decoding ***/ /* Load the dungeon data */ for (x = y = 0; y < p_ptr->cur_map_hgt; ) { /* Grab RLE info */ rd_byte(&count); rd_byte(&tmp8u); /* Apply the RLE info */ for (i = count; i > 0; i--) { feature_type *f_ptr; /* Extract "feat" */ cave_feat[y][x] = tmp8u; update_los_proj_move(y, x); /* Get fast access to feature */ f_ptr = &f_info[tmp8u]; /* Handle glowing grids */ if (_feat_ff2_match(f_ptr, FF2_GLOW)) { int d; /* Turn on super glow */ cave_info[y][x] |= (CAVE_HALO); /* Spread super glow through adjacent grids */ for (d = 0; d < 8; d++) { /* Get coordinates */ int yy = y + ddy_ddd[d]; int xx = x + ddx_ddd[d]; /* Ignore annoying locations */ if (!in_bounds_fully(yy, xx)) { continue; } /* Turn on super glow */ cave_info[yy][xx] |= (CAVE_HALO); } } /* Register dynamic features */ if (_feat_ff3_match(f_ptr, FF3_DYNAMIC)) { (void)add_dynamic_terrain(y, x); } /* Update the flags of the current level */ if (_feat_ff3_match(f_ptr, TERRAIN_MASK)) { level_flag |= get_level_flag((u16b)(f_ptr - f_info)); } /* Advance/Wrap */ if (++x >= p_ptr->cur_map_wid) { /* Wrap */ x = 0; /* Advance/Wrap */ if (++y >= p_ptr->cur_map_hgt) break; } } } /*** Player ***/ /* Load depth */ p_ptr->depth = depth; /* Place player in dungeon */ if (!player_place(py, px)) { note(format("Cannot place player (%d,%d)!", py, px)); return (-1); } /*** Objects ***/ /* Read the item count */ rd_u16b(&limit); /* Verify maximum */ if (limit > z_info->o_max) { note(format("Too many (%d) object entries!", limit)); return (-1); } /* Read the dungeon items */ for (i = 1; i < limit; i++) { object_type *i_ptr; object_type object_type_body; s16b o_idx; object_type *o_ptr; /* Get the object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Make an object */ o_idx = o_pop(); /* Paranoia */ if (o_idx != i) { note(format("Cannot place object %d!", i)); return (-1); } /* Get the object */ o_ptr = &o_list[o_idx]; /* Structure Copy */ object_copy(o_ptr, i_ptr); /* Dungeon floor */ if (!i_ptr->held_m_idx) { int x = i_ptr->ix; int y = i_ptr->iy; /* ToDo: Verify coordinates */ /* Link the object to the pile */ o_ptr->next_o_idx = cave_o_idx[y][x]; /* Link the floor to the object */ cave_o_idx[y][x] = o_idx; /* Rearrange stack if needed */ rearrange_stack(y, x); } } /*** Monsters ***/ /* Read the monster count */ rd_u16b(&limit); /* Hack -- verify */ if (limit > z_info->m_max) { note(format("Too many (%d) monster entries!", limit)); return (-1); } /* Read the monsters */ for (i = 1; i < limit; i++) { monster_type *n_ptr; monster_type monster_type_body; monster_race *r_ptr; int r_idx; /* Get local monster */ n_ptr = &monster_type_body; /* Clear the monster */ (void)WIPE(n_ptr, monster_type); /* Read the monster */ rd_monster(n_ptr); /* Access the "r_idx" of the chosen monster */ r_idx = n_ptr->r_idx; /* Access the actual race */ r_ptr = &r_info[r_idx]; /* If a player ghost, some special features need to be added. */ if (r_ptr->flags2 & (RF2_PLAYER_GHOST)) { (void)prepare_ghost(n_ptr->r_idx); } /* Place monster in dungeon */ if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i) { note(format("Cannot place monster %d", i)); return (-1); } } /*** Holding ***/ /* Reacquire objects */ for (i = 1; i < o_max; ++i) { object_type *o_ptr; monster_type *m_ptr; /* Get the object */ o_ptr = &o_list[i]; /* Ignore dungeon objects */ if (!o_ptr->held_m_idx) continue; /* Verify monster index */ if (o_ptr->held_m_idx > z_info->m_max) { note("Invalid monster index"); return (-1); } /* Get the monster */ m_ptr = &mon_list[o_ptr->held_m_idx]; /* Link the object to the pile */ o_ptr->next_o_idx = m_ptr->hold_o_idx; /* Link the monster to the object */ m_ptr->hold_o_idx = i; } /*** Effects ***/ /* Read the effect count */ rd_u16b(&limit); /* Verify maximum */ if (limit > z_info->x_max) { note(format("Too many (%d) effect entries!", limit)); return (-1); } /* Read the dungeon items */ for (i = 1; i < limit; i++) { /* Read the item */ if (rd_effect()) { note("Error reading effect"); return (-1); } } /*** Success ***/ /* The dungeon is ready */ character_dungeon = TRUE; /* Success */ return (0); }
/* * Read the player inventory * * Note that the inventory is "re-sorted" later by "dungeon()". */ static errr rd_inventory(void) { int slot = 0; object_type *i_ptr; object_type object_type_body; /* Read until done */ while (1) { u16b n; /* Get the next item index */ rd_u16b(&n); /* Nope, we reached the end */ if (n == 0xFFFF) break; /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Read the item */ if (rd_item(i_ptr)) { note("Error reading item"); return (-1); } /* Hack -- verify item */ if (!i_ptr->k_idx) return (-1); /* Verify slot */ if (n >= ALL_INVEN_TOTAL) return (-1); /* Wield equipment */ if (n >= INVEN_WIELD) { /* Copy object */ object_copy(&inventory[n], i_ptr); /* One more item */ if (!IS_QUIVER_SLOT(n)) p_ptr->equip_cnt++; } /* Warning -- backpack is full */ else if (p_ptr->inven_cnt == INVEN_PACK) { /* Oops */ note("Too many items in the inventory!"); /* Fail */ return (-1); } /* Carry inventory */ else { /* Get a slot */ n = slot++; /* Copy object */ object_copy(&inventory[n], i_ptr); /* One more item */ p_ptr->inven_cnt++; } /* Update "p_ptr->pack_size_reduce" */ save_quiver_size(); } /* Success */ return (0); }
object_type::object_type() { object_wipe(); }
/* * Allocate objects upon opening a chest * * Disperse treasures from the given chest, centered at (x,y). * * Small chests often contain "gold", while Large chests always contain * items. Wooden chests contain 2 items, Iron chests contain 4 items, * and Steel chests contain 6 items. The "value" of the items in a * chest is based on the level on which the chest is generated. */ static void chest_death(int y, int x, s16b o_idx) { int number, value; bool tiny; object_type *o_ptr; object_type *i_ptr; object_type object_type_body; /* Get the chest */ o_ptr = object_byid(o_idx); /* Small chests often hold "gold" */ tiny = (o_ptr->sval < SV_CHEST_MIN_LARGE); /* Determine how much to drop (see above) */ number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2; /* Zero pval means empty chest */ if (!o_ptr->pval[DEFAULT_PVAL]) number = 0; /* Determine the "value" of the items */ value = o_ptr->origin_depth - 10 + 2 * o_ptr->sval; if (value < 1) value = 1; /* Drop some objects (non-chests) */ for (; number > 0; --number) { /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Small chests often drop gold */ if (tiny && (randint0(100) < 75)) make_gold(i_ptr, value, SV_GOLD_ANY); /* Otherwise drop an item, as long as it isn't a chest */ else { if (!make_object(cave, i_ptr, value, FALSE, FALSE, NULL)) continue; if (i_ptr->tval == TV_CHEST) continue; } /* Record origin */ i_ptr->origin = ORIGIN_CHEST; i_ptr->origin_depth = o_ptr->origin_depth; /* Drop it in the dungeon */ drop_near(cave, i_ptr, 0, y, x, TRUE); } /* Empty */ o_ptr->pval[DEFAULT_PVAL] = 0; /* Known */ object_notice_everything(o_ptr); }
/* * Try to create an item again. Output some statistics. -Bernd- * * The statistics are correct now. We acquire a clean grid, and then * repeatedly place an object in this grid, copying it into an item * holder, and then deleting the object. We fiddle with the artifact * counter flags to prevent weirdness. We use the items to collect * statistics on item creation relative to the initial item. */ static void wiz_statistics(object_type *o_ptr) { long i, matches, better, worse, other; char ch; char *quality; bool good, great; object_type *i_ptr; object_type object_type_body; cptr q = "Rolls: %ld, Matches: %ld, Better: %ld, Worse: %ld, Other: %ld"; /* Mega-Hack -- allow multiple artifacts XXX XXX XXX */ if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 0; /* Interact */ while (TRUE) { cptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? "; /* Display item */ wiz_display_item(o_ptr); /* Get choices */ if (!get_com(pmt, &ch)) break; if (ch == 'n' || ch == 'N') { good = FALSE; great = FALSE; quality = "normal"; } else if (ch == 'g' || ch == 'G') { good = TRUE; great = FALSE; quality = "good"; } else if (ch == 'e' || ch == 'E') { good = TRUE; great = TRUE; quality = "excellent"; } else { #if 0 /* unused */ good = FALSE; great = FALSE; #endif /* unused */ break; } /* Let us know what we are doing */ msg_format("Creating a lot of %s items. Base level = %d.", quality, p_ptr->depth); message_flush(); /* Set counters to zero */ matches = better = worse = other = 0; /* Let's rock and roll */ for (i = 0; i <= TEST_ROLL; i++) { /* Output every few rolls */ if ((i < 100) || (i % 100 == 0)) { /* Do not wait */ inkey_scan = TRUE; /* Allow interupt */ if (inkey()) { /* Flush */ flush(); /* Stop rolling */ break; } /* Dump the stats */ prt(format(q, i, matches, better, worse, other), 0, 0); Term_fresh(); } /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Create an object */ make_object(i_ptr, good, great); /* Mega-Hack -- allow multiple artifacts XXX XXX XXX */ if (artifact_p(i_ptr)) a_info[i_ptr->name1].cur_num = 0; /* Test for the same tval and sval. */ if ((o_ptr->tval) != (i_ptr->tval)) continue; if ((o_ptr->sval) != (i_ptr->sval)) continue; /* Check for match */ if ((i_ptr->pval == o_ptr->pval) && (i_ptr->to_a == o_ptr->to_a) && (i_ptr->to_h == o_ptr->to_h) && (i_ptr->to_d == o_ptr->to_d)) { matches++; } /* Check for better */ else if ((i_ptr->pval >= o_ptr->pval) && (i_ptr->to_a >= o_ptr->to_a) && (i_ptr->to_h >= o_ptr->to_h) && (i_ptr->to_d >= o_ptr->to_d)) { better++; } /* Check for worse */ else if ((i_ptr->pval <= o_ptr->pval) && (i_ptr->to_a <= o_ptr->to_a) && (i_ptr->to_h <= o_ptr->to_h) && (i_ptr->to_d <= o_ptr->to_d)) { worse++; } /* Assume different */ else { other++; } } /* Final dump */ msg_format(q, i, matches, better, worse, other); message_flush(); } /* Hack -- Normally only make a single artifact */ if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 1; }
/* * Read the player inventory * * Note that the inventory changed in Angband 2.7.4. Two extra * pack slots were added and the equipment was rearranged. Note * that these two features combine when parsing old save-files, in * which items from the old "aux" slot are "carried", perhaps into * one of the two new "inventory" slots. * * Note that the inventory is "re-sorted" later by "dungeon()". */ static errr rd_inventory(void) { int slot = 0; object_type forge; object_type *q_ptr; /* No weight */ p_ptr->total_weight = 0; /* No items */ inven_cnt = 0; equip_cnt = 0; /* Read until done */ while (1) { u16b n; /* Get the next item index */ rd_u16b(&n); /* Nope, we reached the end */ if (n == 0xFFFF) break; /* Get local object */ q_ptr = &forge; /* Wipe the object */ object_wipe(q_ptr); /* Read the item */ rd_item(q_ptr); /* Hack -- verify item */ if (!q_ptr->k_idx) return (53); /* Wield equipment */ if (n >= INVEN_WIELD) { if (q_ptr->k_idx) { /* Player touches it */ q_ptr->marked |= OM_TOUCHED; /* Copy object */ object_copy(&inventory[n], q_ptr); /* Add the weight */ p_ptr->total_weight += (q_ptr->number * q_ptr->weight); /* One more item */ equip_cnt++; } } /* Warning -- backpack is full */ else if (inven_cnt == INVEN_PACK) { /* Oops */ #ifdef JP note("持ち物の中のアイテムが多すぎる!"); #else note("Too many items in the inventory!"); #endif /* Fail */ return (54); } /* Carry inventory */ else { if (q_ptr->k_idx) { /* Get a slot */ n = slot++; /* Player touches it */ q_ptr->marked |= OM_TOUCHED; /* Copy object */ object_copy(&inventory[n], q_ptr); /* Add the weight */ p_ptr->total_weight += (q_ptr->number * q_ptr->weight); /* One more item */ inven_cnt++; } } } /* Success */ return (0); }
/* * Try to create an item again. Output some statistics. -Bernd- * * The statistics are correct now. We acquire a clean grid, and then * repeatedly place an object in this grid, copying it into an item * holder, and then deleting the object. We fiddle with the artifact * counter flags to prevent weirdness. We use the items to collect * statistics on item creation relative to the initial item. */ static void wiz_statistics(object_type *o_ptr, int level) { long i, matches, better, worse, other; int j; struct keypress ch; const char *quality; bool good, great, ismatch, isbetter, isworse; object_type *i_ptr; object_type object_type_body; const char *q = "Rolls: %ld, Matches: %ld, Better: %ld, Worse: %ld, Other: %ld"; /* Allow multiple artifacts, because breaking the game is fine here */ if (o_ptr->artifact) o_ptr->artifact->created = FALSE; /* Interact */ while (TRUE) { const char *pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? "; /* Display item */ wiz_display_item(o_ptr, TRUE); /* Get choices */ if (!get_com(pmt, &ch)) break; if (ch.code == 'n' || ch.code == 'N') { good = FALSE; great = FALSE; quality = "normal"; } else if (ch.code == 'g' || ch.code == 'G') { good = TRUE; great = FALSE; quality = "good"; } else if (ch.code == 'e' || ch.code == 'E') { good = TRUE; great = TRUE; quality = "excellent"; } else { #if 0 /* unused */ good = FALSE; great = FALSE; #endif /* unused */ break; } /* Let us know what we are doing */ msg("Creating a lot of %s items. Base level = %d.", quality, p_ptr->depth); message_flush(); /* Set counters to zero */ matches = better = worse = other = 0; /* Let's rock and roll */ for (i = 0; i <= TEST_ROLL; i++) { /* Output every few rolls */ if ((i < 100) || (i % 100 == 0)) { struct keypress kp; /* Do not wait */ inkey_scan = SCAN_INSTANT; /* Allow interupt */ kp = inkey(); if (kp.type != EVT_NONE) { flush(); break; } /* Dump the stats */ prt(format(q, i, matches, better, worse, other), 0, 0); Term_fresh(); } /* Get local object */ i_ptr = &object_type_body; /* Wipe the object */ object_wipe(i_ptr); /* Create an object */ make_object(cave, i_ptr, level, good, great, NULL); /* Allow multiple artifacts, because breaking the game is fine here */ if (o_ptr->artifact) o_ptr->artifact->created = FALSE; /* Test for the same tval and sval. */ if ((o_ptr->tval) != (i_ptr->tval)) continue; if ((o_ptr->sval) != (i_ptr->sval)) continue; /* Check pvals */ ismatch = TRUE; for (j = 0; j < MAX_PVALS; j++) if (i_ptr->pval[j] != o_ptr->pval[j]) ismatch = FALSE; isbetter = TRUE; for (j = 0; j < MAX_PVALS; j++) if (i_ptr->pval[j] < o_ptr->pval[j]) isbetter = FALSE; isworse = TRUE; for (j = 0; j < MAX_PVALS; j++) if (i_ptr->pval[j] > o_ptr->pval[j]) isworse = FALSE; /* Check for match */ if (ismatch && (i_ptr->to_a == o_ptr->to_a) && (i_ptr->to_h == o_ptr->to_h) && (i_ptr->to_d == o_ptr->to_d) && (i_ptr->num_pvals == o_ptr->num_pvals)) { matches++; } /* Check for better */ else if (isbetter && (i_ptr->to_a >= o_ptr->to_a) && (i_ptr->to_h >= o_ptr->to_h) && (i_ptr->to_d >= o_ptr->to_d)) { better++; } /* Check for worse */ else if (isworse && (i_ptr->to_a <= o_ptr->to_a) && (i_ptr->to_h <= o_ptr->to_h) && (i_ptr->to_d <= o_ptr->to_d)) { worse++; } /* Assume different */ else { other++; } } /* Final dump */ msg(q, i, matches, better, worse, other); message_flush(); } /* Hack -- Normally only make a single artifact */ if (o_ptr->artifact) o_ptr->artifact->created = TRUE; }
/* * 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."); }
/** * Creates a specific monster's drop, including any drops specified * in the monster.txt file. * * Returns true if anything is created, false if nothing is. */ static bool mon_create_drop(struct chunk *c, struct monster *mon, byte origin) { struct monster_drop *drop; bool great, good, gold_ok, item_ok; bool extra_roll = false; bool any = false; int number = 0, level, j, monlevel; struct object *obj; assert(mon); great = (rf_has(mon->race->flags, RF_DROP_GREAT)); good = great || (rf_has(mon->race->flags, RF_DROP_GOOD)); gold_ok = (!rf_has(mon->race->flags, RF_ONLY_ITEM)); item_ok = (!rf_has(mon->race->flags, RF_ONLY_GOLD)); /* Determine how much we can drop */ number = mon_create_drop_count(mon->race, false); /* Give added bonus for unique monters */ monlevel = mon->race->level; if (rf_has(mon->race->flags, RF_UNIQUE)) { monlevel = MIN(monlevel + 15, monlevel * 2); extra_roll = true; } /* Take the best of (average of monster level and current depth) and (monster level) - to reward fighting OOD monsters */ level = MAX((monlevel + player->depth) / 2, monlevel); level = MIN(level, 100); /* Morgoth currently drops all artifacts with the QUEST_ART flag */ if (rf_has(mon->race->flags, RF_QUESTOR) && (mon->race->level == 100)) { /* Search all the artifacts */ for (j = 1; j < z_info->a_max; j++) { struct artifact *art = &a_info[j]; struct object_kind *kind = lookup_kind(art->tval, art->sval); if (!kf_has(kind->kind_flags, KF_QUEST_ART)) { continue; } /* Allocate by hand, prep, apply magic */ obj = mem_zalloc(sizeof(*obj)); object_prep(obj, kind, 100, RANDOMISE); obj->artifact = art; copy_artifact_data(obj, obj->artifact); obj->artifact->created = true; /* Set origin details */ obj->origin = origin; obj->origin_depth = player->depth; obj->origin_race = mon->race; obj->number = 1; /* Try to carry */ if (monster_carry(c, mon, obj)) { any = true; } else { obj->artifact->created = false; object_wipe(obj); mem_free(obj); } } } /* Specified drops */ for (drop = mon->race->drops; drop; drop = drop->next) { if ((unsigned int)randint0(100) >= drop->percent_chance) continue; /* Allocate by hand, prep, apply magic */ obj = mem_zalloc(sizeof(*obj)); object_prep(obj, drop->kind, level, RANDOMISE); apply_magic(obj, level, true, good, great, extra_roll); /* Set origin details */ obj->origin = origin; obj->origin_depth = player->depth; obj->origin_race = mon->race; obj->number = randint0(drop->max - drop->min) + drop->min; /* Try to carry */ if (monster_carry(c, mon, obj)) { any = true; } else { object_wipe(obj); mem_free(obj); } } /* Make some objects */ for (j = 0; j < number; j++) { if (gold_ok && (!item_ok || (randint0(100) < 50))) { obj = make_gold(level, "any"); } else { obj = make_object(c, level, good, great, extra_roll, NULL, 0); if (!obj) continue; } /* Set origin details */ obj->origin = origin; obj->origin_depth = player->depth; obj->origin_race = mon->race; /* Try to carry */ if (monster_carry(c, mon, obj)) { any = true; } else { obj->artifact->created = false; object_wipe(obj); mem_free(obj); } } return any; }