Exemplo n.º 1
0
/*
 * Display equipment
 */
void do_cmd_equip(void)
{
	ui_event e;

	/* Hack -- Start in "equipment" mode */
	p_ptr->command_wrk = (USE_EQUIP);

	/* Save screen */
	screen_save();

	/* Hack -- show empty slots */
	item_tester_full = TRUE;

	/* Display the equipment */
	show_equip(OLIST_WEIGHT);

	/* Hack -- undo the hack above */
	item_tester_full = FALSE;

	/* Prompt for a command */
	prt("(Equipment) Command: ", 0, 0);

	/* Get a new command */
	e = inkey_ex();
	if (!(e.type == EVT_KBRD && e.key.code == ESCAPE))
		Term_event_push(&e);

	/* Load screen */
	screen_load();
}
Exemplo n.º 2
0
/*
 * Display inventory
 */
void do_cmd_inven(void)
{
	ui_event e;
	int diff = weight_remaining();

	/* Hack -- Start in "inventory" mode */
	p_ptr->command_wrk = (USE_INVEN);

	/* Save screen */
	screen_save();

	/* Hack -- show empty slots */
	item_tester_full = TRUE;

	/* Display the inventory */
	show_inven(OLIST_WEIGHT | OLIST_QUIVER);

	/* Hack -- hide empty slots */
	item_tester_full = FALSE;

	/* Prompt for a command */
	prt(format("(Inventory) Burden %d.%d lb (%d.%d lb %s). Command: ",
		        p_ptr->total_weight / 10, p_ptr->total_weight % 10,
		        abs(diff) / 10, abs(diff) % 10,
		        (diff < 0 ? "overweight" : "remaining")),
	    0, 0);

	/* Get a new command */
	e = inkey_ex();
	if (!(e.type == EVT_KBRD && e.key.code == ESCAPE))
		Term_event_push(&e);

	/* Load screen */
	screen_load();
}
Exemplo n.º 3
0
/**
 * Get a command count, with the '0' key.
 */
static int textui_get_count(void)
{
	int count = 0;

	while (1)
	{
		ui_event_data ke;

		prt(format("Count: %d", count), 0, 0);

		ke = inkey_ex();
		if (ke.type != EVT_KBRD)
			continue;

		if (ke.key == ESCAPE)
			return -1;

		/* Simple editing (delete or backspace) */
		else if (ke.key == 0x7F || ke.key == KTRL('H'))
			count = count / 10;

		/* Actual numeric data */
		else if (isdigit((unsigned char) ke.key))
		{
			count = count * 10 + D2I(ke.key);

			if (count >= 9999)
			{
				bell("Invalid repeat count!");
				count = 9999;
			}
		}

		/* Anything non-numeric passes straight to command input */
		else
		{
			/* XXX nasty hardcoding of action menu key */
			if (ke.key != '\n' && ke.key != '\r')
				Term_event_push(&ke);

			break;
		}
	}

	return count;
}
Exemplo n.º 4
0
/**
 * Pick up objects and treasure on the floor, now also used for telekinesis.
 *
 * Called with pickup:
 * 0 to grab gold and describe non-gold objects.
 * 1 to pick up objects either with or without displaying a menu.
 * 2 to pick up objects, forcing a menu for multiple objects.
 * 3 to pick up objects, forcing a menu for any number of objects.
 *
 * Scan the list of objects in that floor grid.   Pick up gold automatically.
 * Pick up objects automatically until pile or backpack space is full if 
 * auto-pickup option is on, carry_query_floor option is not, and menus are 
 * not forced (which the "get" command does). Otherwise, store objects on 
 * floor in an array, and tally both how many there are and can be picked up.
 *
 * If the player is not picking up objects, describe a single object or 
 * indicate the presence of a floor stack.  If player is picking up objects, 
 * name a single object, or indicate a stack of objects, that cannot go in 
 * the backpack.
 *
 * Pick up a single object without menus, unless menus for single items are 
 * forced.  Confirm pickup if that option is on.
 *
 * Pick up multiple objects (unless using autopickup, no confirm) using Tim
 * Baker's menu system.   Recursively call this function (forcing menus for any 
 * number of objects) until objects are gone, backpack is full, or player is 
 * satisfied.
 *
 * Keep track of number of objects picked up (to calculate time spent).
 */
