12 #define MESSAGESIZE 128
13 #define MESSAGELEN 265
15 #define CT_PLR_GREEN 1
16 #define CT_PLR_YELLOW 2
21 #define CT_KEY_GREEN 'g'
22 #define CT_KEY_YELLOW 'y'
23 #define CT_KEY_RED 'r'
24 #define CT_KEY_BLUE 'b'
25 #define CT_KEY_ALL 't'
32 boolean CT_Responder(event_t *ev);
34 char CT_dequeueChatChar(void);
40 void CT_queueChatChar(char ch);
41 void CT_ClearChatMessage(int player);
42 void CT_AddChar(int player, char c);
43 void CT_BackSpace(int player);
47 byte ChatQueue[QUEUESIZE];
48 int chat_dest[MAXPLAYERS];
49 char chat_msg[MAXPLAYERS][MESSAGESIZE];
50 char plr_lastmsg[MAXPLAYERS][MESSAGESIZE+9]; // add in the length of the pre-string
51 int msgptr[MAXPLAYERS];
52 int msglen[MAXPLAYERS];
56 static int FontABaseLump;
58 char *CT_FromPlrText[MAXPLAYERS] =
66 char *chat_macros[10];
72 //===========================================================================
76 // Initialize chat mode data
77 //===========================================================================
83 head = 0; //initialize the queue index
86 memset(ChatQueue, 0, QUEUESIZE);
87 for(i = 0; i < MAXPLAYERS; i++)
91 memset(plr_lastmsg[i], 0, MESSAGESIZE);
92 memset(chat_msg[i], 0, MESSAGESIZE);
94 FontABaseLump = W_GetNumForName("FONTA_S")+1;
98 //===========================================================================
102 //===========================================================================
110 //===========================================================================
114 //===========================================================================
116 boolean CT_Responder(event_t *ev)
126 if(ev->data1 == KEY_LALT || ev->data2 == KEY_RALT)
128 altdown = (ev->type == ev_keydown);
131 if(ev->data1 == KEY_RSHIFT)
133 shiftdown = (ev->type == ev_keydown);
136 if(ev->type != ev_keydown)
143 if(ev->data1 == CT_KEY_ALL)
147 else if(ev->data1 == CT_KEY_GREEN)
149 sendto = CT_PLR_GREEN;
151 else if(ev->data1 == CT_KEY_YELLOW)
153 sendto = CT_PLR_YELLOW;
155 else if(ev->data1 == CT_KEY_RED)
159 else if(ev->data1 == CT_KEY_BLUE)
161 sendto = CT_PLR_BLUE;
163 if(sendto == 0 || (sendto != CT_PLR_ALL && !playeringame[sendto-1])
164 || sendto == consoleplayer+1)
168 CT_queueChatChar(sendto);
176 if(ev->data1 >= '0' && ev->data1 <= '9')
179 { // macro 0 comes after macro 9
182 macro = chat_macros[ev->data1-'1'];
183 CT_queueChatChar(KEY_ENTER); //send old message
184 CT_queueChatChar(chat_dest[consoleplayer]); // chose the dest.
187 CT_queueChatChar(toupper(*macro++));
189 CT_queueChatChar(KEY_ENTER); //send it off...
194 if(ev->data1 == KEY_ENTER)
196 CT_queueChatChar(KEY_ENTER);
200 else if(ev->data1 == KEY_ESCAPE)
202 CT_queueChatChar(CT_ESCAPE);
206 else if(ev->data1 >= 'a' && ev->data1 <= 'z')
208 CT_queueChatChar(ev->data1-32);
215 CT_queueChatChar('!');
218 else if(ev->data1 == '/')
220 CT_queueChatChar('?');
226 if(ev->data1 == ' ' || ev->data1 == ',' || ev->data1 == '.'
227 || (ev->data1 >= '0' && ev->data1 <= '9') || ev->data1 == '\''
228 || ev->data1 == KEY_BACKSPACE || ev->data1 == '-' || ev->data1 == '=')
230 CT_queueChatChar(ev->data1);
238 //===========================================================================
242 //===========================================================================
251 for(i=0; i < MAXPLAYERS; i++)
257 if((c = players[i].cmd.chatchar) != 0)
264 else if(c == CT_ESCAPE)
266 CT_ClearChatMessage(i);
268 else if(c == KEY_ENTER)
271 for(j = 0; j < MAXPLAYERS; j++)
273 numplayers += playeringame[j];
275 CT_AddChar(i, 0); // set the end of message character
278 strcpy(plr_lastmsg[i], CT_FromPlrText[i]);
279 strcat(plr_lastmsg[i], chat_msg[i]);
283 strcpy(plr_lastmsg[i], chat_msg[i]);
285 if(i != consoleplayer && (chat_dest[i] == consoleplayer+1
286 || chat_dest[i] == CT_PLR_ALL) && *chat_msg[i])
288 P_SetMessage(&players[consoleplayer], plr_lastmsg[i],
290 S_StartSound(NULL, sfx_chat);
292 else if(i == consoleplayer && (*chat_msg[i]))
296 P_SetMessage(&players[consoleplayer], "-MESSAGE SENT-",
298 S_StartSound(NULL, sfx_chat);
302 P_SetMessage(&players[consoleplayer],
303 "THERE ARE NO OTHER PLAYERS IN THE GAME!", true);
304 S_StartSound(NULL, sfx_chat);
307 CT_ClearChatMessage(i);
309 else if(c == KEY_BACKSPACE)
322 //===========================================================================
326 //===========================================================================
337 for(i = 0; i < msgptr[consoleplayer]; i++)
339 if(chat_msg[consoleplayer][i] < 33)
345 patch=W_CacheLumpNum(FontABaseLump+
346 chat_msg[consoleplayer][i]-33, PU_CACHE);
347 V_DrawPatch(x, 10, patch);
351 V_DrawPatch(x, 10, W_CacheLumpName("FONTA59", PU_CACHE));
352 BorderTopRefresh = true;
353 UpdateState |= I_MESSAGES;
357 //===========================================================================
361 //===========================================================================
363 void CT_queueChatChar(char ch)
365 if(((tail+1)&(QUEUESIZE-1)) == head)
366 { // the queue is full
369 ChatQueue[tail] = ch;
370 tail = (tail+1)&(QUEUESIZE-1);
373 //===========================================================================
375 // CT_dequeueChatChar
377 //===========================================================================
379 char CT_dequeueChatChar(void)
387 temp = ChatQueue[head];
388 head = (head+1)&(QUEUESIZE-1);
392 //===========================================================================
396 //===========================================================================
398 void CT_AddChar(int player, char c)
402 if(msgptr[player]+1 >= MESSAGESIZE || msglen[player] >= MESSAGELEN)
406 chat_msg[player][msgptr[player]] = c;
414 patch = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
415 msglen[player] += patch->width;
419 //===========================================================================
423 // Backs up a space, when the user hits (obviously) backspace
424 //===========================================================================
426 void CT_BackSpace(int player)
431 if(msgptr[player] == 0)
432 { // message is already blank
436 c = chat_msg[player][msgptr[player]];
443 patch = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
444 msglen[player] -= patch->width;
446 chat_msg[player][msgptr[player]] = 0;
449 //===========================================================================
451 // CT_ClearChatMessage
453 // Clears out the data for the chat message, but the player's message
454 // is still saved in plrmsg.
455 //===========================================================================
457 void CT_ClearChatMessage(int player)
459 memset(chat_msg[player], 0, MESSAGESIZE);