Esempio n. 1
0
int send_inventory_info(connection_type *ct)
{
	u32b i, off = 0;
	char buf[80];

	int start_pos = ct->wbuf.len; /* begin cq "transaction" */

	if (cq_printf(&ct->wbuf, "%c%c", PKT_STRUCT_INFO, STRUCT_INFO_INVEN) <= 0)
	{
		ct->wbuf.len = start_pos; /* rollback */
		client_withdraw(ct);
	}

	if (cq_printf(&ct->wbuf, "%ud%ul%ul%ul", INVEN_TOTAL, eq_name_size, INVEN_WIELD, INVEN_PACK) <= 0)
	{
		ct->wbuf.len = start_pos; /* rollback */
		client_withdraw(ct);
	}

	buf[0] = '\0';
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		off += strlen(buf) + 1;
		if (i < INVEN_WIELD) 
		{
			off = 0;
		}

		my_strcpy(buf, mention_use(0, i), MAX_CHARS);

		if (cq_printf(&ct->wbuf, "%s%ul", buf, off) <= 0)
		{
			ct->wbuf.len = start_pos; /* rollback */
			client_withdraw(ct);
		}
	}
	return 1;
}
Esempio n. 2
0
/*
 * Display the equipment.  Builds a list of objects and passes them
 * off to show_obj_list() for display.  Mode flags documented in
 * object.h
 */
void show_equip(int mode)
{
	int i, last_slot = 0;

	object_type *o_ptr;

	int num_obj = 0;
	char labels[50][80];
	object_type *objects[50];

	char tmp_val[80];

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

	/* Find the last equipment slot to display */
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		o_ptr = &p_ptr->inventory[i];
		if (i < INVEN_TOTAL || o_ptr->kind) last_slot = i;
	}

	/* Build the object list */
	for (i = INVEN_WIELD; i <= last_slot; i++)
	{
		o_ptr = &p_ptr->inventory[i];

		/* May need a blank line to separate the quiver */
		if (i == INVEN_TOTAL)
		{
			int j;
			bool need_spacer = FALSE;
			
			/* Scan the rest of the items for acceptable entries */
			for (j = i; j < last_slot; j++)
			{
				o_ptr = &p_ptr->inventory[j];
				if (item_tester_okay(o_ptr)) need_spacer = TRUE;
			}

			/* Add a spacer between equipment and quiver */
			if (num_obj > 0 && need_spacer)
			{
				my_strcpy(labels[num_obj], "", sizeof(labels[num_obj]));
				objects[num_obj] = NULL;
				num_obj++;
			}

			continue;
		}

		/* Acceptable items get a label */
		if (item_tester_okay(o_ptr))
			strnfmt(labels[num_obj], sizeof(labels[num_obj]), "%c) ", index_to_label(i));

		/* Unacceptable items are still sometimes shown */
		else if ((!o_ptr->kind && show_empty) || in_term)
			my_strcpy(labels[num_obj], "   ", sizeof(labels[num_obj]));

		/* Unacceptable items are skipped in the main window */
		else continue;

		/* Show full slot labels */
		strnfmt(tmp_val, sizeof(tmp_val), "%-14s: ", mention_use(i));
		my_strcat(labels[num_obj], tmp_val, sizeof(labels[num_obj]));

		/* Save the object */
		objects[num_obj] = o_ptr;
		num_obj++;
	}

	/* Display the object list */
	show_obj_list(num_obj, 0, labels, objects, mode);
}
Esempio n. 3
0
/*
 * Display the equipment.  Builds a list of objects and passes them
 * off to show_obj_list() for display.  Mode flags documented in
 * object.h
 */
