-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathACKDOOR.C
398 lines (364 loc) · 13.1 KB
/
ACKDOOR.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
// This source file contains the functions needed to process doors.
// (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"
extern DOORS *gDoor;
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
// Check all the active doors to see what current state they are in. If a
// door's column offset is non-zero, it is either opening or closing,
// so the speed of the door is added in and the door is checked to
// see if it is fully opened or fully closed.
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
void CheckDoors (void)
{
short i, MapPosn, mPos, mPos1;
short mx, my, DeltaGrid;
short xPlayer, yPlayer;
DOORS *dPtr;
xPlayer = xPglobal;
yPlayer = yPglobal;
dPtr = &gDoor[0];
for (i = 0; i < MAX_DOORS; i++)
{
if (dPtr->ColOffset) // Door is not closed
{ // Add speed to door column offset
dPtr->ColOffset += dPtr->Speed;
mPos = dPtr->mPos; // Get grid position of door
mPos1 = dPtr->mPos1;
// Door is closing and is visible. Put old codes back to make non-passable
if (dPtr->Speed < 1 && dPtr->ColOffset < 65)
{ // Get corner of grid
MapPosn = (yPlayer & 0xFFC0) + (xPlayer >> BITMAP_SHIFT);
// Is player in same grid square that the door is in?
if (MapPosn == mPos || MapPosn == mPos1)
{
dPtr->ColOffset -= dPtr->Speed; // Reduce column offset
continue;
}
// Is the door along an x wall
if (dPtr->Type == DOOR_XCODE)
{ // Store bitmap ids for doors
xGridGlobal[mPos] = dPtr->mCode;
xGridGlobal[mPos1] = dPtr->mCode1;
}
else
{ // Door is along a y wall
yGridGlobal[mPos] = dPtr->mCode;
yGridGlobal[mPos1] = dPtr->mCode1;
}
// Door is close enough to fully closed to get rid
// of the door from the array
if (dPtr->ColOffset < 3)
{
dPtr->ColOffset = 0; // Close door
dPtr->mPos = -1;
dPtr->mPos1 = -1;
dPtr->Flags = 0;
}
}
// Door is fully opened--time to start closing it
if (dPtr->ColOffset > 0xA0)
{
dPtr->Speed = -dPtr->Speed; // Start to reduce speed
dPtr->Flags &= ~DOOR_OPENING; // Set flag to indicate door closing
dPtr->Flags |= DOOR_CLOSING;
}
}
dPtr++; // Advance to check next door
}
//=============================================================================
// Now check for any action occuring in a secret door. This is currently
// setup to handle only one door at a time in the X and Y directions, but
// it should be fairly straightforward to use a list of doors, similiar
// to normal doors, to handle more than one.
//=============================================================================
if (xSecretColumn)
{
if (xSecretColumn > 0) // See if the door is to the right of us
{
mPos = xSecretmPos1;
DeltaGrid = -1;
xSecretColumn += aeGlobal->DoorSpeed;
}
else
{
mPos = xSecretmPos;
DeltaGrid = 0;
xSecretColumn -= aeGlobal->DoorSpeed;
}
my = mPos & 0xFFC0;
mx = (mPos - my) << 6;
if (abs (xSecretColumn) > BITMAP_WIDTH) // Beyond one grid square
{
mx += xSecretColumn;
my = my + (mx >> BITMAP_SHIFT);
if (xGridGlobal[my]) // No further, an obstruction
{
xGridGlobal[xSecretmPos] = 0;
xGridGlobal[xSecretmPos1] = 0;
my += DeltaGrid;
xGridGlobal[my] = aeGlobal->NonSecretCode;
xGridGlobal[my + 1] = aeGlobal->NonSecretCode;
yGridGlobal[my] = aeGlobal->NonSecretCode;
yGridGlobal[my + GRID_WIDTH] = aeGlobal->NonSecretCode;
xSecretColumn = 0;
}
else
{
if (my != mPos)
{
xGridGlobal[xSecretmPos] = 0;
xGridGlobal[xSecretmPos1] = 0;
if (xSecretColumn > 0)
{
xSecretColumn -= (BITMAP_WIDTH - 1);
xGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode; //MEH Don't arbitrarily assign bitmap 1. Use the
// right bitmap.
xSecretmPos1 = my;
my--;
xGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
xSecretmPos = my;
}
else
{
xSecretColumn += (BITMAP_WIDTH - 1);
xGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
xGridGlobal[my + 1] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
xSecretmPos = my;
xSecretmPos = my + 1;
}
}
} // End if (xGrid[my]) ... else ...
} // End if (abs(xSecretColumn) > GRID_SIZE)
} // End if (xSecretColumn)
//=============================================================================
// Perform same process on a secret door that may be moving in the Y
// direction. The same door can move either way, depending on which
// angle the player struck it at.
//=============================================================================
if (ySecretColumn)
{
if (ySecretColumn > 0)
{
mPos = ySecretmPos1;
DeltaGrid = -GRID_WIDTH;
ySecretColumn += aeGlobal->DoorSpeed;
}
else
{
mPos = ySecretmPos;
DeltaGrid = 0;
ySecretColumn -= aeGlobal->DoorSpeed;
}
my = mPos & 0xFFC0;
mx = (mPos - my) << 6;
if (abs (ySecretColumn) > BITMAP_WIDTH)
{
my += ySecretColumn;
my = (my & 0xFFC0) + (mx >> 6);
if (yGridGlobal[my])
{
yGridGlobal[ySecretmPos] = 0;
yGridGlobal[ySecretmPos1] = 0;
my += DeltaGrid;
xGridGlobal[my] = aeGlobal->NonSecretCode;
xGridGlobal[my + 1] = aeGlobal->NonSecretCode;
yGridGlobal[my] = aeGlobal->NonSecretCode;
yGridGlobal[my + GRID_WIDTH] = aeGlobal->NonSecretCode;
ySecretColumn = 0;
}
else
{
if (my != mPos)
{
yGridGlobal[ySecretmPos] = 0;
yGridGlobal[ySecretmPos1] = 0;
if (ySecretColumn > 0)
{
ySecretColumn -= (BITMAP_WIDTH - 1);
yGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
ySecretmPos1 = my;
my -= GRID_WIDTH;
yGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
ySecretmPos = my;
}
else
{
ySecretColumn += (BITMAP_WIDTH - 1);
yGridGlobal[my] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
yGridGlobal[my + GRID_WIDTH] = DOOR_TYPE_SECRET + aeGlobal->NonSecretCode;
ySecretmPos = my;
ySecretmPos = my + GRID_WIDTH;
}
}
}
}
}
}
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
// Internal function called by FindDoorSlot(). This function
// locates a door from its map coordinate and return the index.
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
short FindDoor (short MapPosn)
{
short index;
for (index = 0; index < MAX_DOORS; index++)
{
if (MapPosn == gDoor[index].mPos ||
MapPosn == gDoor[index].mPos1)
{
return (index);
}
}
return (-1);
}
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
// Internal routine called by AckCheckDoorOpen() This function
// finds an empty slot for a door. If the door already occupies a slot
// and it is in a non-closed state, an error is returned.
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
short FindDoorSlot (short MapPosn)
{
short index;
index = FindDoor (MapPosn);
if (index >= 0 && gDoor[index].ColOffset)
return (-1);
for (index = 0; index < MAX_DOORS; index++)
{
if (gDoor[index].mPos == -1)
return (index);
}
return (-1);
}
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
// Checks directly in front of the POV to see if a door is there. If so,
// and the door is not locked, the door is set to begin opening.
//±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
short AckCheckDoorOpen (short xPlayer, short yPlayer, short PlayerAngle)
{
short i,j,DoorCode;
DoorCode = POV_NODOOR;
// Check to see if player is close to a wall
i = AckCheckHit (xPlayer, yPlayer, PlayerAngle);
// A secret door is found along an x wall
if (i == 1 && xGridGlobal[xMapPosn] & DOOR_TYPE_SECRET)
{
if (xSecretColumn == 0) // Player is on the right side of door
{
DoorCode = POV_XSECRETDOOR;
// Secret door is locked; can't open
if (xGridGlobal[xMapPosn] & DOOR_LOCKED)
return (DoorCode | POV_DOORLOCKED);
//MEH Save secret door bitmap!
aeGlobal->NonSecretCode = xGridGlobal[xMapPosn] & 0xFF;
// Get grid map position that corresponds with the x wall
// position of where the door starts
xSecretmPos = xMapPosn;
if (iLastX > xPlayer) // Door is to the right of player
{
xSecretmPos1 = xMapPosn + 1;
LastMapPosn = xMapPosn;
xSecretColumn = 1; // Set to indicate player is on right side
yGridGlobal[xMapPosn] = yGridGlobal[xMapPosn - GRID_WIDTH];
}
else
{ // Door is to the left of the player
LastMapPosn = xSecretmPos1 = xMapPosn - 1;
xSecretColumn = -1;
yGridGlobal[xSecretmPos1] = yGridGlobal[xSecretmPos1 - GRID_WIDTH];
}
}
}
// A secret door is found along a y wall
if (i == 2 && yGridGlobal[yMapPosn] & DOOR_TYPE_SECRET)
{
if (ySecretColumn == 0)
{
DoorCode = POV_YSECRETDOOR;
if (yGridGlobal[yMapPosn] & DOOR_LOCKED)
return (DoorCode | POV_DOORLOCKED);
//MEH Save secret door bitmap!
aeGlobal->NonSecretCode = yGridGlobal[yMapPosn] & 0xFF;
ySecretmPos = yMapPosn;
if (iLastY > yPlayer)
{
LastMapPosn = yMapPosn;
ySecretmPos1 = yMapPosn + GRID_WIDTH;
xGridGlobal[yMapPosn] = xGridGlobal[yMapPosn - 1];
ySecretColumn = 1;
}
else
{
LastMapPosn = ySecretmPos1 = yMapPosn - GRID_WIDTH;
xGridGlobal[ySecretmPos1] = xGridGlobal[ySecretmPos1 - 1];
ySecretColumn = -1;
}
}
}
// A sliding or split door is found along an x wall
if (i == 1 && (xGridGlobal[xMapPosn] & (DOOR_TYPE_SLIDE + DOOR_TYPE_SPLIT)))
{
j = FindDoorSlot (xMapPosn);
if (j >= 0)
{
DoorCode = POV_XDOOR;
LastMapPosn = gDoor[j].mPos = xMapPosn;
if ((short) iLastX > xPlayer)
i = xMapPosn + 1;
else
LastMapPosn = i = xMapPosn - 1;
if (xGridGlobal[xMapPosn] & DOOR_LOCKED)
{
gDoor[j].mPos = -1;
return (DoorCode | POV_DOORLOCKED);
}
// Update door data structure
gDoor[j].mCode = xGridGlobal[xMapPosn];
gDoor[j].mCode1 = xGridGlobal[i];
gDoor[j].mPos1 = i;
gDoor[j].ColOffset = 1;
gDoor[j].Speed = aeGlobal->DoorSpeed;
gDoor[j].Type = DOOR_XCODE;
gDoor[j].Flags = DOOR_OPENING;
}
}
// A sliding or split door is found along a y wall
if (i == 2 && (yGridGlobal[yMapPosn] & (DOOR_TYPE_SLIDE + DOOR_TYPE_SPLIT)))
{
j = FindDoorSlot (yMapPosn);
if (j >= 0)
{
DoorCode = POV_YDOOR;
LastMapPosn = gDoor[j].mPos = yMapPosn;
if ((short) iLastY > yPlayer)
i = yMapPosn + GRID_WIDTH;
else
LastMapPosn = i = yMapPosn - GRID_WIDTH;
if (yGridGlobal[yMapPosn] & DOOR_LOCKED)
{
gDoor[j].mPos = -1;
return (DoorCode | POV_DOORLOCKED);
}
gDoor[j].mCode = yGridGlobal[yMapPosn];
gDoor[j].mCode1 = yGridGlobal[i];
gDoor[j].mPos1 = i;
gDoor[j].ColOffset = 1;
gDoor[j].Speed = aeGlobal->DoorSpeed;
gDoor[j].Type = DOOR_YCODE;
gDoor[j].Flags = DOOR_OPENING;
}
}
return (DoorCode);
}
// **** End of Source ****