static bool _create_arrows(void) { int item, slot; object_type forge; item_tester_hook = _create_ammo_p; if (!get_item(&item, "Convert which item? ", "You have no item to convert.", USE_INVEN | USE_FLOOR)) return FALSE; object_prep(&forge, lookup_kind(TV_ARROW, m_bonus(1, p_ptr->lev)+ 1)); forge.number = (byte)rand_range(5, 10); apply_magic(&forge, p_ptr->lev, AM_NO_FIXED_ART); obj_identify(&forge); forge.discount = 99; msg_print("You make some ammo."); if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } slot = inven_carry(&forge); if (slot >= 0) autopick_alter_item(slot, FALSE); return TRUE; }
static void refuel_torch(object_type *j_ptr, object_type *o_ptr, int item) { bitflag f[OF_SIZE]; bitflag g[OF_SIZE]; /* Refuel */ j_ptr->timeout += o_ptr->timeout + 5; /* Message */ msg("You combine the torches."); /* Transfer the LIGHT flag if refuelling from a torch with it to one without it */ object_flags(o_ptr, f); object_flags(j_ptr, g); if (of_has(f, OF_LIGHT) && !of_has(g, OF_LIGHT)) { of_on(j_ptr->flags, OF_LIGHT); if (!j_ptr->ego && o_ptr->ego) j_ptr->ego = o_ptr->ego; msg("Your torch shines further!"); } /* Over-fuel message */ if (j_ptr->timeout >= FUEL_TORCH) { j_ptr->timeout = FUEL_TORCH; msg("Your torch is fully fueled."); } /* Refuel message */ else { msg("Your torch glows more brightly."); } /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } /* Recalculate torch */ p_ptr->update |= (PU_TORCH); /* Redraw stuff */ p_ptr->redraw |= (PR_EQUIP); }
/********************************************************************** * Powers **********************************************************************/ static void _absorb_spell(int cmd, variant *res) { switch (cmd) { case SPELL_NAME: var_set_string(res, "Absorb Weapon"); break; case SPELL_DESC: var_set_string(res, "Destroys a single weapon, absorbing the essence of its power."); break; case SPELL_CAST: { object_type * o_ptr; int item; char o_name[MAX_NLEN]; var_set_bool(res, FALSE); item_tester_hook = object_is_melee_weapon; if (!get_item(&item, "Absorb which item? ", "You have nothing to absorb.", USE_INVEN | USE_FLOOR)) break; if (item >= 0) o_ptr = &inventory[item]; else o_ptr = &o_list[0 - item]; object_desc(o_name, o_ptr, OD_NAME_ONLY); msg_format("You absorb the power of %s!", o_name); _absorb(o_ptr); if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } var_set_bool(res, TRUE); break; } default: default_spell(cmd, res); break; } }
static void do_cmd_refill_torch(object_type *torch) { int item; object_type *o_ptr; item_tester_hook = _is_torch; if (!get_item(&item, "Refuel with which torch? ", "You have no extra torches.", USE_INVEN | USE_FLOOR)) return; if (item >= 0) o_ptr = &inventory[item]; else o_ptr = &o_list[0 - item]; energy_use = 50; torch->xtra4 += o_ptr->xtra4 + 5; msg_print("You combine the torches."); if (_lite_is_darkness(o_ptr) && torch->xtra4 > 0) { torch->xtra4 = 0; msg_print("Your torch has gone out!"); } else if (_lite_is_darkness(o_ptr) || _lite_is_darkness(torch)) { torch->xtra4 = 0; msg_print("Curiously, your torch does not light."); } else if (torch->xtra4 >= FUEL_TORCH) { torch->xtra4 = FUEL_TORCH; msg_print("Your torch is fully fueled."); } else msg_print("Your torch glows more brightly."); if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } p_ptr->update |= PU_TORCH; }
static void _elemental_pack_destroy(object_p p, cptr destroy_fmt, int chance) { int inven_ct = 0; int equip_ct = 0; int i; for (i = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &inventory[i]; char o_name[MAX_NLEN]; int n = chance; int old_ct = 0; if (!o_ptr->k_idx) continue; if (!p(o_ptr)) continue; if (i >= EQUIP_BEGIN) n /= 3; if (randint0(1000) >= MAX(1, n)) continue; old_ct = o_ptr->number; o_ptr->number = 1; object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); o_ptr->number = old_ct; msg_format(destroy_fmt, o_name); stats_on_p_destroy(o_ptr, 1); inven_item_increase(i, -1); inven_item_describe(i); inven_item_optimize(i); if (i >= EQUIP_BEGIN) ++equip_ct; else ++inven_ct; } if (equip_ct) { p_ptr->update |= PU_BONUS; p_ptr->update |= PU_TORCH; p_ptr->update |= PU_MANA; p_ptr->redraw |= PR_EQUIPPY; p_ptr->window |= PW_EQUIP | PW_PLAYER; } if (inven_ct) p_ptr->window |= PW_INVEN; if (equip_ct + inven_ct) disturb(1, 0); }
void rage_mage_gain_spell(void) { int item; if (p_ptr->blind || no_lite()) { msg_print("You cannot see!"); return; } if (p_ptr->confused) { msg_print("You are too confused!"); return; } if (!p_ptr->new_spells) { msg_print("You cannot learn any new techniques!"); return; } msg_format("You can learn %d new technique%s.", p_ptr->new_spells, (p_ptr->new_spells == 1 ? "" : "s")); msg_print(NULL); item_tester_tval = TV_RAGE_BOOK; if (get_item(&item, "Study which book?", "You have no books that you can read.", USE_INVEN)) { int book = inventory[item].sval; if (_gain_spell(book)) { char o_name[MAX_NLEN]; int old_amt = inventory[item].number; inventory[item].number = 1; object_desc(o_name, &inventory[item], 0); inventory[item].number = old_amt; msg_format("%^s is destroyed.", o_name); inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); energy_use = 100; } } }
/* * Refill the players lamp (from the pack or floor) */ static void do_cmd_refill_lamp(object_type *lantern) { int item; object_type *o_ptr; item_tester_hook = item_tester_refill_lantern; if (!get_item(&item, "Refill with which flask? ", "You have no flasks of oil.", USE_INVEN | USE_FLOOR)) return; if (item >= 0) o_ptr = &inventory[item]; else o_ptr = &o_list[0 - item]; energy_use = 50; lantern->xtra4 += o_ptr->xtra4; msg_print("You fuel your lamp."); if ( _lite_is_darkness(o_ptr) && lantern->xtra4 > 0) { lantern->xtra4 = 0; msg_print("Your lamp has gone out!"); } else if (_lite_is_darkness(o_ptr) || _lite_is_darkness(lantern)) { lantern->xtra4 = 0; msg_print("Curiously, your lamp doesn't light."); } else if (lantern->xtra4 >= FUEL_LAMP) { lantern->xtra4 = FUEL_LAMP; msg_print("Your lamp is full."); } if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } p_ptr->update |= PU_TORCH; }
static bool _create_bolts(void) { int item, slot; object_type forge; item_tester_hook = _create_ammo_p; if (!get_item(&item, "Convert which item? ", "You have no item to convert.", USE_INVEN | USE_FLOOR)) return FALSE; /* Note: You won't ever get Steel Bolts this way since I:18:1 is shared with by Bolts and Steel Bolts and lookup_kind() picks the first match in k_info.txt. However, getting Steel from Bones/Junk would be a bit odd anyway ... */ object_prep(&forge, lookup_kind(TV_BOLT, m_bonus(1, p_ptr->lev)+ 1)); forge.number = (byte)rand_range(4, 8); apply_magic(&forge, p_ptr->lev, AM_NO_FIXED_ART); obj_identify(&forge); forge.discount = 99; msg_print("You make some ammo."); if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } slot = inven_carry(&forge); if (slot >= 0) autopick_alter_item(slot, FALSE); return TRUE; }
/* Absorb Magic */ static bool gain_magic(void) { int item; int pval; object_type *o_ptr; int idx; char o_name[MAX_NLEN]; item_tester_hook = item_tester_hook_recharge; if (!get_item(&item, "Gain power of which item? ", "You have nothing to gain power from.", (USE_INVEN | USE_FLOOR))) return (FALSE); if (item >= 0) o_ptr = &inventory[item]; else o_ptr = &o_list[0 - item]; if (!object_is_known(o_ptr)) { msg_print("You need to identify before absorbing."); return FALSE; } if (o_ptr->timeout) { msg_print("This item is still charging."); return FALSE; } idx = _find_idx(o_ptr->tval, o_ptr->sval); if (idx < 0) /* Bug? Tables need to be updated for every new device ... */ { msg_print("You can't eat that!"); return FALSE; } pval = o_ptr->pval; if (o_ptr->tval == TV_ROD) { p_ptr->magic_num2[idx] += o_ptr->number; if (p_ptr->magic_num2[idx] > 99) p_ptr->magic_num2[idx] = 99; } else { int num; for (num = o_ptr->number; num; num--) { int gain_num = pval; if (o_ptr->tval == TV_WAND) gain_num = (pval + num - 1) / num; if (p_ptr->magic_num2[idx]) gain_num = (gain_num + randint0(2))/2; p_ptr->magic_num2[idx] += gain_num; if (p_ptr->magic_num2[idx] > 99) p_ptr->magic_num2[idx] = 99; p_ptr->magic_num1[idx] += pval * _EATER_CHARGE; if (p_ptr->magic_num1[idx] > 99 * _EATER_CHARGE) p_ptr->magic_num1[idx] = 99 * _EATER_CHARGE; if (p_ptr->magic_num1[idx] > p_ptr->magic_num2[idx] * _EATER_CHARGE) p_ptr->magic_num1[idx] = p_ptr->magic_num2[idx] * _EATER_CHARGE; if (o_ptr->tval == TV_WAND) pval -= (pval + num - 1) / num; } } object_desc(o_name, o_ptr, 0); msg_format("You absorb magic of %s.", o_name); /* Eliminate the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -999); inven_item_describe(item); inven_item_optimize(item); } /* Eliminate the item (from the floor) */ else { floor_item_increase(0 - item, -999); floor_item_describe(0 - item); floor_item_optimize(0 - item); } return TRUE; }
static void refill_lamp(object_type *j_ptr, object_type *o_ptr, int item) { /* Refuel */ j_ptr->timeout += o_ptr->timeout ? o_ptr->timeout : o_ptr->pval[DEFAULT_PVAL]; /* Message */ msg("You fuel your lamp."); /* Comment */ if (j_ptr->timeout >= FUEL_LAMP) { j_ptr->timeout = FUEL_LAMP; msg("Your lamp is full."); } /* Refilled from a lantern */ if (o_ptr->sval == SV_LIGHT_LANTERN) { /* Unstack if necessary */ if (o_ptr->number > 1) { object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Obtain a local object */ object_copy(i_ptr, o_ptr); /* Modify quantity */ i_ptr->number = 1; /* Remove fuel */ i_ptr->timeout = 0; /* Unstack the used item */ o_ptr->number--; p_ptr->total_weight -= i_ptr->weight; /* Carry or drop */ if (item >= 0) item = inven_carry(p_ptr, i_ptr); else drop_near(cave, i_ptr, 0, p_ptr->py, p_ptr->px, FALSE); } /* Empty a single lantern */ else { /* No more fuel */ o_ptr->timeout = 0; } /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* Redraw stuff */ p_ptr->redraw |= (PR_INVEN); } /* Refilled from a flask */ else { /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } } /* Recalculate torch */ p_ptr->update |= (PU_TORCH); /* Redraw stuff */ p_ptr->redraw |= (PR_EQUIP); }
static void _shatter_device_spell(int cmd, variant *res) { switch (cmd) { case SPELL_NAME: var_set_string(res, T("Shatter Device", "")); break; case SPELL_DESC: var_set_string(res, T("Destroy a magical device in your inventory for various effects.", "")); break; case SPELL_CAST: { int item; object_type *o_ptr; var_set_bool(res, FALSE); item_tester_hook = item_tester_hook_recharge; if (!get_item(&item, "Shatter which device?", "You have nothing to shatter.", USE_INVEN)) return; o_ptr = &inventory[item]; var_set_bool(res, TRUE); if (_object_is_(o_ptr, TV_STAFF, SV_STAFF_DESTRUCTION)) { if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), 4 * p_ptr->lev)) msg_print("The dungeon collapses..."); else msg_print("The dungeon trembles."); } else if ( _object_is_(o_ptr, TV_STAFF, SV_STAFF_HEALING) || _object_is_(o_ptr, TV_ROD, SV_ROD_HEALING) || _object_is_(o_ptr, TV_ROD, SV_ROD_RESTORATION) ) { msg_print("You feel life flow through your body!"); restore_level(); (void)set_poisoned(0, TRUE); (void)set_blind(0, TRUE); (void)set_confused(0, TRUE); (void)set_image(0, TRUE); (void)set_stun(0, TRUE); (void)set_cut(0, TRUE); (void)do_res_stat(A_STR); (void)do_res_stat(A_CON); (void)do_res_stat(A_DEX); (void)do_res_stat(A_WIS); (void)do_res_stat(A_INT); (void)do_res_stat(A_CHR); update_stuff(); hp_player(5000); } else if (_object_is_(o_ptr, TV_ROD, SV_ROD_TELEPORT_AWAY)) { banish_monsters(p_ptr->lev * 4); } else { project(0, 5, py, px, k_info[o_ptr->k_idx].level * 16, _object_dam_type(o_ptr), PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL, -1); } inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); break; } default: default_spell(cmd, res); break; } }
/* * Throw an object from the pack or floor. * * Note: "unseen" monsters are very hard to hit. * * Should throwing a weapon do full damage? Should it allow the magic * to hit bonus of the weapon to have an effect? Should it ever cause * the item to be destroyed? Should it do any damage at all? */ void do_cmd_throw(cmd_code code, cmd_arg args[]) { int dir, item; int i, j, y, x; s16b ty, tx; int chance, tdam, tdis; int weight; object_type *o_ptr; object_type *i_ptr; object_type object_type_body; bool hit_body = FALSE; byte missile_attr; char missile_char; char o_name[80]; u32b msg_type = 0; int path_n; u16b path_g[256]; int msec = op_ptr->delay_factor * op_ptr->delay_factor; /* Get item to throw and direction in which to throw it. */ item = args[0].item; dir = args[1].direction; /* Make sure the player isn't throwing wielded items */ if (item >= INVEN_WIELD && item < QUIVER_START) { msg_print("You have cannot throw wielded items."); return; } /* Check the item being thrown is usable by the player. */ if (!item_is_available(item, NULL, (USE_EQUIP | USE_INVEN | USE_FLOOR))) { msg_format("That item is not within your reach."); return; } /* Get the object */ o_ptr = object_from_item_idx(item); object_notice_on_firing(o_ptr); /* Get local object */ i_ptr = &object_type_body; /* Obtain a local object */ object_copy(i_ptr, o_ptr); /* Distribute the charges of rods/wands/staves between the stacks */ distribute_charges(o_ptr, i_ptr, 1); /* Single object */ i_ptr->number = 1; /* Reduce and describe inventory */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Reduce and describe floor item */ else { floor_item_increase(0 - item, -1); floor_item_optimize(0 - item); } /* Description */ object_desc(o_name, sizeof(o_name), i_ptr, ODESC_FULL); /* Find the color and symbol for the object for throwing */ missile_attr = object_attr(i_ptr); missile_char = object_char(i_ptr); /* Enforce a minimum "weight" of one pound */ weight = ((i_ptr->weight > 10) ? i_ptr->weight : 10); /* Hack -- Distance -- Reward strength, penalize weight */ tdis = (adj_str_blow[p_ptr->state.stat_ind[A_STR]] + 20) * 10 / weight; /* Max distance of 10 */ if (tdis > 10) tdis = 10; /* Hack -- Base damage from thrown object */ tdam = damroll(i_ptr->dd, i_ptr->ds); if (!tdam) tdam = 1; tdam += i_ptr->to_d; /* Chance of hitting */ chance = (p_ptr->state.skills[SKILL_TO_HIT_THROW] + (p_ptr->state.to_h * BTH_PLUS_ADJ)); /* Take a turn */ p_ptr->energy_use = 100; /* Start at the player */ y = p_ptr->py; x = p_ptr->px; /* Predict the "target" location */ ty = p_ptr->py + 99 * ddy[dir]; tx = p_ptr->px + 99 * ddx[dir]; /* Check for "target request" */ if ((dir == 5) && target_okay()) { target_get(&tx, &ty); } /* Calculate the path */ path_n = project_path(path_g, tdis, p_ptr->py, p_ptr->px, ty, tx, 0); /* Hack -- Handle stuff */ handle_stuff(); /* Project along the path */ for (i = 0; i < path_n; ++i) { int ny = GRID_Y(path_g[i]); int nx = GRID_X(path_g[i]); /* Hack -- Stop before hitting walls */ if (!cave_floor_bold(ny, nx)) break; /* Advance */ x = nx; y = ny; /* Only do visuals if the player can "see" the missile */ if (player_can_see_bold(y, x)) { /* Visual effects */ print_rel(missile_char, missile_attr, y, x); move_cursor_relative(y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(); Term_xtra(TERM_XTRA_DELAY, msec); light_spot(y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(); } /* Delay anyway for consistency */ else { /* Pause anyway, for consistancy */ Term_xtra(TERM_XTRA_DELAY, msec); } /* Handle monster */ 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]; int chance2 = chance - distance(p_ptr->py, p_ptr->px, y, x); int visible = m_ptr->ml; /* Note the collision */ hit_body = TRUE; /* Did we hit it (penalize range) */ if (test_hit(chance2, r_ptr->ac, m_ptr->ml)) { const char *hit_verb = "hits"; bool fear = FALSE; const slay_t *best_s_ptr = NULL; /* Assume a default death */ cptr note_dies = " dies."; /* Some monsters get "destroyed" */ if (monster_is_unusual(r_ptr)) { /* Special note at death */ note_dies = " is destroyed."; } /* Apply special damage - brought forward to fill in hit_verb XXX XXX XXX */ improve_attack_modifier(i_ptr, m_ptr, &best_s_ptr); if (best_s_ptr != NULL) { tdam *= best_s_ptr->mult; hit_verb = best_s_ptr->range_verb; } /* Apply special damage XXX XXX XXX */ tdam = critical_shot(i_ptr->weight, i_ptr->to_h, tdam, &msg_type); /* No negative damage; change verb if no damage done */ if (tdam <= 0) { tdam = 0; hit_verb = "fail to harm"; } /* Handle unseen monster */ if (!visible) { /* Invisible monster */ msg_format("The %s finds a mark.", o_name); } /* Handle visible monster */ else { char m_name[80]; /* Get "the monster" or "it" */ monster_desc(m_name, sizeof(m_name), m_ptr, 0); /* Tell the player what happened */ if (msg_type == MSG_SHOOT_HIT) message_format(MSG_SHOOT_HIT, 0, "The %s %s %s.", o_name, hit_verb, m_name); else { if (msg_type == MSG_HIT_GOOD) { message_format(MSG_HIT_GOOD, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a good hit!"); } else if (msg_type == MSG_HIT_GREAT) { message_format(MSG_HIT_GREAT, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a great hit!"); } else if (msg_type == MSG_HIT_SUPERB) { message_format(MSG_HIT_SUPERB, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a superb hit!"); } } /* Hack -- Track this monster race */ if (m_ptr->ml) monster_race_track(m_ptr->r_idx); /* Hack -- Track this monster */ if (m_ptr->ml) health_track(cave_m_idx[y][x]); } /* Learn the bonuses */ /* XXX Eddie This is messed up, better done for firing, */ /* should use that method [split last] instead */ /* check if inven_optimize removed what o_ptr referenced */ if (object_similar(i_ptr, o_ptr, OSTACK_PACK)) object_notice_attack_plusses(o_ptr); object_notice_attack_plusses(i_ptr); /* Complex message */ if (p_ptr->wizard) msg_format("You do %d (out of %d) damage.", tdam, m_ptr->hp); /* Hit the monster, check for death */ if (mon_take_hit(cave_m_idx[y][x], tdam, &fear, note_dies)) { /* Dead monster */ } /* No death */ else { /* Message */ message_pain(cave_m_idx[y][x], tdam); /* Take note */ if (fear && m_ptr->ml) { char m_name[80]; /* Get the monster name (or "it") */ monster_desc(m_name, sizeof(m_name), m_ptr, 0); /* Message */ message_format(MSG_FLEE, m_ptr->r_idx, "%^s flees in terror!", m_name); } } } /* Stop looking */ break; } } /* Chance of breakage (during attacks) */ j = (hit_body ? breakage_chance(i_ptr) : 0); /* Drop (or break) near that location */ drop_near(i_ptr, j, y, x, TRUE); }
/* * Use an object the right way. * * There may be a BIG problem with any "effect" that can cause "changes" * to the inventory. For example, a "scroll of recharging" can cause * a wand/staff to "disappear", moving the inventory up. Luckily, the * scrolls all appear BEFORE the staffs/wands, so this is not a problem. * But, for example, a "staff of recharging" could cause MAJOR problems. * In such a case, it will be best to either (1) "postpone" the effect * until the end of the function, or (2) "change" the effect, say, into * giving a staff "negative" charges, or "turning a staff into a stick". * It seems as though a "rod of recharging" might in fact cause problems. * The basic problem is that the act of recharging (and destroying) an * item causes the inducer of that action to "move", causing "o_ptr" to * no longer point at the correct item, with horrifying results. */ void do_cmd_use(cmd_code code, cmd_arg args[]) { int item = args[0].item; object_type *o_ptr = object_from_item_idx(item); int effect; bool ident = FALSE, used = FALSE; bool was_aware = object_flavor_is_aware(o_ptr); int dir = 5; int px = p_ptr->px, py = p_ptr->py; int snd, boost, level; use_type use; int items_allowed = 0; /* Determine how this item is used. */ if (obj_is_rod(o_ptr)) { if (!obj_can_zap(o_ptr)) { msg("That rod is still charging."); return; } use = USE_TIMEOUT; snd = MSG_ZAP_ROD; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_wand(o_ptr)) { if (!obj_has_charges(o_ptr)) { msg("That wand has no charges."); return; } use = USE_CHARGE; snd = MSG_ZAP_ROD; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_staff(o_ptr)) { if (!obj_has_charges(o_ptr)) { msg("That staff has no charges."); return; } use = USE_CHARGE; snd = MSG_USE_STAFF; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_food(o_ptr)) { use = USE_SINGLE; snd = MSG_EAT; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_potion(o_ptr)) { use = USE_SINGLE; snd = MSG_QUAFF; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_scroll(o_ptr)) { /* Check player can use scroll */ if (!player_can_read()) return; use = USE_SINGLE; snd = MSG_GENERIC; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_activatable(o_ptr)) { if (!obj_can_activate(o_ptr)) { msg("That item is still charging."); return; } use = USE_TIMEOUT; snd = MSG_ACT_ARTIFACT; items_allowed = USE_EQUIP; } else { msg("The item cannot be used at the moment"); } /* Check if item is within player's reach. */ if (items_allowed == 0 || !item_is_available(item, NULL, items_allowed)) { msg("You cannot use that item from its current location."); return; } /* track the object used */ track_object(item); /* Figure out effect to use */ effect = object_effect(o_ptr); /* If the item requires a direction, get one (allow cancelling) */ if (obj_needs_aim(o_ptr)) dir = args[1].direction; /* Check for use if necessary, and execute the effect */ if ((use != USE_CHARGE && use != USE_TIMEOUT) || check_devices(o_ptr)) { int beam = beam_chance(o_ptr->tval); /* Special message for artifacts */ if (o_ptr->artifact) { msgt(snd, "You activate it."); if (o_ptr->artifact->effect_msg) activation_message(o_ptr, o_ptr->artifact->effect_msg); level = o_ptr->artifact->level; } else { /* Make a noise! */ sound(snd); level = o_ptr->kind->level; } /* A bit of a hack to make ID work better. -- Check for "obvious" effects beforehand. */ if (effect_obvious(effect)) object_flavor_aware(o_ptr); /* Boost damage effects if skill > difficulty */ boost = MAX(p_ptr->state.skills[SKILL_DEVICE] - level, 0); /* Do effect */ used = effect_do(effect, &ident, was_aware, dir, beam, boost); /* Quit if the item wasn't used and no knowledge was gained */ if (!used && (was_aware || !ident)) return; } /* If the item is a null pointer or has been wiped, be done now */ if (!o_ptr || !o_ptr->kind) return; if (ident) object_notice_effect(o_ptr); /* Food feeds the player */ if (o_ptr->tval == TV_FOOD || o_ptr->tval == TV_POTION) (void)set_food(p_ptr->food + o_ptr->pval[DEFAULT_PVAL]); /* Use the turn */ p_ptr->energy_use = 100; /* Mark as tried and redisplay */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); p_ptr->redraw |= (PR_INVEN | PR_EQUIP | PR_OBJECT); /* * If the player becomes aware of the item's function, then mark it as * aware and reward the player with some experience. Otherwise, mark * it as "tried". */ if (ident && !was_aware) { /* Object level */ int lev = o_ptr->kind->level; object_flavor_aware(o_ptr); if (o_ptr->tval == TV_ROD) object_notice_everything(o_ptr); player_exp_gain(p_ptr, (lev + (p_ptr->lev / 2)) / p_ptr->lev); p_ptr->notice |= PN_SQUELCH; } else if (used) { object_flavor_tried(o_ptr); } /* If there are no more of the item left, then we're done. */ if (!o_ptr->number) return; /* Chargeables act differently to single-used items when not used up */ if (used && use == USE_CHARGE) { /* Use a single charge */ o_ptr->pval[DEFAULT_PVAL]--; /* Describe charges */ if (item >= 0) inven_item_charges(item); else floor_item_charges(0 - item); } else if (used && use == USE_TIMEOUT) { /* Artifacts use their own special field */ if (o_ptr->artifact) o_ptr->timeout = randcalc(o_ptr->artifact->time, 0, RANDOMISE); else o_ptr->timeout += randcalc(o_ptr->kind->time, 0, RANDOMISE); } else if (used && use == USE_SINGLE) { /* Destroy a potion in the pack */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Destroy a potion on the floor */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } } /* Hack to make Glyph of Warding work properly */ if (cave->feat[py][px] == FEAT_GLYPH) { /* Push objects off the grid */ if (cave->o_idx[py][px]) push_object(py, px); } }
/* * Refuel the players torch (from the pack or floor) */ static void do_cmd_refill_torch(void) { int item; object_type *o_ptr; object_type *j_ptr; cptr q, s; /* Restrict the choices */ item_tester_hook = item_tester_refill_torch; /* Get an item */ q = "Refuel with which torch? "; s = "You have no extra torches."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Take a partial turn */ p_ptr->energy_use = 50; /* Get the primary torch */ j_ptr = &inventory[INVEN_LIGHT]; /* Refuel */ j_ptr->pval += o_ptr->pval + 5; /* Message */ msg_print("You combine the torches."); /* Over-fuel message */ if (j_ptr->pval >= FUEL_TORCH) { j_ptr->pval = FUEL_TORCH; msg_print("Your torch is fully fueled."); } /* Refuel message */ else { msg_print("Your torch glows more brightly."); } /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } /* Recalculate torch */ p_ptr->update |= (PU_TORCH); /* Window stuff */ p_ptr->window |= (PW_EQUIP); }
/* * Refuel the player's torch (from the pack or floor) */ void do_cmd_refuel_torch(object_type *default_o_ptr, int default_item) { int item; object_type *o_ptr; object_type *j_ptr; cptr q, s; // use specified item if possible if (default_o_ptr != NULL) { o_ptr = default_o_ptr; item = default_item; } /* Get an item */ else { /* Restrict the choices */ item_tester_hook = item_tester_refuel_torch; /* Get an item */ q = "Refuel with which torch? "; s = "You have no extra torches."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } } /* Take a turn */ p_ptr->energy_use = 100; // store the action type p_ptr->previous_action[0] = ACTION_MISC; /* Get the primary torch */ j_ptr = &inventory[INVEN_LITE]; /* Refuel */ j_ptr->timeout += o_ptr->timeout + 5; /* Message */ msg_print("You combine the torches."); /* Over-fuel message */ if (j_ptr->timeout >= FUEL_TORCH) { j_ptr->timeout = FUEL_TORCH; msg_print("Your torch is fully fueled."); } /* Refuel message */ else { msg_print("Your torch glows more brightly."); } /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } /* Window stuff */ p_ptr->window |= (PW_EQUIP); // get another chance to identify the torch ident_on_wield(j_ptr); }
/* * Destroy an item */ void do_cmd_destroy(void) { int item, amt = 1; int old_number; bool force = FALSE; object_type *o_ptr; char o_name[MAX_NLEN]; char out_val[160]; cptr q, s; /* Hack -- force destruction */ if (command_arg > 0) force = TRUE; /* Get an item */ #ifdef JP q = "どのアイテムを壊しますか? "; s = "壊せるアイテムを持っていない。"; #else q = "Destroy which item? "; s = "You have nothing to destroy."; #endif if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Verify unless quantity given */ if (!force && (!(auto_destroy && (object_value(o_ptr) < 1)))) { object_desc(o_name, o_ptr, OD_OMIT_PREFIX); /* Make a verification */ sprintf(out_val, #ifdef JP "本当に%sを壊しますか? [y/n/Auto]", #else "Really destroy %s? [y/n/Auto]", #endif o_name); msg_print(NULL); /* HACK : Add the line to message buffer */ message_add(out_val); p_ptr->window |= (PW_MESSAGE); window_stuff(); /* Get an acceptable answer */ while (TRUE) { char i; /* Prompt */ prt(out_val, 0, 0); i = inkey(); /* Erase the prompt */ prt("", 0, 0); if (i == 'y' || i == 'Y') { break; } if (i == ESCAPE || i == 'n' || i == 'N') { /* Cancel */ return; } if (i == 'A') { /* Add an auto-destroy preference line */ if (autopick_autoregister(o_ptr)) { /* Auto-destroy it */ autopick_alter_item(item, TRUE); } /* The object is already destroyed. */ return; } } /* while (TRUE) */ } /* See how many items */ if (o_ptr->number > 1) { /* Get a quantity */ amt = get_quantity(NULL, o_ptr->number); /* Allow user abort */ if (amt <= 0) return; } /* Describe the object */ old_number = o_ptr->number; o_ptr->number = amt; object_desc(o_name, o_ptr, 0); o_ptr->number = old_number; /* Take a turn */ energy_use = 100; /* Can the player destroy the object? */ if (!can_player_destroy_object(o_ptr)) { /* Don't take a turn */ energy_use = 0; /* Message */ #ifdef JP msg_format("%sは破壊不可能だ。", o_name); #else msg_format("You cannot destroy %s.", o_name); #endif /* Done */ return; } /* Message */ #ifdef JP msg_format("%sを壊した。", o_name); #else msg_format("You destroy %s.", o_name); #endif sound(SOUND_DESTROY); if (high_level_book(o_ptr)) { bool gain_expr = FALSE; if (p_ptr->pclass == CLASS_WARRIOR) { gain_expr = TRUE; } else if (p_ptr->pclass == CLASS_PALADIN) { if (p_ptr->realm1 == REALM_LIFE) { if (o_ptr->tval != TV_LIFE_BOOK) gain_expr = TRUE; } else { if (o_ptr->tval == TV_LIFE_BOOK) gain_expr = TRUE; } } if (gain_expr && (p_ptr->exp < PY_MAX_EXP)) { s32b tester_exp = p_ptr->max_exp / 20; if (tester_exp > 10000) tester_exp = 10000; if (o_ptr->sval < 3) tester_exp /= 4; if (tester_exp < 1) tester_exp = 1; #ifdef JP msg_print("更に経験を積んだような気がする。"); #else msg_print("You feel more experienced."); #endif gain_exp(tester_exp * amt); } } /* Reduce the charges of rods/wands */ reduce_charges(o_ptr, amt); /* Eliminate the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -amt); inven_item_describe(item); inven_item_optimize(item); } /* Eliminate the item (from the floor) */ else { floor_item_increase(0 - item, -amt); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Jam a closed door with a spike * * This command may NOT be repeated */ void do_cmd_spike(cmd_code code, cmd_arg args[]) { int y, x, dir, item = 0; dir = args[0].direction; /* Get a spike */ if (!get_spike(&item)) { /* Message */ msg_print("You have no spikes!"); /* Done */ return; } /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Verify legality */ if (!do_cmd_spike_test(y, x)) return; /* Take a turn */ p_ptr->energy_use = 100; /* Confuse direction */ if (confuse_dir(&dir)) { /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; } /* Monster */ if (cave_m_idx[y][x] > 0) { if (mon_list[cave_m_idx[y][x]].align & (AL_PET_MASK)) { msg_print("There is a friendly monster in the way!"); } else { /* Message */ msg_print("There is a monster in the way!"); /* Attack */ py_attack(y, x); } } /* Go for it */ else { /* Verify legality */ if (!do_cmd_spike_test(y, x)) return; /* Successful jamming */ msg_print("You jam the door with a spike."); /* Convert "locked" to "stuck" XXX XXX XXX */ if (cave_feat[y][x] < FEAT_DOOR_HEAD + 0x08) { cave_feat[y][x] += 0x08; } /* Add one spike to the door */ if (cave_feat[y][x] < FEAT_DOOR_TAIL) { cave_feat[y][x] += 0x01; } /* Use up, and describe, a single spike, from the bottom */ inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } }
/* * Eat some food (from the pack or floor) */ void do_cmd_eat_food(void) { int item, lev; bool ident; object_type *o_ptr; cptr q, s; /* Restrict choices to food */ item_tester_tval = TV_FOOD; /* Get an item */ q = "Eat which item? "; s = "You have nothing to eat."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Sound */ sound(MSG_EAT); /* Take a turn */ p_ptr->energy_use = 100; /* Identity not known yet */ ident = FALSE; /* Object level */ lev = k_info[o_ptr->k_idx].level; /* Eat the food */ use_object(o_ptr, &ident); /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* We have tried it */ object_tried(o_ptr); /* The player is now aware of the object */ if (ident && !object_aware_p(o_ptr)) { object_aware(o_ptr); gain_exp((lev + (p_ptr->lev / 2)) / p_ptr->lev); } /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); /* Destroy a food in the pack */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Destroy a food on the floor */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Destroy an item */ void do_cmd_destroy(void) { int item, amt; int old_number; int old_charges = 0; object_type *o_ptr; char o_name[80]; char out_val[160]; cptr q, s; item_tester_hook = item_tester_hook_destroy; // Special case for prising Silmarils from the Iron Crown of Morgoth o_ptr = &o_list[cave_o_idx[p_ptr->py][p_ptr->px]]; if ((o_ptr->name1 >= ART_MORGOTH_1) && (o_ptr->name1 <= ART_MORGOTH_3)) { // Select the melee weapon o_ptr = &inventory[INVEN_WIELD]; // No weapon if (!o_ptr->k_idx) { msg_print("To prise a Silmaril from the crown, you would need to wield a weapon."); } // Wielding a weapon else { if (get_check("Will you try to prise a Silmaril from the Iron Crown? ")) { prise_silmaril(); /* Take a turn */ p_ptr->energy_use = 100; // store the action type p_ptr->previous_action[0] = ACTION_MISC; return; } } } /* Get an item */ q = "Destroy which item? "; s = "You have nothing to destroy."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } // Special case for Iron Crown of Morgoth, if it has Silmarils left if ((o_ptr->name1 >= ART_MORGOTH_1) && (o_ptr->name1 <= ART_MORGOTH_3)) { if (item >= 0) { msg_print("You would have to put it down first."); } else { /* No weapon */ if (!o_ptr->k_idx) { msg_print("To prise a Silmaril from the crown, you would need to wield a weapon."); } else { msg_print("You decide to try to prise out a Silmaril after all."); prise_silmaril(); /* Take a turn */ p_ptr->energy_use = 100; // store the action type p_ptr->previous_action[0] = ACTION_MISC; return; } } } /* Get a quantity */ amt = get_quantity(NULL, o_ptr->number); /* Allow user abort */ if (amt <= 0) return; /* Describe the object */ old_number = o_ptr->number; /* Hack, state the correct number of charges to be destroyed if staff*/ if ((o_ptr->tval == TV_STAFF) && (amt < o_ptr->number)) { /*save the number of charges*/ old_charges = o_ptr->pval; /*distribute the charges*/ o_ptr->pval -= o_ptr->pval * amt / o_ptr->number; o_ptr->pval = old_charges - o_ptr->pval; } /*hack - make sure we get the right amount displayed*/ o_ptr->number = amt; /*now describe with correct amount*/ object_desc(o_name, sizeof(o_name), o_ptr, TRUE, 3); /*reverse the hack*/ o_ptr->number = old_number; /* Check for known special items */ strnfmt(out_val, sizeof(out_val), "Really destroy %s? ", o_name); if (!get_check(out_val)) return; /* Take a turn */ p_ptr->energy_use = 100; // store the action type p_ptr->previous_action[0] = ACTION_MISC; /* Message */ msg_format("You destroy %s.", o_name); /*hack, restore the proper number of charges after the messages have printed * so the proper number of charges are destroyed*/ if (old_charges) o_ptr->pval = old_charges; /* Eliminate the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -amt); inven_item_describe(item); inven_item_optimize(item); } /* Eliminate the item (from the floor) */ else { floor_item_increase(0 - item, -amt); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Read a scroll (from the pack or floor). * * Certain scrolls can be "aborted" without losing the scroll. These * include scrolls with no effects but recharge or identify, which are * cancelled before use. XXX Reading them still takes a turn, though. */ void do_cmd_read_scroll(void) { int item, used_up, lev; bool ident; object_type *o_ptr; cptr q, s; /* Check some conditions */ if (p_ptr->blind) { msg_print("You can't see anything."); return; } if (no_lite()) { msg_print("You have no light to read by."); return; } if (p_ptr->confused) { msg_print("You are too confused!"); return; } /* Restrict choices to scrolls */ item_tester_tval = TV_SCROLL; /* Get an item */ q = "Read which scroll? "; s = "You have no scrolls to read."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Take a turn */ p_ptr->energy_use = 100; /* Not identified yet */ ident = FALSE; /* Object level */ lev = k_info[o_ptr->k_idx].level; /* Read the scroll */ used_up = use_object(o_ptr, &ident); /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* The item was tried */ object_tried(o_ptr); /* An identification was made */ if (ident && !object_aware_p(o_ptr)) { object_aware(o_ptr); gain_exp((lev + (p_ptr->lev / 2)) / p_ptr->lev); } /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); /* Hack -- allow certain scrolls to be "preserved" */ if (!used_up) return; /* Destroy a scroll in the pack */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Destroy a scroll on the floor */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Quaff a potion (from the pack or the floor) */ void do_cmd_quaff_potion(void) { int item, lev; bool ident; object_type *o_ptr; cptr q, s; /* Restrict choices to potions */ item_tester_tval = TV_POTION; /* Get an item */ q = "Quaff which potion? "; s = "You have no potions to quaff."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Sound */ sound(MSG_QUAFF); /* Take a turn */ p_ptr->energy_use = 100; /* Not identified yet */ ident = FALSE; /* Object level */ lev = k_info[o_ptr->k_idx].level; /* Quaff the potion */ use_object(o_ptr, &ident); /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* The item has been tried */ object_tried(o_ptr); /* An identification was made */ if (ident && !object_aware_p(o_ptr)) { object_aware(o_ptr); gain_exp((lev + (p_ptr->lev / 2)) / p_ptr->lev); } /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); /* Destroy a potion in the pack */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Destroy a potion on the floor */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Jam a closed door with a spike. Now takes only 4/10ths normal energy * if no monster is in the way. -LM- * * This command may NOT be repeated */ void do_cmd_spike(void) { int py = p_ptr->py; int px = p_ptr->px; int y, x, dir, item; /* Get a spike */ if (!get_spike(&item)) { /* Message */ msg_print("You have no spikes!"); /* Done */ return; } /* Get a direction (or abort) */ if (!get_rep_dir(&dir)) return; /* Get location */ y = py + ddy[dir]; x = px + ddx[dir]; /* Verify legality */ if (!do_cmd_spike_test(y, x)) return; /* Take a partial turn. Now jamming is more useful. */ p_ptr->energy_use = 40; /* Confuse direction */ if (confuse_dir(&dir)) { /* Get location */ y = py + ddy[dir]; x = px + ddx[dir]; } /* Monster. Make the action now take a full turn */ if (cave_m_idx[y][x] > 0) { /* Message */ msg_print("There is a monster in the way!"); p_ptr->energy_use += 60; /* Attack */ py_attack(y, x); } /* Go for it */ else { /* Verify legality */ if (!do_cmd_spike_test(y, x)) return; /* Successful jamming */ msg_print("You jam the door with a spike."); /* Convert "locked" to "stuck" XXX XXX XXX */ if (cave_feat[y][x] < FEAT_DOOR_HEAD + 0x08) { cave_feat[y][x] += 0x08; } /* Add one spike to the door */ if (cave_feat[y][x] < FEAT_DOOR_TAIL) { cave_feat[y][x] += 0x01; } /* Use up, and describe, a single spike, from the bottom */ inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } }
/* * Destroy an item */ void do_cmd_destroy(void) { int item, amt; int old_number; object_type *o_ptr; char o_name[80]; char out_val[160]; cptr q, s; /* Get an item */ q = "Destroy which item? "; s = "You have nothing to destroy."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Get a quantity */ amt = get_quantity(NULL, o_ptr->number); /* Allow user abort */ if (amt <= 0) return; /* Describe the object */ old_number = o_ptr->number; o_ptr->number = amt; object_desc(o_name, o_ptr, TRUE, 3); o_ptr->number = old_number; /* Verify destruction */ if (verify_destroy) { sprintf(out_val, "Really destroy %s? ", o_name); if (!get_check(out_val)) return; } /* Take a turn */ p_ptr->energy_use = 100; /* Artifacts cannot be destroyed */ if (artifact_p(o_ptr)) { /* Message */ msg_format("You cannot destroy %s.", o_name); /* Don't mark id'ed objects */ if (object_known_p(o_ptr)) return; /* It has already been sensed */ if (o_ptr->ident & (IDENT_SENSE)) { /* Already sensed objects always get improved feelings */ if (cursed_p(o_ptr) || broken_p(o_ptr)) o_ptr->discount = INSCRIP_TERRIBLE; else o_ptr->discount = INSCRIP_SPECIAL; } else { /* Mark the object as indestructible */ o_ptr->discount = INSCRIP_INDESTRUCTIBLE; } /* Combine the pack */ p_ptr->notice |= (PN_COMBINE); /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); p_ptr->redraw |= (PR_EQUIPPY); /* Done */ return; } /* Message */ msg_format("You destroy %s.", o_name); /* Eliminate the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -amt); inven_item_describe(item); inven_item_optimize(item); } /* Eliminate the item (from the floor) */ else { floor_item_increase(0 - item, -amt); floor_item_describe(0 - item); floor_item_optimize(0 - item); } }
/* * Destroy an item */ void do_cmd_destroy(void) { int item, amt = 1; int old_number; bool force = FALSE; object_type *o_ptr; object_type forge; object_type *q_ptr = &forge; bool is_equipped = FALSE; char o_name[MAX_NLEN]; char out_val[MAX_NLEN+40]; cptr q, s; int mode = USE_INVEN | USE_FLOOR; if (p_ptr->pclass == CLASS_RUNE_KNIGHT) mode |= USE_EQUIP; if (p_ptr->special_defense & KATA_MUSOU) { set_action(ACTION_NONE); } /* Hack -- force destruction */ if (command_arg > 0) force = TRUE; /* Get an item */ q = "Destroy which item? "; s = "You have nothing to destroy."; if (!get_item(&item, q, s, mode)) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; is_equipped = equip_is_valid_slot(item); } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Hack for Rune Knight: They can destroy worn equipment, but only if it has the Sacrifice rune. get_item() is not smart enough to handle this restriction ... */ if (is_equipped && o_ptr->rune != RUNE_SACRIFICE) { msg_print("You must first remove that item before destroying it."); return; } /* Verify unless quantity given beforehand */ if (!force && (confirm_destroy || (object_value(o_ptr) > 0))) { object_desc(o_name, o_ptr, OD_OMIT_PREFIX); /* Make a verification */ sprintf(out_val, "Really destroy %s? [y/n/Auto]", o_name); msg_print(NULL); /* HACK : Add the line to message buffer */ message_add(out_val); p_ptr->window |= (PW_MESSAGE); window_stuff(); /* Get an acceptable answer */ while (TRUE) { char i; /* Prompt */ prt(out_val, 0, 0); i = inkey(); /* Erase the prompt */ prt("", 0, 0); if (i == 'y' || i == 'Y') { break; } if (i == ESCAPE || i == 'n' || i == 'N') { /* Cancel */ return; } if (i == 'A') { /* Add an auto-destroy preference line */ if (autopick_autoregister(o_ptr)) { /* Auto-destroy it */ autopick_alter_item(item, TRUE); } /* The object is already destroyed. */ return; } } /* while (TRUE) */ } /* See how many items */ if (o_ptr->number > 1) { /* Get a quantity */ amt = get_quantity(NULL, o_ptr->number); /* Allow user abort */ if (amt <= 0) return; } /* Describe the object */ old_number = o_ptr->number; o_ptr->number = amt; object_desc(o_name, o_ptr, 0); o_ptr->number = old_number; /* Take a turn */ energy_use = 100; /* Artifacts cannot be destroyed */ if (!can_player_destroy_object(o_ptr)) { energy_use = 0; /* Message */ msg_format("You cannot destroy %s.", o_name); /* Done */ return; } object_copy(q_ptr, o_ptr); stats_on_p_destroy(o_ptr, amt); if (prace_is_(RACE_MON_JELLY)) jelly_eat_object(o_ptr); else if (prace_is_(RACE_MON_SWORD) && object_is_melee_weapon(o_ptr)) sword_absorb_object(o_ptr); else if (prace_is_(RACE_MON_RING) && object_is_jewelry(o_ptr)) ring_absorb_object(o_ptr); else msg_format("You destroy %s.", o_name); if (o_ptr->rune == RUNE_SACRIFICE) { int add_hp = is_equipped ? p_ptr->mhp : p_ptr->mhp/3; int add_sp = is_equipped ? p_ptr->msp : p_ptr->msp/3; msg_print("You feel a surge of wondrous power enter your body."); p_ptr->chp = MIN(p_ptr->mhp, p_ptr->chp + add_hp); p_ptr->chp_frac = 0; p_ptr->csp = MIN(p_ptr->msp, p_ptr->csp + add_sp); p_ptr->csp_frac = 0; p_ptr->redraw |= (PR_MANA); p_ptr->window |= (PW_PLAYER); p_ptr->window |= (PW_SPELL); p_ptr->redraw |= (PR_HP); if (is_equipped) { blast_object(o_ptr); o_ptr->curse_flags = TRC_HEAVY_CURSE; } } else if (is_equipped) blast_object(o_ptr); sound(SOUND_DESTITEM); /* Reduce the charges of rods/wands */ reduce_charges(o_ptr, amt); /* Eliminate the item (from the pack) */ if (item >= 0) { if (!is_equipped) { inven_item_increase(item, -amt); inven_item_describe(item); inven_item_optimize(item); } } /* Eliminate the item (from the floor) */ else { floor_item_increase(0 - item, -amt); floor_item_describe(0 - item); floor_item_optimize(0 - item); } if ( p_ptr->pclass == CLASS_NECROMANCER && (q_ptr->tval == TV_LIFE_BOOK || q_ptr->tval == TV_CRUSADE_BOOK) ) { int sp = 0; int osp = p_ptr->csp; switch (q_ptr->sval) { case 0: sp = 10; break; case 1: sp = 25; break; case 2: sp = 100; break; case 3: sp = 666; break; } p_ptr->csp += sp; if (p_ptr->csp >= p_ptr->msp) { p_ptr->csp = p_ptr->msp; p_ptr->csp_frac = 0; } if (p_ptr->csp > osp) msg_print("You feel your head clear."); p_ptr->redraw |= (PR_MANA); } if (high_level_book(q_ptr)) { bool gain_expr = FALSE; if (p_ptr->prace == RACE_ANDROID) { } else if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER)) { gain_expr = TRUE; } else if (p_ptr->pclass == CLASS_PALADIN) { if (is_good_realm(p_ptr->realm1)) { if (!is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE; } else { if (is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE; } } if (gain_expr && (p_ptr->exp < PY_MAX_EXP)) { s32b tester_exp = p_ptr->max_exp / 20; if (tester_exp > 10000) tester_exp = 10000; if (q_ptr->sval < 3) tester_exp /= 4; if (tester_exp<1) tester_exp = 1; msg_print("You feel more experienced."); gain_exp(tester_exp * amt); } } if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK) { virtue_add(VIRTUE_UNLIFE, 1); virtue_add(VIRTUE_VITALITY, -1); } else if ( high_level_book(q_ptr) && (q_ptr->tval == TV_DEATH_BOOK || q_ptr->tval == TV_NECROMANCY_BOOK) ) { virtue_add(VIRTUE_UNLIFE, -1); virtue_add(VIRTUE_VITALITY, 1); } if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d) virtue_add(VIRTUE_ENCHANTMENT, -1); if (object_value_real(q_ptr) > 30000) virtue_add(VIRTUE_SACRIFICE, 2); else if (object_value_real(q_ptr) > 10000) virtue_add(VIRTUE_SACRIFICE, 1); if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0) virtue_add(VIRTUE_HARMONY, 1); if (equip_is_valid_slot(item)) calc_android_exp(); }
/* * Refill the players lamp (from the pack or floor) */ static void do_cmd_refill_lamp(void) { int item; object_type *o_ptr; object_type *j_ptr; cptr q, s; /* Restrict the choices */ item_tester_hook = item_tester_refill_lantern; /* Get an item */ q = "Refill with which source of oil? "; s = "You have no sources of oil."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Take a partial turn */ p_ptr->energy_use = 50; /* Get the lantern */ j_ptr = &inventory[INVEN_LIGHT]; /* Refuel */ j_ptr->pval += o_ptr->pval; /* Message */ msg_print("You fuel your lamp."); /* Comment */ if (j_ptr->pval >= FUEL_LAMP) { j_ptr->pval = FUEL_LAMP; msg_print("Your lamp is full."); } /* Use fuel from a lantern */ if (o_ptr->sval == SV_LIGHT_LANTERN) { /* No more fuel */ o_ptr->pval = 0; /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* Window stuff */ p_ptr->window |= (PW_INVEN); } /* Decrease the item (from the pack) */ else if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } /* Recalculate torch */ p_ptr->update |= (PU_TORCH); /* Window stuff */ p_ptr->window |= (PW_EQUIP); }
/* * Fire an object from the pack or floor. * * You may only fire items that "match" your missile launcher. * * See "calc_bonuses()" for more calculations and such. * * Note that "firing" a missile is MUCH better than "throwing" it. * * Note: "unseen" monsters are very hard to hit. * * Objects are more likely to break if they "attempt" to hit a monster. * * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots. * The "extra shot" code works by decreasing the amount of energy * required to make each shot, spreading the shots out over time. * * Note that when firing missiles, the launcher multiplier is applied * after all the bonuses are added in, making multipliers very useful. * * Note that Bows of "Extra Might" get extra range and an extra bonus * for the damage multiplier. */ void do_cmd_fire(cmd_code code, cmd_arg args[]) { int dir, item; int i, j, y, x; s16b ty, tx; int tdam, tdis, thits; int bonus, chance; object_type *o_ptr; object_type *j_ptr; object_type *i_ptr; object_type object_type_body; bool hit_body = FALSE; byte missile_attr; char missile_char; char o_name[80]; u32b msg_type = 0; int path_n; u16b path_g[256]; int msec = op_ptr->delay_factor * op_ptr->delay_factor; /* Get the "bow" */ j_ptr = &p_ptr->inventory[INVEN_BOW]; /* Require a usable launcher */ if (!j_ptr->tval || !p_ptr->state.ammo_tval) { msg_print("You have nothing to fire with."); return; } /* Get item to fire and direction to fire in. */ item = args[0].item; dir = args[1].direction; /* Check the item being fired is usable by the player. */ if (!item_is_available(item, NULL, (USE_EQUIP | USE_INVEN | USE_FLOOR))) { msg_format("That item is not within your reach."); return; } /* Get the object for the ammo */ o_ptr = object_from_item_idx(item); /* Check the ammo can be used with the launcher */ if (o_ptr->tval != p_ptr->state.ammo_tval) { msg_format("That ammo cannot be fired by your current weapon."); return; } /* Base range XXX XXX */ tdis = 6 + 2 * p_ptr->state.ammo_mult; /* Start at the player */ x = p_ptr->px; y = p_ptr->py; /* Predict the "target" location */ ty = y + 99 * ddy[dir]; tx = x + 99 * ddx[dir]; /* Check for target validity */ if ((dir == 5) && target_okay()) { target_get(&tx, &ty); if (distance(y, x, ty, tx) > tdis) { if (!get_check("Target out of range. Fire anyway? ")) return; } } /* Sound */ sound(MSG_SHOOT); object_notice_on_firing(o_ptr); /* Describe the object */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_FULL | ODESC_SINGULAR); /* Find the color and symbol for the object for throwing */ missile_attr = object_attr(o_ptr); missile_char = object_char(o_ptr); /* Use the proper number of shots */ thits = p_ptr->state.num_fire; /* Actually "fire" the object */ bonus = (p_ptr->state.to_h + o_ptr->to_h + j_ptr->to_h); chance = p_ptr->state.skills[SKILL_TO_HIT_BOW] + (bonus * BTH_PLUS_ADJ); /* Take a (partial) turn */ p_ptr->energy_use = (100 / thits); /* Calculate the path */ path_n = project_path(path_g, tdis, y, x, ty, tx, 0); /* Hack -- Handle stuff */ handle_stuff(); /* Project along the path */ for (i = 0; i < path_n; ++i) { int ny = GRID_Y(path_g[i]); int nx = GRID_X(path_g[i]); /* Hack -- Stop before hitting walls */ if (!cave_floor_bold(ny, nx)) break; /* Advance */ x = nx; y = ny; /* Only do visuals if the player can "see" the missile */ if (player_can_see_bold(y, x)) { /* Visual effects */ print_rel(missile_char, missile_attr, y, x); move_cursor_relative(y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(); Term_xtra(TERM_XTRA_DELAY, msec); light_spot(y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(); } /* Delay anyway for consistency */ else { /* Pause anyway, for consistancy */ Term_xtra(TERM_XTRA_DELAY, msec); } /* Handle monster */ 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]; int chance2 = chance - distance(p_ptr->py, p_ptr->px, y, x); int visible = m_ptr->ml; int multiplier = 1; const char *hit_verb = "hits"; const slay_t *best_s_ptr = NULL; /* Note the collision */ hit_body = TRUE; /* Did we hit it (penalize distance travelled) */ if (test_hit(chance2, r_ptr->ac, m_ptr->ml)) { bool fear = FALSE; /* Assume a default death */ cptr note_dies = " dies."; improve_attack_modifier(o_ptr, m_ptr, &best_s_ptr); improve_attack_modifier(j_ptr, m_ptr, &best_s_ptr); if (best_s_ptr != NULL) hit_verb = best_s_ptr->range_verb; /* Some monsters get "destroyed" */ if (monster_is_unusual(r_ptr)) { /* Special note at death */ note_dies = " is destroyed."; } /* Calculate multiplier */ multiplier = p_ptr->state.ammo_mult; if (best_s_ptr != NULL) multiplier += best_s_ptr->mult; /* Apply damage: multiplier, slays, criticals, bonuses */ tdam = damroll(o_ptr->dd, o_ptr->ds); tdam += o_ptr->to_d + j_ptr->to_d; tdam *= multiplier; tdam = critical_shot(o_ptr->weight, o_ptr->to_h, tdam, &msg_type); object_notice_attack_plusses(o_ptr); object_notice_attack_plusses(&p_ptr->inventory[INVEN_BOW]); /* No negative damage; change verb if no damage done */ if (tdam <= 0) { tdam = 0; hit_verb = "fail to harm"; } /* Handle unseen monster */ if (!visible) { /* Invisible monster */ message_format(MSG_SHOOT_HIT, 0, "The %s finds a mark.", o_name); } /* Handle visible monster */ else { char m_name[80]; /* Get "the monster" or "it" */ monster_desc(m_name, sizeof(m_name), m_ptr, 0); /* Tell the player what happened */ if (msg_type == MSG_SHOOT_HIT) message_format(MSG_SHOOT_HIT, 0, "The %s %s %s.", o_name, hit_verb, m_name); else { if (msg_type == MSG_HIT_GOOD) { message_format(MSG_HIT_GOOD, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a good hit!"); } else if (msg_type == MSG_HIT_GREAT) { message_format(MSG_HIT_GREAT, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a great hit!"); } else if (msg_type == MSG_HIT_SUPERB) { message_format(MSG_HIT_SUPERB, 0, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a superb hit!"); } } /* Hack -- Track this monster race */ if (m_ptr->ml) monster_race_track(m_ptr->r_idx); /* Hack -- Track this monster */ if (m_ptr->ml) health_track(cave_m_idx[y][x]); } /* Complex message */ if (p_ptr->wizard) { msg_format("You do %d (out of %d) damage.", tdam, m_ptr->hp); } /* Hit the monster, check for death */ if (mon_take_hit(cave_m_idx[y][x], tdam, &fear, note_dies)) { /* Dead monster */ } /* No death */ else { /* Message */ message_pain(cave_m_idx[y][x], tdam); /* Take note */ if (fear && m_ptr->ml) { char m_name[80]; /* Get the monster name (or "it") */ monster_desc(m_name, sizeof(m_name), m_ptr, 0); /* Message */ message_format(MSG_FLEE, m_ptr->r_idx, "%^s flees in terror!", m_name); } } } /* Stop looking */ break; } } /* Get local object */ i_ptr = &object_type_body; /* Obtain a local object */ object_copy(i_ptr, o_ptr); /* Single object */ i_ptr->number = 1; if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Reduce and describe floor item */ else { floor_item_increase(0 - item, -1); floor_item_optimize(0 - item); } /* Chance of breakage (during attacks) */ j = (hit_body ? breakage_chance(i_ptr) : 0); /* Drop (or break) near that location */ drop_near(i_ptr, j, y, x, TRUE); }
/** * This is a helper function used by do_cmd_throw and do_cmd_fire. * * It abstracts out the projectile path, display code, identify and clean up * logic, while using the 'attack' parameter to do work particular to each * kind of attack. */ static void ranged_helper(int item, int dir, int range, int shots, ranged_attack attack) { /* Get the ammo */ object_type *o_ptr = object_from_item_idx(item); int i, j; byte missile_attr = object_attr(o_ptr); char missile_char = object_char(o_ptr); object_type object_type_body; object_type *i_ptr = &object_type_body; char o_name[80]; int path_n; u16b path_g[256]; int msec = op_ptr->delay_factor; /* Start at the player */ int x = p_ptr->px; int y = p_ptr->py; /* Predict the "target" location */ s16b ty = y + 99 * ddy[dir]; s16b tx = x + 99 * ddx[dir]; bool hit_target = FALSE; /* Check for target validity */ if ((dir == 5) && target_okay()) { int taim; char msg[80]; target_get(&tx, &ty); taim = distance(y, x, ty, tx); if (taim > range) { sprintf (msg, "Target out of range by %d squares. Fire anyway? ", taim - range); if (!get_check(msg)) return; } } /* Sound */ sound(MSG_SHOOT); object_notice_on_firing(o_ptr); /* Describe the object */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_FULL | ODESC_SINGULAR); /* Actually "fire" the object -- Take a partial turn */ p_ptr->energy_use = (100 / shots); /* Calculate the path */ path_n = project_path(path_g, range, y, x, ty, tx, 0); /* Hack -- Handle stuff */ handle_stuff(p_ptr); /* Start at the player */ x = p_ptr->px; y = p_ptr->py; /* Project along the path */ for (i = 0; i < path_n; ++i) { int ny = GRID_Y(path_g[i]); int nx = GRID_X(path_g[i]); /* Hack -- Stop before hitting walls */ if (!cave_floor_bold(ny, nx)) break; /* Advance */ x = nx; y = ny; /* Only do visuals if the player can "see" the missile */ if (player_can_see_bold(y, x)) { print_rel(missile_char, missile_attr, y, x); move_cursor_relative(y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(p_ptr); Term_xtra(TERM_XTRA_DELAY, msec); cave_light_spot(cave, y, x); Term_fresh(); if (p_ptr->redraw) redraw_stuff(p_ptr); } else { /* Delay anyway for consistency */ Term_xtra(TERM_XTRA_DELAY, msec); } /* Handle monster */ if (cave->m_idx[y][x] > 0) break; } /* Try the attack on the monster at (x, y) if any */ if (cave->m_idx[y][x] > 0) { monster_type *m_ptr = cave_monster(cave, cave->m_idx[y][x]); monster_race *r_ptr = &r_info[m_ptr->r_idx]; int visible = m_ptr->ml; bool fear = FALSE; char m_name[80]; const char *note_dies = monster_is_unusual(r_ptr) ? " is destroyed." : " dies."; struct attack_result result = attack(o_ptr, y, x); int dmg = result.dmg; u32b msg_type = result.msg_type; const char *hit_verb = result.hit_verb; if (result.success) { hit_target = TRUE; /* Get "the monster" or "it" */ monster_desc(m_name, sizeof(m_name), m_ptr, 0); object_notice_attack_plusses(o_ptr); /* No negative damage; change verb if no damage done */ if (dmg <= 0) { dmg = 0; hit_verb = "fail to harm"; } if (!visible) { /* Invisible monster */ msgt(MSG_SHOOT_HIT, "The %s finds a mark.", o_name); } else { /* Visible monster */ if (msg_type == MSG_SHOOT_HIT) msgt(MSG_SHOOT_HIT, "The %s %s %s.", o_name, hit_verb, m_name); else if (msg_type == MSG_HIT_GOOD) { msgt(MSG_HIT_GOOD, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a good hit!"); } else if (msg_type == MSG_HIT_GREAT) { msgt(MSG_HIT_GREAT, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a great hit!"); } else if (msg_type == MSG_HIT_SUPERB) { msgt(MSG_HIT_SUPERB, "The %s %s %s. %s", o_name, hit_verb, m_name, "It was a superb hit!"); } /* Track this monster */ if (m_ptr->ml) monster_race_track(m_ptr->r_idx); if (m_ptr->ml) health_track(p_ptr, cave->m_idx[y][x]); } /* Complex message */ if (p_ptr->wizard) msg("You do %d (out of %d) damage.", dmg, m_ptr->hp); /* Hit the monster, check for death */ if (!mon_take_hit(cave->m_idx[y][x], dmg, &fear, note_dies)) { message_pain(cave->m_idx[y][x], dmg); if (fear && m_ptr->ml) add_monster_message(m_name, cave->m_idx[y][x], MON_MSG_FLEE_IN_TERROR, TRUE); } } } /* Obtain a local object */ object_copy(i_ptr, o_ptr); object_split(i_ptr, o_ptr, 1); /* See if the ammunition broke or not */ j = breakage_chance(i_ptr, hit_target); /* Drop (or break) near that location */ drop_near(cave, i_ptr, j, y, x, TRUE); if (item >= 0) { /* The ammo is from the inventory */ inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } else { /* The ammo is from the floor */ floor_item_increase(0 - item, -1); floor_item_optimize(0 - item); } }
/* * Refill the player's lamp (from the pack or floor) */ void do_cmd_refuel_lamp(object_type *default_o_ptr, int default_item) { int item; object_type *o_ptr; object_type *j_ptr; cptr q, s; // use specified item if possible if (default_o_ptr != NULL) { o_ptr = default_o_ptr; item = default_item; } /* Get an item */ else { /* Restrict the choices */ item_tester_hook = item_tester_refuel_lantern; /* Get an item */ q = "Refill with which source of oil? "; s = "You have no sources of oil."; if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } } /* Take a turn */ p_ptr->energy_use = 100; // store the action type p_ptr->previous_action[0] = ACTION_MISC; /* Get the lantern */ j_ptr = &inventory[INVEN_LITE]; /* Refuel from a latern */ if (o_ptr->sval == SV_LIGHT_LANTERN) { j_ptr->timeout += o_ptr->timeout; } /* Refuel from a flask */ else { j_ptr->timeout += o_ptr->pval; } /* Message */ msg_print("You fuel your lamp."); /* Comment */ if (j_ptr->timeout >= FUEL_LAMP) { j_ptr->timeout = FUEL_LAMP; msg_print("Your lamp is full."); } /* Refilled from a latern */ if (o_ptr->sval == SV_LIGHT_LANTERN) { /* Unstack if necessary */ if (o_ptr->number > 1) { object_type *i_ptr; object_type object_type_body; /* Get local object */ i_ptr = &object_type_body; /* Obtain a local object */ object_copy(i_ptr, o_ptr); /* Modify quantity */ i_ptr->number = 1; /* Remove fuel */ i_ptr->timeout = 0; /* Unstack the used item */ o_ptr->number--; /* Carry or drop */ if (item >= 0) item = inven_carry(i_ptr); else drop_near(i_ptr, 0, p_ptr->py, p_ptr->px); } /* Empty a single latern */ else { /* No more fuel */ o_ptr->timeout = 0; } /* Combine / Reorder the pack (later) */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); /* Window stuff */ p_ptr->window |= (PW_INVEN); } /* Refilled from a flask */ else { /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } } /* Window stuff */ p_ptr->window |= (PW_EQUIP); // get another chance to identify the lamp ident_on_wield(j_ptr); }
static void _shatter_device_spell(int cmd, variant *res) { switch (cmd) { case SPELL_NAME: var_set_string(res, "Shatter Device"); break; case SPELL_DESC: var_set_string(res, "Destroy a magical device in your inventory for various effects."); break; case SPELL_CAST: { int item; object_type *o_ptr; var_set_bool(res, FALSE); item_tester_hook = object_is_device; if (!get_item(&item, "Shatter which device?", "You have nothing to shatter.", USE_INVEN)) return; o_ptr = &inventory[item]; var_set_bool(res, TRUE); if (o_ptr->activation.type == EFFECT_NONE) { msg_print("Nothing happens."); } else if (o_ptr->activation.type == EFFECT_DESTRUCTION) { if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), 4 * p_ptr->lev)) msg_print("The dungeon collapses..."); else msg_print("The dungeon trembles."); } else if ( o_ptr->activation.type == EFFECT_HEAL_CURING || o_ptr->activation.type == EFFECT_HEAL_CURING_HERO || o_ptr->activation.type == EFFECT_RESTORING ) { msg_print("You feel life flow through your body!"); restore_level(); (void)set_poisoned(0, TRUE); (void)set_blind(0, TRUE); (void)set_confused(0, TRUE); (void)set_image(0, TRUE); (void)set_stun(0, TRUE); (void)set_cut(0, TRUE); (void)do_res_stat(A_STR); (void)do_res_stat(A_CON); (void)do_res_stat(A_DEX); (void)do_res_stat(A_WIS); (void)do_res_stat(A_INT); (void)do_res_stat(A_CHR); update_stuff(); /* hp may change if Con was drained ... */ hp_player(5000); } else if ( o_ptr->activation.type == EFFECT_TELEPORT_AWAY || o_ptr->activation.type == EFFECT_BANISH_EVIL || o_ptr->activation.type == EFFECT_BANISH_ALL ) { banish_monsters(p_ptr->lev * 4); } else { project(0, 5, py, px, o_ptr->activation.difficulty * 16, _object_dam_type(o_ptr), PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL, -1); } inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); break; } default: default_spell(cmd, res); break; } }
/* * Refuel the players torch (from the pack or floor) */ static void do_cmd_refill_torch(void) { int item; object_type *o_ptr; object_type *j_ptr; cptr q, s; /* Restrict the choices */ item_tester_hook = item_tester_refill_torch; /* Get an item */ #ifdef JP q = "どの松明で明かりを強めますか? "; s = "他に松明がない。"; #else q = "Refuel with which torch? "; s = "You have no extra torches."; #endif if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Take a partial turn */ energy_use = 50; /* Access the primary torch */ j_ptr = &inventory[INVEN_LITE]; /* Refuel */ j_ptr->xtra3 += o_ptr->xtra3 + 5; /* Message */ #ifdef JP msg_print("松明を結合した。"); #else msg_print("You combine the torches."); #endif /* Over-fuel message */ if (j_ptr->xtra3 >= FUEL_TORCH) { j_ptr->xtra3 = FUEL_TORCH; #ifdef JP msg_print("松明の寿命は十分だ。"); #else msg_print("Your torch is fully fueled."); #endif } /* Refuel message */ else { #ifdef JP msg_print("松明はいっそう明るく輝いた。"); #else msg_print("Your torch glows more brightly."); #endif } /* Decrease the item (from the pack) */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Decrease the item (from the floor) */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } /* Recalculate torch */ p_ptr->update |= (PU_TORCH); }