-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADVENTUR.HXX
473 lines (415 loc) · 14.8 KB
/
ADVENTUR.HXX
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
/* ========================================================================
Copyright (c) 1990,1996 Synergistic Software
All Rights Reserved
Author: G. Powell
======================================================================== */
#ifndef _ADVENTUR_HXX
#define _ADVENTUR_HXX
/* ------------------------------------------------------------------------
Sub Includes
------------------------------------------------------------------------ */
#if !defined(_TYPEDEFS_H)
#include "typedefs.h"
#endif
#if !defined(_ENGINE_H)
#include "engine.h"
#endif
#if !defined(_SYSTEM_H)
#include "system.h"
#endif
#if !defined(_PLAYER_HXX)
#include "player.hxx"
#endif
#if !defined(_THINGTYP_H)
#include "thingtyp.h"
#endif
#if !defined(_HANDLE_HXX)
#include "handle.hxx"
#endif
#if !defined(_VECTOR_HXX)
#include "vector.hxx"
#endif
/* ------------------------------------------------------------------------
Defines and Compile Flags
------------------------------------------------------------------------ */
#define MAX_ADVENTURERS 4
#define MAX_TRAIL_POINTS 50
/* ------------------------------------------------------------------------
Enums
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Typedefs
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Macros
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Class Definition
------------------------------------------------------------------------ */
class ADVENTURER_TEAM_ITOR;
class CAvatar;
typedef BOOL const (CAvatar::*CAvatar_pmfv)() const;
typedef void (CAvatar::*CAvatar_pmf)();
// Class to hold positional information about the adventure team. Also can
// be called to test whether conditions about the team.
class ADVENTURER {
public:
friend class ADVENTURER_TEAM_ITOR;
// Helper class to hold the positional data necessary to move the team
// members through the world.
class ADVENTURER_POSITION {
public:
friend class ADVENTURER;
void mfUpdatePosition(PLAYER const * const pPlayer);
void mfFillReversePlayerInfo ( PLAYER * const pPlayer, LONG const ThingIndex) const;
BOOL const mfHasMoved(PLAYER const * const pPlayer) const;
BOOL const mfAmICrouching() const;
BOOL const mfCanIMoveHere(ADVENTURER_POSITION const * const pPosition,
LONG const AvatarWidth) const;
protected:
private:
PLAYER fPlayer;
};
inline void mfInitData();
inline void mfRelease();
BOOL const mfJoinAdventureTeam(SHORT const hdlAvatar);
BOOL const mfDidIMove(LONG const /* X */,
LONG const /* Y */,
LONG const /* Z */,
LONG const /* A */) const;
BOOL const mfAmICrouching() const;
void mfSwapPlaces( ADVENTURER & const /* rAdventurer */);
// [d4-25-97 JPC] Added new parameter pStartFallZ.
inline WadThingType const mfBumpAndFloor(LONG * const /* pThingIndex */,
LONG * const /* pFloor */,
LONG * const /* pFallHeight */,
LONG * const /* pStartFallZ */) const;
void mfGetMyPosition(LONG * const /* pX */,
LONG * const /* pY */,
LONG * const /* pZ */,
LONG * const /* pA */) const;
BOOL const mfCanIWalkThruWall() const;
// Call every AI pass to keep the group moving.
static void mfUpdateAdventureTeam(PLAYER const * const /* pPlayer */);
static LONG const mfNumberOfAdventurers();
static void mfInitAdventureTeam(PLAYER const * const /* pPlayer */);
static void mfReleaseAdventureTeam();
static BOOL const mfIsAdventureTeam(CAvatar_pmfv);
static SHORT const mfFirstAdventurerIs(CAvatar_pmfv);
static void mfDoToAllAdventurers(CAvatar_pmf);
static LONG const mfNumberOfTrailPts();
static void mfFillReversePlayerPts(PLAYER * const /* pPlayerPts */,
LONG const /* NumberOfPts */,
LONG const /* ThingIndex */ );
static BOOL const mfDoesAdventureTeamHave(THINGTYPE const);
inline static SHORT const mfWhoGetsObjectsPickedUp();
static void mfSetWhoGetsObjectsPickedUp( SHORT const /* hAvatar */);
// First member of the team. Return only valid handles.
static ADVENTURER_TEAM_ITOR const begin();
// Past the end of the Team array.
static ADVENTURER_TEAM_ITOR const end();
protected:
private:
SBYTE fAdventurerPathIndex; // Which path follower am I.
SHORT fhAvatar; // Back handle to my avatar data.
static BOOL fPlayerMoved;
static SHORT fhdlPathPositions;
static DECL_VECTOR_CLASS_S(SHORT,fAdventurersHdl,MAX_ADVENTURERS);
static SBYTE fAdventurerCount;
static LONG fTimeLastBump;
static LONG fTimeLastSplash; // [d11-14-96 JPC]
static BOOL fLavaSoundOn; // [d11-14-96 JPC]
static SHORT fLavaSoundID; // [d11-14-96 JPC]
static SBYTE const fFirstAdventurerIndex;
static SBYTE fNumberOfGoodTrailPts;
static SHORT fhWhoGetsObjects; // When walking around inventory is added to...
};
// Iterator class for the Adventurer team.
// This class is modeled to follow the STL convention for member fns and
// operators.
class ADVENTURER_TEAM_ITOR {
public:
// Constructor for the adventure team iterator
ADVENTURER_TEAM_ITOR(SBYTE const val = 0) :
fCurrentIndex(val) {}
ADVENTURER_TEAM_ITOR(ADVENTURER_TEAM_ITOR const &rhs) :
fCurrentIndex(rhs.fCurrentIndex) {}
// Advance the iterator to the next Adventurer on the team.
ADVENTURER_TEAM_ITOR const &operator++(int) {
for (++fCurrentIndex; ADVENTURER::end() != fCurrentIndex; fCurrentIndex++)
{
if (ADVENTURER::fAdventurersHdl[fCurrentIndex] != fERROR)
{
break;
}
}
return *this;
}
// Let the iterator become positioned at this index.
ADVENTURER_TEAM_ITOR const & operator=(ADVENTURER_TEAM_ITOR const &rhs) {
fCurrentIndex = rhs.fCurrentIndex;
return *this;
}
void mfSet(SHORT const hAvatar)
{
ADVENTURER::fAdventurersHdl[fCurrentIndex] = hAvatar;
}
// Return the handle to the avatar.
// Note: It doesn't check for out of range values.
SHORT & operator*() const {
return ADVENTURER::fAdventurersHdl[fCurrentIndex];
}
// Comparison operator is a member to avoid an extra copy of the iterator.
BOOL const operator!=(ADVENTURER_TEAM_ITOR const &rhs) const
{
return (fCurrentIndex != rhs.fCurrentIndex) ? TRUE : FALSE;
}
protected:
// Comparison operator is a member to avoid an extra copy of the iterator.
BOOL const operator!=(SBYTE const &rhs) const
{
return (fCurrentIndex != rhs) ? TRUE : FALSE;
}
private:
SBYTE fCurrentIndex;
};
/* ------------------------------------------------------------------------
Prototypes
------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------
Inline functions
------------------------------------------------------------------------ */
inline void ADVENTURER::ADVENTURER_POSITION::mfUpdatePosition(
PLAYER const * const pPlayer)
{
fPlayer.x = PLAYER_INT_VAL(pPlayer->x);
fPlayer.y = PLAYER_INT_VAL(pPlayer->y);
fPlayer.z = pPlayer->z;
fPlayer.a = (SHORT) pPlayer->a;
fPlayer.h = pPlayer->h;
fPlayer.Crouching = (SBYTE) pPlayer->Crouching;
fPlayer.floor = (SHORT) pPlayer->floor;
fPlayer.ceiling = (SHORT) pPlayer->ceiling;
fPlayer.bump = pPlayer->bump;
fPlayer.BumpIndex = (SHORT)pPlayer->BumpIndex;
fPlayer.WalkThruWall = pPlayer->WalkThruWall;
fPlayer.currentSector = pPlayer->currentSector;
fPlayer.fallHeight = pPlayer->fallHeight;
fPlayer.startFallZ = pPlayer->startFallZ; // [d4-25-97 JPC]
}
inline void ADVENTURER::ADVENTURER_POSITION::mfFillReversePlayerInfo (
PLAYER * const pPlayer, LONG const ThingIndex) const
{
pPlayer->x = fPlayer.x << PLAYER_FIXEDPT;
pPlayer->y = fPlayer.y << PLAYER_FIXEDPT;
pPlayer->z = fPlayer.z;
pPlayer->a = (fPlayer.a - 128 ) & 0xFF;
pPlayer->Crouching = fPlayer.Crouching;
pPlayer->floor = fPlayer.floor;
pPlayer->ceiling = fPlayer.ceiling;
pPlayer->currentSector = fPlayer.currentSector;
// We won't bump objects while retreating. (We'll still go around.)
if (fPlayer.bump == iOBJECT)
{
pPlayer->bump = iNOTHING;
}
else
{
pPlayer->bump = fPlayer.bump;
}
pPlayer->BumpIndex = fPlayer.BumpIndex;
pPlayer->WalkThruWall = fPlayer.WalkThruWall;
// Just keep using the default height and width.
pPlayer->w = player.w;
// [d11-20-96 JPC]
// If crouching, height is halved, so we need to know the height.
// OLD: pPlayer->h = player.h;
pPlayer->h = fPlayer.h;
pPlayer->Flying = FALSE;
pPlayer->ThingIndex = ThingIndex;
pPlayer->p = 0; // No pitch.
pPlayer->fallHeight = fPlayer.fallHeight;
pPlayer->startFallZ = fPlayer.startFallZ; // [d4-25-97 JPC]
}
inline BOOL const ADVENTURER::ADVENTURER_POSITION::mfHasMoved(
PLAYER const * const pPlayer) const
{
return ((fPlayer.x != PLAYER_INT_VAL(pPlayer->x) ||
fPlayer.y != PLAYER_INT_VAL(pPlayer->y) ||
fPlayer.z != pPlayer->z ||
fPlayer.a != pPlayer->a )
? TRUE : FALSE );
}
inline BOOL const ADVENTURER::ADVENTURER_POSITION::mfAmICrouching() const
{
return ((fPlayer.Crouching == TRUE) ? TRUE : FALSE);
}
inline BOOL const ADVENTURER::ADVENTURER_POSITION::mfCanIMoveHere(
ADVENTURER_POSITION const * const pPosition,
LONG const AvatarWidth) const
{
// [d11-24-96 JPC] Need to take Z into account for falling damage.
// The team may stack up--the lesser evil.
if (fPlayer.z != pPosition->fPlayer.z)
return TRUE;
return ((AvatarWidth <= aprox_dist(fPlayer.x, fPlayer.y,
pPosition->fPlayer.x,
pPosition->fPlayer.y)) ? TRUE : FALSE );
}
inline void ADVENTURER::mfInitData()
{
fAdventurerPathIndex = -1;
fhAvatar = -1;
}
inline void ADVENTURER::mfRelease()
{
LONG i;
for (i = 0; i < MAX_ADVENTURERS; i++)
{
if (fhAvatar == fAdventurersHdl[i])
{
fAdventurersHdl[i] = fERROR;
break;
}
}
fAdventurerPathIndex = -1;
fAdventurerCount--;
if (fAdventurerCount < 0)
{
fAdventurerCount = 0;
}
mfInitData();
}
// return the total in the team.
inline LONG const ADVENTURER::mfNumberOfAdventurers()
{
return fAdventurerCount;
}
// Check whether to use the crouch art or not.
inline BOOL const ADVENTURER::mfAmICrouching() const
{
BOOL Result = FALSE;
if (fhdlPathPositions != fERROR && fAdventurerPathIndex != -1)
{
DumbHandleArray<ADVENTURER_POSITION const> const pPosition(fhdlPathPositions);
Result = pPosition[fAdventurerPathIndex].mfAmICrouching();
}
return Result;
}
// check whether the adventurer can walk through wall or not.
inline BOOL const ADVENTURER::mfCanIWalkThruWall() const
{
BOOL Result = FALSE;
if (fhdlPathPositions != fERROR && fAdventurerPathIndex != -1)
{
DumbHandleArray<ADVENTURER_POSITION const> const pPosition(fhdlPathPositions);
Result = (BOOL)(pPosition[fAdventurerPathIndex].fPlayer.WalkThruWall);
}
return Result;
}
// return the thing we bumped.
inline WadThingType const ADVENTURER::mfBumpAndFloor(LONG * const pThingIndex,
LONG * const pFloor,
LONG * const pFallHeight,
LONG * const pStartFallZ) const // [d4-25-97 JPC] new param
{
WadThingType bump = iNOTHING;
if (fhdlPathPositions != fERROR && fAdventurerPathIndex != -1)
{
DumbHandleArray<ADVENTURER_POSITION const> const pPosition(fhdlPathPositions);
bump = pPosition[fAdventurerPathIndex].fPlayer.bump;
*pThingIndex = pPosition[fAdventurerPathIndex].fPlayer.BumpIndex;
*pFloor = pPosition[fAdventurerPathIndex].fPlayer.floor;
*pFallHeight = pPosition[fAdventurerPathIndex].fPlayer.fallHeight;
*pStartFallZ = pPosition[fAdventurerPathIndex].fPlayer.startFallZ; // [d4-25-97 JPC]
}
return bump;
}
// Get the position data for this bread crumb follower.
inline void ADVENTURER::mfGetMyPosition(
LONG * const pX,
LONG * const pY,
LONG * const pZ,
LONG * const pA) const
{
if (fhdlPathPositions != fERROR && fAdventurerPathIndex != -1)
{
DumbHandleArray<ADVENTURER_POSITION const> const pPosition(fhdlPathPositions);
*pX = pPosition[fAdventurerPathIndex].fPlayer.x;
*pY = pPosition[fAdventurerPathIndex].fPlayer.y;
*pZ = pPosition[fAdventurerPathIndex].fPlayer.z;
// Only the first person in line follows the player the rest, the direction
// of travel.
if (fAdventurerPathIndex == fFirstAdventurerIndex)
{
*pA = pPosition[fAdventurerPathIndex].fPlayer.a;
}
else
{
// Face the followers the way they are traveling.
*pA = AngleFromPoint(pPosition[fAdventurerPathIndex].fPlayer.x,
pPosition[fAdventurerPathIndex].fPlayer.y,
pPosition[fAdventurerPathIndex + 1].fPlayer.x,
pPosition[fAdventurerPathIndex + 1].fPlayer.y,
RESOLUTION_8);
}
}
}
// Test this current position to the next position.
inline BOOL const ADVENTURER::mfDidIMove(
LONG const X,
LONG const Y,
LONG const Z,
LONG const Angle) const
{
BOOL Result = FALSE;
if (fhdlPathPositions != fERROR && fAdventurerPathIndex != -1)
{
DumbHandleArray<ADVENTURER_POSITION const> const pPosition(fhdlPathPositions);
if (X != pPosition[fAdventurerPathIndex].fPlayer.x ||
Y != pPosition[fAdventurerPathIndex].fPlayer.y ||
Z != pPosition[fAdventurerPathIndex].fPlayer.z ||
(fAdventurerPathIndex == fFirstAdventurerIndex &&
Angle != pPosition[fAdventurerPathIndex].fPlayer.a))
{
Result = TRUE;
}
}
return Result;
}
// Get the number of trail points.
inline LONG const ADVENTURER::mfNumberOfTrailPts()
{
return fNumberOfGoodTrailPts;
}
// First member of the team. Return only valid handles.
inline ADVENTURER_TEAM_ITOR const ADVENTURER::begin()
{
SBYTE Result = MAX_ADVENTURERS;
for (SBYTE i = 0; i < MAX_ADVENTURERS; i++)
{
if (fAdventurersHdl[i] != fERROR)
{
Result = i;
break;
}
}
return ADVENTURER_TEAM_ITOR(Result);
}
// Past the end of the Team array.
inline ADVENTURER_TEAM_ITOR const ADVENTURER::end()
{
return ADVENTURER_TEAM_ITOR(MAX_ADVENTURERS);
}
// Return who Gets the objects.
inline static SHORT const ADVENTURER::mfWhoGetsObjectsPickedUp()
{
return fhWhoGetsObjects;
}
// Change who gets the objects. (Does no error checking...maybe later..)
inline static void ADVENTURER::mfSetWhoGetsObjectsPickedUp( SHORT const hAvatar)
{
fhWhoGetsObjects = hAvatar;
}
#endif // _ADVENTUR_HXX