byte py_pickup(int pickup, int y, int x)
{
    s16b this_o_idx, next_o_idx = 0;

    char o_name[120];
    object_type *o_ptr;

    /* Objects picked up.  Used to determine time cost of command. */
    byte objs_picked_up = 0;

    size_t floor_num = 0;
    int floor_list[MAX_FLOOR_STACK + 1], floor_o_idx = 0;

    int can_pickup = 0;
    bool call_function_again = FALSE;
    bool blind = ((p_ptr->timed[TMD_BLIND]) || (no_light()));
    bool msg = TRUE;
    bool telekinesis = (!(y == p_ptr->py) || !(x == p_ptr->px));

    /* Nothing to pick up -- return */
    if (!cave_o_idx[y][x]) return (0);

    /* Always pickup gold, effortlessly */
    if (!telekinesis) py_pickup_gold();

    /* Scan the pile of objects */
    for (this_o_idx = cave_o_idx[y][x]; this_o_idx; this_o_idx = next_o_idx) {

	/* Access the object */
	o_ptr = &o_list[this_o_idx];

	/* Access the next object */
	next_o_idx = o_ptr->next_o_idx;

	/* Ordinary pickup */
	if (!telekinesis) {

	    /* Ignore all hidden objects and non-objects */
	    if (squelch_hide_item(o_ptr) || !o_ptr->k_idx)
		continue;

	    /* Hack -- disturb */
	    disturb(0, 0);

	    /* Automatically pick up some items */
	    if (auto_pickup_okay(o_ptr)) {
		/* Pick up the object */
		py_pickup_aux(this_o_idx, TRUE);
		objs_picked_up++;

		/* Check the next object */
		continue;
	    }
	}

	/* Tally objects and store them in an array. */
	
	/* Remember this object index */
	floor_list[floor_num] = this_o_idx;
	
	/* Count non-gold objects that remain on the floor. */
	floor_num++;
	
	/* Tally objects that can be picked up.*/
	if (inven_carry_okay(o_ptr))
	    can_pickup++;
    }

    /* There are no non-gold objects */
    if (!floor_num)
	return (objs_picked_up);

    /* Get hold of the last floor index */
    floor_o_idx = floor_list[floor_num - 1];

    /* Mention the objects if player is not picking them up. */
    if (pickup == 0 || !(can_pickup || telekinesis))
    {
	const char *p = "see";

	/* One object */
	if (floor_num == 1)
	{
	    if (!can_pickup)	p = "have no room for";
	    else if (blind)     p = "feel";

	    /* Get the object */
	    o_ptr = &o_list[floor_o_idx];

	    /* Describe the object.  Less detail if blind. */
	    if (blind)
		object_desc(o_name, sizeof(o_name), o_ptr,
			    ODESC_PREFIX | ODESC_BASE);
	    else
		object_desc(o_name, sizeof(o_name), o_ptr,
			    ODESC_PREFIX | ODESC_FULL);

	    /* Message */
	    message_flush();
	    msg_format("You %s %s.", p, o_name);
	}
	else
	{
	    /* Optionally, display more information about floor items */
	    if (OPT(pickup_detail))
	    {
		ui_event_data e;

		if (!can_pickup)	p = "have no room for the following objects";
		else if (blind)     p = "feel something on the floor";

		/* Scan all marked objects in the grid */
		floor_num = scan_floor(floor_list, N_ELEMENTS(floor_list), y, x, 0x03);

		/* Save screen */
		screen_save();

		/* Display objects on the floor */
		show_floor(floor_list, floor_num, (OLIST_WEIGHT));

		/* Display prompt */
		prt(format("You %s: ", p), 0, 0);

		/* Move cursor back to character, if needed */
		if (OPT(highlight_player)) move_cursor_relative(p_ptr->py, p_ptr->px);

		/* Wait for it.  Use key as next command. */
		e = inkey_ex();
		Term_event_push(&e);

		/* Restore screen */
		screen_load();
	    }

	    /* Show less detail */
	    else
	    {
		message_flush();

		if (!can_pickup)
		    msg_print("You have no room for any of the items on the floor.");
		else
		    msg_format("You %s a pile of %d items.", (blind ? "feel" : "see"), floor_num);
	    }
	}

	/* Done */
	return (objs_picked_up);
    }

    /* We can pick up objects.  Menus are not requested (yet). */
    if (pickup == 1)
    {
	/* Scan floor (again) */
	floor_num = scan_floor(floor_list, N_ELEMENTS(floor_list), y, x, 0x03);

	/* Use a menu interface for multiple objects, or get single objects */
	if (floor_num > 1)
	    pickup = 2;
	else
	    this_o_idx = floor_o_idx;
    }


    /* Display a list if requested. */
    if (pickup == 2)
    {
	cptr q, s;
	int item;

	/* Get an object or exit. */
	q = "Get which item?";
	s = "You see nothing there.";

	/* Telekinesis */
	if (telekinesis) {
	    item_tester_hook = inven_carry_okay;

	    if (!get_item(&item, q, s, CMD_PICKUP, USE_TARGET))
		return (objs_picked_up);

	    this_o_idx = 0 - item;
	}
	else {
	    /* Restrict the choices */
	    item_tester_hook = inven_carry_okay;

	    if (!get_item(&item, q, s, CMD_PICKUP, USE_FLOOR))
		return (objs_picked_up);

	    this_o_idx = 0 - item;
	    call_function_again = TRUE;
	}

	/* With a list, we do not need explicit pickup messages */
	msg = FALSE;
    }

    /* Pick up object, if legal */
    if (this_o_idx)
    {
	/* Regular pickup or telekinesis with pack not full */
	if (can_pickup) {
	    /* Pick up the object */
	    py_pickup_aux(this_o_idx, msg);
	}
	/* Telekinesis with pack full */
	else {
	    /* Access the object */
	    o_ptr = &o_list[this_o_idx];
	    
	    /* Drop it */
	    drop_near(o_ptr, -1, p_ptr->py, p_ptr->px, TRUE);
	    
	    /* Delete the old object */
	    delete_object_idx(this_o_idx);
	}
    }

    /* Indicate an object picked up. */
    objs_picked_up = 1;

    /* If requested, call this function recursively.  Count objects picked up.
     * Force the display of a menu in all cases. */
    if (call_function_again)
	objs_picked_up += py_pickup(3, y, x);

    /* Indicate how many objects have been picked up. */
    return (objs_picked_up);
}