-
Notifications
You must be signed in to change notification settings - Fork 11
/
f_main.c
622 lines (537 loc) · 12.8 KB
/
f_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/* f_main.c -- finale */
#include "doomdef.h"
#include "r_local.h"
typedef struct
{
char *name;
mobjtype_t type;
} castinfo_t;
static const castinfo_t castorder[] = {
{"zombieman", MT_POSSESSED},
{"shotgun guy", MT_SHOTGUY},
{"imp", MT_TROOP},
{"demon", MT_SERGEANT},
{"spectre", MT_SERGEANT},
{"lost soul", MT_SKULL},
{"cacodemon", MT_HEAD},
{"baron of hell", MT_BRUISER},
{"cyberdemon", MT_CYBORG},
{"spider mastermind", MT_SPIDER},
{"our hero", MT_PLAYER},
{NULL,0}
};
typedef enum
{
fin_endtext,
fin_charcast
} final_e;
#define TEXTTIME 4
#define STARTX 8
#define STARTY 8
#define SPACEWIDTH 8
#define NUMENDOBJ 28
typedef struct
{
int castnum;
int casttics;
const state_t *caststate;
boolean castdeath;
int castframes;
int castonmelee;
boolean castattacking;
final_e status;
boolean textprint; /* is endtext done printing? */
int textindex;
VINT textdelay;
VINT text_x;
VINT text_y;
VINT drawbg;
jagobj_t **endobj;
drawcol_t drcol;
} finale_t;
finale_t *fin;
static void F_DrawBackground(void);
/*
==================
=
= BufferedDrawSprite
=
= Cache and draw a game sprite to the 8 bit buffered screen
==================
*/
void BufferedDrawSprite (int sprite, int frame, int rotation, int top, int left)
{
spritedef_t *sprdef;
spriteframe_t *sprframe;
VINT *sprlump;
patch_t *patch;
byte *pixels, *src;
int x, sprleft, sprtop, spryscale;
fixed_t spriscale;
column_t *column;
int lump;
boolean flip;
int texturecolumn;
int light = HWLIGHT(143);
int height = I_FrameBufferHeight();
if ((unsigned)sprite >= NUMSPRITES)
I_Error ("BufferedDrawSprite: invalid sprite number %i "
,sprite);
sprdef = &sprites[sprite];
if ( (frame&FF_FRAMEMASK) >= sprdef->numframes )
I_Error ("BufferedDrawSprite: invalid sprite frame %i : %i "
,sprite,frame);
sprframe = &spriteframes[sprdef->firstframe + (frame & FF_FRAMEMASK)];
sprlump = &spritelumps[sprframe->lump];
if (sprlump[rotation] != -1)
lump = sprlump[rotation];
else
lump = sprlump[0];
flip = false;
if (lump < 0)
{
lump = -(lump + 1);
flip = true;
}
if (lump <= 0)
return;
patch = (patch_t *)W_POINTLUMPNUM(lump);
pixels = R_CheckPixels(lump + 1);
S_UpdateSounds ();
/* */
/* coordinates are in a 160*112 screen (doubled pixels) */
/* */
sprtop = top;
sprleft = left;
spryscale = 2;
spriscale = FRACUNIT/spryscale;
sprtop -= patch->topoffset;
sprleft -= patch->leftoffset;
/* */
/* draw it by hand */
/* */
for (x=0 ; x<patch->width ; x++)
{
if (sprleft+x < 0)
continue;
if (sprleft+x >= 160)
break;
if (flip)
texturecolumn = patch->width-1-x;
else
texturecolumn = x;
column = (column_t *) ((byte *)patch +
BIGSHORT(patch->columnofs[texturecolumn]));
/* */
/* draw a masked column */
/* */
for ( ; column->topdelta != 0xff ; column++)
{
int top = column->topdelta + sprtop;
int bottom = top + column->length - 1;
top *= spryscale;
bottom *= spryscale;
src = pixels + BIGSHORT(column->dataofs);
if (top < 0) top = 0;
if (bottom >= height) bottom = height - 1;
if (top > bottom) continue;
fin->drcol(sprleft+x, top, bottom, light, 0, spriscale, src, 128);
}
}
}
/*============================================================================ */
#if 0
/* '*' = newline */
static const char endtextstring[] =
"you did it! by turning*"
"the evil of the horrors*"
"of hell in upon itself*"
"you have destroyed the*"
"power of the demons.**"
"their dreadful invasion*"
"has been stopped cold!*"
"now you can retire to*"
"a lifetime of frivolity.**"
" congratulations!";
/* '*' = newline */
static const char endtextstring[] =
" id software*"
" salutes you!*"
"*"
" the horrors of hell*"
" could not kill you.*"
" their most cunning*"
" traps were no match*"
" for you. you have*"
" proven yourself the*"
" best of all!*"
"*"
" congratulations!";
#endif
/*=============================================== */
/* */
/* Print a string in big font - LOWERCASE INPUT ONLY! */
/* */
/*=============================================== */
void F_PrintString1(const char *string)
{
int index;
int val;
index = 0;
while(1)
{
switch(string[index])
{
case 0: return;
case ' ':
fin->text_x += SPACEWIDTH;
val = 30;
break;
case '.':
val = 26;
break;
case '!':
val = 27;
break;
case '*':
val = 30;
fin->text_x = STARTX;
fin->text_y += fin->endobj[0]->height + 4;
break;
default:
val = string[index] - 'a';
break;
}
if (val < NUMENDOBJ)
{
DrawJagobj(fin->endobj[val],fin->text_x,fin->text_y);
fin->text_x += fin->endobj[val]->width;
if (fin->text_x > 316)
{
fin->text_x = STARTX;
fin->text_y += fin->endobj[val]->height + 4;
}
}
index++;
}
}
// Prints to both framebuffers, if needed.
void F_PrintString2(const char* string)
{
#ifdef MARS
int btext_x, btext_y;
btext_x = fin->text_x;
btext_y = fin->text_y;
F_PrintString1(string);
UpdateBuffer();
fin->text_x = btext_x;
fin->text_y = btext_y;
#endif
F_PrintString1(string);
}
/*=============================================== */
/* */
/* Print character cast strings */
/* */
/*=============================================== */
void F_CastPrint(char *string)
{
int i,width,slen;
width = 0;
slen = mystrlen(string);
for (i = 0;i < slen; i++)
switch(string[i])
{
case ' ': width += SPACEWIDTH; break;
default : width += fin->endobj[string[i] - 'a']->width;
}
fin->text_x = 160 - (width >> 1);
fin->text_y = 10;
F_PrintString1(string);
}
/*
=======================
=
= F_Start
=
=======================
*/
void F_Start (void)
{
int i;
int l;
if (gameinfo.endMus <= 0)
S_StartSong(gameinfo.victoryMus, 1, cdtrack_end);
else
S_StartSong(gameinfo.endMus, 1, cdtrack_end);
fin = Z_Malloc(sizeof(*fin), PU_STATIC);
D_memset(fin, 0, sizeof(*fin));
fin->status = fin_endtext; /* END TEXT PRINTS FIRST */
fin->textprint = false;
fin->textindex = 0;
fin->textdelay = TEXTTIME;
fin->text_x = STARTX;
fin->text_y = STARTY;
fin->drawbg = 3;
fin->endobj = Z_Malloc(sizeof(*fin->endobj) * NUMENDOBJ, PU_STATIC);
l = W_GetNumForName ("CHAR_097");
for (i = 0; i < NUMENDOBJ; i++)
fin->endobj[i] = W_CacheLumpNum(l+i, PU_STATIC);
fin->castnum = 0;
fin->caststate = &states[mobjinfo[castorder[fin->castnum].type].seestate];
fin->casttics = fin->caststate->tics;
fin->castdeath = false;
fin->castframes = 0;
fin->castonmelee = 0;
fin->castattacking = false;
#ifndef MARS
backgroundpic = W_POINTLUMPNUM(W_GetNumForName("M_TITLE"));
DoubleBufferSetup ();
#endif
I_SetPalette(W_POINTLUMPNUM(W_GetNumForName("PLAYPALS")));
R_InitColormap(true);
}
void F_Stop (void)
{
int i;
R_InitColormap(lowResMode);
for (i = 0;i < NUMENDOBJ; i++)
Z_Free(fin->endobj[i]);
Z_Free(fin->endobj);
Z_Free(fin);
}
/*
=======================
=
= F_Ticker
=
=======================
*/
int F_Ticker (void)
{
int st;
int buttons, oldbuttons;
/* */
/* check for press a key to kill actor */
/* */
buttons = ticbuttons[consoleplayer];
oldbuttons = oldticbuttons[consoleplayer];
if (ticon <= 10)
return 0;
if ((buttons & BT_START) && !(oldbuttons & BT_START))
return 1;
if (fin->status == fin_endtext)
{
if (fin->textindex == (3*15)/TEXTTIME)
fin->textprint = true;
if (( ((buttons & BT_ATTACK) && !(oldbuttons & BT_ATTACK) )
|| ((buttons & BT_SPEED) && !(oldbuttons & BT_SPEED) )
|| ((buttons & BT_USE) && !(oldbuttons & BT_USE) ) ) &&
fin->textprint == true && gameinfo.endShowCast)
{
fin->status = fin_charcast;
if (gameinfo.victoryMus <= 0)
S_StartSong(gameinfo.endMus, 1, cdtrack_victory);
else
S_StartSong(gameinfo.victoryMus, 1, cdtrack_victory);
#ifndef JAGUAR
if (mobjinfo[castorder[fin->castnum].type].seesound)
S_StartSound (NULL, mobjinfo[castorder[fin->castnum].type].seesound);
#endif
}
return 0;
}
if (!fin->castdeath)
{
if ( ((buttons & BT_ATTACK) && !(oldbuttons & BT_ATTACK) )
|| ((buttons & BT_SPEED) && !(oldbuttons & BT_SPEED) )
|| ((buttons & BT_USE) && !(oldbuttons & BT_USE) ) )
{
/* go into death frame */
#ifndef JAGUAR
if (mobjinfo[castorder[fin->castnum].type].deathsound)
S_StartSound(NULL, mobjinfo[castorder[fin->castnum].type].deathsound);
#endif
fin->castdeath = true;
fin->caststate = &states[mobjinfo[castorder[fin->castnum].type].deathstate];
fin->casttics = fin->caststate->tics;
fin->castframes = 0;
fin->castattacking = false;
}
}
if (ticon & 1)
return 0;
/* */
/* advance state */
/* */
if (--fin->casttics > 0)
return 0; /* not time to change state yet */
if (fin->caststate->tics == -1 || fin->caststate->nextstate == S_NULL)
{ /* switch from deathstate to next monster */
int oldnum = fin->castnum;
do {
fin->castnum++;
if (castorder[fin->castnum].name == NULL)
fin->castnum = 0;
if (sprites[states[mobjinfo[castorder[fin->castnum].type].seestate].sprite].numframes == 0)
continue;
break;
} while (fin->castnum != oldnum);
fin->castdeath = false;
#ifndef JAGUAR
if (mobjinfo[castorder[fin->castnum].type].seesound)
S_StartSound (NULL, mobjinfo[castorder[fin->castnum].type].seesound);
#endif
fin->caststate = &states[mobjinfo[castorder[fin->castnum].type].seestate];
fin->castframes = 0;
}
else
{ /* just advance to next state in animation */
if (fin->caststate == &states[S_PLAY_ATK2])
goto stopattack; /* Oh, gross hack! */
st = fin->caststate->nextstate;
fin->caststate = &states[st];
fin->castframes++;
#if 1
/*============================================== */
/* sound hacks.... */
{
int sfx;
switch (st)
{
case S_PLAY_ATK2: sfx = sfx_shotgn; break;
case S_POSS_ATK2: sfx = sfx_pistol; break;
case S_SPOS_ATK2: sfx = sfx_shotgn; break;
//case S_VILE_ATK2: sfx = sfx_vilatk; break;
//case S_SKEL_FIST2: sfx = sfx_skeswg; break;
//case S_SKEL_FIST4: sfx = sfx_skepch; break;
//case S_SKEL_MISS2: sfx = sfx_skeatk; break;
//case S_FATT_ATK8:
//case S_FATT_ATK5:
//case S_FATT_ATK2: sfx = sfx_firsht; break;
//case S_CPOS_ATK2:
//case S_CPOS_ATK3:
//case S_CPOS_ATK4: sfx = sfx_shotgn; break;
case S_TROO_ATK3: sfx = sfx_claw; break;
case S_SARG_ATK2: sfx = sfx_sgtatk; break;
case S_BOSS_ATK2:
//case S_BOS2_ATK2:
case S_HEAD_ATK2: sfx = sfx_firsht; break;
case S_SKULL_ATK2: sfx = sfx_sklatk; break;
case S_SPID_ATK4:
case S_SPID_ATK3: sfx = sfx_shotgn; break;
//case S_BSPI_ATK2: sfx = sfx_plasma; break;
case S_CYBER_ATK2:
case S_CYBER_ATK4:
case S_CYBER_ATK6: sfx = sfx_rlaunc; break;
//case S_PAIN_ATK3: sfx = sfx_sklatk; break;
default: sfx = 0; break;
}
if (sfx)
S_StartSound (NULL, sfx);
}
#endif
/*============================================== */
}
if (fin->castframes == 12)
{ /* go into attack frame */
fin->castattacking = true;
if (fin->castonmelee)
fin->caststate=&states[mobjinfo[castorder[fin->castnum].type].meleestate];
else
fin->caststate=&states[mobjinfo[castorder[fin->castnum].type].missilestate];
fin->castonmelee ^= 1;
if (fin->caststate == &states[S_NULL])
{
if (fin->castonmelee)
fin->caststate=
&states[mobjinfo[castorder[fin->castnum].type].meleestate];
else
fin->caststate=
&states[mobjinfo[castorder[fin->castnum].type].missilestate];
}
}
if (fin->castattacking)
{
if (fin->castframes == 24
|| fin->caststate == &states[mobjinfo[castorder[fin->castnum].type].seestate] )
{
stopattack:
fin->castattacking = false;
fin->castframes = 0;
fin->caststate = &states[mobjinfo[castorder[fin->castnum].type].seestate];
}
}
fin->casttics = fin->caststate->tics;
if (fin->casttics == -1)
fin->casttics = 15;
return 0;
}
static void F_DrawBackground(void)
{
#ifdef MARS
DrawTiledBackground2(gameinfo.endFlat);
#else
EraseBlock(0, 0, 320, 200);
#endif
}
/*
=======================
=
= F_Drawer
=
=======================
*/
void F_Drawer (void)
{
int top, left;
fin->drcol = I_DrawColumnLow;
if (D_strcasecmp(castorder[fin->castnum].name, "spectre") == 0)
fin->drcol = I_DrawFuzzColumnLow;
// HACK
viewportWidth = 320;
viewportHeight = I_FrameBufferHeight();
viewportbuffer = (pixel_t*)I_FrameBuffer();
if (fin->drawbg) {
fin->drawbg--;
F_DrawBackground();
}
switch(fin->status)
{
case fin_endtext:
if (!--fin->textdelay)
{
char str[2];
if (!gameinfo.endText)
return;
str[1] = 0;
str[0] = gameinfo.endText[fin->textindex];
if (!str[0])
return;
F_PrintString2(str);
fin->textdelay = TEXTTIME;
fin->textindex++;
}
break;
case fin_charcast:
fin->drawbg = 2;
switch (castorder[fin->castnum].type) {
case MT_CYBORG:
top = 115;
left = 80;
break;
case MT_SPIDER:
top = 110;
left = 90;
break;
default:
top = 90;
left = 80;
break;
}
BufferedDrawSprite (fin->caststate->sprite,
fin->caststate->frame&FF_FRAMEMASK,0,top,left);
F_CastPrint (castorder[fin->castnum].name);
break;
}
}