Pasting items into chat

Ideas for cool stuff in the future.
Post Reply
Tues
Posts: 5
Joined: Tue Feb 23, 2010 3:40 pm

Pasting items into chat

Post by Tues »

Some people were asking about this...
I've modified the client a bit, here are the patches:

First patch:

Code: Select all

--- src/client/c-cmd.c	2010-01-31 13:48:24.000000000 +0100
+++ src/client/c-cmd.c	2010-02-26 21:36:09.134700336 +0100
@@ -777,7 +777,15 @@
 	ch = inkey();
 	if (ch >= 'A' && ch < 'A' + INVEN_PACK) { /* using capital letters to force SHIFT key usage, less accidental spam that way probably */
 		c = ch - 'A';
-		if (inventory[c].tval) Send_msg(format("\377s%s", inventory_name[c]));
+
+		if (inventory[c].tval) {
+			if (chat_mode == CHAT_MODE_PARTY)
+				Send_msg(format("!:\377s%s", inventory_name[c]));
+			else if (chat_mode == CHAT_MODE_LEVEL)
+				Send_msg(format("#:\377s%s", inventory_name[c]));
+			else
+				Send_msg(format("\377s%s", inventory_name[c]));
+		}
 	}
 
 	/* restore the screen */
Second patch:

Code: Select all

--- src/client/c-store.c	2010-01-31 13:48:24.000000000 +0100
+++ src/client/c-store.c	2010-02-26 21:32:57.918701699 +0100
@@ -305,6 +305,114 @@
 	Send_store_purchase(item, amt);
 }
 
+static void store_chat(void)
+{
+	int		     i, amt;
+	int		     item;
+
+	object_type	     *o_ptr;
+
+	char	    out_val[160];
+
+
+	/* Empty? */
+	if (store.stock_num <= 0)
+	{
+		if (store_num == 7) c_msg_print("Your home is empty.");
+		else c_msg_print("I am currently out of stock.");
+		return;
+	}
+
+
+	/* Find the number of objects on this and following pages */
+	i = (store.stock_num - store_top);
+
+	/* And then restrict it to the current page */
+	if (i > 12) i = 12;
+
+	/* Prompt */
+	if (store_num == 7)
+	{
+		sprintf(out_val, "Which item? ");
+	}
+	else
+	{
+		sprintf(out_val, "Which item? ");
+	}
+
+	/* Get the item number to be pasted */
+	if (!get_stock(&item, out_val, 0, i-1)) return;
+
+	/* Get the actual index */
+	item = item + store_top;
+
+	/* Get the actual item */
+	o_ptr = &store.stock[item];
+
+	/* Convert the price to more readable format */
+	char price [16];
+	if (store_prices[item] >= 10000)
+		sprintf (price, "%dk", store_prices[item] / 1000);
+	else
+		sprintf (price, "%d", store_prices[item]);
+
+	/* Hack -- Get the shop symbol */
+	char where [16];
+	char where_char, where_attr;
+	switch (store_num)
+	{
+	case 0:
+		where_char = '1';
+		where_attr = 'U';
+		break;
+	case 1:
+		where_char = '2';
+		where_attr = 's';
+		break;
+	case 2:
+		where_char = '3';
+		where_attr = 'w';
+		break;
+	case 3:
+		where_char = '4';
+		where_attr = 'g';
+		break;
+	case 4:
+		where_char = '5';
+		where_attr = 'b';
+		break;
+	case 5:
+		where_char = '6';
+		where_attr = 'r';
+		break;
+	case 6:
+		where_char = '7';
+		where_attr = 'D';
+		break;
+	case 8:
+		where_char = '9';
+		where_attr = 'o';
+		break;
+	case 48:
+		where_char = '7';
+		where_attr = 'v';
+		break;
+	default:
+		where_char = '?';
+		where_attr = 's';
+		break;
+	}
+	sprintf (where, "%d,%d \377%c%c\377s", p_ptr->wpos.wx, p_ptr->wpos.wy, where_attr, where_char);
+
+	/* Tell the server */
+	if (chat_mode == CHAT_MODE_PARTY)
+		Send_msg(format("!:\377s%s: %s (%s gp)", where, store_names[item], price));
+	else if (chat_mode == CHAT_MODE_LEVEL)
+		Send_msg(format("#:\377s%s: %s (%s gp)", where, store_names[item], price));
+	else
+		Send_msg(format("\377s%s:: %s (%s gp)", where, store_names[item], price));
+}
+
 static void store_sell(void)
 {
 	int item, amt;
@@ -514,6 +622,13 @@
 			break;
 		}
 
+		/* Paste on Chat */
+		case 'c':
+		{
+			store_chat();
+			break;
+		}
+
 		/* Ignore return */
 		case '\r':
 		{
The first patch makes it possible to paste items into party and level channels, depending on the chat mode selected (you can change chat modes by pressing tab while typing messages, btw). The second patch allows you to paste items from shops by pressing 'c' and selecting an item. Unfortunately the code responsible for pasting the shop symbol is only a hack. However, it works for most shops, so you can use it if you need.

I hope someone finds it useful.
C. Blue
Developer
Posts: 392
Joined: Sun Dec 13, 2009 6:28 pm

Re: Pasting items into chat

Post by C. Blue »

Thanks for your contribution; Mikael just modified it to make it fit in smoothly (no hardcoded shop info), and now it's been added to the client sources on CVS, and will also be in 4.4.4a which we actually happen to release now. :)
Tues
Posts: 5
Joined: Tue Feb 23, 2010 3:40 pm

Re: Pasting items into chat

Post by Tues »

Thanks :)
Post Reply