-
Notifications
You must be signed in to change notification settings - Fork 54
/
C3_PLAY.C
584 lines (478 loc) · 11.6 KB
/
C3_PLAY.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
/* Catacomb 3-D Source Code
* Copyright (C) 1993-2014 Flat Rock Software
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// C3_PLAY.C
#include "C3_DEF.H"
#pragma hdrstop
/*
=============================================================================
LOCAL CONSTANTS
=============================================================================
*/
#define POINTTICS 6
/*
=============================================================================
GLOBAL VARIABLES
=============================================================================
*/
ControlInfo c;
boolean running,slowturn;
int bordertime;
objtype objlist[MAXACTORS],*new,*obj,*player,*lastobj,*objfreelist;
unsigned farmapylookup[MAPSIZE];
byte *nearmapylookup[MAPSIZE];
boolean singlestep,godmode;
int extravbls;
//
// replacing refresh manager
//
unsigned mapwidth,mapheight,tics;
boolean compatability;
byte *updateptr;
unsigned mapwidthtable[64];
unsigned uwidthtable[UPDATEHIGH];
unsigned blockstarts[UPDATEWIDE*UPDATEHIGH];
#define UPDATESCREENSIZE (UPDATEWIDE*PORTTILESHIGH+2)
#define UPDATESPARESIZE (UPDATEWIDE*2+4)
#define UPDATESIZE (UPDATESCREENSIZE+2*UPDATESPARESIZE)
byte update[UPDATESIZE];
int mousexmove,mouseymove;
int pointcount,pointsleft;
/*
=============================================================================
LOCAL VARIABLES
=============================================================================
*/
void CalcBounds (objtype *ob);
void DrawPlayScreen (void);
//
// near data map array (wall values only, get text number from far data)
//
byte tilemap[MAPSIZE][MAPSIZE];
byte spotvis[MAPSIZE][MAPSIZE];
objtype *actorat[MAPSIZE][MAPSIZE];
objtype dummyobj;
int bordertime;
int objectcount;
void StopMusic(void);
void StartMusic(void);
//==========================================================================
///////////////////////////////////////////////////////////////////////////
//
// CenterWindow() - Generates a window of a given width & height in the
// middle of the screen
//
///////////////////////////////////////////////////////////////////////////
#define MAXX 264
#define MAXY 146
void CenterWindow(word w,word h)
{
US_DrawWindow(((MAXX / 8) - w) / 2,((MAXY / 8) - h) / 2,w,h);
}
//===========================================================================
/*
=====================
=
= CheckKeys
=
=====================
*/
void CheckKeys (void)
{
if (screenfaded) // don't do anything with a faded screen
return;
//
// pause key wierdness can't be checked as a scan code
//
if (Paused)
{
CenterWindow (8,3);
US_PrintCentered ("PAUSED");
VW_UpdateScreen ();
SD_MusicOff();
IN_Ack();
SD_MusicOn();
Paused = false;
if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement
}
//
// F1-F7/ESC to enter control panel
//
if ( (LastScan >= sc_F1 && LastScan <= sc_F7) || LastScan == sc_Escape)
{
StopMusic ();
NormalScreen ();
FreeUpMemory ();
US_CenterWindow (20,8);
US_CPrint ("Loading");
VW_UpdateScreen ();
US_ControlPanel();
if (abortgame)
{
playstate = ex_abort;
return;
}
StartMusic ();
IN_ClearKeysDown();
if (restartgame)
playstate = ex_resetgame;
if (loadedgame)
playstate = ex_loadedgame;
DrawPlayScreen ();
CacheScaleds ();
lasttimecount = TimeCount;
if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement
}
//
// F10-? debug keys
//
if (Keyboard[sc_F10])
{
DebugKeys();
if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement
lasttimecount = TimeCount;
}
}
//===========================================================================
/*
#############################################################################
The objlist data structure
#############################################################################
objlist containt structures for every actor currently playing. The structure
is accessed as a linked list starting at *player, ending when ob->next ==
NULL. GetNewObj inserts a new object at the end of the list, meaning that
if an actor spawn another actor, the new one WILL get to think and react the
same frame. RemoveObj unlinks the given object and returns it to the free
list, but does not damage the objects ->next pointer, so if the current object
removes itself, a linked list following loop can still safely get to the
next element.
<backwardly linked free list>
#############################################################################
*/
/*
=========================
=
= InitObjList
=
= Call to clear out the entire object list, returning them all to the free
= list. Allocates a special spot for the player.
=
=========================
*/
void InitObjList (void)
{
int i;
for (i=0;i<MAXACTORS;i++)
{
objlist[i].prev = &objlist[i+1];
objlist[i].next = NULL;
}
objlist[MAXACTORS-1].prev = NULL;
objfreelist = &objlist[0];
lastobj = NULL;
objectcount = 0;
//
// give the player and score the first free spots
//
GetNewObj (false);
player = new;
}
//===========================================================================
/*
=========================
=
= GetNewObj
=
= Sets the global variable new to point to a free spot in objlist.
= The free spot is inserted at the end of the liked list
=
= When the object list is full, the caller can either have it bomb out ot
= return a dummy object pointer that will never get used
=
=========================
*/
void GetNewObj (boolean usedummy)
{
if (!objfreelist)
{
if (usedummy)
{
new = &dummyobj;
return;
}
Quit ("GetNewObj: No free spots in objlist!");
}
new = objfreelist;
objfreelist = new->prev;
memset (new,0,sizeof(*new));
if (lastobj)
lastobj->next = new;
new->prev = lastobj; // new->next is allready NULL from memset
new->active = false;
lastobj = new;
objectcount++;
}
//===========================================================================
/*
=========================
=
= RemoveObj
=
= Add the given object back into the free list, and unlink it from it's
= neighbors
=
=========================
*/
void RemoveObj (objtype *gone)
{
objtype **spotat;
if (gone == player)
Quit ("RemoveObj: Tried to remove the player!");
//
// fix the next object's back link
//
if (gone == lastobj)
lastobj = (objtype *)gone->prev;
else
gone->next->prev = gone->prev;
//
// fix the previous object's forward link
//
gone->prev->next = gone->next;
//
// add it back in to the free list
//
gone->prev = objfreelist;
objfreelist = gone;
}
//==========================================================================
/*
===================
=
= PollControls
=
===================
*/
void PollControls (void)
{
unsigned buttons;
IN_ReadControl(0,&c);
if (MousePresent)
{
Mouse(MButtons);
buttons = _BX;
Mouse(MDelta);
mousexmove = _CX;
mouseymove = _DX;
if (buttons&1)
c.button0 = 1;
if (buttons&2)
c.button1 = 1;
}
if (Controls[0]==ctrl_Joystick)
{
if (c.x>120 || c.x <-120 || c.y>120 || c.y<-120)
running = true;
else
running = false;
if (c.x>-48 && c.x<48)
slowturn = true;
else
slowturn = false;
}
else
{
if (Keyboard[sc_RShift])
running = true;
else
running = false;
if (c.button0)
slowturn = true;
else
slowturn = false;
}
}
//==========================================================================
/*
=================
=
= StopMusic
=
=================
*/
void StopMusic(void)
{
int i;
SD_MusicOff();
for (i = 0;i < LASTMUSIC;i++)
if (audiosegs[STARTMUSIC + i])
{
MM_SetPurge(&((memptr)audiosegs[STARTMUSIC + i]),3);
MM_SetLock(&((memptr)audiosegs[STARTMUSIC + i]),false);
}
}
//==========================================================================
/*
=================
=
= StartMusic
=
=================
*/
// JAB - Cache & start the appropriate music for this level
void StartMusic(void)
{
musicnames chunk;
SD_MusicOff();
chunk = TOOHOT_MUS;
// if ((chunk == -1) || (MusicMode != smm_AdLib))
//DEBUG control panel return;
MM_BombOnError (false);
CA_CacheAudioChunk(STARTMUSIC + chunk);
MM_BombOnError (true);
if (mmerror)
mmerror = false;
else
{
MM_SetLock(&((memptr)audiosegs[STARTMUSIC + chunk]),true);
SD_StartMusic((MusicGroup far *)audiosegs[STARTMUSIC + chunk]);
}
}
//==========================================================================
/*
===================
=
= PlayLoop
=
===================
*/
void PlayLoop (void)
{
int give;
void (*think)();
ingame = true;
playstate = TimeCount = 0;
gamestate.shotpower = handheight = 0;
pointcount = pointsleft = 0;
DrawLevelNumber (gamestate.mapon);
DrawBars ();
#ifndef PROFILE
fizzlein = true; // fizzle fade in the first refresh
#endif
TimeCount = lasttimecount = lastnuke = 0;
PollControls (); // center mouse
StartMusic ();
do
{
#ifndef PROFILE
PollControls();
#else
c.xaxis = 1;
if (++TimeCount == 300)
return;
#endif
for (obj = player;obj;obj = obj->next)
if (obj->active)
{
if (obj->ticcount)
{
obj->ticcount-=tics;
while ( obj->ticcount <= 0)
{
think = obj->state->think;
if (think)
{
think (obj);
if (!obj->state)
{
RemoveObj (obj);
goto nextactor;
}
}
obj->state = obj->state->next;
if (!obj->state)
{
RemoveObj (obj);
goto nextactor;
}
if (!obj->state->tictime)
{
obj->ticcount = 0;
goto nextactor;
}
if (obj->state->tictime>0)
obj->ticcount += obj->state->tictime;
}
}
think = obj->state->think;
if (think)
{
think (obj);
if (!obj->state)
RemoveObj (obj);
}
nextactor:;
}
if (bordertime)
{
bordertime -= tics;
if (bordertime<=0)
{
bordertime = 0;
VW_ColorBorder (3);
}
}
if (pointcount)
{
pointcount -= tics;
if (pointcount <= 0)
{
pointcount += POINTTICS;
give = (pointsleft > 1000)? 1000 :
(
(pointsleft > 100)? 100 :
((pointsleft < 20)? pointsleft : 20)
);
SD_PlaySound (GETPOINTSSND);
AddPoints (give);
pointsleft -= give;
if (!pointsleft)
pointcount = 0;
}
}
ThreeDRefresh ();
CheckKeys();
if (singlestep)
{
VW_WaitVBL(14);
lasttimecount = TimeCount;
}
if (extravbls)
VW_WaitVBL(extravbls);
}while (!playstate);
StopMusic ();
ingame = false;
if (bordertime)
{
bordertime = 0;
VW_ColorBorder (3);
}
if (!abortgame)
AddPoints (pointsleft);
else
abortgame = false;
}