Ejemplo n.º 1
0
/**
 * Bring up objects to act on 
 */
void do_cmd_show_obj(void)
{
    cptr q, s;
    int j, item;
    object_type *o_ptr;

    char o_name[120];
    byte out_color;
    bool accepted = FALSE;

    /* No restrictions */
    item_tester_tval = 0;
    item_tester_hook = NULL;

    /* See what's available */
    q = "Pick an item to use:";
    s = "You have no items to hand.";
    if (!get_item(&item, q, s, CMD_NULL, (USE_INVEN | USE_EQUIP | USE_FLOOR)))
	return;

    /* Got it */
    if (item >= 0) {
	o_ptr = &p_ptr->inventory[item];
    }

    /* Get the item (on the floor) */
    else {
	o_ptr = &o_list[0 - item];
    }

    /* Is it really an item? */
    if (!o_ptr->k_idx)
	return;

    /* No commands yet */
    poss = 0;

    /* Describe the object */
    object_desc(o_name, sizeof(o_name), o_ptr, ODESC_FULL);

    /* Hack -- enforce max length */
    o_name[Term->wid - 3] = '\0';

    /* Acquire inventory color.  Apply spellbook hack. */
    out_color = proc_list_color_hack(o_ptr);

    /* Wear/wield */
    if ((wield_slot(o_ptr) >= INVEN_WIELD) && (!SCHANGE)
	&& (item < INVEN_WIELD)) {
	comm[poss] = 'w';
	comm_code[poss] = CMD_WIELD;
	comm_descr[poss++] = "Wield";
    }

    /* Take off equipment */
    if ((item >= INVEN_WIELD) && (item < INVEN_TOTAL) && (!SCHANGE)) {
	comm[poss] = 't';
	comm_code[poss] = CMD_TAKEOFF;
	comm_descr[poss++] = "Take off";
    }

    /* Drop an item */
    if ((item >= 0) && ((item < INVEN_WIELD) || (!SCHANGE))) {
	comm[poss] = 'd';
	comm_code[poss] = CMD_DROP;
	comm_descr[poss++] = "Drop";
    }


    /* Destroy an item */
    if (item < INVEN_WIELD) {
	comm[poss] = 'k';
	comm_code[poss] = CMD_DESTROY;
	comm_descr[poss++] = "Destroy";
    }


    /* Identify an object */
    comm[poss] = 'I';
    comm_code[poss] = CMD_NULL;
    comm_descr[poss++] = "Inspect";

    /* Pick up an object */
    if ((item < 0) && inven_carry_okay(o_ptr)) {
	comm[poss] = 'g';
	comm_code[poss] = CMD_PICKUP;
	comm_descr[poss++] = "Pick up";
    }

    /* Book learnin' */
    if (mp_ptr->spell_book == o_ptr->tval) {
	if (p_ptr->new_spells) {
	    comm[poss] = 'G';
	    comm_code[poss] = CMD_STUDY_SPELL;
	    comm_descr[poss++] = "Gain a spell";
	}
	comm[poss] = 'b';
	comm_code[poss] = CMD_BROWSE_SPELL;
	comm_descr[poss++] = "Browse";
	comm[poss] = 'm';
	comm_code[poss] = CMD_CAST;
	comm_descr[poss++] = "Cast a spell";
    }

    /* Inscribe an object */
    comm[poss] = '{';
    comm_code[poss] = CMD_INSCRIBE;
    comm_descr[poss++] = "Inscribe";

    /* Uninscribe an object */
    if (o_ptr->note) {
	comm[poss] = '}';
	comm_code[poss] = CMD_UNINSCRIBE;
	comm_descr[poss++] = "Uninscribe";
    }

    /* Activate equipment */
    if ((o_ptr->effect) && (item >= INVEN_WIELD)) {
	comm[poss] = 'A';
	comm_code[poss] = CMD_ACTIVATE;
	comm_descr[poss++] = "Activate";
    }

    /* Eat some food */
    if (o_ptr->tval == TV_FOOD) {
	comm[poss] = 'E';
	comm_code[poss] = CMD_EAT;
	comm_descr[poss++] = "Eat";
    }

    if ((item < INVEN_WIELD)
	&& ((o_ptr->tval == TV_LIGHT) || (o_ptr->tval == TV_FLASK))) {
	object_type *o1_ptr = &p_ptr->inventory[INVEN_LIGHT];

	if (((o1_ptr->sval == SV_LIGHT_LANTERN)
	     && ((o_ptr->tval == TV_FLASK)
		 || ((o_ptr->tval == TV_LIGHT)
		     && (o_ptr->sval == SV_LIGHT_LANTERN))))
	    || ((o1_ptr->sval == SV_LIGHT_TORCH) && (o_ptr->tval == TV_LIGHT)
		&& (o_ptr->sval == SV_LIGHT_TORCH)))
	{
	    comm[poss] = 'F';
	    comm_code[poss] = CMD_REFILL;
	    comm_descr[poss++] = "Refuel";
	}
    }

    /* Fire an item */
    if (p_ptr->state.ammo_tval == o_ptr->tval) {
	comm[poss] = 'f';
	comm_code[poss] = CMD_FIRE;
	comm_descr[poss++] = "Fire";
    }

    /* Throw an item */
    if ((item < INVEN_WIELD) || (!SCHANGE)) {
	comm[poss] = 'v';
	comm_code[poss] = CMD_THROW;
	comm_descr[poss++] = "Throw";
    }

    /* Aim a wand */
    if (o_ptr->tval == TV_WAND) {
	comm[poss] = 'a';
	comm_code[poss] = CMD_USE_WAND;
	comm_descr[poss++] = "Aim";
    }

    /* Zap a rod */
    if (o_ptr->tval == TV_ROD) {
	comm[poss] = 'z';
	comm_code[poss] = CMD_USE_ROD;
	comm_descr[poss++] = "Zap";
    }

    /* Quaff a potion */
    if (o_ptr->tval == TV_POTION) {
	comm[poss] = 'q';
	comm_code[poss] = CMD_QUAFF;
	comm_descr[poss++] = "Quaff";
    }

    /* Read a scroll */
    if (o_ptr->tval == TV_SCROLL) {
	comm[poss] = 'r';
	comm_code[poss] = CMD_READ_SCROLL;
	comm_descr[poss++] = "Read";
    }

    /* Use a staff */
    if (o_ptr->tval == TV_STAFF) {
	comm[poss] = 'u';
	comm_code[poss] = CMD_USE_STAFF;
	comm_descr[poss++] = "Use";
    }

    /* Set up the screen */
    screen_save();

    /* Prompt */
    put_str("Choose a command, or ESC:", 0, 0);

    /* Clear the line */
    prt("", 1, 0);

    /* Display the item */
    c_put_str(out_color, o_name, 1, 0);

    /* Hack - delete exact graphics rows */
    if (tile_height > 1) {
	j = poss + 2;
	while ((j % tile_height) && (j <= SCREEN_ROWS))
	    prt("", ++j, 0);
    }

    /* Get a choice */
    accepted = show_cmd_menu(TRUE);

    /* Load de screen */
    screen_load();

    /* Now set the item if valid */
    if (accepted)
	cmd_set_arg_item(cmd_get_top(), 0, item);
}
Ejemplo n.º 2
0
/*
 * Display an object.  Each object may be prefixed with a label.
 * Used by show_inven(), show_equip(), and show_floor().  Mode flags are
 * documented in object.h
 */
