1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
19 // DESCRIPTION: Heads-up displays
21 //-----------------------------------------------------------------------------
24 rcsid[] = "$Id: hu_stuff.c,v 1.4 1997/02/03 16:47:52 b1 Exp $";
47 // Locally used constants, shortcuts.
49 #define HU_TITLE (mapnames[(gameepisode-1)*9+gamemap-1])
50 #define HU_TITLE2 (mapnames2[gamemap-1])
51 #define HU_TITLEP (mapnamesp[gamemap-1])
52 #define HU_TITLET (mapnamest[gamemap-1])
53 #define HU_TITLEHEIGHT 1
55 #define HU_TITLEY (167 - SHORT(hu_font[0]->height))
57 #define HU_INPUTTOGGLE 't'
58 #define HU_INPUTX HU_MSGX
59 #define HU_INPUTY (HU_MSGY + HU_MSGHEIGHT*(SHORT(hu_font[0]->height) +1))
60 #define HU_INPUTWIDTH 64
61 #define HU_INPUTHEIGHT 1
79 char* player_names[] =
88 char chat_char; // remove later.
90 patch_t* hu_font[HU_FONTSIZE];
91 static hu_textline_t w_title;
93 static hu_itext_t w_chat;
94 static boolean always_off = false;
95 static char chat_dest[MAXPLAYERS];
96 static hu_itext_t w_inputbuffer[MAXPLAYERS];
98 static boolean message_on;
99 boolean message_dontfuckwithme;
100 static boolean message_nottobefuckedwith;
102 static hu_stext_t w_message;
103 static int message_counter;
105 extern int showMessages;
106 extern boolean automapactive;
108 static boolean headsupactive = false;
111 // Builtin map names.
112 // The actual names can be found in DStrings.h.
115 char* mapnames[] = // DOOM shareware/registered/retail (Ultimate) names.
169 char* mapnames2[] = // DOOM 2 map names.
208 char* mapnamesp[] = // Plutonia WAD map names.
247 char *mapnamest[] = // TNT WAD map names.
293 // load the heads-up font
295 for (i=0;i<HU_FONTSIZE;i++)
297 sprintf(buffer, "STCFN%.3d", j++);
298 hu_font[i] = (patch_t *) W_CacheLumpName(buffer, PU_STATIC);
305 headsupactive = false;
317 plr = &players[consoleplayer];
319 message_dontfuckwithme = false;
320 message_nottobefuckedwith = false;
323 // create the message widget
324 HUlib_initSText(&w_message,
325 HU_MSGX, HU_MSGY, HU_MSGHEIGHT,
327 HU_FONTSTART, &message_on);
329 // create the map title widget
330 HUlib_initTextLine(&w_title,
331 HU_TITLEX, HU_TITLEY,
359 HUlib_addCharToTextLine(&w_title, *(s++));
361 // create the chat widget
362 HUlib_initIText(&w_chat,
363 HU_INPUTX, HU_INPUTY,
365 HU_FONTSTART, &chat_on);
367 // create the inputbuffer widgets
368 for (i=0 ; i<MAXPLAYERS ; i++)
369 HUlib_initIText(&w_inputbuffer[i], 0, 0, 0, 0, &always_off);
371 headsupactive = true;
378 HUlib_drawSText(&w_message);
379 HUlib_drawIText(&w_chat);
381 HUlib_drawTextLine(&w_title, false);
388 HUlib_eraseSText(&w_message);
389 HUlib_eraseIText(&w_chat);
390 HUlib_eraseTextLine(&w_title);
400 // tick down message counter if message is up
401 if (message_counter && !--message_counter)
404 message_nottobefuckedwith = false;
407 if (showMessages || message_dontfuckwithme)
410 // display message if necessary
411 if ((plr->message && !message_nottobefuckedwith)
412 || (plr->message && message_dontfuckwithme))
414 HUlib_addMessageToSText(&w_message, 0, plr->message);
417 message_counter = HU_MSGTIMEOUT;
418 message_nottobefuckedwith = message_dontfuckwithme;
419 message_dontfuckwithme = 0;
422 } // else message_on = false;
424 // check for incoming chat characters
427 for (i=0 ; i<MAXPLAYERS; i++)
429 if (!playeringame[i])
431 if (i != consoleplayer
432 && (c = players[i].cmd.chatchar))
434 if (c <= HU_BROADCAST)
438 rc = HUlib_keyInIText(&w_inputbuffer[i], c);
439 if (rc && c == KEY_ENTER)
441 if (w_inputbuffer[i].l.len
442 && (chat_dest[i] == consoleplayer+1
443 || chat_dest[i] == HU_BROADCAST))
445 HUlib_addMessageToSText(&w_message,
447 w_inputbuffer[i].l.l);
449 message_nottobefuckedwith = true;
451 message_counter = HU_MSGTIMEOUT;
452 if ( gamemode == commercial )
453 S_StartSound(0, sfx_radio);
455 S_StartSound(0, sfx_tink);
457 HUlib_resetIText(&w_inputbuffer[i]);
460 players[i].cmd.chatchar = 0;
467 #define QUEUESIZE 128
469 static char chatchars[QUEUESIZE];
474 void HU_queueChatChar(char c)
476 if (((head + 1) & (QUEUESIZE-1)) == tail)
478 plr->message = HUSTR_MSGU;
483 head = (head + 1) & (QUEUESIZE-1);
487 char HU_dequeueChatChar(void)
494 tail = (tail + 1) & (QUEUESIZE-1);
504 boolean HU_Responder(event_t *ev)
507 static char lastmessage[HU_MAXLINELENGTH+1];
509 boolean eatkey = false;
510 static boolean altdown = false;
515 static char destination_keys[MAXPLAYERS] =
523 static int num_nobrainers = 0;
526 for (i=0 ; i<MAXPLAYERS ; i++)
527 numplayers += playeringame[i];
532 if (ev->data1 == KEY_RALT || ev->data1 == KEY_LALT)
534 altdown = ev->type == ev_keydown;
546 if (ev->data1 == HU_MSGREFRESH)
549 message_counter = HU_MSGTIMEOUT;
552 else if (netgame && ev->data1 == HU_INPUTTOGGLE)
554 eatkey = chat_on = true;
555 HUlib_resetIText(&w_chat);
556 HU_queueChatChar(HU_BROADCAST);
558 else if (netgame && numplayers > 2)
560 for (i=0; i<MAXPLAYERS ; i++)
562 if (ev->data1 == destination_keys[i])
564 if (playeringame[i] && i!=consoleplayer)
566 eatkey = chat_on = true;
567 HUlib_resetIText(&w_chat);
568 HU_queueChatChar(i+1);
571 else if (i == consoleplayer)
574 if (num_nobrainers < 3)
575 plr->message = HUSTR_TALKTOSELF1;
576 else if (num_nobrainers < 6)
577 plr->message = HUSTR_TALKTOSELF2;
578 else if (num_nobrainers < 9)
579 plr->message = HUSTR_TALKTOSELF3;
580 else if (num_nobrainers < 32)
581 plr->message = HUSTR_TALKTOSELF4;
583 plr->message = HUSTR_TALKTOSELF5;
599 macromessage = chat_macros[c];
601 // kill last message with a '\n'
602 HU_queueChatChar(KEY_ENTER); // DEBUG!!!
604 // send the macro message
605 while (*macromessage)
606 HU_queueChatChar(*macromessage++);
607 HU_queueChatChar(KEY_ENTER);
609 // leave chat mode and notify that it was sent
611 strcpy(lastmessage, chat_macros[c]);
612 plr->message = lastmessage;
617 eatkey = HUlib_keyInIText(&w_chat, c);
627 strcpy(lastmessage, w_chat.l.l);
628 plr->message = lastmessage;
631 else if (c == KEY_ESCAPE)