Debian Codegraph @

prboom2/src/hexen/f_finale.c

raw
1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16
17 #include "doomstat.h"
18 #include "w_wad.h"
19 #include "v_video.h"
20 #include "s_sound.h"
21 #include "sounds.h"
22 #include "lprintf.h"
23
24 #include "dsda/palette.h"
25
26 #include "hexen/f_finale.h"
27
28 #define TEXTSPEED 3
29 #define TEXTWAIT 250
30
31 static void TextWrite(void);
32 static void DrawPic(void);
33 static void InitializeFade(dboolean fadeIn);
34 static void DeInitializeFade(void);
35 static void FadePic(void);
36 static char *GetFinaleText(int sequence);
37
38 static int FinaleStage;
39 static int FinaleCount;
40 static int FinaleEndCount;
41 static const char* FinaleLumpName;
42 static int FontABaseLump;
43 static char *FinaleText;
44
45 // static fixed_t *Palette;
46 // static fixed_t *PaletteDelta;
47 // static byte *RealPalette;
48
49 void Hexen_F_StartFinale(void)
50 {
51 gameaction = ga_nothing;
52 gamestate = GS_FINALE;
53 automap_active = false;
54
55 FinaleStage = 0;
56 FinaleCount = 0;
57 FinaleText = GetFinaleText(0);
58 FinaleEndCount = 70;
59 FinaleLumpName = "FINALE1";
60 FontABaseLump = W_GetNumForName("FONTA_S") + 1;
61 InitializeFade(1);
62
63 S_StartSongName("hall", false); // don't loop the song
64 }
65
66 dboolean Hexen_F_Responder(event_t * event)
67 {
68 return false;
69 }
70
71 void Hexen_F_Ticker(void)
72 {
73 FinaleCount++;
74 if (FinaleStage < 5 && FinaleCount >= FinaleEndCount)
75 {
76 FinaleCount = 0;
77 FinaleStage++;
78 switch (FinaleStage)
79 {
80 case 1: // Text 1
81 FinaleEndCount = strlen(FinaleText) * TEXTSPEED + TEXTWAIT;
82 break;
83 case 2: // Pic 2, Text 2
84 FinaleText = GetFinaleText(1);
85 FinaleEndCount = strlen(FinaleText) * TEXTSPEED + TEXTWAIT;
86 FinaleLumpName = "FINALE2";
87 S_StartSongName("orb", false);
88 break;
89 case 3: // Pic 2 -- Fade out
90 FinaleEndCount = 70;
91 DeInitializeFade();
92 InitializeFade(0);
93 break;
94 case 4: // Pic 3 -- Fade in
95 FinaleLumpName = "FINALE3";
96 FinaleEndCount = 71;
97 DeInitializeFade();
98 InitializeFade(1);
99 S_StartSongName("chess", true);
100 break;
101 case 5: // Pic 3 , Text 3
102 FinaleText = GetFinaleText(2);
103 DeInitializeFade();
104 break;
105 default:
106 break;
107 }
108 return;
109 }
110 if (FinaleStage == 0 || FinaleStage == 3 || FinaleStage == 4)
111 {
112 FadePic();
113 }
114 }
115
116 static void TextWrite(void)
117 {
118 int count;
119 char *ch;
120 int c;
121 int cx, cy;
122 int lump;
123 int width;
124
125 V_DrawRawScreen(FinaleLumpName);
126 if (FinaleStage == 5)
127 { // Chess pic, draw the correct character graphic
128 if (netgame)
129 {
130 V_DrawNamePatch(20, 0, 0, "chessall", CR_DEFAULT, VPT_STRETCH);
131 }
132 else if (PlayerClass[consoleplayer] > 1)
133 {
134 V_DrawNumPatch(60, 0, 0,
135 W_GetNumForName("chessc") + PlayerClass[consoleplayer] - 2,
136 CR_DEFAULT, VPT_STRETCH);
137 }
138 }
139 // Draw the actual text
140 if (FinaleStage == 5)
141 {
142 cy = 135;
143 }
144 else
145 {
146 cy = 5;
147 }
148 cx = 20;
149 ch = FinaleText;
150 count = (FinaleCount - 10) / TEXTSPEED;
151 if (count < 0)
152 {
153 count = 0;
154 }
155 for (; count; count--)
156 {
157 c = *ch++;
158 if (!c)
159 {
160 break;
161 }
162 if (c == '\n')
163 {
164 cx = 20;
165 cy += 9;
166 continue;
167 }
168 if (c < 32)
169 {
170 continue;
171 }
172 c = toupper(c);
173 if (c == 32)
174 {
175 cx += 5;
176 continue;
177 }
178 lump = FontABaseLump + c - 33;
179 width = R_NumPatchWidth(lump);
180 if (cx + width > SCREENWIDTH)
181 {
182 break;
183 }
184 V_DrawNumPatch(cx, cy, 0, lump, CR_DEFAULT, VPT_STRETCH);
185 cx += width;
186 }
187 }
188
189 // hexen_note: dynamic palette editing
190 static void InitializeFade(dboolean fadeIn)
191 {
192 // unsigned i;
193 //
194 // Palette = Z_Malloc(768 * sizeof(fixed_t));
195 // PaletteDelta = Z_Malloc(768 * sizeof(fixed_t),);
196 // RealPalette = Z_Malloc(768 * sizeof(byte));
197 //
198 // if (fadeIn)
199 // {
200 // memset(RealPalette, 0, 768 * sizeof(byte));
201 // for (i = 0; i < 768; i++)
202 // {
203 // Palette[i] = 0;
204 // PaletteDelta[i] = FixedDiv((*((byte *) W_LumpByName("playpal") +
205 // i)) << FRACBITS, 70 * FRACUNIT);
206 // }
207 // }
208 // else
209 // {
210 // for (i = 0; i < 768; i++)
211 // {
212 // RealPalette[i] =
213 // *((byte *) W_LumpByName("playpal") + i);
214 // Palette[i] = RealPalette[i] << FRACBITS;
215 // PaletteDelta[i] = FixedDiv(Palette[i], -70 * FRACUNIT);
216 // }
217 // }
218 // I_SetPalette(RealPalette);
219 }
220
221 static void DeInitializeFade(void)
222 {
223 // Z_Free(Palette);
224 // Z_Free(PaletteDelta);
225 // Z_Free(RealPalette);
226 }
227
228 static void FadePic(void)
229 {
230 // unsigned i;
231 //
232 // for (i = 0; i < 768; i++)
233 // {
234 // Palette[i] += PaletteDelta[i];
235 // RealPalette[i] = Palette[i] >> FRACBITS;
236 // }
237 // I_SetPalette(RealPalette);
238 }
239
240 static void DrawPic(void)
241 {
242 V_DrawRawScreen(FinaleLumpName);
243 if (FinaleStage == 4 || FinaleStage == 5)
244 { // Chess pic, draw the correct character graphic
245 if (netgame)
246 {
247 V_DrawNamePatch(20, 0, 0, "chessall", CR_DEFAULT, VPT_STRETCH);
248 }
249 else if (PlayerClass[consoleplayer] > 1)
250 {
251 V_DrawNumPatch(60, 0, 0,
252 W_GetNumForName("chessc") + PlayerClass[consoleplayer] - 2,
253 CR_DEFAULT, VPT_STRETCH);
254 }
255 }
256 }
257
258 void Hexen_F_Drawer(void)
259 {
260 switch (FinaleStage)
261 {
262 case 0: // Fade in initial finale screen
263 DrawPic();
264 break;
265 case 1:
266 case 2:
267 TextWrite();
268 break;
269 case 3: // Fade screen out
270 DrawPic();
271 break;
272 case 4: // Fade in chess screen
273 DrawPic();
274 break;
275 case 5:
276 TextWrite();
277 break;
278 }
279 }
280
281 extern char ClusterMessage[MAX_INTRMSN_MESSAGE_SIZE];
282
283 static char *GetFinaleText(int sequence)
284 {
285 const char *msgLumpName;
286 int msgSize;
287 int msgLump;
288 static const char *winMsgLumpNames[] = {
289 "win1msg",
290 "win2msg",
291 "win3msg"
292 };
293
294 msgLumpName = winMsgLumpNames[sequence];
295 msgLump = W_GetNumForName(msgLumpName);
296 msgSize = W_LumpLength(msgLump);
297 if (msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
298 {
299 I_Error("Finale message too long (%s)", msgLumpName);
300 }
301
302 memcpy(ClusterMessage, W_LumpByNum(msgLump), msgSize);
303 ClusterMessage[msgSize] = '\0'; // Append terminator
304 return ClusterMessage;
305 }