-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVATAR.HXX
1291 lines (1102 loc) · 35.5 KB
/
AVATAR.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
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
/* ========================================================================
Copyright (c) 1990,1996 Synergistic Software
All Rights Reserved
========================================================================
Filename: Avatar.hxx
======================================================================== */
#if !defined(_AVATAR_HXX)
#define _AVATAR_HXX
#include <stdio.h>
#include <limits.h>
#if !defined(_SYSTEM_H)
#include "system.h"
#endif
#if !defined(_ENGINE_H)
#include "engine.h"
#endif
#if !defined(_CTHING_HXX)
#include "cthing.hxx"
#endif
#if !defined(_AIFTSEQ_HXX)
#include "aiftseq.hxx"
#endif
#if !defined(_REALM_HXX)
#include "realm.hxx"
#endif
#if !defined(_MACHINE_H)
#include "machine.h"
#endif
#if !defined(_MENU_H)
#include "menu.h"
#endif
#if !defined(_SCNMGR_HXX)
#include "scnmgr.hxx"
#endif
#if !defined(_SOUND_HXX)
#include "sound.hxx"
#endif
#if !defined(_SPECIAL_H)
#include "special.h"
#endif
typedef SHORT HDL_AVATAR;
// ai subclasses
#if !defined(_AI_LEADER_HXX)
#include "aileader.hxx"
#endif
// ai classes
#if !defined(_AIBTLCAP_HXX)
#include "aibtlcap.hxx"
#endif
#if !defined(_AIFOLPLY_HXX)
#include "aifolply.hxx"
#endif
#if !defined(_AIFIREBL_HXX)
#include "aifirebl.hxx"
#endif
#if !defined(_AIFOLID_HXX)
#include "aifolid.hxx"
#endif
#if !defined(_AIFOLPTH_HXX)
#include "aifolpth.hxx"
#endif
#if !defined(_AIGARGL_HXX)
#include "aigargl.hxx"
#endif
#if !defined(_AIGUARD_HXX)
#include "aiguard.hxx"
#endif
#if !defined(_AIPONG_HXX)
#include "aipong.hxx"
#endif
#if !defined(_AIPTHLDR_HXX)
#include "aipthldr.hxx"
#endif
#if !defined(_AIFOLCAP_HXX)
#include "aifolcap.hxx"
#endif
#if !defined(_AISPIDER_HXX)
#include "aispider.hxx"
#endif
#if !defined(_AIHHOUND_HXX)
#include "aihhound.hxx"
#endif
#if !defined(_AIHARPY_HXX)
#include "aiharpy.hxx"
#endif
#if !defined(_AIWYVERN_HXX)
#include "aiwyvern.hxx"
#endif
#if !defined(_AISPECTR_HXX)
#include "aispectr.hxx"
#endif
#if !defined(_AIHORSE_HXX)
#include "aihorse.hxx"
#endif
#if !defined(_AISTUN_HXX)
#include "aistun.hxx"
#endif
/* -----------------------------------------------------------------
Defines
----------------------------------------------------------------- */
#define PLAYER_WIDTH 16
#define PLAYER_HEIGHT 70
#define HIGHLIGHT_TICK_TIME 15
typedef enum {
STANDSEQ = ANIMATION0SEQ,
WALKSEQ = ANIMATION1SEQ,
DEFENDSEQ = ANIMATION2SEQ,
ATTACK1SEQ = ANIMATION3SEQ,
ATTACK2SEQ = ANIMATION4SEQ,
EXPIRESEQ = ANIMATION5SEQ,
CROUCHSEQ = ANIMATION6SEQ,
SITGESTSEQ = ANIMATION7SEQ,
LISTENSEQ = ANIMATION8SEQ,
GEST1SEQ = ANIMATION9SEQ,
MARCHSEQ = ANIMATION11SEQ,
BOWSEQ = ANIMATION10SEQ,
DEADSEQ = ANIMATION12SEQ,
MAGICSEQ = ANIMATION4SEQ,
} ANIMATION_SEQ;
#define MAX_SND_QUEUE 4
#define HIT_FRAME_CNT 0
#define BIG_HIT_FRAME_CNT 1
#define PAIN_FRAME_CNT 2
#define DEATH_SCREAM_FRAME_CNT 2
// avatar control bits
#define AIC_ENGAGED 0x00000001
#define AIC_UNUSED 0x00000002
#define MAX_TICK (ULONG)-1
#define MAX_ATTACK_ROLLS 2
#define ATTACK_TURN_NOT_DECIDED -1
// Currently there are Five bits set by DCK which we have decree'd will drive
// the automatic AI's.
#define LARGE_PARTY_ONLY 0x01 // Otherwise remove from wad. (3 or 4 adventurers.)
#define STAND_WAITING 0x02 // Otherwise PingPong inside the Monster box.
#define TELEPORT_HOME_AFTERWARD 0x04 // otherwise do your ai where you lost the player.
#define IGNORE_MONSTER_BOX 0x08 // for chasing the player.
#define HARD_LEVEL_ONLY 0x10 // Unless hard is on.
/* -----------------------------------------------------------------
Prototypes
----------------------------------------------------------------- */
SHORT AvatarIdToHdl ( LONG Id );
inline LONG AvatarHdlToId ( SHORT Hdl );
void mfReadType(FILE *, THINGTYPE *);
void mfWriteType(FILE *, THINGTYPE);
void mfReadTextType(FILE *, THINGTYPE *);
void mfWriteTextType(FILE *, THINGTYPE);
/* -----------------------------------------------------------------
Globals
----------------------------------------------------------------- */
/* -----------------------------------------------------------------
Avatar class
----------------------------------------------------------------- */
class SCENE;
class PLAYER_STATS;
class CAvatar : public CThing
{
public: // Public for the dialog editor
typedef enum {
AI_INIT = 0,
AI_RELEASE,
AI_BEGIN_PAUSE,
AI_PAUSED,
AI_END_PAUSE,
AI_MOVING,
AI_READFILE,
AI_RUNNING,
AI_SEARCH,
AI_ATTACK,
AI_DEFEND,
AI_FALLBACK,
AI_CASTSPELL,
AI_BEGIN_LISTEN,
AI_LISTEN,
AI_END_LISTEN,
AI_BEGIN_LISTEN_BOW,
AI_END_LISTEN_BOW,
AI_ROTATE_TO_CAMERA,
AI_RETURN_TO_POSITION,
AI_DEAD,
AI_FIDGET,
AI_FALLING,
AI_STONE,
AI_CONSUME,
AI_RESURRECTION,
// Add above here
AI_MAX_STATUS
} AISTATUS;
typedef enum
{
AI_FUNC_NULL = 0,
AI_FUNC_FOLLOW_PATH,
AI_FUNC_PING_PONG,
AI_FUNC_BATTLE_CAPTAIN,
AI_FUNC_FOLLOW_PLAYER,
AI_FUNC_FOLLOW_BTLCAP,
AI_FUNC_SPIDERS,
AI_FUNC_HELLHOUND,
AI_FUNC_HARPIES,
AI_FUNC_WYVERNS,
AI_FUNC_FIREBALL,
AI_FUNC_SPECTRE,
AI_FUNC_GARGOYLES,
AI_FUNC_STUNNED,
AI_FUNC_HORSE,
// Add above here
AI_MAX_NUMBER
} AIFUNC;
// Data to be used while Avatar is in Paused mode.
typedef struct _PREV_STATE {
AISTATUS Status; // my current status before pausing.
LONG A; // The angle I used to be facing.
ANIMATION_SEQ Sequence; // What was it I used to be doing?
ULONG TimeLastRotate; // Used to slow down a turn.
} PREV_STATE;
typedef struct _AVATAR_BIT_DATA {
unsigned RuntimeCreated : 1; // Created by another avatar.
unsigned SceneInstance : 1; // Created by the scene. (No special .ava file)
unsigned Engaged : 1; // unused.
unsigned IsFlying : 1; // is this guy flying.
unsigned IsFeathered : 1; // is this guy feather falling.
unsigned CanSeeInDark : 1; // can this guy see in the dark
unsigned CanSeeInfra : 1; // Predator!
unsigned IssuedChallange : 1; // Challanged my enemy.
unsigned IssuedTaunt : 1; // Taunted my enemy.
unsigned IsFollowPath : 1; // does this guy have a path to follow
unsigned KilledBySpectre : 1;
unsigned AttackMode : 4; // Uses a quick, or slow attack instead of regular slow attack.
unsigned PlayedFightSnd : 1;
unsigned IsJumpEnhanced : 1; // is this guy using any of various jumping/springing items or spells
unsigned DiedLastFrame : 1; //used by AI to determine when to spit out items
unsigned BeingControlled : 1; // used by combat to say who is the hot avatar.
unsigned KilledByLava : 1; // used by resurrection to determine if he can be resurrected
} AVATAR_BIT_DATA;
typedef struct _AVATAR_SND_DATA {
BIRTHRT_SND SndId; // which sound to play
SHORT Range; // range of the random number count
LONG TriggerFrame; // gFrames count the fires this sound
SBYTE Loop;
SBYTE TotalFrames;
} AVATAR_SND_DATA;
LONG Version; // which game version this avatar belongs with
LONG Id; // Unique identifier for this avatar.
LONG UnitIndex; // my index in the units array
ANIMATION_SEQ CurSequence; // Which flick am I running?
SHORT hThis; // The handle from NewBlock that allocated this Avatar.
AVATAR_BIT_DATA attrib; // This has info about how this avatar was created.
AISTATUS Status; // my current status
SHORT hPlayerStats; // AD&D stats (not set for battle troops)
REALM Realm; // what kingdom am I from
SHORT Engaged; // Count of avatars attacking me.
HDL_AVATAR hEnemy; // The handle of your target.
THINGTYPE KillType; // what type of special kill
SBYTE fOriginalRemapColor; // to be reset to when dead.
SBYTE fDamageFlag; // When damage can be done > 0.
SBYTE fAttackTurnFlag; // Number of attack swings I get before letting the enemy have a chance.
SHORT fDamage; // Damage dealt by you. (For report to combat menus.)
SHORT fContactDistance; // Distance in front of avatar where the sword hits.
SBYTE fAttackRolls[MAX_ATTACK_ROLLS]; //
ULONG fHighlightEndTime;
FIGHT_SEQUENCE fFightSeq; // Fight sequence for this avatar.
WadThingType lastBump;
LONG bumpTimer; // For movement.
LONG dAngle;
LONG fTimeLastChanged;
LONG fFrameLastChanged;
LONG fTimeLastMoved;
PREV_STATE fPrev;
AVATAR_SND_DATA SndData[MAX_SND_QUEUE]; // snds to play on a given seq frame
// Any mutually exclusive data should be stored here.
union {
FOLLOW_ID_DATA fFollowId;
PINGPONG_DATA fPingPong;
FOLLOW_PLAYER_DATA fFollowPlayer;
BATTLE_CAPTAIN_DATA fBtlCap;
FOLLOW_BTLCAP_DATA fFollowBtlCap;
SPIDER_DATA fSpider;
HELLHOUND_DATA fHellHound;
HARPY_DATA fHarpy;
WYVERN_DATA fWyvern;
FIREBALL_DATA fFireBall;
SPECTRE_DATA fSpectre;
STUNNED_DATA fStunned;
GARGOYLE_DATA fGargoyle;
HORSE_DATA fHorse;
};
FOLLOW_PATH_DATA fFollowPath;
void Save(void);
void DoAI(void);
inline AISTATUS DoAI(AISTATUS st);
void SetAIFuncIndex(AIFUNC);
inline AIFUNC GetAIFuncIndex() const;
inline void mfGetContactPoint(POINT_3D * const) const;
inline BOOL mfShouldSaveToSceneFile();
void mfWriteSceneData(FILE * const fp);
inline void mfInitVals();
inline LONG mfReadRestOfSceneData(FILE * const fp);
static SHORT NewAvatar(void); // This routine modifies memory, refresh the pointer.
static void DeleteAvatar(SHORT hAvatar);
// GWP Remove the default Realm value when aibtlcap.cpp is available.
static LONG CAvatar::CreateAvatar(
LONG Id,
THINGTYPE Type,
LONG X,
LONG Y,
LONG A,
CAvatar::AIFUNC FuncIndex,
SCENE *pScene ,
const REALM::REALM_TYPE);
void mfCreateFireBall(
LONG Id,
THINGTYPE Type,
LONG DamageLevel) const;
void mfCreateHorse(
LONG Id,
THINGTYPE Type) const;
inline void mfSetOriginalRemapColor(LONG const /* remapColor */);
inline void CAvatar::mfSetBeingControlled(BOOL const /* flag */);
// The Menu Fns.
static void mfSwitchToStandStill(LONG);
static void mfSwitchToGuardPt(LONG);
// start some animation
inline void mfStartAnimationOnce(ANIMATION_SEQ const /* sequence */ );
inline void mfPlayAnimationOnce(ANIMATION_SEQ const /* sequence */ );
inline void mfStartAnimationLoop(ANIMATION_SEQ const /* sequence */ );
inline void mfStartAnimationStand(ANIMATION_SEQ const /* sequence */ );
inline BOOL mfPlayAnimationBackward(ANIMATION_SEQ const /* sequence */ );
inline void mfFreezeFrame(ANIMATION_SEQ const /* sequence */, SHORT const /* Frame number */);
// Cover fn until the engine can tell us the real number.
BOOL const mfTestSequenceDone() const;
BOOL const mfTestSequencePastHalf() const;
BOOL const mfTestSequenceAtHit() const;
BOOL const mfTestSequence2ndLastFrame() const;
inline BOOL mfTestFrame(LONG const frame);
const UBYTE mfGetWalkRate() const;
const UBYTE mfGetMarchRate() const;
void mfCheckCrush();
inline void mfSetDamageDealt(LONG const /* damage */ );
inline LONG const mfGetDamageDealt() const;
// check to see if I generated a sound and need to play it.
void mfCheckSnds();
void mfQueueSnd(BIRTHRT_SND const /* SndId */,
SHORT const /* range */,
LONG const /* inNumbFrames */);
void mfSetLoopingSnd(BIRTHRT_SND const SndId, SBYTE totalFrames); // start sound, has to call mfQueueSnd first
void mfClearLoopingSnd(BIRTHRT_SND const SndId); // stop loop sound
void mfClearAllLoopingSnds(); // stop all the loop sounds
// am I on the Home Team
BOOL const mfIsHomeTeam() const;
inline void mfSetRealm(REALM::REALM_TYPE const);
// returns TRUE if Him is an ally of Me
inline const BOOL mfIsAlly(CAvatar const * const Him) const;
inline void mfConvertPositionToPlayer(PLAYER &) const;
inline void mfUpdatePositionOfPlayer(PLAYER &) const;
WadThingType const mfCheckNewPosition(LONG const /* dx */, LONG const /* dx */, LONG const /* Rate */) const;
WadThingType const mfCheckNewPosition2(FIXED_VECTOR_3D * const /* tp */, LONG const /* Rate */) const;
inline const LONG mfDistanceToPlayer() const;
const BOOL mfCanSeeAvatar(const CAvatar *) const;
HDL_AVATAR mfFindClosestFoe() const;
HDL_AVATAR mfFindClosestVisibleFoe() const;
inline BOOL const mfCanIHitHim(CAvatar const * const /* pEnemy */ ,
LONG const /* distance */,
LONG const /* attackDist */) const;
BOOL mfCanHarpyHitHim (CAvatar *pAvatarEnemy,
LONG distance,
LONG AttackDistance) const;
//AI Modifier Tests. Used by the Auto AI's
inline BOOL const mfStandWaiting() const;
inline const BOOL mfStayInMonsterBox() const; // After I'm active can I leave?
inline static const BOOL mfLargePartyOnly(LONG const);
inline static const BOOL mfHardLevelOnly(LONG const);
inline const BOOL mfTeleportHome() const; // When I loose the player go home?
inline static const BOOL mfDeadFlicSeq(const LONG);
inline void mfEngage(); // When I am attacked the enemy calls this.
inline void mfDisEngage(); // When I stop being attacked, the enemy calls this.
BOOL const mfAmIBeingAttacked() const;
BOOL const mfAmICastingASpell() const;
BOOL const mfAmIChasingAnEnemy() const;
inline BOOL const mfAmIImmoblized() const;
BOOL const mfAmIAlive() const;
void mfIfAliveRestoreHealth();
inline FIGHT_SEQUENCE::ATTACK_MODE const mfGetAttackMode() const;
void mfSetAttackMode(FIGHT_SEQUENCE::ATTACK_MODE const);
void mfSetAttackSequence(FIGHT_SEQUENCE::ATTACK_MODE const);
inline BOOL const mfIsAllDamageDone() const;
void mfSetDamageFlag();
void mfSetMyTurnToAttack();
void mfDecideWhoseTurnToAttack();
inline void mfClearTurnToAttack();
BOOL const mfIsMyTurnToAttack() const;
inline void mfDecrementAttackTurnCount();
BOOL mfWackEm(HDL_AVATAR const hEnemyTarget);
void mfKillAvatar(CAvatar * const pAvatar);
BOOL mfInflictMagicDamage(CAvatar * const /* pEnemy */,
THINGTYPE const /* KillType */,
LONG const /* Damage */);
LONG const mfToHitEnemy(SHORT const /* hEnemyTarget */ ) const;
void mfFightSounds(HDL_AVATAR const hEnemyTarget);
void mfPainSounds();
void mfSpewAll(); // dead guys drop stuff
void mfTestAndGiveDamage(HDL_AVATAR const hEnemyTarget);
void mfTestAndGiveMagicDamage(HDL_AVATAR const /* hEnemyTarget */,
THINGTYPE const /* ThingCausingDamage */,
LONG const /* Damage */);
static SHORT PlayerAvatarHandle; // The avatar that is following the player structure
static const LONG ActivationDistance;
static const LONG fgTauntDelay; // How long to wait for the next taunt.
// Which avatar is being controled by the keyboard "player."
inline static SHORT const mfGetPlayerAvatarHandle();
inline void mfSetMeToThePlayer() const;
static BOOL CAvatar::mfSetKillType(CAvatar *, THINGTYPE, LONG DamageLevel );
void mfStartNextFightSequence();
inline BOOL mfIsNastySector (LONG const x, LONG const y); // [d11-30-96 JPC] returns TRUE if
// sector is lava, deep water, or acid
// Magic Effects
void mfTurnToStone();
void mfTurnToSpectre();
inline void mfRestartFightSequence();
void mfSethEnemy(SHORT const /* EnemyHdl */);
inline BOOL const mfAmIBeingControled() const;
inline void mfSetHighlightAvatar();
inline void mfSetHighlightEnemy();
inline void mfTurnHighlightOff();
inline void mfDoHighlight();
protected:
private:
// The AI fns.
static void FollowPath(CAvatar *, AISTATUS);
static void BattleCapt(CAvatar *, AISTATUS);
static void FollowPlayer(CAvatar *, AISTATUS);
static void PingPong(CAvatar *, AISTATUS);
static void FollowBtlCap(CAvatar *, AISTATUS);
static void Spiders(CAvatar *, AISTATUS);
static void HellHounds(CAvatar *, AISTATUS);
static void Harpies(CAvatar *, AISTATUS);
static void Wyverns(CAvatar *, AISTATUS);
static void FireBall(CAvatar *, AISTATUS);
static void Spectres(CAvatar *, AISTATUS);
static void Gargoyles(CAvatar *, AISTATUS);
static void Stunned(CAvatar *, AISTATUS);
static void Horse(CAvatar *, AISTATUS);
LONG const mfCalculateAttackModifier( SHORT const /* hEnemyTarget */) const;
void CreateBattleTroops();
void MoveBattleTroops();
LONG MoveToward(LONG /* lTargetX */,
LONG /* lTargetY */,
LONG /* Bump */ ,
LONG /* Rate */);
WadThingType mfMoveTowardWithBump(LONG /* distance */,
LONG /* lTargetX */, // 24.8
LONG /* lTargetY */, // 24.8
LONG /* Bump */,
LONG /* Rate */,
SHORT /* sSpecial */,
LONG * /* pAngle */,
LONG * /* pmyThingBumped */ );
WadThingType mfFlyTowardWithBump(LONG /* distance */,
LONG /* lTargetX */, // 24.8
LONG /* lTargetY */, // 24.8
LONG /* lTargetZ */,
LONG /* Bump */,
LONG /* Rate */,
SHORT /* sSpecial */,
LONG * /* pAngle */,
LONG * /* pmyThingBumped */ );
LONG AvatarNear( THINGTYPE /* type */,
LONG & /* Distance */,
SHORT & /* HandleToAvatar */);
// Subroutines to help make noise for combat.
void mfFightMissSounds(PLAYER_STATS const * const /* pAvatarStats */,
CAvatar * const /* pEnemyTarget */,
PLAYER_STATS const * const /* pEnemyStats */) const;
void mfFightStartSounds(PLAYER_STATS const * const /* pAvatarStats */) const;
void mfDieSounds();
void mfFightHitSounds(PLAYER_STATS const * const /* pAvatarStats */,
CAvatar * const /* pEnemyTarget */,
PLAYER_STATS const * const /* pEnemyStats */) const;
void mfBeginPause();
inline void mfEndPause();
inline void mfBeginListen();
void mfRotateToCamera();
inline void mfReturnToPosition();
inline void mfBeginListenBow();
inline void mfEndListenBow();
inline void mfListen();
inline void mfEndListen();
inline void mfStandAndFidget();
LONG mfRotateToward(LONG /* Starting Angle */,
LONG /* Target Angle */ );
inline void mfReflect(const LONG /* Angle */,
LONG &/* NewAngle */) const;
// [d9-19-96 JPC]
// [d4-25-97 JPC] Added return type of BOOL
BOOL mfFallingDamage (WadThingType bump, LONG floor, LONG fallHeight);
AIFUNC AIFuncIndex; // AI ENUMERATED TYPE
void (*pAvatarFunc)(CAvatar *, AISTATUS);
// These operators are defined but not implemented they will cause a
// link error if accidently used
CAvatar();
~CAvatar();
const CAvatar& operator=( const CAvatar& );
CAvatar(const CAvatar &);
void *operator new( size_t stAllocateBlock);
void operator delete( void *p );
};
// set my kingdom alliance
inline void CAvatar::mfSetRealm(REALM::REALM_TYPE const NewRealm)
{
Realm.HomeRealm = NewRealm;
}
// returns TRUE if Him is an ally of Me
inline const BOOL CAvatar::mfIsAlly(CAvatar const * const Him) const
{
// return( Realm.mfIsMyAlly(Him->Realm.HomeRealm) );
return AREALLIED(Realm.HomeRealm,Him->Realm.HomeRealm); // changed 9/3 ABC
}
// This routine calls the current AI routine every render frame.
inline void CAvatar::DoAI(void)
{
if (pAvatarFunc != 0)
{
mfTestAndUseLowResArt();
mfDoHighlight();
(*pAvatarFunc)(this, Status);
}
mfCheckSnds();
}
// This routine forces the AI routine to do a specific command
// returns the new status
inline CAvatar::AISTATUS CAvatar::DoAI(CAvatar::AISTATUS st)
{
if (pAvatarFunc != 0)
{
mfTestAndUseLowResArt();
mfDoHighlight();
(*pAvatarFunc)(this, st);
}
mfCheckSnds();
return (Status);
}
// This routine provide access for dlg_edit
inline CAvatar::AIFUNC CAvatar::GetAIFuncIndex() const
{
return AIFuncIndex;
}
// Start a new animation. Cover func sets all our internal vars.
inline void CAvatar::mfStartAnimationOnce(ANIMATION_SEQ const ulNewSeq)
{
CurSequence = ulNewSeq;
fTimeLastChanged = SCENE_MGR::gTick;
fFrameLastChanged = SCENE_MGR::gFrame;
attrib.PlayedFightSnd = FALSE;
// GWP Need routine that return error condition.
LoopSequenceOnce(ThingIndex, ulNewSeq);
if ((attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_HIGH ||
attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_LOW) &&
(ulNewSeq == ATTACK1SEQ ||
ulNewSeq == ATTACK2SEQ))
{
mfSetQuickAnimation(TRUE);
}
}
// Start a new animation. Cover func sets all our internal vars.
inline void CAvatar::mfPlayAnimationOnce(ANIMATION_SEQ const ulNewSeq)
{
CurSequence = ulNewSeq;
fTimeLastChanged = SCENE_MGR::gTick;
fFrameLastChanged = SCENE_MGR::gFrame;
attrib.PlayedFightSnd = FALSE;
// GWP Need routine that return error condition.
PlaySequenceOnce(ThingIndex, ulNewSeq);
if ((attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_HIGH ||
attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_LOW) &&
(ulNewSeq == ATTACK1SEQ ||
ulNewSeq == ATTACK2SEQ))
{
mfSetQuickAnimation(TRUE);
}
}
// Switch to a new standing still frame. Cover func sets all our internal vars.
inline void CAvatar::mfStartAnimationStand(ANIMATION_SEQ const ulNewSeq)
{
CurSequence = ulNewSeq;
fTimeLastChanged = SCENE_MGR::gTick;
fFrameLastChanged = SCENE_MGR::gFrame;
attrib.PlayedFightSnd = FALSE;
// GWP Need routine that return error condition and sets the frame!.
LoopSequenceOnce(ThingIndex, ulNewSeq);
if ((attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_HIGH ||
attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_LOW) &&
(ulNewSeq == ATTACK1SEQ ||
ulNewSeq == ATTACK2SEQ))
{
mfSetQuickAnimation(TRUE);
}
}
// Start a new animation loop. Cover func sets all our internal vars.
inline void CAvatar::mfStartAnimationLoop(ANIMATION_SEQ const ulNewSeq)
{
CurSequence = ulNewSeq;
fTimeLastChanged = SCENE_MGR::gTick;
fFrameLastChanged = SCENE_MGR::gFrame;
attrib.PlayedFightSnd = FALSE;
LoopSequenceContinuously(ThingIndex, ulNewSeq);
if ((attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_HIGH ||
attrib.AttackMode == FIGHT_SEQUENCE::ATM_QUICK_LOW) &&
(ulNewSeq == ATTACK1SEQ ||
ulNewSeq == ATTACK2SEQ))
{
mfSetQuickAnimation(TRUE);
}
}
// Start a new animation and play it backwards
inline BOOL CAvatar::mfPlayAnimationBackward(ANIMATION_SEQ const ulNewSeq)
{
SHORT Result = FALSE;
if(bumpTimer > 8)
bumpTimer = 8; // use bumpTimer as a frame counter
CurSequence = ulNewSeq;
fTimeLastChanged = SCENE_MGR::gTick;
fFrameLastChanged = SCENE_MGR::gFrame;
if(bumpTimer > 0)
{
SetFrame(ThingIndex, ulNewSeq, (SHORT)bumpTimer);
bumpTimer--;
}
else
{
Result = TRUE;
bumpTimer = 100;
}
return Result;
}
// Set the avatar to this frame of this sequence.
inline void CAvatar::mfFreezeFrame(ANIMATION_SEQ const NewSequence , SHORT const FrameNumber)
{
CurSequence = NewSequence;
fTimeLastChanged = SCENE_MGR::gFrame;
fFrameLastChanged = SCENE_MGR::gFrame;
SetFrame(ThingIndex, NewSequence, FrameNumber);
}
// Check if all Damage has been done.
inline BOOL const CAvatar::mfIsAllDamageDone() const
{
return (hEnemy == fERROR || // If you have no enemy you can't give damage.
(!(Status == AI_CONSUME ||
((Status == AI_ATTACK || Status == AI_CASTSPELL) && fDamageFlag > 0))
)
);
}
inline BOOL CAvatar::mfTestFrame(LONG const frame)
{
BOOL Result = FALSE;
if((frame + fFrameLastChanged) < SCENE_MGR::gFrame)
Result = TRUE;
return Result;
}
// Begin a Listening Sequence
inline void CAvatar::mfBeginListen()
{
mfPlayAnimationOnce(STANDSEQ);
Status = AI_BEGIN_LISTEN_BOW;
FaceTo(CAMERA_INT_VAL(camera.x), CAMERA_INT_VAL(camera.y));
fPrev.TimeLastRotate = 0; // so that we'll rotate on the first pass.
//fFreeze = TRUE; // Stop the camera movement.
}
// Wait for Bow to complete.
inline void CAvatar::mfBeginListenBow()
{
if (mfTestSequenceDone())
{
Status = AI_LISTEN;
}
}
inline void CAvatar::mfEndListenBow()
{
if (mfTestSequenceDone())
{
Status = AI_RETURN_TO_POSITION;
fPrev.TimeLastRotate = SCENE_MGR::gTick;
}
}
// Listen sequence
inline void CAvatar::mfListen()
{
// Follow the camera around.
FaceTo(CAMERA_INT_VAL(camera.x), CAMERA_INT_VAL(camera.y));
}
// Terminate a listening sequence
inline void CAvatar::mfEndListen()
{
// Since we currently recieve no messages just resume like AI_END_PAUSE
Status = AI_END_LISTEN_BOW;
mfPlayAnimationOnce(BOWSEQ); // Bow once again.
// fFreeze = FALSE; // Let go of the camera.
}
// Get the avatar facing back where he was before we clicked on them.
inline void CAvatar::mfReturnToPosition()
{
if (mfAngle() == fPrev.A)
{
Status = AI_END_PAUSE;
}
else
{
// Rotate at a reasonable speed
if ((SCENE_MGR::gTick - fPrev.TimeLastRotate) > 1) // GWP Phoney time count.
{
fPrev.TimeLastRotate = SCENE_MGR::gTick;
mfRotateToward(mfAngle(), fPrev.A);
}
}
}
inline void CAvatar::mfEndPause()
{
if (Status == AI_PAUSED ||
Status == AI_BEGIN_PAUSE)
{
Status = fPrev.Status;
mfStartAnimationLoop(fPrev.Sequence);
}
}
// While waiting figet every so often.
inline void CAvatar::mfStandAndFidget()
{
if (!mfAmIImmoblized() &&
(SCENE_MGR::gTick - fTimeLastChanged) > (ULONG)(600 + random(100))) // Time to fidget.
{
// Randomly choose a fidget sequence.
switch (random(2))
{
case 0:
mfPlayAnimationOnce(STANDSEQ);
break;
// GWP case 1:
// GWP mfStartAnimationStand(WALKSEQ);
// GWP break;
case 1:
mfPlayAnimationOnce(GEST1SEQ);
break;
}
}
}
// Before reading the rest of the AI data call this routine.
inline void CAvatar::mfInitVals()
{
attrib.KilledByLava=0;
switch(GetAIFuncIndex())
{
case AI_FUNC_PING_PONG:
fPingPong.mfInitVals();
break;
case AI_FUNC_FOLLOW_PLAYER:
fFollowPlayer.mfInitVals(&player, hThis);
break;
}
}
// Once the Avatar AI is determined get that AI data.
inline LONG CAvatar::mfReadRestOfSceneData(FILE * const fp)
{
LONG Result;
switch(GetAIFuncIndex())
{
case AI_FUNC_FOLLOW_PATH:
Result = fFollowPath.mfReadData(fp);
break;
case AI_FUNC_PING_PONG:
Result = fPingPong.mfReadData(fp);
break;
case AI_FUNC_BATTLE_CAPTAIN:
Result = fBtlCap.mfReadData(fp);
break;
case AI_FUNC_FOLLOW_PLAYER:
Result = fFollowPlayer.mfReadData(fp);
break;
}
return Result;
}
// Test to see if this avatar will be saved in the scene file.
inline BOOL CAvatar::mfShouldSaveToSceneFile()
{
return ((attrib.RuntimeCreated == FALSE) ? TRUE : FALSE);
}
/* ========================================================================
Function - AvatarHdlToId
Description - decode the hdl and return the Id
Returns -
======================================================================== */
inline LONG AvatarHdlToId ( SHORT Hdl )
{
LONG hdl = fERROR; // assume id not found
if (Hdl != fERROR)
{
const CAvatar *pA = (const CAvatar *) BLKPTR(Hdl);
hdl = pA->Id;
}
return hdl;
}
// Convert an Avatars current location to a Player structure.
inline void CAvatar::mfConvertPositionToPlayer(PLAYER &rPlayer) const
{
rPlayer.x = (mfX()) << PLAYER_FIXEDPT;
rPlayer.y = (mfY()) << PLAYER_FIXEDPT;
rPlayer.z = mfZ();
rPlayer.a = mfAngle();
rPlayer.p = 0;
rPlayer.w = mfWidth();
rPlayer.h = mfHeight();
rPlayer.Flying = attrib.IsFlying;
rPlayer.ThingIndex = ThingIndex;
rPlayer.bump = iNOTHING;
rPlayer.BumpIndex = fERROR;
rPlayer.currentSector = mfGetSector();
}
// For a follow player, who is now leading the player from an
// auto AI or keyboard control.
inline void CAvatar::mfUpdatePositionOfPlayer(PLAYER &rPlayer) const
{
rPlayer.x = (mfX()) << PLAYER_FIXEDPT;
rPlayer.y = (mfY()) << PLAYER_FIXEDPT;
rPlayer.z = mfZ();
rPlayer.a = mfAngle();
rPlayer.p = 0;
rPlayer.currentSector = mfGetSector();
}
/* ========================================================================
Function - mfDistanceToPlayer
Description - Get the distance to the player.
Returns - Distance to player.
======================================================================== */
inline const LONG CAvatar::mfDistanceToPlayer() const
{
// Note: If the camera is following the player the distance computed
// by the engine is correct, otherwise recalculate.
return ((SCENE_MGR::fgCamera.mfGetCurrentState() == GAME_CAMERA::FOLLOW_PLAYER) ?
mythings[ThingIndex].dist >> PLAYER_FIXEDPT:
aprox_dist(mfX(),
mfY(),
PLAYER_INT_VAL(player.x),
PLAYER_INT_VAL(player.y)));
}
/* ========================================================================
Function - mfCanIHitHim
Description - inline Check whether the Avatar hit the enmey.