1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
|
/*
* File: message.cc
* Summary: Functions used to print messages.
* Written by: Linley Henzell
*
* Change History (most recent first):
*
* <3> 5/20/99 BWR Extended screen lines support
* <2> 5/08/99 JDJ mpr takes a const char* instead of a char array.
* <1> -/--/-- LRH Created
*/
#include "AppHdr.h"
#include "message.h"
#include "religion.h"
#include <string.h>
#ifdef DOS
#include <conio.h>
#endif
#include "externs.h"
#include "stuff.h"
#include "view.h"
#ifdef MACROS
#include "macro.h"
#endif
// circular buffer for keeping past messages
message_item Store_Message[ NUM_STORED_MESSAGES ]; // buffer of old messages
int Next_Message = 0; // end of messages
char Message_Line = 0; // line of next (previous?) message
static char god_message_altar_colour( char god )
{
int rnd;
switch (god)
{
case GOD_SHINING_ONE:
return (YELLOW);
case GOD_ZIN:
return (WHITE);
case GOD_ELYVILON:
return (LIGHTBLUE); // really, LIGHTGREY but that's plain text
case GOD_OKAWARU:
return (CYAN);
case GOD_YREDELEMNUL:
return (coinflip() ? DARKGREY : RED);
case GOD_KIKUBAAQUDGHA:
return (DARKGREY);
case GOD_XOM:
return (random2(15) + 1);
case GOD_VEHUMET:
rnd = random2(3);
return ((rnd == 0) ? LIGHTMAGENTA :
(rnd == 1) ? LIGHTRED
: LIGHTBLUE);
case GOD_MAKHLEB:
rnd = random2(3);
return ((rnd == 0) ? RED :
(rnd == 1) ? LIGHTRED
: YELLOW);
case GOD_TROG:
return (RED);
case GOD_NEMELEX_XOBEH:
return (LIGHTMAGENTA);
case GOD_SIF_MUNA:
return (BLUE);
case GOD_NO_GOD:
default:
return(YELLOW);
}
}
#ifdef USE_COLOUR_MESSAGES
// returns a colour or MSGCOL_MUTED
static char channel_to_colour( int channel, int param )
{
char ret;
switch (Options.channels[ channel ])
{
case MSGCOL_PLAIN:
// note that if the plain channel is muted, then we're protecting
// the player from having that spead to other other channels here.
// The intent of plain is to give non-coloured messages, not to
// supress them.
if (Options.channels[ MSGCH_PLAIN ] >= MSGCOL_DEFAULT)
ret = LIGHTGREY;
else
ret = Options.channels[ MSGCH_PLAIN ];
break;
case MSGCOL_DEFAULT:
case MSGCOL_ALTERNATE:
switch (channel)
{
case MSGCH_GOD:
ret = (Options.channels[ channel ] == MSGCOL_DEFAULT)
? god_colour( param )
: god_message_altar_colour( param );
break;
case MSGCH_DURATION:
ret = LIGHTBLUE;
break;
case MSGCH_DANGER:
ret = RED;
break;
case MSGCH_WARN:
ret = LIGHTRED;
break;
case MSGCH_FOOD:
ret = YELLOW;
break;
case MSGCH_INTRINSIC_GAIN:
ret = GREEN;
break;
case MSGCH_RECOVERY:
ret = LIGHTGREEN;
break;
case MSGCH_TALK:
ret = WHITE;
break;
case MSGCH_MONSTER_SPELL:
case MSGCH_MONSTER_ENCHANT:
ret = LIGHTMAGENTA;
break;
case MSGCH_MONSTER_DAMAGE:
ret = ((param == MDAM_DEAD) ? RED :
(param >= MDAM_HORRIBLY_DAMAGED) ? LIGHTRED :
(param >= MDAM_MODERATELY_DAMAGED) ? YELLOW
: LIGHTGREY);
break;
case MSGCH_PROMPT:
ret = CYAN;
break;
case MSGCH_DIAGNOSTIC:
ret = DARKGREY; // makes is easier to ignore at times -- bwr
break;
case MSGCH_PLAIN:
case MSGCH_ROTTEN_MEAT:
case MSGCH_EQUIPMENT:
default:
ret = LIGHTGREY;
break;
}
break;
case MSGCOL_MUTED:
ret = MSGCOL_MUTED;
break;
default:
// Setting to a specific colour is handled here, special
// cases should be handled above.
if (channel == MSGCH_MONSTER_DAMAGE)
{
// a special case right now for monster damage (at least until
// the init system is improved)... selecting a specific
// colour here will result in only the death messages coloured
if (param == MDAM_DEAD)
ret = Options.channels[ channel ];
else if (Options.channels[ MSGCH_PLAIN ] >= MSGCOL_DEFAULT)
ret = LIGHTGREY;
else
ret = Options.channels[ MSGCH_PLAIN ];
}
else
ret = Options.channels[ channel ];
break;
}
return (ret);
}
#else // don't use colour messages
static char channel_to_colour( int channel, int param )
{
return (LIGHTGREY);
}
#endif
void mpr(const char *inf, int channel, int param)
{
char info2[80];
int colour = channel_to_colour( channel, param );
if (colour == MSGCOL_MUTED)
return;
you.running = 0;
#ifdef DOS_TERM
window(1, 1, 80, 25);
#endif
textcolor(LIGHTGREY);
if (Message_Line == get_number_of_lines() - 18) // ( Message_Line == 8 )
more();
gotoxy(1, Message_Line + 18); // (1, Message_Line + 17)
strncpy(info2, inf, 78);
info2[78] = 0;
textcolor( colour );
cprintf(info2);
//
// reset colour
textcolor(LIGHTGREY);
Message_Line++;
// equipment lists just waste space in the message recall
if (channel != MSGCH_EQUIPMENT)
{
/* Put the message into Store_Message, and move the '---' line forward */
Store_Message[ Next_Message ].text = inf;
Store_Message[ Next_Message ].channel = channel;
Store_Message[ Next_Message ].param = param;
Next_Message++;
if (Next_Message >= NUM_STORED_MESSAGES)
Next_Message = 0;
}
} // end mpr()
bool any_messages(void)
{
return (Message_Line > 0);
}
void mesclr(void)
{
// if no messages, return.
if (Message_Line == 0)
return;
// turn cursor off -- avoid 'cursor dance'
_setcursortype(_NOCURSOR);
#ifdef DOS_TERM
window(1, 18, 78, 25);
clrscr();
window(1, 1, 80, 25);
#endif
#ifdef PLAIN_TERM
int startLine = 18;
gotoxy(1, startLine);
#ifdef LINUX
clear_to_end_of_screen();
#else
int numLines = get_number_of_lines() - startLine + 1;
for (int i = 0; i < numLines; i++)
{
cprintf( " " );
if (i < numLines - 1)
{
cprintf(EOL);
}
}
#endif
#endif
// turn cursor back on
_setcursortype(_NORMALCURSOR);
Message_Line = 0;
} // end mseclr()
void more(void)
{
char keypress = 0;
#ifdef PLAIN_TERM
gotoxy(2, get_number_of_lines());
#endif
#ifdef DOS_TERM
window(1, 18, 80, 25);
gotoxy(2, 7);
#endif
textcolor(LIGHTGREY);
//cdl -- cprintf("\r--more--");
#ifdef DOS
cprintf(EOL);
#endif
cprintf("--more--");
do
{
keypress = getch();
}
while (keypress != 32 && keypress != 13);
/* Juho Snellman rewrote this part of the function: */
mesclr();
} // end more()
void replay_messages(void)
{
int win_start_line = 0;
unsigned char keyin;
bool full_buffer = true;
int num_msgs = NUM_STORED_MESSAGES;
int first_message = Next_Message;
const int num_lines = get_number_of_lines();
if (Store_Message[ NUM_STORED_MESSAGES - 1 ].text.length() == 0)
{
full_buffer = false;
first_message = 0;
num_msgs = Next_Message;
}
int last_message = Next_Message - 1;
if (last_message < 0)
last_message += NUM_STORED_MESSAGES;
#ifdef DOS_TERM
char buffer[4800];
window(1, 1, 80, 25);
gettext(1, 1, 80, 25, buffer);
#endif
// track back a screen's worth of messages from the end
win_start_line = Next_Message - (num_lines - 2);
if (win_start_line < 0)
{
if (full_buffer)
win_start_line += NUM_STORED_MESSAGES;
else
win_start_line = 0;
}
for(;;)
{
// turn cursor off
_setcursortype(_NOCURSOR);
clrscr();
gotoxy(1, 1);
for (int i = 0; i < num_lines - 2; i++)
{
// calculate line in circular buffer
int line = win_start_line + i;
if (line >= NUM_STORED_MESSAGES)
line -= NUM_STORED_MESSAGES;
// avoid wrap-around
if (line == first_message && i != 0)
break;
int colour = channel_to_colour( Store_Message[ line ].channel,
Store_Message[ line ].param );
if (colour == MSGCOL_MUTED)
continue;
textcolor( colour );
#if DEBUG_DIAGNOSTICS
cprintf( "%d: %s", line, Store_Message[ line ].text.c_str() );
#else
cprintf( Store_Message[ line ].text.c_str() );
#endif
cprintf(EOL);
textcolor(LIGHTGREY);
}
// print a footer -- note: relative co-ordinates start at 1
int rel_start;
if (!full_buffer)
{
if (Next_Message == 0) // no messages!
rel_start = 0;
else
rel_start = win_start_line + 1;
}
else if (win_start_line >= first_message)
rel_start = win_start_line - first_message + 1;
else
rel_start = (win_start_line + NUM_STORED_MESSAGES) - first_message + 1;
int rel_end = rel_start + (num_lines - 2) - 1;
if (rel_end > num_msgs)
rel_end = num_msgs;
cprintf( "-------------------------------------------------------------------------------" );
cprintf(EOL);
cprintf( "<< Lines %d-%d of %d >>", rel_start, rel_end, num_msgs );
// turn cursor back on
_setcursortype(_NORMALCURSOR);
keyin = get_ch();
if ((full_buffer && NUM_STORED_MESSAGES > num_lines - 2)
|| (!full_buffer && Next_Message > num_lines - 2))
{
int new_line;
int end_mark;
if (keyin == 'k' || keyin == '8' || keyin == '-')
{
new_line = win_start_line - (num_lines - 2);
// end_mark is equivalent to Next_Message, but
// is always less than win_start_line.
end_mark = first_message;
if (end_mark > win_start_line)
end_mark -= NUM_STORED_MESSAGES;
ASSERT( end_mark <= win_start_line );
if (new_line <= end_mark)
new_line = end_mark; // hit top
// handle wrap-around
if (new_line < 0)
{
if (full_buffer)
new_line += NUM_STORED_MESSAGES;
else
new_line = 0;
}
}
else if (keyin == 'j' || keyin == '2' || keyin == '+')
{
new_line = win_start_line + (num_lines - 2);
// as above, but since we're adding we want
// this mark to always be greater.
end_mark = last_message;
if (end_mark < win_start_line)
end_mark += NUM_STORED_MESSAGES;
ASSERT( end_mark >= win_start_line );
// hit bottom
if (new_line >= end_mark - (num_lines - 2))
new_line = end_mark - (num_lines - 2) + 1;
if (new_line >= NUM_STORED_MESSAGES)
new_line -= NUM_STORED_MESSAGES;
}
else
break;
win_start_line = new_line;
}
else
{
if (keyin != 'k' && keyin != '8' && keyin != '-'
&& keyin != 'j' && keyin != '2' && keyin != '+')
{
break;
}
}
}
#ifdef DOS_TERM
puttext(1, 1, 80, 25, buffer);
#endif
return;
} // end replay_messages()
|