-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathACKPOV.C
678 lines (608 loc) · 23.7 KB
/
ACKPOV.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
// Source file ACKPOV.C - Player and Object Movement routines
// (c) 1995 ACK Software (Lary Myers)
//#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//#include <dos.h>
//#include <mem.h>
//#include <io.h>
//#include <fcntl.h>
#include <time.h>
#include <string.h>
//#include <sys\stat.h>
#include "ACK3D.H"
#include "ACKENG.H"
#include "ACKEXT.H"
//************************************************************************
// Internal function called by AckMovePOV(). Checks the passed X and Y
// coordinates of the player against the object coordinates to see if the player will
// encouner an object.
//************************************************************************
short AckCheckObjPosn(short xPlayer,short yPlayer, short oIndex)
{
short i,result,maxObj;
short MapPosn;
NEWOBJECT **oList;
NEWOBJECT *oPtr;
result = POV_NOTHING; // Initialize to nothing found
MapPosn = (yPlayer & 0xFFC0) + (xPlayer >> 6); // Calculate grid square the player will be in
maxObj = aeGlobal->MaxObjects; // Total number of objects used
oList = &aeGlobal->ObjList[0]; // Reference the list of objects
for (i = 0; i < maxObj; i++) // Loop and check each object in the list
{
oPtr = oList[i]; // Point to current object
if (oPtr == NULL) // No object here; skip to next object in list
continue;
if (!oPtr->Active || oPtr->Flags & OF_PASSABLE) // Object is not active or is passable
continue; // Skip to next object in list
if (MapPosn == oPtr->mPos && i != oIndex) // Object is found in the player's grid position
{
LastObjectHit = i; // Store the number of the object found
return(POV_OBJECT); // Return flag to indicate an object is found
}
}
return(result);
}
//************************************************************************
// Internal function called by AckMovePOV() to see if a wall or object is located in
// the player's current grid square. This function checks for walls or objects in the
// x-plane using the xGrid array. The bitmap code for the wall or object is returned.
// A value returned of 0 indicates that no wall or object is present or that the wall
// is passable.
//************************************************************************
USHORT GetWallX(short mPos)
{
USHORT mCode;
//MEH Can't check outside of bounds!
if(mPos < 0 || mPos >= GRID_ARRAY)
return 0;
mCode = xGridGlobal[mPos]; // Get bitmap code at specified map position
if (mCode & WALL_TYPE_PASS) // Passable walls can be walked through
mCode = 0;
return(mCode);
}
//************************************************************************
// Internal function called by AckMovePOV() to see if a wall or object is located in
// the player's current grid square. This function checks for walls or objects in the
// y-plane using the yGrid array. The bitmap code for the wall or object is returned.
// A value returned of 0 indicates that no wall or object is present or that the wall
// is passable.
//************************************************************************
USHORT GetWallY(short mPos)
{
USHORT mCode;
//MEH Can't check outside of bounds!
if(mPos < 0 || mPos >= GRID_ARRAY)
return 0;
mCode = yGridGlobal[mPos]; // Get bitmap code at specified map position
if (mCode & WALL_TYPE_PASS) // Passable walls can be walked through
mCode = 0;
return(mCode);
}
//************************************************************************
// Moves the POV based on Angle for Amount. After moving but prior to
// returning the position of the POV is check for collisions.
//************************************************************************
short AckMovePOV(short Angle,short Amount)
{
short x1,y1,HitResult; // New coordinate position
short xp,yp; // Starting player coordinates
short xLeft,xRight,yTop,yBottom; // Coordinates for grid square
short mPos; // Map position for xGrid[], yGrid[]
USHORT mCodeX,mCodeY; // Return codes for x,y wall arrays
HitResult = POV_NOTHING; // We haven't hit anything yet
xp = aeGlobal->xPlayer; // Get the current x,y player coordinates
yp = aeGlobal->yPlayer;
xLeft = xp & 0xFFC0; // Determine coordinates of the boundaries
yTop = yp & 0xFFC0; // of the grid square we're in.
xRight = xLeft + GRID_SIZE;
yBottom = yTop + GRID_SIZE;
// Calculate the x,y distance of movement using the angle and distance
// x1,y1 = the new coordinate position of the player.
x1 = xp + (int32_t)((CosTable[Angle] * Amount) >> FP_SHIFT);
y1 = yp + (int32_t)((SinTable[Angle] * Amount) >> FP_SHIFT);
// Calculate current map position for the xGrid[] and yGrid[] arrays
mPos = yTop + (xp >> 6); // Current Map Posn
// It's time to see what happens when we move
if (x1 < xp) // Are we moving left?
{
if (GetWallX(mPos)) // Wall found in current square (left edge)
{
if (x1 < xLeft || abs(x1-xLeft) < 28) // We crossed the wall or we're too close
{
x1 = xp; // Use the previous x position
HitResult = POV_SLIDEX; // We're possibly sliding along the left x wall
}
}
}
if (x1 > xp) // Are we moving right?
{
if (GetWallX(mPos+1)) // Wall found in current square (right edge)
{
if (x1 > xRight || abs(xRight-x1) < 28) // We crossed the wall or we're too close
{
x1 = xp; // Use the previous x position
HitResult = POV_SLIDEX; // We're possibly sliding along the right x wall
}
}
}
if (y1 < yp) // Are we moving up?
{
if (GetWallY(mPos)) // Wall found in current square (top edge)
{
if (y1 < yTop || abs(y1-yTop) < 28) // We crossed the wall or we're too close
{
y1 = yp; // Use the previous y position
HitResult = POV_SLIDEY; // We're possibly sliding along the top wall
}
}
}
if (y1 > yp) // Are we moving down?
{
if (GetWallY(mPos+GRID_WIDTH)) // Wall found in current square (bottom edge)
{
if (y1 > yBottom || abs(yBottom-y1) < 28) // We crossed the wall or we're too close
{
y1 = yp; // Use the previous y position
HitResult = POV_SLIDEY; // We're sliding along the bottom wall
}
}
}
// A wall or object hasn't been hit yet--we must look further.
// The current grid sqaure will be divided into four regions:
// A = top left; B = top right; C = bottom left; D = bottom right
// Each of these regions will be checked to see if the player's new position (x1,y1)
// is close to a wall or object that borders one of these regions.
// Each grid square is 64x64 units, so each region to check is 32x32 units.
if (!HitResult)
{ // Check region A--top left area of grid
if (y1 < (yTop+32)) // New y position falls in top half
{
if (x1 < (xLeft+32)) // New x position falls in left half
{
mCodeX = GetWallX(mPos-GRID_WIDTH); // Check adjacent x wall (to left)
mCodeY = GetWallY(mPos-1); // Check adjacent y wall (above)
if (mCodeX && y1 < (yTop+28)) // Adjacent x wall found and new y coord
{ // is within 28 units
if (x1 < (xLeft+28)) // New x coord. is within 28 units of edge
{
if (xp > (xLeft+27)) // Previous x position was outside range
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 < (xLeft+28)) // Adjacent y wall found and new x coord.
{ // is within 28 units
if (y1 < (yTop+28)) // New y coord. is within 28 units of edge
{
if (yp > (yTop+27)) // Previous y position was outside range
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
}
}
}
// Check region B--top right area
if (x1 > (xRight-32) && !HitResult)// New x is at top right
{
mCodeX = GetWallX(mPos+1-GRID_WIDTH); // Check adjacent x wall (to right)
mCodeY = GetWallY(mPos+1); // Check adjacent y wall (above)
if (mCodeX && y1 < (yTop+28)) // Adjacent x wall found
{
if (x1 > (xRight-28))
{
if (xp < (xRight-27))
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 > (xRight-28)) // Adjacent y wall found
{
if (y1 < (yTop+28))
{
if (yp > (yTop+27))
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
}
}
}
}
// Check region C--bottom left area
if (y1 > (yTop+32) && !HitResult) // We are below upper half of square
{
if (x1 < (xLeft+32)) // and on the left half of square
{
mCodeX = GetWallX(mPos+GRID_WIDTH); // Check adjacent x wall (to left)
mCodeY = GetWallY(mPos-1+GRID_WIDTH); // Check adjacent y wall (below)
if (mCodeX && y1 > (yBottom-28)) // Adjacent x wall found
{
if (x1 < (xLeft+28))
{
if (xp > (xLeft+27))
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 < (xLeft+28)) // Adjacent y wall found
{
if (y1 > (yBottom-28))
{
if (yp < (yBottom-27))
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
}
}
}
// Check region D--bottom right area
if (x1 > (xRight-32) && !HitResult) // Check right side of square
{
mCodeX = GetWallX(mPos+1+GRID_WIDTH); // Check adjacent x wall (to right)
mCodeY = GetWallY(mPos+1+GRID_WIDTH); // Check adjacent y wall (below)
if (mCodeX && y1 > (yBottom-28)) // Adjacent x wall found
{
if (x1 > (xRight-28))
{
if (xp < (xRight-27))
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 > (xRight-28)) // Adjacent y wall found
{
if (y1 > (yBottom-28))
{
if (yp < (yBottom-27))
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
}
}
}
}
}
if (AckCheckObjPosn(x1,y1,0)) // We've hit an object--not a wall
return(POV_OBJECT);
if (HitResult == POV_SLIDEX && y1 == yp) // We've hit an x wall and we're not sliding
HitResult = POV_XWALL;
if (HitResult == POV_SLIDEY && x1 == xp) // We've hit a y wall and we're not sliding
HitResult = POV_YWALL;
aeGlobal->xPlayer = x1; // Update player's new x,y position
aeGlobal->yPlayer = y1;
return(HitResult);
}
//************************************************************************
// Moves an object based on Angle and Amount then checks for collision
// with other objects AND the POV.
//************************************************************************
short AckMoveObjectPOV(short ObjIndex,short Angle,short Amount)
{
short xp,yp,x1,y1,HitResult,oNum;
USHORT mCodeX,mCodeY;
short xLeft,xRight,yTop,yBottom,mPos;
short MapPosn,PlayerPosn;
NEWOBJECT **oList;
NEWOBJECT *oPtr;
oList = &aeGlobal->ObjList[0]; // Reference the start of the object list
oPtr = oList[ObjIndex]; // Set a pointer to the object being moved
if (oPtr == NULL) // no object is available to move; we're done
return(0);
xp = oPtr->x; // Get the current x,y coordinate of the object
yp = oPtr->y;
// Calculate the new x,y, cordinates of the object (after moving)
x1 = xp + (short)((CosTable[Angle] * Amount) >> FP_SHIFT);
y1 = yp + (short)((SinTable[Angle] * Amount) >> FP_SHIFT);
xLeft = xp & 0xFFC0; // Determine the coordinates of the grid square the
xRight = xLeft + GRID_SIZE - 1; // object is currently in
yTop = yp & 0xFFC0;
yBottom = yTop + GRID_SIZE - 1;
mPos = yTop + (xp >> 6); // Calculate the map position of the grid square the object is in
MapPosn = (y1 & 0xFFC0) + (x1 >> 6); // Calculate the map position of the grid square the
// object is moving to
// Check to see if the object will encouner another object while moving
oNum = AckCheckObjPosn(x1,y1,ObjIndex);
if (oNum > 0) // Yes, return falg to indicate object found
return(POV_OBJECT);
HitResult = POV_NOTHING; // Nothing found yet, initialize flag
if (x1 < xp) // Are we moving left?
{
if (GetWallX(mPos)) // Wall found in current square (left edge)
{
if (x1 < xLeft || abs(x1-xLeft) < 28) // We crossed the wall or we're too close
{
x1 = xp; // Use the previous x position
HitResult = POV_SLIDEX; // We're possibly sliding along the left x wall
}
}
}
if (x1 > xp) // Are we moving right?
{
if (GetWallX(mPos+1)) // Wall found in current square (right edge)
{
if (x1 > xRight || abs(xRight-x1) < 28) // We crossed the wall or we're too close
{
x1 = xp; // Use the previous x position
HitResult = POV_SLIDEX; // We're possibly sliding along the right x wall
}
}
}
if (y1 < yp) // Are we moving up?
{
if (GetWallY(mPos)) // Wall found in current square (top edge)
{
if (y1 < yTop || abs(y1-yTop) < 28) // We crossed the wall or we're too close
{
y1 = yp; // Use the previous y position
HitResult = POV_SLIDEY; // We're possibly sliding along the top wall
}
}
}
if (y1 > yp) // Are we moving down?
{
if (GetWallY(mPos+GRID_WIDTH)) // Wall found in current square (bottom edge)
{
if (y1 > yBottom || abs(yBottom-y1) < 28) // We crossed the wall or we're too close
{
y1 = yp; // Use the previous y position
HitResult = POV_SLIDEY; // We're sliding along the bottom wall
}
}
}
if (!HitResult) // Nothing hit yet, look further
{
if (y1 < (yTop+32)) // We are above upper half of square
{
if (x1 < (xLeft+32)) // and on the left half of square
{
mCodeX = GetWallX(mPos-GRID_WIDTH); // Check adjacent x wall (to left)
mCodeY = GetWallY(mPos-1); // Check adjacent y wall (above)
if (mCodeX && y1 < (yTop+28)) // Adjacent x wall found and new y coord
{ // is within 28 units
if (x1 < (xLeft+28)) // New x coord. is within 28 units of edge
{
if (xp > (xLeft+27)) // Previous x position was outside range
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 < (xLeft+28)) // Adjacent y wall found and new x coord.
{ // is within 28 units
if (y1 < (yTop+28)) // New y coord. is within 28 units of edge
{
if (yp > (yTop+27)) // Previous y position was outside range
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
}
}
}
if (x1 > (xRight-32) && !HitResult) // New x is at top right
{
mCodeX = GetWallX(mPos+1-GRID_WIDTH); // Check adjacent x wall (to right)
mCodeY = GetWallY(mPos+1); // Check adjacent y wall (above)
if (mCodeX && y1 < (yTop+28)) // Adjacent x wall found
{
if (x1 > (xRight-28))
{
if (xp < (xRight-27))
{
x1 = xp; // Use previous x position
HitResult = POV_SLIDEX;
}
else
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 > (xRight-28)) // Adjacent y wall found
{
if (y1 < (yTop+28))
{
if (yp > (yTop+27))
{
y1 = yp; // Use previous y position
HitResult = POV_SLIDEY;
}
else
{
x1 = xp;
HitResult = POV_SLIDEX;
}
}
}
}
}
if (y1 > (yTop+32) && !HitResult) // We are below upper half of square
{
if (x1 < (xLeft+32)) // and on the left half of square
{
mCodeX = GetWallX(mPos+GRID_WIDTH);
mCodeY = GetWallY(mPos-1+GRID_WIDTH);
if (mCodeX && y1 > (yBottom-28))
{
if (x1 < (xLeft+28))
{
if (xp > (xLeft+27))
{
x1 = xp;
HitResult = POV_SLIDEX;
}
else
{
y1 = yp;
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 < (xLeft+28))
{
if (y1 > (yBottom-28))
{
if (yp < (yBottom-27))
{
y1 = yp;
HitResult = POV_SLIDEY;
}
else
{
x1 = xp;
HitResult = POV_SLIDEX;
}
}
}
}
if (x1 > (xRight-32) && !HitResult) // on right side of square
{
mCodeX = GetWallX(mPos+1+GRID_WIDTH);
mCodeY = GetWallY(mPos+1+GRID_WIDTH);
if (mCodeX && y1 > (yBottom-28))
{
if (x1 > (xRight-28))
{
if (xp < (xRight-27))
{
x1 = xp;
HitResult = POV_SLIDEX;
}
else
{
y1 = yp;
HitResult = POV_SLIDEY;
}
}
}
if (mCodeY && x1 > (xRight-28))
{
if (y1 > (yBottom-28))
{
if (yp < (yBottom-27))
{
y1 = yp;
HitResult = POV_SLIDEY;
}
else
{
x1 = xp;
HitResult = POV_SLIDEX;
}
}
}
}
}
}
oPtr->x = x1; // Update the new x,y coordinates for the object
oPtr->y = y1;
oPtr->mPos = MapPosn; // Update the grid map position for the object
PlayerPosn = (aeGlobal->yPlayer & 0xFFC0) + (aeGlobal->xPlayer >> 6);
if (MapPosn == PlayerPosn)
return(POV_PLAYER);
return(HitResult);
}
//************************************************************************
// Checks the list of objects used in an application and sets up the current bitmap for
// each object that can be animated. Object animation is performed by displaying
// different bitmaps for an object in sequence.
//************************************************************************
void AckCheckObjectMovement(void)
{
short i,maxObj;
short dx;
NEWOBJECT **oList;
NEWOBJECT *oPtr;
maxObj = aeGlobal->MaxObjects; // Get the number of objects used
oList = &aeGlobal->ObjList[0]; // Reference the list of objects
for (i = 1; i < maxObj; i++) // Loop to check each object in the list
{
oPtr = oList[i]; // Access current object in list
if (oPtr == NULL) // No object here; skip
continue;
if (!oPtr->Active) // Object is not active; skip
continue;
if (!oPtr->Speed) // Object has no speed setting; skip
continue;
if (!(oPtr->Flags & OF_ANIMATE)) // Object is not set up for animation
continue;
dx = oPtr->CurrentBm + 1; // Use the next bitmap
if (dx >= oPtr->Maxbm) // We're at the end of the list of bitmaps
{
if (oPtr->Flags & OF_ANIMONCE) // Object should only be animated once
{
oPtr->Flags &= ~OF_ANIMATE; // Reset flags to indicate that we're done
oPtr->Flags |= OF_ANIMDONE; // animating the object
dx = oPtr->CurrentBm; // Keep current bitmap number
}
else
dx = 0; // Start at the beginning of the set of bitmaps
}
oPtr->CurrentBm = dx; // Store the next bitmap as the current one
}
}
// **** End of Source ****