static void show_obj(int onum, size_t max_len, char label[80],
		     const object_type *object, bool cursor,
		     olist_detail_t mode)
{
    int row = 0, col = 0;
    int ex_width = 0, ex_offset, ex_offset_ctr;

    object_type *o_ptr = (object_type *) object;
    char o_name[160];
    char tmp_val[80];

    bool in_term;
    byte attr = proc_list_color_hack(o_ptr);

    /* Highlight */
    if (cursor) attr = get_color(attr, ATTR_HIGH, 1);

    in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE;

    /* Object name */
    object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL);

    /* Width of extra fields */
    if (mode & OLIST_WEIGHT)
	ex_width += 9;
    if (mode & OLIST_PRICE)
	ex_width += 9;
    if (mode & OLIST_FAIL)
	ex_width += 10;

    /* Determine beginning row and column */
    if (in_term) 
    {
	/* Term window */
	row = offset;
	col = 0;
    } 
    else 
    {
	/* Main window */
	row = 1;
	col = Term->wid - 3 - max_len - ex_width;
	col = MIN(col, COL_MAP + tile_width);

	if (col < 3)
	    col = 0;
    }

    /* Column offset of the first extra field */
    ex_offset = MIN(max_len, (size_t) (Term->wid - 1 - ex_width - col));

    /* Clear the line */
    prt("", row + onum, MAX(col - 2, 0));

    /* Print the label */
    put_str(label, row + onum, col);

    /* Print the object */
    if (o_ptr != NULL) {
	/* Limit object name */
	if (strlen(label) + strlen(o_name) > (size_t) ex_offset) {
	    int truncate = ex_offset - strlen(label);

	    if (truncate < 0)
		truncate = 0;
	    if ((size_t) truncate > sizeof(o_name) - 1)
		truncate = sizeof(o_name) - 1;

	    o_name[truncate] = '\0';
	}

	/* Object name */
	c_put_str(attr, o_name, row + onum, col + strlen(label));

	/* Extra fields */
	ex_offset_ctr = ex_offset;

	if (mode & OLIST_PRICE) {
	    int price = price_item(o_ptr, TRUE, o_ptr->number);
	    strnfmt(tmp_val, sizeof(tmp_val), "%6d au", price);
	    put_str(tmp_val, row + onum, col + ex_offset_ctr);
	    ex_offset_ctr += 9;
	}

	if (mode & OLIST_FAIL) {
	    int fail = (9 + get_use_device_chance(o_ptr)) / 10;
	    if (object_aware_p(o_ptr))
		strnfmt(tmp_val, sizeof(tmp_val), "%4d%% fail", fail);
	    else
		my_strcpy(tmp_val, "    ? fail", sizeof(tmp_val));
	    put_str(tmp_val, row + onum, col + ex_offset_ctr);
	    ex_offset_ctr += 10;
	}

	if (mode & OLIST_WEIGHT) {
	    int weight = o_ptr->weight * o_ptr->number;
	    strnfmt(tmp_val, sizeof(tmp_val), "%4d.%1d lb", weight / 10,
		    weight % 10);
	    put_str(tmp_val, row + onum, col + ex_offset_ctr);
	    ex_offset_ctr += 9;
	}
    }
}