forked from keendreams/keen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kd_play.c
1928 lines (1630 loc) · 39.1 KB
/
kd_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
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Keen Dreams Source Code
* Copyright (C) 2014 Javier M. Chavez
*
* 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.
*/
// KD_PLAY.C
#include "KD_DEF.H"
#pragma hdrstop
/*
=============================================================================
LOCAL CONSTANTS
=============================================================================
*/
#define INACTIVATEDIST 10
#define MAXMOVE (TILEGLOBAL-17)
#define NUMLUMPS 22
#define CONTROLSLUMP 0
#define KEENLUMP 1
#define WORLDKEENLUMP 2
#define BROCCOLUMP 3
#define TOMATLUMP 4
#define CARROTLUMP 5
#define ASPARLUMP 6
#define GRAPELUMP 7
#define TATERLUMP 8
#define CARTLUMP 9
#define FRENCHYLUMP 10
#define MELONLUMP 11
#define SQUASHLUMP 12
#define APELLUMP 13
#define PEALUMP 14
#define BOOBUSLUMP 15
/*
=============================================================================
GLOBAL VARIABLES
=============================================================================
*/
exittype playstate;
gametype gamestate;
boolean button0held,button1held;
objtype *new,*check,*player,*scoreobj;
unsigned originxtilemax,originytilemax;
ControlInfo c;
objtype dummyobj;
char *levelnames[21] =
{
"The Land of Tuberia",
"Horseradish Hill",
"The Melon Mines",
"Bridge Bottoms",
"Rhubarb Rapids",
"Parsnip Pass",
"Level 6",
"Spud City",
"Level 8",
"Apple Acres",
"Grape Grove",
"Level 11",
"Brussels Sprout Bay",
"Level 13",
"Squash Swamp",
"Boobus' Chamber",
"Castle Tuberia",
"",
"Title Page"
};
/*
=============================================================================
LOCAL VARIABLES
=============================================================================
*/
// for asm scaning of map planes
unsigned mapx,mapy,mapxcount,mapycount,maptile,mapspot;
int plummet;
int objectcount;
objtype objarray[MAXACTORS],*lastobj,*objfreelist;
int oldtileleft,oldtiletop,oldtileright,oldtilebottom,oldtilemidx;
int oldleft,oldtop,oldright,oldbottom,oldmidx;
int leftmoved,topmoved,rightmoved,bottommoved,midxmoved;
int topmove,bottommove,midxmove;
int inactivateleft,inactivateright,inactivatetop,inactivatebottom;
int fadecount;
boolean bombspresent;
boolean lumpneeded[NUMLUMPS];
int lumpstart[NUMLUMPS] =
{
CONTROLS_LUMP_START,
KEEN_LUMP_START,
WORLDKEEN_LUMP_START,
BROCCOLASH_LUMP_START,
TOMATO_LUMP_START,
CARROT_LUMP_START,
ASPAR_LUMP_START,
GRAPE_LUMP_START,
TATER_LUMP_START,
CANTA_LUMP_START,
FRENCHY_LUMP_START,
MELONLIPS_LUMP_START,
SQUASHER_LUMP_START,
APEL_LUMP_START,
PEAS_LUMP_START,
BOOBUS_LUMP_START,
};
int lumpend[NUMLUMPS] =
{
CONTROLS_LUMP_END,
KEEN_LUMP_END,
WORLDKEEN_LUMP_END,
BROCCOLASH_LUMP_END,
TOMATO_LUMP_END,
CARROT_LUMP_END,
ASPAR_LUMP_END,
GRAPE_LUMP_END,
TATER_LUMP_END,
CANTA_LUMP_END,
FRENCHY_LUMP_END,
MELONLIPS_LUMP_END,
SQUASHER_LUMP_END,
APEL_LUMP_END,
PEAS_LUMP_END,
BOOBUS_LUMP_END,
};
void CheckKeys (void);
void CalcInactivate (void);
void InitObjArray (void);
void GetNewObj (boolean usedummy);
void RemoveObj (objtype *gone);
void ScanInfoPlane (void);
void PatchWorldMap (void);
void MarkTileGraphics (void);
void FadeAndUnhook (void);
void SetupGameLevel (boolean loadnow);
void ScrollScreen (void);
void MoveObjVert (objtype *ob, int ymove);
void MoveObjHoriz (objtype *ob, int xmove);
void GivePoints (unsigned points);
void ClipToEnds (objtype *ob);
void ClipToEastWalls (objtype *ob);
void ClipToWestWalls (objtype *ob);
void ClipToWalls (objtype *ob);
void ClipToSpriteSide (objtype *push, objtype *solid);
void ClipToSprite (objtype *push, objtype *solid, boolean squish);
int DoActor (objtype *ob,int tics);
void StateMachine (objtype *ob);
void NewState (objtype *ob,statetype *state);
void PlayLoop (void);
void GameLoop (void);
//===========================================================================
/*
=====================
=
= CheckKeys
=
=====================
*/
void CheckKeys (void)
{
if (screenfaded) // don't do anything with a faded screen
return;
//
// space for status screen
//
if (Keyboard[sc_Space])
{
StatusWindow ();
IN_ClearKeysDown();
RF_ForceRefresh();
lasttimecount = TimeCount;
}
//
// pause key wierdness can't be checked as a scan code
//
if (Paused)
{
VW_FixRefreshBuffer ();
US_CenterWindow (8,3);
US_PrintCentered ("PAUSED");
VW_UpdateScreen ();
IN_Ack();
RF_ForceRefresh ();
Paused = false;
}
//
// F1-F7/ESC to enter control panel
//
if ( (LastScan >= sc_F1 && LastScan <= sc_F7) || LastScan == sc_Escape)
{
VW_FixRefreshBuffer ();
US_CenterWindow (20,8);
US_CPrint ("Loading");
VW_UpdateScreen ();
US_ControlPanel();
IN_ClearKeysDown();
if (restartgame)
playstate = resetgame;
else if (!loadedgame)
RF_ForceRefresh(); // don't refresh if loading a new game
lasttimecount = TimeCount;
}
//
// F10-? debug keys
//
if (Keyboard[sc_F10] && DebugKeys() )
{
RF_ForceRefresh();
lasttimecount = TimeCount;
}
}
//===========================================================================
/*
=======================
=
= CalcInactivate
=
=======================
*/
void CalcInactivate (void)
{
originxtilemax = originxtile+PORTTILESWIDE-1;
originytilemax = originytile+PORTTILESHIGH-1;
inactivateleft = originxtile-INACTIVATEDIST;
if (inactivateleft < 0)
inactivateleft = 0;
inactivateright = originxtilemax+INACTIVATEDIST;
inactivatetop = originytile-INACTIVATEDIST;
if (inactivatetop < 0)
inactivatetop = 0;
inactivatebottom = originytilemax+INACTIVATEDIST;
}
//===========================================================================
/*
#############################################################################
The objarray data structure
#############################################################################
Objarray 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>
#############################################################################
*/
/*
=========================
=
= InitObjArray
=
= Call to clear out the entire object list, returning them all to the free
= list. Allocates a special spot for the player.
=
=========================
*/
void InitObjArray (void)
{
int i;
for (i=0;i<MAXACTORS;i++)
{
objarray[i].prev = &objarray[i+1];
objarray[i].next = NULL;
}
objarray[MAXACTORS-1].prev = NULL;
objfreelist = &objarray[0];
lastobj = NULL;
objectcount = 0;
//
// give the player and score the first free spots
//
GetNewObj (false);
player = new;
GetNewObj (false);
scoreobj = new;
}
//===========================================================================
/*
=========================
=
= GetNewObj
=
= Sets the global variable new to point to a free spot in objarray.
= 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 objarray!");
}
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 = yes;
new->needtoclip = true;
lastobj = new;
objectcount++;
}
//===========================================================================
/*
=========================
=
= RemoveObj
=
= Add the given object back into the free list, and unlink it from it's
= neighbors
=
=========================
*/
void RemoveObj (objtype *gone)
{
if (gone == player)
Quit ("RemoveObj: Tried to remove the player!");
//
// erase it from the refresh manager
//
RF_RemoveSprite (&gone->sprite);
//
// 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;
}
//===========================================================================
void near HandleInfo (void)
{
switch (maptile)
{
case 1:
SpawnKeen(mapx,mapy,1);
break;
case 2:
SpawnKeen(mapx,mapy,-1);
break;
case 19:
SpawnWorldKeen(mapx,mapy);
lumpneeded[WORLDKEENLUMP] = true;
break;
case 31:
bombspresent = true;
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 32:
SpawnBonus(mapx,mapy,maptile-21);
new->active = false;
break;
case 33:
SpawnDoor(mapx,mapy);
new->active = false;
break;
case 41:
SpawnBrocco(mapx,mapy);
new->active = false;
lumpneeded[BROCCOLUMP] = true;
break;
case 42:
SpawnTomat(mapx,mapy);
new->active = false;
lumpneeded[TOMATLUMP] = true;
break;
case 43:
SpawnCarrot(mapx,mapy);
new->active = false;
lumpneeded[CARROTLUMP] = true;
break;
case 45:
SpawnAspar(mapx,mapy);
new->active = false;
lumpneeded[ASPARLUMP] = true;
break;
case 46:
SpawnGrape(mapx,mapy);
new->active = false;
lumpneeded[GRAPELUMP] = true;
break;
case 47:
SpawnTater(mapx,mapy);
new->active = false;
lumpneeded[TATERLUMP] = true;
break;
case 48:
SpawnCart(mapx,mapy);
lumpneeded[CARTLUMP] = true;
break;
case 49:
SpawnFrenchy(mapx,mapy);
new->active = false;
lumpneeded[FRENCHYLUMP] = true;
break;
case 50:
case 51:
case 52:
SpawnMelon(mapx,mapy,maptile-50);
new->active = false;
lumpneeded[MELONLUMP] = true;
break;
case 57:
SpawnSquasher(mapx,mapy);
new->active = false;
lumpneeded[SQUASHLUMP] = true;
break;
case 58:
SpawnApel(mapx,mapy);
new->active = false;
lumpneeded[APELLUMP] = true;
break;
case 59:
SpawnPeaPod(mapx,mapy);
new->active = false;
lumpneeded[PEALUMP] = true;
break;
case 60:
SpawnPeaBrain(mapx,mapy);
new->active = false;
lumpneeded[PEALUMP] = true;
break;
case 61:
SpawnBoobus(mapx,mapy);
lumpneeded[BOOBUSLUMP] = true;
break;
}
if (new->active != allways)
new->active = false;
}
/*
==========================
=
= ScanInfoPlane
=
= Spawn all actors and mark down special places
=
==========================
*/
void ScanInfoPlane (void)
{
unsigned x,y,i,j;
int tile;
unsigned far *start;
InitObjArray(); // start spawning things with a clean slate
memset (lumpneeded,0,sizeof(lumpneeded));
#if 0
start = mapsegs[2];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
if (!tile)
continue;
}
#endif
//
// This doesn't really need to be in asm. I thought it was a bottleneck,
// but I was wrong...
//
asm mov es,[WORD PTR mapsegs+4]
asm xor si,si
asm mov [mapy],0
asm mov ax,[mapheight]
asm mov [mapycount],ax
yloop:
asm mov [mapx],0
asm mov ax,[mapwidth]
asm mov [mapxcount],ax
xloop:
asm mov ax,[es:si]
asm or ax,ax
asm jz nothing
asm mov [maptile],ax
HandleInfo (); // si is saved
asm mov es,[WORD PTR mapsegs+4]
nothing:
asm inc [mapx]
asm add si,2
asm dec [mapxcount]
asm jnz xloop
asm inc [mapy]
asm dec [mapycount]
asm jnz yloop
for (i=0;i<NUMLUMPS;i++)
if (lumpneeded[i])
for (j=lumpstart[i];j<=lumpend[i];j++)
CA_MarkGrChunk(j);
}
//===========================================================================
/*
==========================
=
= PatchWorldMap
=
= Takes out blocking squares and puts in dones
=
==========================
*/
void PatchWorldMap (void)
{
unsigned size,spot,info,foreground;
size = mapwidth*mapheight;
spot = 0;
do
{
info = *(mapsegs[2] + spot);
// finished a city here?
if (info>=3 && info<=18 && gamestate.leveldone[info-2])
{
*(mapsegs[2] + spot) = 0;
foreground = *(mapsegs[1] + spot);
if (foreground == 130)
*(mapsegs[1]+spot) = 0; // not blocking now
else if (foreground == 90)
{
// plant done flag
*(mapsegs[1]+spot) = 133;
*(mapsegs[1]+(spot-mapwidth-1)) = 131;
*(mapsegs[1]+(spot-mapwidth)) = 132;
}
}
spot++;
} while (spot<size);
}
//===========================================================================
/*
==========================
=
= FadeAndUnhook
=
= Latch this onto the refresh so the screen only gets faded in after two
= refreshes. This lets all actors draw themselves to both pages before
= fading the screen in.
=
==========================
*/
void FadeAndUnhook (void)
{
if (++fadecount==2)
{
RF_ForceRefresh();
VW_FadeIn ();
RF_SetRefreshHook (NULL);
lasttimecount = TimeCount; // don't adaptively time the fade
}
}
//===========================================================================
/*
==========================
=
= SetupGameLevel
=
= Load in map mapon and cache everything needed for it
=
==========================
*/
void SetupGameLevel (boolean loadnow)
{
long orgx,orgy;
bombspresent = false;
//
// load the level header and three map planes
//
CA_CacheMap (gamestate.mapon);
//
// let the refresh manager set up some variables
//
RF_NewMap ();
//
// decide which graphics are needed and spawn actors
//
CA_ClearMarks ();
if (!mapon)
PatchWorldMap ();
if (mapon!=20) // map 20 is the title screen
ScanInfoPlane ();
RF_MarkTileGraphics ();
//
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
if (loadnow)
{
if (bombspresent)
{
VW_FixRefreshBuffer ();
US_DrawWindow (10,1,20,2);
US_PrintCentered ("Boobus Bombs Near!");
VW_UpdateScreen ();
}
CA_CacheMarks (levelnames[mapon], 0);
}
#if 0
VW_FixRefreshBuffer ();
US_CenterWindow (20,8);
US_Print ("\n\n\nObject count:");
itoa (objectcount,str,10);
US_Print (str);
VW_UpdateScreen ();
IN_Ack ();
#endif
if (mapon!=20 && loadnow) // map 20 is the title screen
{
VW_FadeOut ();
fadecount = 0;
RF_SetRefreshHook (&FadeAndUnhook);
SpawnScore ();
//
// start the initial view position to center the player
//
orgx = (long)player->x - (150<<G_P_SHIFT);
orgy = (long)player->y-(84<<G_P_SHIFT);
if (orgx<0)
orgx=0;
if (orgy<0)
orgy=0;
RF_NewPosition (orgx,orgy);
CalcInactivate ();
}
}
//==========================================================================
/*
===============
=
= ScrollScreen
=
= Scroll if Keen is nearing an edge
= Set playstate to levelcomplete
=
===============
*/
void ScrollScreen (void)
{
int xscroll,yscroll;
//
// walked off edge of map?
//
if (player->left < originxmin
|| player->right > originxmax+20*TILEGLOBAL)
{
playstate = levelcomplete;
return;
}
//
// fallen off bottom of world?
//
if (!plummet && player->bottom > originymax+13*TILEGLOBAL)
{
godmode = 0;
plummet = 1;
KillKeen ();
return;
}
if (player->x < originxglobal+SCROLLWEST)
xscroll = player->x - (originxglobal+SCROLLWEST);
else if (player->x > originxglobal+SCROLLEAST)
xscroll = player->x - (originxglobal+SCROLLEAST);
else
xscroll = 0;
if (player->y < originyglobal+SCROLLNORTH)
yscroll = player->y - (originyglobal+SCROLLNORTH);
else if (player->y > originyglobal+SCROLLSOUTH)
yscroll = player->y - (originyglobal+SCROLLSOUTH);
else yscroll = 0;
if (xscroll || yscroll)
{
RF_Scroll (xscroll,yscroll);
CalcInactivate ();
scoreobj->needtoreact = true;
}
}
//==========================================================================
/*
====================
=
= GivePoints
=
= Grants extra men at 20k,40k,80k,160k,320k
=
====================
*/
void GivePoints (unsigned points)
{
gamestate.score += points;
if (gamestate.score >= gamestate.nextextra)
{
SD_PlaySound (EXTRAKEENSND);
gamestate.lives++;
gamestate.nextextra*=2;
}
}
//==========================================================================
/*
====================
=
= MoveObjVert
=
====================
*/
void MoveObjVert (objtype *ob, int ymove)
{
ob->y += ymove;
ob->top += ymove;
ob->bottom += ymove;
ob->tiletop = ob->top >> G_T_SHIFT;
ob->tilebottom = ob->bottom >> G_T_SHIFT;
}
/*
====================
=
= MoveObjHoriz
=
====================
*/
void MoveObjHoriz (objtype *ob, int xmove)
{
ob->x += xmove;
ob->left += xmove;
ob->right += xmove;
ob->tileleft = ob->left >> G_T_SHIFT;
ob->tileright = ob->right >> G_T_SHIFT;
}
/*
=============================================================================
Actor to tile clipping rouitnes
=============================================================================
*/
// walltype / x coordinate (0-15)
int wallclip[8][16] = { // the height of a given point in a tile
{ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78},
{0x80,0x88,0x90,0x98,0xa0,0xa8,0xb0,0xb8,0xc0,0xc8,0xd0,0xd8,0xe0,0xe8,0xf0,0xf8},
{ 0,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0},
{0x78,0x70,0x68,0x60,0x58,0x50,0x48,0x40,0x38,0x30,0x28,0x20,0x18,0x10,0x08, 0},
{0xf8,0xf0,0xe8,0xe0,0xd8,0xd0,0xc8,0xc0,0xb8,0xb0,0xa8,0xa0,0x98,0x90,0x88,0x80},
{0xf0,0xe0,0xd0,0xc0,0xb0,0xa0,0x90,0x80,0x70,0x60,0x50,0x40,0x30,0x20,0x10, 0}
};
// assignment within ifs are used heavily here, so turn off the warning
#pragma warn -pia
/*
===========================
=
= ClipToEnds
=
===========================
*/
void ClipToEnds (objtype *ob)
{
unsigned far *map,tile,facetile,info,wall;
int leftpix,rightpix,midtiles,toppix,bottompix;
int x,y,clip,move,totalmove,maxmove,midxpix;
midxpix = (ob->midx&0xf0) >> 4;
maxmove = -abs(midxmoved) - bottommoved - 16;
map = (unsigned far *)mapsegs[1] +
mapbwidthtable[oldtilebottom-1]/2 + ob->tilemidx;
for (y=oldtilebottom-1 ; y<=ob->tilebottom ; y++,map+=mapwidth)
{
if (wall = tinf[NORTHWALL+*map])
{
clip = wallclip[wall&7][midxpix];
move = ( (y<<G_T_SHIFT)+clip - 1) - ob->bottom;
if (move<0 && move>=maxmove)
{
ob->hitnorth = wall;
MoveObjVert (ob,move);
return;
}
}
}
maxmove = abs(midxmoved) - topmoved + 16;
map = (unsigned far *)mapsegs[1] +
mapbwidthtable[oldtiletop+1]/2 + ob->tilemidx;
for (y=oldtiletop+1 ; y>=ob->tiletop ; y--,map-=mapwidth)
{
if (wall = tinf[SOUTHWALL+*map])
{
clip = wallclip[wall&7][midxpix];
move = ( ((y+1)<<G_T_SHIFT)-clip ) - ob->top;
if (move > 0 && move<=maxmove)
{
totalmove = ob->ymove + move;
if (totalmove < TILEGLOBAL && totalmove > -TILEGLOBAL)
{
ob->hitsouth = wall;
MoveObjVert (ob,move);
}
}
}
}
}
/*
===========================
=
= ClipToEastWalls / ClipToWestWalls
=
===========================
*/
void ClipToEastWalls (objtype *ob)
{
int y,move,top,bottom;
unsigned far *map,tile,info,wall;
// clip to east walls if moving west
top = ob->tiletop;
if (ob->hitsouth>1)
top++; // on a slope inside a tile
bottom = ob->tilebottom;
if (ob->hitnorth>1)