void show_equip(olist_detail_t mode)
{
	int i, last_slot = 0;

	object_type *o_ptr;

   int num_obj = 0;
   char labels[50][80];
   object_type *objects[50];

	char tmp_val[80];

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

	/* Find the last equipment slot to display */
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		o_ptr = &p_ptr->inventory[i];
		if (i < INVEN_TOTAL || o_ptr->k_idx) last_slot = i;
	}

	/* Build the object list */
	for (i = INVEN_WIELD; i <= last_slot; i++)
	{
		if (((i >= INVEN_WIELD) && (i < (INVEN_WIELD + rp_ptr->melee_slots)))
			|| ((i >= INVEN_BOW) && (i < (INVEN_BOW + rp_ptr->range_slots)))
			|| ((i >= INVEN_FINGER) && (i < (INVEN_FINGER + rp_ptr->ring_slots)))
			|| ((i >= INVEN_NECK) && (i < (INVEN_NECK + rp_ptr->amulet_slots)))
			|| ((i >= INVEN_LIGHT) && (i < (INVEN_LIGHT + rp_ptr->light_slots)))
			|| ((i >= INVEN_BODY) && (i < (INVEN_BODY + rp_ptr->body_slots)))
			|| ((i >= INVEN_OUTER) && (i < (INVEN_OUTER + rp_ptr->cloak_slots)))
			|| ((i >= INVEN_ARM) && (i < (INVEN_ARM + rp_ptr->shield_slots)))
			|| ((i >= INVEN_HEAD) && (i < (INVEN_HEAD + rp_ptr->helm_slots)))
			|| ((i >= INVEN_HANDS) && (i < (INVEN_HANDS + rp_ptr->glove_slots)))
			|| ((i >= INVEN_FEET) && (i < (INVEN_FEET + rp_ptr->boot_slots))))
		{
			o_ptr = &p_ptr->inventory[i];

			/* May need a blank line to separate the quiver */
			if (i == INVEN_TOTAL)
			{
				int j;
				bool need_spacer = FALSE;
				
				/* Scan the rest of the items for acceptable entries */
				for (j = i; j < last_slot; j++)
				{
					o_ptr = &p_ptr->inventory[j];
					if (item_tester_okay(o_ptr)) need_spacer = TRUE;
				}

				/* Add a spacer between equipment and quiver */
				if (num_obj > 0 && need_spacer)
				{
					my_strcpy(labels[num_obj], "", sizeof(labels[num_obj]));
					objects[num_obj] = NULL;
					num_obj++;
				}

				continue;
			}

			/* Acceptable items get a label */
			//if (item_tester_okay(o_ptr))
				strnfmt(labels[num_obj], sizeof(labels[num_obj]), "%c) ", index_to_label(num_obj));

			/* Unacceptable items are still displayed in term windows */
			//else if (in_term)
			//	my_strcpy(labels[num_obj], "   ", sizeof(labels[num_obj]));

			/* Unacceptable items are skipped in the main window */
			//else continue;

			/* Show full slot labels */
			if (TRUE)//OPT(show_labels))
			{
				strnfmt(tmp_val, sizeof(tmp_val), "%-14s: ", mention_use(i));
				my_strcat(labels[num_obj], tmp_val, sizeof(labels[num_obj]));
			}

			/* Otherwise only show short quiver labels */
			else if (i >= QUIVER_START)
			{
				strnfmt(tmp_val, sizeof(tmp_val), "[f%d]: ", i - QUIVER_START);
				my_strcat(labels[num_obj], tmp_val, sizeof(labels[num_obj]));
			}

			/* Save the object */
			objects[num_obj] = o_ptr;
			num_obj++;
		}
	}

	/* Display the object list */
	show_obj_list(num_obj, labels, objects, mode);
}
Esempio n. 4
0
/* 
 * Build the object list.  Note that only the equipment has first non-zero. 
 */
static void build_obj_list(int first, int last, const int *floor_list, 
			   olist_detail_t mode)
{
    int i;
    object_type *o_ptr;
    bool in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE;

    need_spacer = FALSE;
    offset = 0;
    num_obj = 0;

    /* Clear the existing contents */
    for (i = 0; i < 50; i++)
    {
	items[i].object = NULL;
	items[i].index = 0;
	items[i].key = '\0';
	my_strcpy(items[i].label, "", sizeof(items[i].label));
    }

    /* Leave top line clear for inventory subwindow */
    if (!first && !floor_list && in_term) 
	offset = 1;
    
    for (i = first; i <= last; i++)
    {
	if (floor_list)
	    o_ptr = &o_list[floor_list[i]];
	else
	    o_ptr = &p_ptr->inventory[i];

	/* May need a blank line to separate equipment and quiver */
	if ((i == INVEN_TOTAL) && (first))
	{
	    int j;
	    
	    /* Scan the rest of the items for acceptable entries */
	    for (j = i; j <= last; j++)
	    {
		o_ptr = &p_ptr->inventory[j];
		if (item_tester_okay(o_ptr) || in_term) need_spacer = TRUE;
	    }

	    continue;
	}

	/* Tester always skips gold. When gold should be displayed,
	 * only test items that are not gold.
	 */
	if (((o_ptr->tval == TV_GOLD) && (mode & OLIST_GOLD)) ||
	    item_tester_okay(o_ptr)) 
	    strnfmt(items[num_obj].label, sizeof(items[num_obj].label), "%c) ", 
		    index_to_label(i));
		
	/* Unacceptable carried items are still displayed in term windows */
	else if ((in_term) && (!floor_list))
	    my_strcpy(items[num_obj].label, "   ", 
		      sizeof(items[num_obj].label));

	/* Unacceptable items are skipped in the main window */
	else continue;

	/* Special labels for equipment */
	if (first){
	    char tmp_val[80];

	    /* Show full slot labels */
	    if (OPT(show_labels))
	    {
		strnfmt(tmp_val, sizeof(tmp_val), "%-14s: ", mention_use(i));
		my_strcat(items[num_obj].label, tmp_val, 
			  sizeof(items[num_obj].label));
	    }

	    /* Otherwise only show short quiver labels */
	    else if (i >= QUIVER_START)
	    {
		strnfmt(tmp_val, sizeof(tmp_val), "[f%d]: ", i - QUIVER_START);
		my_strcat(items[num_obj].label, tmp_val, 
			  sizeof(items[num_obj].label));
	    }
	}

	/* Save the object */
	items[num_obj].object = o_ptr;
	items[num_obj].index = i;
	items[num_obj].key = (items[num_obj].label)[0];
	num_obj++;
    }
}