-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
message.cc
2135 lines (1867 loc) · 55.8 KB
/
message.cc
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
* @brief Functions used to print messages.
**/
#include "AppHdr.h"
#include "message.h"
#include <sstream>
#include "areas.h"
#include "colour.h"
#include "delay.h"
#include "english.h"
#include "hints.h"
#include "initfile.h"
#include "libutil.h"
#ifdef WIZARD
#include "luaterp.h"
#endif
#include "menu.h"
#include "monster.h"
#include "mon-util.h"
#include "notes.h"
#include "output.h"
#include "religion.h"
#include "scroller.h"
#include "sound.h"
#include "state.h"
#include "stringutil.h"
#include "tiles-build-specific.h"
#include "unwind.h"
#include "view.h"
static void _mpr(string text, msg_channel_type channel=MSGCH_PLAIN, int param=0,
bool nojoin=false, bool cap=true);
void mpr(const string &text)
{
_mpr(text);
}
void mpr_nojoin(msg_channel_type channel, string text)
{
_mpr(text, channel, 0, true);
}
static bool _ends_in_punctuation(const string& text)
{
if (text.size() == 0)
return false;
switch (text[text.size() - 1])
{
case '.':
case '!':
case '?':
case ',':
case ';':
case ':':
return true;
default:
return false;
}
}
struct message_particle
{
string text; /// text of message (tagged string...)
int repeats; /// Number of times the message is in succession (x2)
string pure_text() const
{
return formatted_string::parse_string(text).tostring();
}
string with_repeats() const
{
// TODO: colour the repeats indicator?
string rep = "";
if (repeats > 1)
rep = make_stringf(" x%d", repeats);
return text + rep;
}
string pure_text_with_repeats() const
{
string rep = "";
if (repeats > 1)
rep = make_stringf(" x%d", repeats);
return pure_text() + rep;
}
/**
* If this is followed by another message particle on the same line,
* should there be a semicolon between them?
*/
bool needs_semicolon() const
{
return repeats > 1 || !_ends_in_punctuation(pure_text());
}
};
struct message_line
{
msg_channel_type channel; // message channel
int param; // param for channel (god, enchantment)
vector<message_particle> messages; // a set of possibly-repeated messages
int turn;
bool join; /// may we merge this message w/others?
message_line() : channel(NUM_MESSAGE_CHANNELS), param(0), turn(-1),
join(true)
{
}
message_line(string msg, msg_channel_type chan, int par, bool jn)
: channel(chan), param(par), turn(you.num_turns)
{
messages = { { msg, 1 } };
// Don't join long messages.
join = jn && strwidth(last_msg().pure_text()) < 40;
}
// Constructor for restored messages.
message_line(string text, msg_channel_type chan, int par, int trn)
: channel(chan), param(par), messages({{ text, 1 }}), turn(trn),
join(false)
{
}
operator bool() const
{
return !messages.empty();
}
const message_particle& last_msg() const
{
return messages.back();
}
// Tries to condense the argument into this message.
// Either *this needs to be an empty item, or it must be the
// same as the argument.
bool merge(const message_line& other)
{
if (! *this)
{
*this = other;
return true;
}
if (!other)
return true;
if (crawl_state.game_is_arena())
return false; // dangerous for hacky code (looks at EOL for '!'...)
if (!Options.msg_condense_repeats)
return false;
if (other.channel != channel || other.param != param)
return false;
if (other.messages.size() > 1)
{
return false; // not gonna try to handle this complexity
// shouldn't come up...
}
if (Options.msg_condense_repeats
&& other.last_msg().text == last_msg().text)
{
messages.back().repeats += other.last_msg().repeats;
return true;
}
else if (Options.msg_condense_short
&& turn == other.turn
&& join && other.join
&& _ends_in_punctuation(last_msg().pure_text())
== _ends_in_punctuation(other.last_msg().pure_text()))
// punct check is a hack to avoid pickup messages merging with
// combat on the same turn - should find a nicer heuristic
{
// "; " or " "?
const int seplen = last_msg().needs_semicolon() ? 2 : 1;
const int total_len = pure_len() + seplen + other.pure_len();
if (total_len > (int)msgwin_line_length())
return false;
// merge in other's messages; they'll be delimited when printing.
messages.insert(messages.end(),
other.messages.begin(), other.messages.end());
return true;
}
return false;
}
/// What's the length of the actual combined text of the particles, not
/// including non-rendering text (<red> etc)?
int pure_len() const
{
// could we do this more functionally?
int len = 0;
for (auto &msg : messages)
{
if (len > 0) // not first msg
len += msg.needs_semicolon() ? 2 : 1; // " " vs "; "
len += strwidth(msg.pure_text_with_repeats());
}
return len;
}
/// The full string, with elements joined as appropriate.
string full_text() const
{
string text = "";
bool needs_semicolon = false;
for (auto &msg : messages)
{
if (!text.empty())
{
text += make_stringf("<lightgrey>%s </lightgrey>",
needs_semicolon ? ";" : "");
}
text += msg.with_repeats();
needs_semicolon = msg.needs_semicolon();
}
return text;
}
string pure_text_with_repeats() const
{
return formatted_string::parse_string(full_text()).tostring();
}
};
static int _mod(int num, int denom)
{
ASSERT(denom > 0);
div_t res = div(num, denom);
return res.rem >= 0 ? res.rem : res.rem + denom;
}
template <typename T, int SIZE>
class circ_vec
{
T data[SIZE];
int end; // first unfilled index
bool has_circled;
// TODO: properly track the tail, and make this into a real data
// structure with an iterator and whatnot
static void inc(int* index)
{
ASSERT_RANGE(*index, 0, SIZE);
*index = _mod(*index + 1, SIZE);
}
static void dec(int* index)
{
ASSERT_RANGE(*index, 0, SIZE);
*index = _mod(*index - 1, SIZE);
}
public:
circ_vec() : end(0), has_circled(false) {}
void clear()
{
end = 0;
has_circled = false;
for (int i = 0; i < SIZE; ++i)
data[i] = T();
}
int size() const
{
return SIZE;
}
int filled_size() const
{
if (has_circled)
return SIZE;
else
return end;
}
T& operator[](int i)
{
ASSERT(_mod(i, SIZE) < size());
return data[_mod(end + i, SIZE)];
}
const T& operator[](int i) const
{
ASSERT(_mod(i, SIZE) < size());
return data[_mod(end + i, SIZE)];
}
void push_back(const T& item)
{
data[end] = item;
inc(&end);
if (end == 0)
has_circled = true;
}
void roll_back(int n)
{
for (int i = 0; i < n; ++i)
{
dec(&end);
data[end] = T();
}
// don't bother to worry about has_circled in this case
// TODO: properly track the tail
}
/**
* Append the contents of `buf` to the current buffer.
* If `buf` has cycled, this will overwrite the entire contents of `this`.
*/
void append(const circ_vec<T, SIZE> buf)
{
const int buf_size = buf.filled_size();
for (int i = 0; i < buf_size; i++)
push_back(buf[i - buf_size]);
}
};
static void readkey_more(bool user_forced=false);
// Types of message prefixes.
// Higher values override lower.
enum class prefix_type
{
none,
turn_start,
turn_end,
new_cmd, // new command, but no new turn
new_turn,
full_more, // single-character more prompt (full window)
other_more, // the other type of --more-- prompt
};
// Could also go with coloured glyphs.
static cglyph_t _prefix_glyph(prefix_type p)
{
cglyph_t g;
switch (p)
{
case prefix_type::turn_start:
g.ch = Options.show_newturn_mark ? '-' : ' ';
g.col = LIGHTGRAY;
break;
case prefix_type::turn_end:
case prefix_type::new_turn:
g.ch = Options.show_newturn_mark ? '_' : ' ';
g.col = LIGHTGRAY;
break;
case prefix_type::new_cmd:
g.ch = Options.show_newturn_mark ? '_' : ' ';
g.col = DARKGRAY;
break;
case prefix_type::full_more:
g.ch = '+';
g.col = channel_to_colour(MSGCH_PROMPT);
break;
case prefix_type::other_more:
g.ch = '+';
g.col = LIGHTRED;
break;
default:
g.ch = ' ';
g.col = LIGHTGRAY;
break;
}
return g;
}
static bool _pre_more();
static bool _temporary = false;
class message_window
{
int next_line;
int temp_line; // starting point of temporary messages
int input_line; // last line-after-input
vector<formatted_string> lines;
prefix_type prompt; // current prefix prompt
int height() const
{
return crawl_view.msgsz.y;
}
int use_last_line() const
{
return first_col_more();
}
int width() const
{
return crawl_view.msgsz.x;
}
void out_line(const formatted_string& line, int n) const
{
cgotoxy(1, n + 1, GOTO_MSG);
line.display();
cprintf("%*s", width() - line.width(), "");
}
// Place cursor at end of last non-empty line to handle prompts.
// TODO: might get rid of this by clearing the whole window when writing,
// and then just writing the actual non-empty lines.
void place_cursor()
{
// XXX: the screen may have resized since the last time we
// called lines.resize(). Consider only the last height()
// lines if this has happened.
const int diff = max(int(lines.size()) - height(), 0);
int i;
for (i = lines.size() - 1; i >= diff && lines[i].width() == 0; --i)
;
if (i >= diff)
{
// If there was room, put the cursor at the end of that line.
// Otherwise, put it at the beginning of the next line.
if ((int) lines[i].width() < crawl_view.msgsz.x)
cgotoxy(lines[i].width() + 1, i - diff + 1, GOTO_MSG);
else if (i - diff + 2 <= height())
cgotoxy(1, i - diff + 2, GOTO_MSG);
else
{
// Scroll to make room for the next line, then redraw.
scroll(1);
// Results in a recursive call to place_cursor! But scroll()
// made lines[height()] empty, so that recursive call shouldn't
// hit this case again.
show();
return;
}
}
else
{
// If there were no lines, put the cursor at the upper left.
cgotoxy(1, 1, GOTO_MSG);
}
}
// Whether to show msgwin-full more prompts.
bool more_enabled() const
{
return crawl_state.show_more_prompt
&& (Options.clear_messages || Options.show_more);
}
int make_space(int n)
{
int space = out_height() - next_line;
if (space >= n)
return 0;
int s = 0;
if (input_line > 0)
{
s = min(input_line, n - space);
scroll(s);
space += s;
}
if (space >= n)
return s;
if (more_enabled())
more(true);
// We could consider just scrolling off after --more--;
// that would require marking the last message before
// the prompt.
if (!Options.clear_messages && !more_enabled())
{
scroll(n - space);
return s + n - space;
}
else
{
clear();
return height();
}
}
void add_line(const formatted_string& line)
{
resize(); // TODO: get rid of this
lines[next_line] = line;
next_line++;
}
void output_prefix(prefix_type p)
{
if (!use_first_col())
return;
if (p <= prompt)
return;
prompt = p;
if (next_line > 0)
{
formatted_string line;
line.add_glyph(_prefix_glyph(prompt));
lines[next_line-1].del_char();
line += lines[next_line-1];
lines[next_line-1] = line;
}
show();
}
public:
message_window()
: next_line(0), temp_line(0), input_line(0), prompt(prefix_type::none)
{
clear_lines(); // initialize this->lines
}
void resize()
{
// XXX: broken (why?)
lines.resize(height());
}
unsigned int out_width() const
{
return width() - (use_first_col() ? 1 : 0);
}
unsigned int out_height() const
{
return height() - (use_last_line() ? 0 : 1);
}
void clear_lines()
{
lines.clear();
lines.resize(height());
}
bool first_col_more() const
{
return Options.small_more;
}
bool use_first_col() const
{
return !Options.clear_messages;
}
void set_starting_line()
{
// TODO: start at end (sometimes?)
next_line = 0;
input_line = 0;
temp_line = 0;
}
void clear()
{
clear_lines();
set_starting_line();
show();
}
void scroll(int n)
{
// We might be asked to scroll off everything by the line reader.
if (next_line < n)
n = next_line;
int i;
for (i = 0; i < height() - n; ++i)
lines[i] = lines[i + n];
for (; i < height(); ++i)
lines[i].clear();
next_line -= n;
temp_line -= n;
input_line -= n;
}
// write to screen (without refresh)
void show()
{
// XXX: this should not be necessary as formatted_string should
// already do it
textcolour(LIGHTGREY);
// XXX: the screen may have resized since the last time we
// called lines.resize(). Consider only the last height()
// lines if this has happened.
const int diff = max(int(lines.size()) - height(), 0);
for (size_t i = diff; i < lines.size(); ++i)
out_line(lines[i], i - diff);
place_cursor();
#ifdef USE_TILE
tiles.set_need_redraw();
#endif
}
// temporary: to be overwritten with next item, e.g. new turn
// leading dash or prompt without response
void add_item(string text, prefix_type first_col = prefix_type::none,
bool temporary = false)
{
prompt = prefix_type::none; // reset prompt
vector<formatted_string> newlines;
linebreak_string(text, out_width());
formatted_string::parse_string_to_multiple(text, newlines);
for (const formatted_string &nl : newlines)
{
make_space(1);
formatted_string line;
if (use_first_col())
line.add_glyph(_prefix_glyph(first_col));
line += nl;
add_line(line);
}
if (!temporary)
reset_temp();
show();
}
void roll_back()
{
temp_line = max(temp_line, 0);
for (int i = temp_line; i < next_line; ++i)
lines[i].clear();
next_line = temp_line;
}
/**
* Consider any formerly-temporary messages permanent.
*/
void reset_temp()
{
temp_line = next_line;
}
void got_input()
{
input_line = next_line;
}
void new_cmdturn(bool new_turn)
{
output_prefix(new_turn ? prefix_type::new_turn : prefix_type::new_cmd);
}
bool any_messages()
{
return next_line > input_line;
}
/*
* Handling of more prompts (both types).
*/
void more(bool full, bool user=false)
{
if (_pre_more())
return;
print_stats();
show();
int last_row = crawl_view.msgsz.y;
if (first_col_more())
{
cgotoxy(1, last_row, GOTO_MSG);
cglyph_t g = _prefix_glyph(full ? prefix_type::full_more : prefix_type::other_more);
formatted_string f;
f.add_glyph(g);
f.display();
// Move cursor back for nicer display.
cgotoxy(1, last_row, GOTO_MSG);
// Need to read_key while cursor_control in scope.
cursor_control con(true);
readkey_more();
}
else
{
cgotoxy(use_first_col() ? 2 : 1, last_row, GOTO_MSG);
textcolour(channel_to_colour(MSGCH_PROMPT));
if (crawl_state.game_is_hints())
{
string more_str = "--more-- Press Space ";
if (is_tiles())
more_str += "or click ";
more_str += "to continue. You can later reread messages with "
"Ctrl-P.";
cprintf(more_str.c_str());
}
else
cprintf("--more--");
readkey_more(user);
}
}
};
message_window msgwin;
void display_message_window()
{
msgwin.show();
}
void clear_message_window()
{
msgwin = message_window();
}
void scroll_message_window(int n)
{
msgwin.scroll(n);
msgwin.show();
}
bool any_messages()
{
return msgwin.any_messages();
}
typedef circ_vec<message_line, NUM_STORED_MESSAGES> store_t;
class message_store
{
store_t msgs;
message_line prev_msg;
bool last_of_turn;
int temp; // number of temporary messages
#ifdef USE_TILE_WEB
int unsent; // number of messages not yet sent to the webtiles client
int client_rollback;
bool send_ignore_one;
#endif
public:
message_store() : last_of_turn(false), temp(0)
#ifdef USE_TILE_WEB
, unsent(0), client_rollback(0), send_ignore_one(false)
#endif
{}
void add(const message_line& msg)
{
string orig_full_text = msg.full_text();
if (!(msg.channel != MSGCH_PROMPT && prev_msg.merge(msg)))
{
flush_prev();
prev_msg = msg;
if (msg.channel == MSGCH_PROMPT || _temporary)
flush_prev();
}
// If we play sound, wait until the corresponding message is printed
// in case we intend on holding up output that comes after.
//
// FIXME This doesn't work yet, and causes the game to play the sound,
// THEN display the text. This appears to only be solvable by reworking
// the way the game outputs messages, as the game it prints messages
// one line at a time, not one message at a time.
//
// However, it should only print one message at a time when it really
// needs to, i.e. an sound that interrupts the game. Otherwise it is
// more efficent to print text together.
#ifdef USE_SOUND
play_sound(check_sound_patterns(orig_full_text));
#endif
}
void store_msg(const message_line& msg)
{
prefix_type p = prefix_type::none;
msgs.push_back(msg);
if (_temporary)
temp++;
else
reset_temp();
#ifdef USE_TILE_WEB
// ignore this message until it's actually displayed in case we run out
// of space and have to display --more-- instead
unwind_bool dontsend(send_ignore_one, true);
#endif
if (crawl_state.io_inited && crawl_state.game_started)
msgwin.add_item(msg.full_text(), p, _temporary);
}
void roll_back()
{
#ifdef USE_TILE_WEB
client_rollback = max(0, temp - unsent);
unsent = max(0, unsent - temp);
#endif
msgs.roll_back(temp);
temp = 0;
}
void reset_temp()
{
temp = 0;
}
void flush_prev()
{
if (!prev_msg)
return;
message_line msg = prev_msg;
// Clear prev_msg before storing it, since
// writing out to the message window might
// in turn result in a recursive flush_prev.
prev_msg = message_line();
#ifdef USE_TILE_WEB
unsent++;
#endif
store_msg(msg);
if (last_of_turn)
{
msgwin.new_cmdturn(true);
last_of_turn = false;
}
}
void new_turn()
{
if (prev_msg)
last_of_turn = true;
else
msgwin.new_cmdturn(true);
}
// XXX: this should not need to exist
const store_t& get_store()
{
return msgs;
}
void append_store(store_t store)
{
msgs.append(store);
const int msgs_to_print = store.filled_size();
#ifdef USE_TILE_WEB
unwind_bool dontsend(send_ignore_one, true);
#endif
for (int i = 0; i < msgs_to_print; i++)
msgwin.add_item(msgs[i - msgs_to_print].full_text(), prefix_type::none, false);
}
void clear()
{
msgs.clear();
prev_msg = message_line();
last_of_turn = false;
temp = 0;
#ifdef USE_TILE_WEB
unsent = 0;
#endif
}
#ifdef USE_TILE_WEB
void send()
{
if (unsent == 0 || (send_ignore_one && unsent == 1)) return;
if (client_rollback > 0)
{
tiles.json_write_int("rollback", client_rollback);
client_rollback = 0;
}
tiles.json_open_array("messages");
for (int i = -unsent; i < (send_ignore_one ? -1 : 0); ++i)
{
message_line& msg = msgs[i];
tiles.json_open_object();
tiles.json_write_string("text", msg.full_text());
tiles.json_write_int("turn", msg.turn);
tiles.json_write_int("channel", msg.channel);
tiles.json_close_object();
}
tiles.json_close_array();
unsent = send_ignore_one ? 1 : 0;
}
#endif
};
// Circular buffer for keeping past messages.
message_store buffer;
#ifdef USE_TILE_WEB
bool _more = false, _last_more = false;
void webtiles_send_messages()
{
// defer sending any messages to client in this form until a game is
// started up. It's still possible to send them as a popup. When this is
// eventually called, it'll send any queued messages.
if (!crawl_state.io_inited || !crawl_state.game_started)
return;
tiles.json_open_object();
tiles.json_write_string("msg", "msgs");
tiles.json_treat_as_empty();
if (_more != _last_more)
{
tiles.json_write_bool("more", _more);
_last_more = _more;
}
buffer.send();
tiles.json_close_object(true);
tiles.finish_message();
}
#else
void webtiles_send_messages() { }
#endif
static FILE* _msg_dump_file = nullptr;
static bool suppress_messages = false;
static msg_colour_type prepare_message(const string& imsg,
msg_channel_type channel,
int param);
no_messages::no_messages() : msuppressed(suppress_messages)
{
suppress_messages = true;
}
// Push useful RAII conditional logic into a constructor
// Won't override an outer suppressing no_messages
no_messages::no_messages(bool really_suppress) : msuppressed(suppress_messages)
{
suppress_messages = suppress_messages || really_suppress;
}
no_messages::~no_messages()
{
suppress_messages = msuppressed;
}
msg_colour_type msg_colour(int col)
{
return static_cast<msg_colour_type>(col);
}
static int colour_msg(msg_colour_type col)
{
if (col == MSGCOL_MUTED)
return DARKGREY;
else
return static_cast<int>(col);
}
// Returns a colour or MSGCOL_MUTED.
static msg_colour_type channel_to_msgcol(msg_channel_type channel, int param)
{
msg_colour_type 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 spread to other channels here.
// The intent of plain is to give non-coloured messages, not to
// suppress them.
if (Options.channels[MSGCH_PLAIN] >= MSGCOL_DEFAULT)
ret = MSGCOL_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)
? msg_colour(god_colour(static_cast<god_type>(param)))
: msg_colour(god_message_altar_colour(static_cast<god_type>(param)));
break;
case MSGCH_DURATION:
ret = MSGCOL_LIGHTBLUE;
break;