hu_stuff.c (10656B)
1 #include <ctype.h> 2 3 #include "doomdef.h" 4 #include "z_zone.h" 5 #include "hu_stuff.h" 6 #include "hu_lib.h" 7 #include "w_wad.h" 8 #include "s_sound.h" 9 #include "doomstat.h" 10 #include "dstrings.h" 11 #include "sounds.h" 12 13 #define HU_TITLE (lang[mapnames[(gameepisode-1)*9+gamemap-1]]) 14 #define HU_TITLE2 (lang[mapnames2[gamemap-1]]) 15 #define HU_TITLEP (lang[mapnamesp[gamemap-1]]) 16 #define HU_TITLET (lang[mapnamest[gamemap-1]]) 17 #define HU_TITLEHEIGHT 1 18 #define HU_TITLEX 0 19 #define HU_TITLEY (167 - hu_font[0]->height) 20 #define HU_INPUTTOGGLE 't' 21 #define HU_INPUTX HU_MSGX 22 #define HU_INPUTY (HU_MSGY + HU_MSGHEIGHT*(hu_font[0]->height) +1) 23 #define HU_INPUTWIDTH 64 24 #define HU_INPUTHEIGHT 1 25 #define QUEUESIZE 128 26 27 int chat_macros[] = { 28 HUSTR_CHATMACRO0, 29 HUSTR_CHATMACRO1, 30 HUSTR_CHATMACRO2, 31 HUSTR_CHATMACRO3, 32 HUSTR_CHATMACRO4, 33 HUSTR_CHATMACRO5, 34 HUSTR_CHATMACRO6, 35 HUSTR_CHATMACRO7, 36 HUSTR_CHATMACRO8, 37 HUSTR_CHATMACRO9 38 }; 39 40 int player_names[] = { 41 HUSTR_PLRGREEN, 42 HUSTR_PLRINDIGO, 43 HUSTR_PLRBROWN, 44 HUSTR_PLRRED 45 }; 46 47 char chat_char; 48 static player_t* plr; 49 patch_t* hu_font[HU_FONTSIZE]; 50 static hu_textline_t w_title; 51 boolean chat_on; 52 static hu_itext_t w_chat; 53 static boolean always_off = false; 54 static char chat_dest[MAXPLAYERS]; 55 static hu_itext_t w_inputbuffer[MAXPLAYERS]; 56 static boolean message_on; 57 boolean message_dontfuckwithme; 58 static boolean message_nottobefuckedwith; 59 static hu_stext_t w_message; 60 static int message_counter; 61 extern int showMessages; 62 extern boolean automapactive; 63 static boolean headsupactive = false; 64 static char chatchars[QUEUESIZE]; 65 static int head = 0; 66 static int tail = 0; 67 68 69 int mapnames[] = { 70 HUSTR_E1M1, 71 HUSTR_E1M2, 72 HUSTR_E1M3, 73 HUSTR_E1M4, 74 HUSTR_E1M5, 75 HUSTR_E1M6, 76 HUSTR_E1M7, 77 HUSTR_E1M8, 78 HUSTR_E1M9, 79 HUSTR_E2M1, 80 HUSTR_E2M2, 81 HUSTR_E2M3, 82 HUSTR_E2M4, 83 HUSTR_E2M5, 84 HUSTR_E2M6, 85 HUSTR_E2M7, 86 HUSTR_E2M8, 87 HUSTR_E2M9, 88 HUSTR_E3M1, 89 HUSTR_E3M2, 90 HUSTR_E3M3, 91 HUSTR_E3M4, 92 HUSTR_E3M5, 93 HUSTR_E3M6, 94 HUSTR_E3M7, 95 HUSTR_E3M8, 96 HUSTR_E3M9, 97 HUSTR_E4M1, 98 HUSTR_E4M2, 99 HUSTR_E4M3, 100 HUSTR_E4M4, 101 HUSTR_E4M5, 102 HUSTR_E4M6, 103 HUSTR_E4M7, 104 HUSTR_E4M8, 105 HUSTR_E4M9, 106 NEWLEVEL, 107 NEWLEVEL, 108 NEWLEVEL, 109 NEWLEVEL, 110 NEWLEVEL, 111 NEWLEVEL, 112 NEWLEVEL, 113 NEWLEVEL, 114 NEWLEVEL 115 }; 116 117 int mapnames2[] = { 118 HUSTR_1, 119 HUSTR_2, 120 HUSTR_3, 121 HUSTR_4, 122 HUSTR_5, 123 HUSTR_6, 124 HUSTR_7, 125 HUSTR_8, 126 HUSTR_9, 127 HUSTR_10, 128 HUSTR_11, 129 HUSTR_12, 130 HUSTR_13, 131 HUSTR_14, 132 HUSTR_15, 133 HUSTR_16, 134 HUSTR_17, 135 HUSTR_18, 136 HUSTR_19, 137 HUSTR_20, 138 HUSTR_21, 139 HUSTR_22, 140 HUSTR_23, 141 HUSTR_24, 142 HUSTR_25, 143 HUSTR_26, 144 HUSTR_27, 145 HUSTR_28, 146 HUSTR_29, 147 HUSTR_30, 148 HUSTR_31, 149 HUSTR_32 150 }; 151 152 int mapnamesp[] = { 153 PHUSTR_1, 154 PHUSTR_2, 155 PHUSTR_3, 156 PHUSTR_4, 157 PHUSTR_5, 158 PHUSTR_6, 159 PHUSTR_7, 160 PHUSTR_8, 161 PHUSTR_9, 162 PHUSTR_10, 163 PHUSTR_11, 164 PHUSTR_12, 165 PHUSTR_13, 166 PHUSTR_14, 167 PHUSTR_15, 168 PHUSTR_16, 169 PHUSTR_17, 170 PHUSTR_18, 171 PHUSTR_19, 172 PHUSTR_20, 173 PHUSTR_21, 174 PHUSTR_22, 175 PHUSTR_23, 176 PHUSTR_24, 177 PHUSTR_25, 178 PHUSTR_26, 179 PHUSTR_27, 180 PHUSTR_28, 181 PHUSTR_29, 182 PHUSTR_30, 183 PHUSTR_31, 184 PHUSTR_32 185 }; 186 187 int mapnamest[] = { 188 THUSTR_1, 189 THUSTR_2, 190 THUSTR_3, 191 THUSTR_4, 192 THUSTR_5, 193 THUSTR_6, 194 THUSTR_7, 195 THUSTR_8, 196 THUSTR_9, 197 THUSTR_10, 198 THUSTR_11, 199 THUSTR_12, 200 THUSTR_13, 201 THUSTR_14, 202 THUSTR_15, 203 THUSTR_16, 204 THUSTR_17, 205 THUSTR_18, 206 THUSTR_19, 207 THUSTR_20, 208 THUSTR_21, 209 THUSTR_22, 210 THUSTR_23, 211 THUSTR_24, 212 THUSTR_25, 213 THUSTR_26, 214 THUSTR_27, 215 THUSTR_28, 216 THUSTR_29, 217 THUSTR_30, 218 THUSTR_31, 219 THUSTR_32 220 }; 221 222 const char* shiftxform; 223 const char french_shiftxform[] = { 224 0, 225 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 226 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 227 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 228 31, 229 ' ', '!', '"', '#', '$', '%', '&', 230 '"', 231 '(', ')', '*', '+', 232 '?', 233 '_', 234 '>', 235 '?', 236 '0', 237 '1', 238 '2', 239 '3', 240 '4', 241 '5', 242 '6', 243 '7', 244 '8', 245 '9', 246 '/', 247 '.', 248 '<', 249 '+', 250 '>', '?', '@', 251 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 252 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 253 '[', 254 '!', 255 ']', 256 '"', '_', 257 '\'', 258 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 259 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 260 '{', '|', '}', '~', 127 261 262 }; 263 264 const char english_shiftxform[] = { 265 0, 266 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 267 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 268 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 269 31, 270 ' ', '!', '"', '#', '$', '%', '&', 271 '"', 272 '(', ')', '*', '+', 273 '<', 274 '_', 275 '>', 276 '?', 277 ')', 278 '!', 279 '@', 280 '#', 281 '$', 282 '%', 283 '^', 284 '&', 285 '*', 286 '(', 287 ':', 288 ':', 289 '<', 290 '+', 291 '>', '?', '@', 292 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 293 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 294 '[', 295 '!', 296 ']', 297 '"', '_', 298 '\'', 299 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 300 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 301 '{', '|', '}', '~', 127 302 }; 303 304 char frenchKeyMap[128] = { 305 0, 306 1,2,3,4,5,6,7,8,9,10, 307 11,12,13,14,15,16,17,18,19,20, 308 21,22,23,24,25,26,27,28,29,30, 309 31, 310 ' ','!','"','#','$','%','&','%','(',')','*','+',';','-',':','!', 311 '0','1','2','3','4','5','6','7','8','9',':','M','<','=','>','?', 312 '@','Q','B','C','D','E','F','G','H','I','J','K','L',',','N','O', 313 'P','A','R','S','T','U','V','Z','X','Y','W','^','\\','$','^','_', 314 '@','Q','B','C','D','E','F','G','H','I','J','K','L',',','N','O', 315 'P','A','R','S','T','U','V','Z','X','Y','W','^','\\','$','^',127 316 }; 317 318 char ForeignTranslation(unsigned char ch) 319 { 320 return ch < 128 ? frenchKeyMap[ch] : ch; 321 } 322 323 void 324 HU_Init() 325 { 326 327 int i, j; 328 char buffer[9]; 329 330 shiftxform = english_shiftxform; 331 j = HU_FONTSTART; 332 for (i = 0; i < HU_FONTSIZE; ++i) { 333 sprintf(buffer, "STCFN%.3d", j++); 334 hu_font[i] = (patch_t*)W_CacheLumpName(buffer, PU_STATIC); 335 } 336 } 337 338 void 339 HU_Stop() 340 { 341 headsupactive = false; 342 } 343 344 void 345 HU_Start() 346 { 347 char* s; 348 int i; 349 350 if (headsupactive) 351 HU_Stop(); 352 plr = &players[consoleplayer]; 353 message_on = false; 354 message_dontfuckwithme = false; 355 message_nottobefuckedwith = false; 356 chat_on = false; 357 HUlib_initSText(&w_message, HU_MSGX, HU_MSGY, HU_MSGHEIGHT, hu_font, HU_FONTSTART, &message_on); 358 HUlib_initTextLine(&w_title, HU_TITLEX, HU_TITLEY, hu_font, HU_FONTSTART); 359 s = HU_TITLE; 360 while (*s) 361 HUlib_addCharToTextLine(&w_title, *(s++)); 362 HUlib_initIText(&w_chat, HU_INPUTX, HU_INPUTY, hu_font, HU_FONTSTART, &chat_on); 363 for (i = 0; i < MAXPLAYERS; ++i) 364 HUlib_initIText(&w_inputbuffer[i], 0, 0, 0, 0, &always_off); 365 headsupactive = true; 366 } 367 368 void 369 HU_Drawer() 370 { 371 HUlib_drawSText(&w_message); 372 HUlib_drawIText(&w_chat); 373 if (automapactive) 374 HUlib_drawTextLine(&w_title, false); 375 } 376 377 void 378 HU_Erase() 379 { 380 HUlib_eraseSText(&w_message); 381 HUlib_eraseIText(&w_chat); 382 HUlib_eraseTextLine(&w_title); 383 } 384 385 void 386 HU_Ticker() 387 { 388 int i, rc; 389 char c; 390 391 if (message_counter && !--message_counter) { 392 message_on = false; 393 message_nottobefuckedwith = false; 394 } 395 if (showMessages || message_dontfuckwithme) { 396 if ((plr->message && !message_nottobefuckedwith) || (plr->message && message_dontfuckwithme)) { 397 HUlib_addMessageToSText(&w_message, 0, plr->message); 398 plr->message = 0; 399 message_on = true; 400 message_counter = HU_MSGTIMEOUT; 401 message_nottobefuckedwith = message_dontfuckwithme; 402 message_dontfuckwithme = 0; 403 } 404 } 405 if (netgame) { 406 for (i = 0 ; i < MAXPLAYERS; ++i) { 407 if (!playeringame[i]) continue; 408 if (i != consoleplayer && (c = players[i].cmd.chatchar)) { 409 if (c <= HU_BROADCAST) 410 chat_dest[i] = c; 411 else { 412 if (c >= 'a' && c <= 'z') 413 c = (char) shiftxform[(unsigned char) c]; 414 rc = HUlib_keyInIText(&w_inputbuffer[i], c); 415 if (rc && c == KEY_ENTER) { 416 if (w_inputbuffer[i].l.len && (chat_dest[i] == consoleplayer+1 || chat_dest[i] == HU_BROADCAST)) { 417 HUlib_addMessageToSText(&w_message, lang[player_names[i]], w_inputbuffer[i].l.l); 418 message_nottobefuckedwith = true; 419 message_on = true; 420 message_counter = HU_MSGTIMEOUT; 421 S_StartSound(0, sfx_tink); 422 } 423 HUlib_resetIText(&w_inputbuffer[i]); 424 } 425 } 426 players[i].cmd.chatchar = 0; 427 } 428 } 429 } 430 } 431 432 433 void 434 HU_queueChatChar(char c) 435 { 436 if (((head + 1) & (QUEUESIZE-1)) == tail) 437 plr->message = lang[HUSTR_MSGU]; 438 else { 439 chatchars[head] = c; 440 head = (head + 1) & (QUEUESIZE-1); 441 } 442 } 443 444 char 445 HU_dequeueChatChar() 446 { 447 char c; 448 449 if (head != tail) { 450 c = chatchars[tail]; 451 tail = (tail + 1) & (QUEUESIZE-1); 452 } else c = 0; 453 return c; 454 } 455 456 boolean 457 HU_Responder(event_t *ev) 458 { 459 static char lastmessage[HU_MAXLINELENGTH+1]; 460 static boolean shiftdown = false; 461 static boolean altdown = false; 462 static int num_nobrainers = 0; 463 static char destination_keys[MAXPLAYERS] = { 'g', 'i', 'b', 'r' } ; 464 char* macromessage; 465 boolean eatkey; 466 unsigned char c; 467 int i, numplayers; 468 469 eatkey = false; 470 numplayers = 0; 471 for (i = 0; i < MAXPLAYERS; ++i) 472 numplayers += playeringame[i]; 473 if (ev->data1 == KEY_RSHIFT) { 474 shiftdown = ev->type == ev_keydown; 475 return false; 476 } 477 if (ev->data1 == KEY_RALT || ev->data1 == KEY_LALT) { 478 altdown = ev->type == ev_keydown; 479 return false; 480 } 481 if (ev->type != ev_keydown) 482 return false; 483 if (!chat_on) { 484 if (ev->data1 == HU_MSGREFRESH) { 485 message_on = true; 486 message_counter = HU_MSGTIMEOUT; 487 eatkey = true; 488 } 489 if (netgame && ev->data1 == HU_INPUTTOGGLE) { 490 eatkey = chat_on = true; 491 HUlib_resetIText(&w_chat); 492 HU_queueChatChar(HU_BROADCAST); 493 } 494 if (netgame && numplayers > 2) { 495 for (i = 0; i < MAXPLAYERS; ++i) { 496 if (ev->data1 == destination_keys[i]) { 497 if (playeringame[i] && i!=consoleplayer) { 498 eatkey = chat_on = true; 499 HUlib_resetIText(&w_chat); 500 HU_queueChatChar(i+1); 501 break; 502 } 503 if (i == consoleplayer) { 504 ++num_nobrainers; 505 if (num_nobrainers < 3) plr->message = lang[HUSTR_TALKTOSELF1]; 506 else if (num_nobrainers < 6) plr->message = lang[HUSTR_TALKTOSELF2]; 507 else if (num_nobrainers < 9) plr->message = lang[HUSTR_TALKTOSELF3]; 508 else if (num_nobrainers < 32) plr->message = lang[HUSTR_TALKTOSELF4]; 509 else plr->message = lang[HUSTR_TALKTOSELF5]; 510 } 511 } 512 } 513 } 514 } else { 515 c = ev->data1; 516 if (altdown) { 517 c = c - '0'; 518 if (c > 9) 519 return false; 520 macromessage = lang[chat_macros[c]]; 521 HU_queueChatChar(KEY_ENTER); 522 while (*macromessage) 523 HU_queueChatChar(*macromessage++); 524 HU_queueChatChar(KEY_ENTER); 525 chat_on = false; 526 strcpy(lastmessage, lang[chat_macros[c]]); 527 plr->message = lastmessage; 528 eatkey = true; 529 } else { 530 if (shiftdown || (c >= 'a' && c <= 'z')) 531 c = shiftxform[c]; 532 eatkey = HUlib_keyInIText(&w_chat, c); 533 if (eatkey) 534 HU_queueChatChar(c); 535 if (c == KEY_ENTER) { 536 chat_on = false; 537 if (w_chat.l.len) { 538 strcpy(lastmessage, w_chat.l.l); 539 plr->message = lastmessage; 540 } 541 } 542 if (c == KEY_ESCAPE) 543 chat_on = false; 544 } 545 } 546 return eatkey; 547 }