]> icculus.org git repositories - theoddone33/hheretic.git/blob - base/f_finale.c
Initial revision
[theoddone33/hheretic.git] / base / f_finale.c
1 // F_finale.c
2
3 #include <ctype.h>      // for toupper()
4 #include "doomdef.h"
5 #include "soundst.h"
6 #ifdef RENDER3D
7 #include "ogl_def.h"
8 #define WR_CacheLumpName(a,b)        W_GetNumForName(a)
9 #define V_DrawPatch(x,y,p)          OGL_DrawPatch(x,y,p)
10 #define V_DrawFuzzPatch(x,y,p)      OGL_DrawFuzzPatch(x,y,p)
11 #define V_DrawAltFuzzPatch(x,y,p)   OGL_DrawAltFuzzPatch(x,y,p)
12 #define V_DrawShadowedPatch(x,y,p)  OGL_DrawShadowedPatch(x,y,p)
13 #define V_DrawRawScreen(a)          OGL_DrawRawScreen(a)
14 #else
15 #define WR_CacheLumpName(a,b)           W_CacheLumpName(a,b)
16 #endif
17
18 int             finalestage;            // 0 = text, 1 = art screen
19 int             finalecount;
20
21 #define TEXTSPEED       3
22 #define TEXTWAIT        250
23
24 char    *e1text = E1TEXT;
25 char    *e2text = E2TEXT;
26 char    *e3text = E3TEXT;
27 char    *e4text = E4TEXT;
28 char    *e5text = E5TEXT;
29 char    *finaletext;
30 char    *finaleflat;
31
32 int FontABaseLump;
33
34 extern boolean automapactive;
35 extern boolean viewactive;
36
37 extern void D_StartTitle(void);
38
39 /*
40 =======================
41 =
42 = F_StartFinale
43 =
44 =======================
45 */
46
47 void F_StartFinale (void)
48 {
49         gameaction = ga_nothing;
50         gamestate = GS_FINALE;
51         viewactive = false;
52         automapactive = false;
53         players[consoleplayer].messageTics = 1;
54         players[consoleplayer].message = NULL;
55
56         switch(gameepisode)
57         {
58                 case 1:
59                         finaleflat = "FLOOR25";
60                         finaletext = e1text;
61                         break;
62                 case 2:
63                         finaleflat = "FLATHUH1";
64                         finaletext = e2text;
65                         break;
66                 case 3:
67                         finaleflat = "FLTWAWA2";
68                         finaletext = e3text;
69                         break;
70                 case 4:
71                         finaleflat = "FLOOR28";
72                         finaletext = e4text;
73                         break;
74                 case 5:
75                         finaleflat = "FLOOR08";
76                         finaletext = e5text;
77                         break;
78         }
79
80         finalestage = 0;
81         finalecount = 0;
82         FontABaseLump = W_GetNumForName("FONTA_S")+1;
83
84 //      S_ChangeMusic(mus_victor, true);
85         S_StartSong(mus_cptd, true);
86 }
87
88
89
90 boolean F_Responder (event_t *event)
91 {
92         if(event->type != ev_keydown)
93         {
94                 return false;
95         }
96         if(finalestage == 1 && gameepisode == 2)
97         { // we're showing the water pic, make any key kick to demo mode
98                 finalestage++;
99                 // Hmm... naughty Heretic again :/ - DDOI
100                 //memset((byte *)0xa0000, 0, SCREENWIDTH*SCREENHEIGHT);
101                 //memset(screen, 0, SCREENWIDTH*SCREENHEIGHT);
102                 I_SetPalette(W_CacheLumpName("PLAYPAL", PU_CACHE));
103                 return true;
104         }
105         return false;
106 }
107
108
109 /*
110 =======================
111 =
112 = F_Ticker
113 =
114 =======================
115 */
116
117 void F_Ticker (void)
118 {
119         finalecount++;
120         if (!finalestage && finalecount>strlen (finaletext)*TEXTSPEED + TEXTWAIT)
121         {
122                 finalecount = 0;
123                 if(!finalestage)
124                 {
125                         finalestage = 1;
126                 }
127
128 //              wipegamestate = -1;             // force a wipe
129 /*
130                 if (gameepisode == 3)
131                         S_StartMusic (mus_bunny);
132 */
133         }
134 }
135
136
137 /*
138 =======================
139 =
140 = F_TextWrite
141 =
142 =======================
143 */
144
145 //#include "HU_stuff.h"
146 //extern        patch_t *hu_font[HU_FONTSIZE];
147
148 void F_TextWrite (void)
149 {
150 #ifndef RENDER3D
151         byte    *src, *dest;
152         int             x,y;
153 #endif
154         int             count;
155         char    *ch;
156         int             c;
157         int             cx, cy;
158         patch_t *w;
159
160 //
161 // erase the entire screen to a tiled background
162 //
163 #ifndef RENDER3D
164         src = W_CacheLumpName(finaleflat, PU_CACHE);
165         dest = screen;
166         for (y=0 ; y<SCREENHEIGHT ; y++)
167         {
168                 for (x=0 ; x<SCREENWIDTH/64 ; x++)
169                 {
170                         memcpy (dest, src+((y&63)<<6), 64);
171                         dest += 64;
172                 }
173                 if (SCREENWIDTH&63)
174                 {
175                         memcpy (dest, src+((y&63)<<6), SCREENWIDTH&63);
176                         dest += (SCREENWIDTH&63);
177                 }
178         }
179 #else
180         OGL_SetFlat (R_FlatNumForName(finaleflat));
181         OGL_DrawRectTiled(0,0,SCREENWIDTH,SCREENHEIGHT,64,64);
182 #endif
183
184 //      V_MarkRect (0, 0, SCREENWIDTH, SCREENHEIGHT);
185
186 //
187 // draw some of the text onto the screen
188 //
189         cx = 20;
190         cy = 5;
191         ch = finaletext;
192
193         count = (finalecount - 10)/TEXTSPEED;
194         if (count < 0)
195                 count = 0;
196         for ( ; count ; count-- )
197         {
198                 c = *ch++;
199                 if (!c)
200                         break;
201                 if (c == '\n')
202                 {
203                         cx = 20;
204                         cy += 9;
205                         continue;
206                 }
207
208                 c = toupper(c);
209                 if (c < 33)
210                 {
211                         cx += 5;
212                         continue;
213                 }
214
215                 w = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
216                 if (cx+w->width > SCREENWIDTH)
217                         break;
218 #ifdef RENDER3D
219                 OGL_DrawPatch (cx,cy,FontABaseLump+c-33);
220 #else
221                 V_DrawPatch(cx, cy, w);
222 #endif
223                 cx += w->width;
224         }
225
226 }
227
228 void F_DrawPatchCol (int x, patch_t *patch, int col)
229 {
230         column_t        *column;
231         byte            *source, *dest, *desttop;
232         int                     count;
233
234         column = (column_t *)((byte *)patch + LONG(patch->columnofs[col]));
235         desttop = screen+x;
236
237 // step through the posts in a column
238
239         while (column->topdelta != 0xff )
240         {
241                 source = (byte *)column + 3;
242                 dest = desttop + column->topdelta*SCREENWIDTH;
243                 count = column->length;
244
245                 while (count--)
246                 {
247                         *dest = *source++;
248                         dest += SCREENWIDTH;
249                 }
250                 column = (column_t *)(  (byte *)column + column->length+ 4 );
251         }
252 }
253
254 /*
255 ==================
256 =
257 = F_DemonScroll
258 =
259 ==================
260 */
261
262 void F_DemonScroll(void)
263 {
264         byte *p1, *p2;
265         static int yval = 0;
266         static int nextscroll = 0;
267
268         if(finalecount < nextscroll)
269         {
270                 return;
271         }
272         p1 = W_CacheLumpName("FINAL1", PU_LEVEL);
273         p2 = W_CacheLumpName("FINAL2", PU_LEVEL);
274         if(finalecount < 70)
275         {
276                 memcpy(screen, p1, SCREENHEIGHT*SCREENWIDTH);
277                 nextscroll = finalecount;
278                 return;
279         }
280         if(yval < 64000)
281         {
282                 memcpy(screen, p2+SCREENHEIGHT*SCREENWIDTH-yval, yval);
283                 memcpy(screen+yval, p1, SCREENHEIGHT*SCREENWIDTH-yval);
284                 yval += SCREENWIDTH;
285                 nextscroll = finalecount+3;
286         }
287         else
288         { //else, we'll just sit here and wait, for now
289                 memcpy(screen, p2, SCREENWIDTH*SCREENHEIGHT);
290         }
291 }
292
293 /*
294 ==================
295 =
296 = F_DrawUnderwater
297 =
298 ==================
299 */
300
301 void F_DrawUnderwater(void)
302 {
303 #ifndef RENDER3D
304         static boolean underwawa;
305 #endif
306         extern boolean MenuActive;
307         extern boolean askforquit;
308
309         switch(finalestage)
310         {
311                 case 1:
312 #ifndef RENDER3D        
313                         if(!underwawa)
314                         {
315                                 underwawa = true;
316                                 // Naughty Heretic :/ - DDOI
317                                 //memset((byte *)0xa0000, 0, SCREENWIDTH*SCREENHEIGHT);
318                                 I_SetPalette(W_CacheLumpName("E2PAL", PU_CACHE));
319                                 memcpy(screen, W_CacheLumpName("E2END", PU_CACHE),
320                                         SCREENWIDTH*SCREENHEIGHT);
321                         }
322 #endif
323                         paused = false;
324                         MenuActive = false;
325                         askforquit = false;
326
327                         break;
328                 case 2:
329 #ifndef RENDER3D                
330                         memcpy(screen, W_CacheLumpName("TITLE", PU_CACHE),
331                                 SCREENWIDTH*SCREENHEIGHT);
332 #else
333                         OGL_DrawRawScreen(W_GetNumForName("TITLE"));
334 #endif
335                         //D_StartTitle(); // go to intro/demo mode.
336         }
337 }
338
339
340 #if 0
341 /*
342 ==================
343 =
344 = F_BunnyScroll
345 =
346 ==================
347 */
348
349 void F_BunnyScroll (void)
350 {
351         int                     scrolled, x;
352         patch_t         *p1, *p2;
353         char            name[10];
354         int                     stage;
355         static int      laststage;
356
357         p1 = W_CacheLumpName ("PFUB2", PU_LEVEL);
358         p2 = W_CacheLumpName ("PFUB1", PU_LEVEL);
359
360         V_MarkRect (0, 0, SCREENWIDTH, SCREENHEIGHT);
361
362         scrolled = 320 - (finalecount-230)/2;
363         if (scrolled > 320)
364                 scrolled = 320;
365         if (scrolled < 0)
366                 scrolled = 0;
367
368         for ( x=0 ; x<SCREENWIDTH ; x++)
369         {
370                 if (x+scrolled < 320)
371                         F_DrawPatchCol (x, p1, x+scrolled);
372                 else
373                         F_DrawPatchCol (x, p2, x+scrolled - 320);
374         }
375
376         if (finalecount < 1130)
377                 return;
378         if (finalecount < 1180)
379         {
380                 V_DrawPatch ((SCREENWIDTH-13*8)/2, (SCREENHEIGHT-8*8)/2,0, W_CacheLumpName ("END0",PU_CACHE));
381                 laststage = 0;
382                 return;
383         }
384
385         stage = (finalecount-1180) / 5;
386         if (stage > 6)
387                 stage = 6;
388         if (stage > laststage)
389         {
390                 S_StartSound (NULL, sfx_pistol);
391                 laststage = stage;
392         }
393
394         sprintf (name,"END%i",stage);
395         V_DrawPatch ((SCREENWIDTH-13*8)/2, (SCREENHEIGHT-8*8)/2, W_CacheLumpName (name,PU_CACHE));
396 }
397 #endif
398
399 /*
400 =======================
401 =
402 = F_Drawer
403 =
404 =======================
405 */
406
407 void F_Drawer(void)
408 {
409         UpdateState |= I_FULLSCRN;
410         if (!finalestage)
411                 F_TextWrite ();
412         else
413         {
414                 switch (gameepisode)
415                 {
416                         case 1:
417                                 if(shareware)
418                                 {
419                                         V_DrawRawScreen(WR_CacheLumpName("ORDER", PU_CACHE));
420                                 }
421                                 else
422                                 {
423                                         V_DrawRawScreen(WR_CacheLumpName("CREDIT", PU_CACHE));
424                                 }
425                                 break;
426                         case 2:
427                                 F_DrawUnderwater();
428                                 break;
429                         case 3:
430                                 F_DemonScroll();
431                                 break;
432                         case 4: // Just show credits screen for extended episodes
433                         case 5:
434                                 V_DrawRawScreen(WR_CacheLumpName("CREDIT", PU_CACHE));
435                                 break;
436                 }
437         }
438 }