2 //**************************************************************************
4 //** f_finale.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
13 // HEADER FILES ------------------------------------------------------------
20 // MACROS ------------------------------------------------------------------
25 // TYPES -------------------------------------------------------------------
27 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
29 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
31 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
33 static void TextWrite(void);
34 static void DrawPic(void);
35 static void InitializeFade(boolean fadeIn);
36 static void DeInitializeFade(void);
37 static void FadePic(void);
38 static char *GetFinaleText(int sequence);
40 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
42 extern boolean automapactive;
43 extern boolean viewactive;
45 // PUBLIC DATA DECLARATIONS ------------------------------------------------
47 // PRIVATE DATA DEFINITIONS ------------------------------------------------
49 static int FinaleStage;
50 static int FinaleCount;
51 static int FinaleEndCount;
52 static int FinaleLumpNum;
53 static int FontABaseLump;
54 static char *FinaleText;
56 static fixed_t *Palette;
57 static fixed_t *PaletteDelta;
58 static byte *RealPalette;
60 // CODE --------------------------------------------------------------------
62 //===========================================================================
66 //===========================================================================
68 void F_StartFinale (void)
70 gameaction = ga_nothing;
71 gamestate = GS_FINALE;
73 automapactive = false;
74 P_ClearMessage(&players[consoleplayer]);
78 FinaleText = GetFinaleText(0);
80 FinaleLumpNum = W_GetNumForName("FINALE1");
81 FontABaseLump = W_GetNumForName("FONTA_S")+1;
84 // S_ChangeMusic(mus_victor, true);
85 S_StartSongName("hall", false); // don't loop the song
88 //===========================================================================
92 //===========================================================================
94 boolean F_Responder(event_t *event)
99 //===========================================================================
103 //===========================================================================
108 if(FinaleStage < 5 && FinaleCount >= FinaleEndCount)
115 FinaleEndCount = strlen(FinaleText)*TEXTSPEED+TEXTWAIT;
117 case 2: // Pic 2, Text 2
118 FinaleText = GetFinaleText(1);
119 FinaleEndCount = strlen(FinaleText)*TEXTSPEED+TEXTWAIT;
120 FinaleLumpNum = W_GetNumForName("FINALE2");
121 S_StartSongName("orb", false);
123 case 3: // Pic 2 -- Fade out
128 case 4: // Pic 3 -- Fade in
129 FinaleLumpNum = W_GetNumForName("FINALE3");
133 S_StartSongName("chess", true);
135 case 5: // Pic 3 , Text 3
136 FinaleText = GetFinaleText(2);
144 if(FinaleStage == 0 || FinaleStage == 3 || FinaleStage == 4)
150 //===========================================================================
154 //===========================================================================
156 static void TextWrite (void)
164 memcpy(screen, W_CacheLumpNum(FinaleLumpNum, PU_CACHE),
165 SCREENWIDTH*SCREENHEIGHT);
167 { // Chess pic, draw the correct character graphic
170 V_DrawPatch(20, 0, W_CacheLumpName("chessall", PU_CACHE));
173 /* jim Looks like Dan got this one wrong! 8-) */
174 /* else if(PlayerClass[consoleplayer] = PCLASS_ASS) */
175 else if(PlayerClass[consoleplayer] == PCLASS_ASS)
177 V_DrawPatch(60,0, W_CacheLumpNum(W_GetNumForName("chessa"), PU_CACHE));
180 else if(PlayerClass[consoleplayer])
182 V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
183 +PlayerClass[consoleplayer]-1, PU_CACHE));
186 // Draw the actual text
197 count = (FinaleCount-10)/TEXTSPEED;
202 for(; count; count--)
225 w = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
226 if(cx+w->width > SCREENWIDTH)
230 V_DrawPatch(cx, cy, w);
235 //===========================================================================
239 //===========================================================================
241 static void InitializeFade(boolean fadeIn)
245 Palette = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
246 PaletteDelta = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
247 RealPalette = Z_Malloc(768*sizeof(byte), PU_STATIC, 0);
251 memset(RealPalette, 0, 768*sizeof(byte));
252 for(i = 0; i < 768; i++)
255 PaletteDelta[i] = FixedDiv((*((byte *)W_CacheLumpName("playpal",
256 PU_CACHE)+i))<<FRACBITS, 70*FRACUNIT);
261 for(i = 0; i < 768; i++)
263 RealPalette[i] = *((byte *)W_CacheLumpName("playpal", PU_CACHE)+i);
264 Palette[i] = RealPalette[i]<<FRACBITS;
265 PaletteDelta[i] = FixedDiv(Palette[i], -70*FRACUNIT);
268 I_SetPalette(RealPalette);
271 //===========================================================================
275 //===========================================================================
277 static void DeInitializeFade(void)
280 Z_Free(PaletteDelta);
284 //===========================================================================
288 //===========================================================================
290 static void FadePic(void)
294 for(i = 0; i < 768; i++)
296 Palette[i] += PaletteDelta[i];
297 RealPalette[i] = Palette[i]>>FRACBITS;
299 I_SetPalette(RealPalette);
302 //===========================================================================
306 //===========================================================================
308 static void DrawPic(void)
310 memcpy(screen, W_CacheLumpNum(FinaleLumpNum, PU_CACHE),
311 SCREENWIDTH*SCREENHEIGHT);
312 if(FinaleStage == 4 || FinaleStage == 5)
313 { // Chess pic, draw the correct character graphic
316 V_DrawPatch(20, 0, W_CacheLumpName("chessall", PU_CACHE));
318 else if(PlayerClass[consoleplayer])
320 V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
321 +PlayerClass[consoleplayer]-1, PU_CACHE));
326 //===========================================================================
330 //===========================================================================
336 case 0: // Fade in initial finale screen
343 case 3: // Fade screen out
346 case 4: // Fade in chess screen
353 UpdateState |= I_FULLSCRN;
356 //==========================================================================
360 //==========================================================================
362 static char *GetFinaleText(int sequence)
367 static char *winMsgLumpNames[] =
373 msgLumpName = winMsgLumpNames[sequence];
374 msgLump = W_GetNumForName(msgLumpName);
375 msgSize = W_LumpLength(msgLump);
376 if(msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
378 I_Error("Finale message too long (%s)", msgLumpName);
380 W_ReadLump(msgLump, ClusterMessage);
381 ClusterMessage[msgSize] = 0; // Append terminator
382 return ClusterMessage;