1 /**
2 * @file error.cpp
3 *
4 * Implementation of in-game message functions.
5 */
6 #include "all.h"
7
8 DEVILUTION_BEGIN_NAMESPACE
9
10 char msgtable[MAX_SEND_STR_LEN];
11 DWORD msgdelay;
12 char msgflag;
13 char msgcnt;
14
15 /** Maps from error_id to error message. */
16 const char *const MsgStrings[] = {
17 "",
18 "No automap available in town",
19 "No multiplayer functions in demo",
20 "Direct Sound Creation Failed",
21 "Not available in shareware version",
22 "Not enough space to save",
23 "No Pause in town",
24 "Copying to a hard disk is recommended",
25 "Multiplayer sync problem",
26 "No pause in multiplayer",
27 "Loading...",
28 "Saving...",
29 "Some are weakened as one grows strong",
30 "New strength is forged through destruction",
31 "Those who defend seldom attack",
32 "The sword of justice is swift and sharp",
33 "While the spirit is vigilant the body thrives",
34 "The powers of mana refocused renews",
35 "Time cannot diminish the power of steel",
36 "Magic is not always what it seems to be",
37 "What once was opened now is closed",
38 "Intensity comes at the cost of wisdom",
39 "Arcane power brings destruction",
40 "That which cannot be held cannot be harmed",
41 "Crimson and Azure become as the sun",
42 "Knowledge and wisdom at the cost of self",
43 "Drink and be refreshed",
44 "Wherever you go, there you are",
45 "Energy comes at the cost of wisdom",
46 "Riches abound when least expected",
47 "Where avarice fails, patience gains reward",
48 "Blessed by a benevolent companion!",
49 "The hands of men may be guided by fate",
50 "Strength is bolstered by heavenly faith",
51 "The essence of life flows from within",
52 "The way is made clear when viewed from above",
53 "Salvation comes at the cost of wisdom",
54 "Mysteries are revealed in the light of reason",
55 "Those who are last may yet be first",
56 "Generosity brings its own rewards",
57 "You must be at least level 8 to use this.",
58 "You must be at least level 13 to use this.",
59 "You must be at least level 17 to use this.",
60 "Arcane knowledge gained!",
61 "That which does not kill you...",
62 "Knowledge is power.",
63 "Give and you shall receive.",
64 "Some experience is gained by touch.",
65 "There's no place like home.",
66 "Spirtual energy is restored.",
67 "You feel more agile.",
68 "You feel stronger.",
69 "You feel wiser.",
70 "You feel refreshed.",
71 "That which can break will.",
72 };
73
InitDiabloMsg(char e)74 void InitDiabloMsg(char e)
75 {
76 int i;
77
78 if (msgcnt >= sizeof(msgtable))
79 return;
80
81 for (i = 0; i < msgcnt; i++) {
82 if (msgtable[i] == e)
83 return;
84 }
85
86 msgtable[msgcnt] = e; // BUGFIX: missing out-of-bounds check (fixed)
87 msgcnt++;
88
89 msgflag = msgtable[0];
90 msgdelay = SDL_GetTicks();
91 }
92
ClrDiabloMsg()93 void ClrDiabloMsg()
94 {
95 int i;
96
97 for (i = 0; i < sizeof(msgtable); i++)
98 msgtable[i] = 0;
99
100 msgflag = 0;
101 msgcnt = 0;
102 }
103
DrawDiabloMsg(CelOutputBuffer out)104 void DrawDiabloMsg(CelOutputBuffer out)
105 {
106 int i, len, width, sx, sy;
107 BYTE c;
108
109 CelDrawTo(out, PANEL_X + 101, DIALOG_Y, pSTextSlidCels, 1, 12);
110 CelDrawTo(out, PANEL_X + 527, DIALOG_Y, pSTextSlidCels, 4, 12);
111 CelDrawTo(out, PANEL_X + 101, DIALOG_Y + 48, pSTextSlidCels, 2, 12);
112 CelDrawTo(out, PANEL_X + 527, DIALOG_Y + 48, pSTextSlidCels, 3, 12);
113
114 sx = PANEL_X + 109;
115 for (i = 0; i < 35; i++) {
116 CelDrawTo(out, sx, DIALOG_Y, pSTextSlidCels, 5, 12);
117 CelDrawTo(out, sx, DIALOG_Y + 48, pSTextSlidCels, 7, 12);
118 sx += 12;
119 }
120 sy = DIALOG_Y + 12;
121 for (i = 0; i < 3; i++) {
122 CelDrawTo(out, PANEL_X + 101, sy, pSTextSlidCels, 6, 12);
123 CelDrawTo(out, PANEL_X + 527, sy, pSTextSlidCels, 8, 12);
124 sy += 12;
125 }
126
127 DrawHalfTransparentRectTo(out, PANEL_X + 104, DIALOG_Y - 8, 432, 54);
128
129 strcpy(tempstr, MsgStrings[msgflag]);
130 sx = PANEL_X + 101;
131 sy = DIALOG_Y + 24;
132 len = strlen(tempstr);
133 width = 0;
134
135 for (i = 0; i < len; i++) {
136 width += fontkern[fontframe[gbFontTransTbl[(BYTE)tempstr[i]]]] + 1;
137 }
138
139 if (width < 442) {
140 sx += (442 - width) >> 1;
141 }
142
143 for (i = 0; i < len; i++) {
144 c = fontframe[gbFontTransTbl[(BYTE)tempstr[i]]];
145 if (c != '\0') {
146 PrintChar(out, sx, sy, c, COL_GOLD);
147 }
148 sx += fontkern[c] + 1;
149 }
150
151 if (msgdelay > 0 && msgdelay <= SDL_GetTicks() - 3500) {
152 msgdelay = 0;
153 }
154 if (msgdelay == 0) {
155 msgcnt--;
156 if (msgcnt == 0) {
157 msgflag = 0;
158 } else {
159 msgflag = msgtable[msgcnt];
160 msgdelay = SDL_GetTicks();
161 }
162 }
163 }
164
165 DEVILUTION_END_NAMESPACE
166