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));
172 /* jim Looks like Dan got this one wrong! 8-) */
173 /* else if(PlayerClass[consoleplayer] = PCLASS_ASS) */
174 else if(PlayerClass[consoleplayer] == PCLASS_ASS)
176 V_DrawPatch(60,0, W_CacheLumpNum(W_GetNumForName("chessa"), PU_CACHE));
178 else if(PlayerClass[consoleplayer])
180 V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
181 +PlayerClass[consoleplayer]-1, PU_CACHE));
184 // Draw the actual text
195 count = (FinaleCount-10)/TEXTSPEED;
200 for(; count; count--)
223 w = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
224 if(cx+w->width > SCREENWIDTH)
228 V_DrawPatch(cx, cy, w);
233 //===========================================================================
237 //===========================================================================
239 static void InitializeFade(boolean fadeIn)
243 Palette = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
244 PaletteDelta = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
245 RealPalette = Z_Malloc(768*sizeof(byte), PU_STATIC, 0);
249 memset(RealPalette, 0, 768*sizeof(byte));
250 for(i = 0; i < 768; i++)
253 PaletteDelta[i] = FixedDiv((*((byte *)W_CacheLumpName("playpal",
254 PU_CACHE)+i))<<FRACBITS, 70*FRACUNIT);
259 for(i = 0; i < 768; i++)
261 RealPalette[i] = *((byte *)W_CacheLumpName("playpal", PU_CACHE)+i);
262 Palette[i] = RealPalette[i]<<FRACBITS;
263 PaletteDelta[i] = FixedDiv(Palette[i], -70*FRACUNIT);
266 I_SetPalette(RealPalette);
269 //===========================================================================
273 //===========================================================================
275 static void DeInitializeFade(void)
278 Z_Free(PaletteDelta);
282 //===========================================================================
286 //===========================================================================
288 static void FadePic(void)
292 for(i = 0; i < 768; i++)
294 Palette[i] += PaletteDelta[i];
295 RealPalette[i] = Palette[i]>>FRACBITS;
297 I_SetPalette(RealPalette);
300 //===========================================================================
304 //===========================================================================
306 static void DrawPic(void)
308 memcpy(screen, W_CacheLumpNum(FinaleLumpNum, PU_CACHE),
309 SCREENWIDTH*SCREENHEIGHT);
310 if(FinaleStage == 4 || FinaleStage == 5)
311 { // Chess pic, draw the correct character graphic
314 V_DrawPatch(20, 0, W_CacheLumpName("chessall", PU_CACHE));
316 else if(PlayerClass[consoleplayer])
318 V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
319 +PlayerClass[consoleplayer]-1, PU_CACHE));
324 //===========================================================================
328 //===========================================================================
334 case 0: // Fade in initial finale screen
341 case 3: // Fade screen out
344 case 4: // Fade in chess screen
351 UpdateState |= I_FULLSCRN;
354 //==========================================================================
358 //==========================================================================
360 static char *GetFinaleText(int sequence)
365 static char *winMsgLumpNames[] =
371 msgLumpName = winMsgLumpNames[sequence];
372 msgLump = W_GetNumForName(msgLumpName);
373 msgSize = W_LumpLength(msgLump);
374 if(msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
376 I_Error("Finale message too long (%s)", msgLumpName);
378 W_ReadLump(msgLump, ClusterMessage);
379 ClusterMessage[msgSize] = 0; // Append terminator
380 return ClusterMessage;