-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathNPC.cpp
2724 lines (2444 loc) · 65.1 KB
/
NPC.cpp
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
//
// NPC.cpp - generic functions
//
// leave this line at the top for all NPC_xxxx.cpp files...
#include "g_headers.h"
#include "b_local.h"
#include "anims.h"
#include "g_functions.h"
#include "say.h"
#include "Q3_Interface.h"
#include "g_vehicles.h"
extern vec3_t playerMins;
extern vec3_t playerMaxs;
//extern void PM_SetAnimFinal(int *torsoAnim,int *legsAnim,int type,int anim,int priority,int *torsoAnimTimer,int *legsAnimTimer,gentity_t *gent);
extern void PM_SetTorsoAnimTimer( gentity_t *ent, int *torsoAnimTimer, int time );
extern void PM_SetLegsAnimTimer( gentity_t *ent, int *legsAnimTimer, int time );
extern void NPC_BSNoClip ( void );
extern void G_AddVoiceEvent( gentity_t *self, int event, int speakDebounceTime );
extern void NPC_ApplyRoff (void);
extern void NPC_TempLookTarget ( gentity_t *self, int lookEntNum, int minLookTime, int maxLookTime );
extern void NPC_CheckPlayerAim ( void );
extern void NPC_CheckAllClear ( void );
extern void G_AddVoiceEvent( gentity_t *self, int event, int speakDebounceTime );
extern qboolean NPC_CheckLookTarget( gentity_t *self );
extern void NPC_SetLookTarget( gentity_t *self, int entNum, int clearTime );
extern void Mark1_dying( gentity_t *self );
extern void NPC_BSCinematic( void );
extern int GetTime ( int lastTime );
extern void G_CheckCharmed( gentity_t *self );
extern qboolean Boba_Flying( gentity_t *self );
extern qboolean RT_Flying( gentity_t *self );
extern qboolean Jedi_CultistDestroyer( gentity_t *self );
extern void Boba_Update();
extern bool Boba_Flee();
extern bool Boba_Tactics();
extern void BubbleShield_Update();
extern qboolean PM_LockedAnim( int anim );
extern cvar_t *g_dismemberment;
extern cvar_t *g_saberRealisticCombat;
extern cvar_t *g_corpseRemovalTime;
//Local Variables
// ai debug cvars
cvar_t *debugNPCAI; // used to print out debug info about the bot AI
cvar_t *debugNPCFreeze; // set to disable bot ai and temporarily freeze them in place
cvar_t *debugNPCName;
cvar_t *d_saberCombat;
cvar_t *d_JediAI;
cvar_t *d_noGroupAI;
cvar_t *d_asynchronousGroupAI;
cvar_t *d_slowmodeath;
extern qboolean stop_icarus;
gentity_t *NPC;
gNPC_t *NPCInfo;
gclient_t *client;
usercmd_t ucmd;
visibility_t enemyVisibility;
void NPC_SetAnim(gentity_t *ent,int setAnimParts,int anim,int setAnimFlags, int iBlend);
static bState_t G_CurrentBState( gNPC_t *gNPC );
extern int eventClearTime;
void CorpsePhysics( gentity_t *self )
{
// run the bot through the server like it was a real client
memset( &ucmd, 0, sizeof( ucmd ) );
ClientThink( self->s.number, &ucmd );
VectorCopy( self->s.origin, self->s.origin2 );
//FIXME: match my pitch and roll for the slope of my groundPlane
if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE && !(self->flags&FL_DISINTEGRATED) )
{//on the ground
//FIXME: check 4 corners
pitch_roll_for_slope( self );
}
if ( eventClearTime == level.time + ALERT_CLEAR_TIME )
{//events were just cleared out so add me again
if ( !(self->client->ps.eFlags&EF_NODRAW) )
{
AddSightEvent( self->enemy, self->currentOrigin, 384, AEL_DISCOVERED );
}
}
if ( level.time - self->s.time > 3000 )
{//been dead for 3 seconds
if ( g_dismemberment->integer < 11381138 && !g_saberRealisticCombat->integer )
{//can't be dismembered once dead
if ( self->client->NPC_class != CLASS_PROTOCOL )
{
self->client->dismembered = true;
}
}
}
if ( level.time - self->s.time > 500 )
{//don't turn "nonsolid" until about 1 second after actual death
if ((self->client->NPC_class != CLASS_MARK1) && (self->client->NPC_class != CLASS_INTERROGATOR)) // The Mark1 & Interrogator stays solid.
{
self->contents = CONTENTS_CORPSE;
}
if ( self->message )
{
self->contents |= CONTENTS_TRIGGER;
}
}
}
/*
----------------------------------------
NPC_RemoveBody
Determines when it's ok to ditch the corpse
----------------------------------------
*/
#define REMOVE_DISTANCE 128
#define REMOVE_DISTANCE_SQR (REMOVE_DISTANCE * REMOVE_DISTANCE)
extern qboolean InFOVFromPlayerView ( gentity_t *ent, int hFOV, int vFOV );
qboolean G_OkayToRemoveCorpse( gentity_t *self )
{
//if we're still on a vehicle, we won't remove ourselves until we get ejected
if ( self->client && self->client->NPC_class != CLASS_VEHICLE && self->s.m_iVehicleNum != 0 )
{
Vehicle_t *pVeh = g_entities[self->s.m_iVehicleNum].m_pVehicle;
if ( pVeh )
{
if ( !pVeh->m_pVehicleInfo->Eject( pVeh, self, qtrue ) )
{//dammit, still can't get off the vehicle...
return qfalse;
}
}
else
{
assert(0);
#ifndef FINAL_BUILD
Com_Printf(S_COLOR_RED"ERROR: Dead pilot's vehicle removed while corpse was riding it (pilot: %s)???\n",self->targetname);
#endif
}
}
if ( self->message )
{//I still have a key
return qfalse;
}
if ( IIcarusInterface::GetIcarus()->IsRunning( self->m_iIcarusID ) )
{//still running a script
return qfalse;
}
if ( self->activator
&& self->activator->client
&& ((self->activator->client->ps.eFlags&EF_HELD_BY_RANCOR)
|| (self->activator->client->ps.eFlags&EF_HELD_BY_SAND_CREATURE)
|| (self->activator->client->ps.eFlags&EF_HELD_BY_WAMPA)) )
{//still holding a victim?
return qfalse;
}
if ( self->client
&& ((self->client->ps.eFlags&EF_HELD_BY_RANCOR)
|| (self->client->ps.eFlags&EF_HELD_BY_SAND_CREATURE)
|| (self->client->ps.eFlags&EF_HELD_BY_WAMPA) ) )
{//being held by a creature
return qfalse;
}
if ( self->client->ps.heldByClient < ENTITYNUM_WORLD )
{//being dragged
return qfalse;
}
//okay, well okay to remove us...?
return qtrue;
}
void NPC_RemoveBody( gentity_t *self )
{
self->nextthink = level.time + FRAMETIME/2;
//run physics at 20fps
CorpsePhysics( self );
if ( self->NPC->nextBStateThink <= level.time )
{//run logic at 10 fps
if( self->m_iIcarusID != IIcarusInterface::ICARUS_INVALID && !stop_icarus )
{
IIcarusInterface::GetIcarus()->Update( self->m_iIcarusID );
}
self->NPC->nextBStateThink = level.time + FRAMETIME;
if ( !G_OkayToRemoveCorpse( self ) )
{
return;
}
// I don't consider this a hack, it's creative coding . . .
// I agree, very creative... need something like this for ATST and GALAKMECH too!
if (self->client->NPC_class == CLASS_MARK1)
{
Mark1_dying( self );
}
// Since these blow up, remove the bounding box.
if ( self->client->NPC_class == CLASS_REMOTE
|| self->client->NPC_class == CLASS_SENTRY
|| self->client->NPC_class == CLASS_PROBE
|| self->client->NPC_class == CLASS_INTERROGATOR
|| self->client->NPC_class == CLASS_PROBE
|| self->client->NPC_class == CLASS_MARK2 )
{
G_FreeEntity( self );
return;
}
//FIXME: don't ever inflate back up?
self->maxs[2] = self->client->renderInfo.eyePoint[2] - self->currentOrigin[2] + 4;
if ( self->maxs[2] < -8 )
{
self->maxs[2] = -8;
}
if ( (self->NPC->aiFlags&NPCAI_HEAL_ROSH) )
{//kothos twins' bodies are never removed
return;
}
if ( self->client->NPC_class == CLASS_GALAKMECH )
{//never disappears
return;
}
if ( self->NPC && self->NPC->timeOfDeath <= level.time )
{
self->NPC->timeOfDeath = level.time + 1000;
// Only do all of this nonsense for Scav boys ( and girls )
/// if ( self->client->playerTeam == TEAM_SCAVENGERS || self->client->playerTeam == TEAM_KLINGON
// || self->client->playerTeam == TEAM_HIROGEN || self->client->playerTeam == TEAM_MALON )
// should I check NPC_class here instead of TEAM ? - dmv
if( self->client->playerTeam == TEAM_ENEMY || self->client->NPC_class == CLASS_PROTOCOL )
{
self->nextthink = level.time + FRAMETIME; // try back in a second
if ( DistanceSquared( g_entities[0].currentOrigin, self->currentOrigin ) <= REMOVE_DISTANCE_SQR )
{
return;
}
if ( (InFOVFromPlayerView( self, 110, 90 )) ) // generous FOV check
{
if ( (NPC_ClearLOS( &g_entities[0], self->currentOrigin )) )
{
return;
}
}
}
//FIXME: there are some conditions - such as heavy combat - in which we want
// to remove the bodies... but in other cases it's just weird, like
// when they're right behind you in a closed room and when they've been
// placed as dead NPCs by a designer...
// For now we just assume that a corpse with no enemy was
// placed in the map as a corpse
if ( self->enemy )
{
if ( self->client && self->client->ps.saberEntityNum > 0 && self->client->ps.saberEntityNum < ENTITYNUM_WORLD )
{
gentity_t *saberent = &g_entities[self->client->ps.saberEntityNum];
if ( saberent )
{
G_FreeEntity( saberent );
}
}
G_FreeEntity( self );
}
}
}
}
/*
----------------------------------------
NPC_RemoveBody
Determines when it's ok to ditch the corpse
----------------------------------------
*/
int BodyRemovalPadTime( gentity_t *ent )
{
int time;
if ( !ent || !ent->client )
return 0;
/*
switch ( ent->client->playerTeam )
{
case TEAM_KLINGON: // no effect, we just remove them when the player isn't looking
case TEAM_SCAVENGERS:
case TEAM_HIROGEN:
case TEAM_MALON:
case TEAM_IMPERIAL:
case TEAM_STARFLEET:
time = 10000; // 15 secs.
break;
case TEAM_BORG:
time = 2000;
break;
case TEAM_STASIS:
return qtrue;
break;
case TEAM_FORGE:
time = 1000;
break;
case TEAM_BOTS:
// if (!Q_stricmp( ent->NPC_type, "mouse" ))
// {
time = 0;
// }
// else
// {
// time = 10000;
// }
break;
case TEAM_8472:
time = 2000;
break;
default:
// never go away
time = Q3_INFINITE;
break;
}
*/
// team no longer indicates species/race, so in this case we'd use NPC_class, but
switch( ent->client->NPC_class )
{
case CLASS_MOUSE:
case CLASS_GONK:
case CLASS_R2D2:
case CLASS_R5D2:
//case CLASS_PROTOCOL:
case CLASS_MARK1:
case CLASS_MARK2:
case CLASS_PROBE:
case CLASS_SEEKER:
case CLASS_REMOTE:
case CLASS_SENTRY:
case CLASS_INTERROGATOR:
time = 0;
break;
default:
// never go away
if ( g_corpseRemovalTime->integer <= 0 )
{
time = Q3_INFINITE;
}
else
{
time = g_corpseRemovalTime->integer*1000;
}
break;
}
return time;
}
/*
----------------------------------------
NPC_RemoveBodyEffect
Effect to be applied when ditching the corpse
----------------------------------------
*/
static void NPC_RemoveBodyEffect(void)
{
// vec3_t org;
// gentity_t *tent;
if ( !NPC || !NPC->client || (NPC->s.eFlags & EF_NODRAW) )
return;
/*
switch(NPC->client->playerTeam)
{
case TEAM_STARFLEET:
//FIXME: Starfleet beam out
break;
case TEAM_BOTS:
// VectorCopy( NPC->currentOrigin, org );
// org[2] -= 16;
// tent = G_TempEntity( org, EV_BOT_EXPLODE );
// tent->owner = NPC;
break;
default:
break;
}
*/
// team no longer indicates species/race, so in this case we'd use NPC_class, but
// stub code
switch(NPC->client->NPC_class)
{
case CLASS_PROBE:
case CLASS_SEEKER:
case CLASS_REMOTE:
case CLASS_SENTRY:
case CLASS_GONK:
case CLASS_R2D2:
case CLASS_R5D2:
//case CLASS_PROTOCOL:
case CLASS_MARK1:
case CLASS_MARK2:
case CLASS_INTERROGATOR:
case CLASS_ATST: // yeah, this is a little weird, but for now I'm listing all droids
// VectorCopy( NPC->currentOrigin, org );
// org[2] -= 16;
// tent = G_TempEntity( org, EV_BOT_EXPLODE );
// tent->owner = NPC;
break;
default:
break;
}
}
/*
====================================================================
void pitch_roll_for_slope (edict_t *forwhom, vec3_t *slope, vec3_t storeAngles )
MG
This will adjust the pitch and roll of a monster to match
a given slope - if a non-'0 0 0' slope is passed, it will
use that value, otherwise it will use the ground underneath
the monster. If it doesn't find a surface, it does nothinh\g
and returns.
====================================================================
*/
void pitch_roll_for_slope( gentity_t *forwhom, vec3_t pass_slope, vec3_t storeAngles )
{
vec3_t slope;
vec3_t nvf, ovf, ovr, startspot, endspot, new_angles = { 0, 0, 0 };
float pitch, mod, dot;
//if we don't have a slope, get one
if( !pass_slope || VectorCompare( vec3_origin, pass_slope ) )
{
trace_t trace;
VectorCopy( forwhom->currentOrigin, startspot );
startspot[2] += forwhom->mins[2] + 4;
VectorCopy( startspot, endspot );
endspot[2] -= 300;
gi.trace( &trace, forwhom->currentOrigin, vec3_origin, vec3_origin, endspot, forwhom->s.number, MASK_SOLID );
// if(trace_fraction>0.05&&forwhom.movetype==MOVETYPE_STEP)
// forwhom.flags(-)FL_ONGROUND;
if ( trace.fraction >= 1.0 )
return;
if( !( &trace.plane ) )
return;
if ( VectorCompare( vec3_origin, trace.plane.normal ) )
return;
VectorCopy( trace.plane.normal, slope );
}
else
{
VectorCopy( pass_slope, slope );
}
if ( forwhom->client && forwhom->client->NPC_class == CLASS_VEHICLE )
{//special code for vehicles
Vehicle_t *pVeh = forwhom->m_pVehicle;
vec3_t tempAngles;
tempAngles[PITCH] = tempAngles[ROLL] = 0;
tempAngles[YAW] = pVeh->m_vOrientation[YAW];
AngleVectors( tempAngles, ovf, ovr, NULL );
}
else
{
AngleVectors( forwhom->currentAngles, ovf, ovr, NULL );
}
vectoangles( slope, new_angles );
pitch = new_angles[PITCH] + 90;
new_angles[ROLL] = new_angles[PITCH] = 0;
AngleVectors( new_angles, nvf, NULL, NULL );
mod = DotProduct( nvf, ovr );
if ( mod<0 )
mod = -1;
else
mod = 1;
dot = DotProduct( nvf, ovf );
if ( storeAngles )
{
storeAngles[PITCH] = dot * pitch;
storeAngles[ROLL] = ((1-Q_fabs(dot)) * pitch * mod);
}
else if ( forwhom->client )
{
forwhom->client->ps.viewangles[PITCH] = dot * pitch;
forwhom->client->ps.viewangles[ROLL] = ((1-Q_fabs(dot)) * pitch * mod);
float oldmins2 = forwhom->mins[2];
forwhom->mins[2] = -24 + 12 * fabs(forwhom->client->ps.viewangles[PITCH])/180.0f;
//FIXME: if it gets bigger, move up
if ( oldmins2 > forwhom->mins[2] )
{//our mins is now lower, need to move up
//FIXME: trace?
forwhom->client->ps.origin[2] += (oldmins2 - forwhom->mins[2]);
forwhom->currentOrigin[2] = forwhom->client->ps.origin[2];
gi.linkentity( forwhom );
}
}
else
{
forwhom->currentAngles[PITCH] = dot * pitch;
forwhom->currentAngles[ROLL] = ((1-Q_fabs(dot)) * pitch * mod);
}
}
/*
void NPC_PostDeathThink( void )
{
float mostdist;
trace_t trace1, trace2, trace3, trace4, movetrace;
vec3_t org, endpos, startpos, forward, right;
int whichtrace = 0;
float cornerdist[4];
qboolean frontbackbothclear = false;
qboolean rightleftbothclear = false;
if( NPC->client->ps.groundEntityNum == ENTITYNUM_NONE || !VectorCompare( vec3_origin, NPC->client->ps.velocity ) )
{
if ( NPC->client->ps.groundEntityNum != ENTITYNUM_NONE && NPC->client->ps.friction == 1.0 )//check avelocity?
{
pitch_roll_for_slope( NPC );
}
return;
}
cornerdist[FRONT] = cornerdist[BACK] = cornerdist[RIGHT] = cornerdist[LEFT] = 0.0f;
mostdist = MIN_DROP_DIST;
AngleVectors( NPC->currentAngles, forward, right, NULL );
VectorCopy( NPC->currentOrigin, org );
org[2] += NPC->mins[2];
VectorMA( org, NPC->dead_size, forward, startpos );
VectorCopy( startpos, endpos );
endpos[2] -= 128;
gi.trace( &trace1, startpos, vec3_origin, vec3_origin, endpos, NPC->s.number, MASK_SOLID, );
if( !trace1.allsolid && !trace1.startsolid )
{
cornerdist[FRONT] = trace1.fraction;
if ( trace1.fraction > mostdist )
{
mostdist = trace1.fraction;
whichtrace = 1;
}
}
VectorMA( org, -NPC->dead_size, forward, startpos );
VectorCopy( startpos, endpos );
endpos[2] -= 128;
gi.trace( &trace2, startpos, vec3_origin, vec3_origin, endpos, NPC->s.number, MASK_SOLID );
if( !trace2.allsolid && !trace2.startsolid )
{
cornerdist[BACK] = trace2.fraction;
if ( trace2.fraction > mostdist )
{
mostdist = trace2.fraction;
whichtrace = 2;
}
}
VectorMA( org, NPC->dead_size/2, right, startpos );
VectorCopy( startpos, endpos );
endpos[2] -= 128;
gi.trace( &trace3, startpos, vec3_origin, vec3_origin, endpos, NPC->s.number, MASK_SOLID );
if ( !trace3.allsolid && !trace3.startsolid )
{
cornerdist[RIGHT] = trace3.fraction;
if ( trace3.fraction>mostdist )
{
mostdist = trace3.fraction;
whichtrace = 3;
}
}
VectorMA( org, -NPC->dead_size/2, right, startpos );
VectorCopy( startpos, endpos );
endpos[2] -= 128;
gi.trace( &trace4, startpos, vec3_origin, vec3_origin, endpos, NPC->s.number, MASK_SOLID );
if ( !trace4.allsolid && !trace4.startsolid )
{
cornerdist[LEFT] = trace4.fraction;
if ( trace4.fraction > mostdist )
{
mostdist = trace4.fraction;
whichtrace = 4;
}
}
//OK! Now if two opposite sides are hanging, use a third if any, else, do nothing
if ( cornerdist[FRONT] > MIN_DROP_DIST && cornerdist[BACK] > MIN_DROP_DIST )
frontbackbothclear = true;
if ( cornerdist[RIGHT] > MIN_DROP_DIST && cornerdist[LEFT] > MIN_DROP_DIST )
rightleftbothclear = true;
if ( frontbackbothclear && rightleftbothclear )
return;
if ( frontbackbothclear )
{
if ( cornerdist[RIGHT] > MIN_DROP_DIST )
whichtrace = 3;
else if ( cornerdist[LEFT] > MIN_DROP_DIST )
whichtrace = 4;
else
return;
}
if ( rightleftbothclear )
{
if ( cornerdist[FRONT] > MIN_DROP_DIST )
whichtrace = 1;
else if ( cornerdist[BACK] > MIN_DROP_DIST )
whichtrace = 2;
else
return;
}
switch ( whichtrace )
{//check for stuck
case 1:
VectorMA( NPC->currentOrigin, NPC->maxs[0], forward, endpos );
gi.trace( &movetrace, NPC->currentOrigin, NPC->mins, NPC->maxs, endpos, NPC->s.number, MASK_MONSTERSOLID );
if ( movetrace.allsolid || movetrace.startsolid || movetrace.fraction < 1.0 )
if ( canmove( movetrace.ent ) )
whichtrace = -1;
else
whichtrace = 0;
break;
case 2:
VectorMA( NPC->currentOrigin, -NPC->maxs[0], forward, endpos );
gi.trace( &movetrace, NPC->currentOrigin, NPC->mins, NPC->maxs, endpos, NPC->s.number, MASK_MONSTERSOLID );
if ( movetrace.allsolid || movetrace.startsolid || movetrace.fraction < 1.0 )
if ( canmove( movetrace.ent ) )
whichtrace = -1;
else
whichtrace = 0;
break;
case 3:
VectorMA( NPC->currentOrigin, NPC->maxs[0], right, endpos );
gi.trace( &movetrace, NPC->currentOrigin, NPC->mins, NPC->maxs, endpos, NPC->s.number, MASK_MONSTERSOLID );
if ( movetrace.allsolid || movetrace.startsolid || movetrace.fraction < 1.0 )
if ( canmove( movetrace.ent ) )
whichtrace = -1;
else
whichtrace = 0;
break;
case 4:
VectorMA( NPC->currentOrigin, -NPC->maxs[0], right, endpos );
gi.trace( &movetrace, NPC->currentOrigin, NPC->mins, NPC->maxs, endpos, NPC->s.number, MASK_MONSTERSOLID );
if (movetrace.allsolid || movetrace.startsolid || movetrace.fraction < 1.0 )
if ( canmove( movetrace.ent ) )
whichtrace = -1;
else
whichtrace = 0;
break;
}
switch ( whichtrace )
{
case 1:
VectorMA( NPC->client->ps.velocity, 200, forward, NPC->client->ps.velocity );
if ( trace1.fraction >= 0.9 )
{
//can't anymore, origin not in center of deathframe!
// NPC->avelocity[PITCH] = -300;
NPC->client->ps.friction = 1.0;
}
else
{
pitch_roll_for_slope( NPC, &trace1.plane.normal );
NPC->client->ps.friction = trace1.plane.normal[2] * 0.1;
}
return;
break;
case 2:
VectorMA( NPC->client->ps.velocity, -200, forward, NPC->client->ps.velocity );
if(trace2.fraction >= 0.9)
{
//can't anymore, origin not in center of deathframe!
// NPC->avelocity[PITCH] = 300;
NPC->client->ps.friction = 1.0;
}
else
{
pitch_roll_for_slope( NPC, &trace2.plane.normal );
NPC->client->ps.friction = trace2.plane.normal[2] * 0.1;
}
return;
break;
case 3:
VectorMA( NPC->client->ps.velocity, 200, right, NPC->client->ps.velocity );
if ( trace3.fraction >= 0.9 )
{
//can't anymore, origin not in center of deathframe!
// NPC->avelocity[ROLL] = -300;
NPC->client->ps.friction = 1.0;
}
else
{
pitch_roll_for_slope( NPC, &trace3.plane.normal );
NPC->client->ps.friction = trace3.plane.normal[2] * 0.1;
}
return;
break;
case 4:
VectorMA( NPC->client->ps.velocity, -200, right, NPC->client->ps.velocity );
if ( trace4.fraction >= 0.9 )
{
//can't anymore, origin not in center of deathframe!
// NPC->avelocity[ROLL] = 300;
NPC->client->ps.friction = 1.0;
}
else
{
pitch_roll_for_slope( NPC, &trace4.plane.normal );
NPC->client->ps.friction = trace4.plane.normal[2] * 0.1;
}
return;
break;
}
//on solid ground
if ( whichtrace == -1 )
{
return;
}
NPC->client->ps.friction = 1.0;
//VectorClear( NPC->avelocity );
pitch_roll_for_slope( NPC );
//gi.linkentity (NPC);
}
*/
/*
----------------------------------------
DeadThink
----------------------------------------
*/
static void DeadThink ( void )
{
trace_t trace;
//HACKHACKHACKHACKHACK
//We should really have a seperate G2 bounding box (seperate from the physics bbox) for G2 collisions only
//FIXME: don't ever inflate back up?
//GAH! With Ragdoll, they get stuck in the ceiling
float oldMaxs2 = NPC->maxs[2];
NPC->maxs[2] = NPC->client->renderInfo.eyePoint[2] - NPC->currentOrigin[2] + 4;
if ( NPC->maxs[2] < -8 )
{
NPC->maxs[2] = -8;
}
if ( NPC->maxs[2] > oldMaxs2 )
{//inflating maxs, make sure we're not inflating into solid
gi.trace (&trace, NPC->currentOrigin, NPC->mins, NPC->maxs, NPC->currentOrigin, NPC->s.number, NPC->clipmask );
if ( trace.allsolid )
{//must be inflating
NPC->maxs[2] = oldMaxs2;
}
}
/*
{
if ( VectorCompare( NPC->client->ps.velocity, vec3_origin ) )
{//not flying through the air
if ( NPC->mins[0] > -32 )
{
NPC->mins[0] -= 1;
gi.trace (&trace, NPC->currentOrigin, NPC->mins, NPC->maxs, NPC->currentOrigin, NPC->s.number, NPC->clipmask );
if ( trace.allsolid )
{
NPC->mins[0] += 1;
}
}
if ( NPC->maxs[0] < 32 )
{
NPC->maxs[0] += 1;
gi.trace (&trace, NPC->currentOrigin, NPC->mins, NPC->maxs, NPC->currentOrigin, NPC->s.number, NPC->clipmask );
if ( trace.allsolid )
{
NPC->maxs[0] -= 1;
}
}
if ( NPC->mins[1] > -32 )
{
NPC->mins[1] -= 1;
gi.trace (&trace, NPC->currentOrigin, NPC->mins, NPC->maxs, NPC->currentOrigin, NPC->s.number, NPC->clipmask );
if ( trace.allsolid )
{
NPC->mins[1] += 1;
}
}
if ( NPC->maxs[1] < 32 )
{
NPC->maxs[1] += 1;
gi.trace (&trace, NPC->currentOrigin, NPC->mins, NPC->maxs, NPC->currentOrigin, NPC->s.number, NPC->clipmask );
if ( trace.allsolid )
{
NPC->maxs[1] -= 1;
}
}
}
}
//HACKHACKHACKHACKHACK
*/
//FIXME: tilt and fall off of ledges?
//NPC_PostDeathThink();
/*
if ( !NPCInfo->timeOfDeath && NPC->client != NULL && NPCInfo != NULL )
{
//haven't finished death anim yet and were NOT given a specific amount of time to wait before removal
int legsAnim = NPC->client->ps.legsAnim;
animation_t *animations = knownAnimFileSets[NPC->client->clientInfo.animFileIndex].animations;
NPC->bounceCount = -1; // This is a cheap hack for optimizing the pointcontents check below
//ghoul doesn't tell us this anymore
//if ( NPC->client->renderInfo.legsFrame == animations[legsAnim].firstFrame + (animations[legsAnim].numFrames - 1) )
{
//reached the end of the death anim
NPCInfo->timeOfDeath = level.time + BodyRemovalPadTime( NPC );
}
}
else
*/
{
//death anim done (or were given a specific amount of time to wait before removal), wait the requisite amount of time them remove
if ( level.time >= NPCInfo->timeOfDeath + BodyRemovalPadTime( NPC ) )
{
if ( NPC->client->ps.eFlags & EF_NODRAW )
{
if ( !IIcarusInterface::GetIcarus()->IsRunning( NPC->m_iIcarusID ) )
{
NPC->e_ThinkFunc = thinkF_G_FreeEntity;
NPC->nextthink = level.time + FRAMETIME;
}
}
else
{
// Start the body effect first, then delay 400ms before ditching the corpse
NPC_RemoveBodyEffect();
//FIXME: keep it running through physics somehow?
NPC->e_ThinkFunc = thinkF_NPC_RemoveBody;
NPC->nextthink = level.time + FRAMETIME/2;
// if ( NPC->client->playerTeam == TEAM_FORGE )
// NPCInfo->timeOfDeath = level.time + FRAMETIME * 8;
// else if ( NPC->client->playerTeam == TEAM_BOTS )
class_t npc_class = NPC->client->NPC_class;
// check for droids
if ( npc_class == CLASS_SEEKER || npc_class == CLASS_REMOTE || npc_class == CLASS_PROBE || npc_class == CLASS_MOUSE ||
npc_class == CLASS_GONK || npc_class == CLASS_R2D2 || npc_class == CLASS_R5D2 ||
npc_class == CLASS_MARK2 || npc_class == CLASS_SENTRY )//npc_class == CLASS_PROTOCOL ||
{
NPC->client->ps.eFlags |= EF_NODRAW;
NPCInfo->timeOfDeath = level.time + FRAMETIME * 8;
}
else
{
NPCInfo->timeOfDeath = level.time + FRAMETIME * 4;
}
}
return;
}
}
// If the player is on the ground and the resting position contents haven't been set yet...(BounceCount tracks the contents)
if ( NPC->bounceCount < 0 && NPC->s.groundEntityNum >= 0 )
{
// if client is in a nodrop area, make him/her nodraw
int contents = NPC->bounceCount = gi.pointcontents( NPC->currentOrigin, -1 );
if ( ( contents & CONTENTS_NODROP ) )
{
NPC->client->ps.eFlags |= EF_NODRAW;
}
}
CorpsePhysics( NPC );
}
/*
===============
SetNPCGlobals
local function to set globals used throughout the AI code
===============
*/
void SetNPCGlobals( gentity_t *ent )
{
NPC = ent;
NPCInfo = ent->NPC;
client = ent->client;
memset( &ucmd, 0, sizeof( usercmd_t ) );
}
gentity_t *_saved_NPC;
gNPC_t *_saved_NPCInfo;
gclient_t *_saved_client;
usercmd_t _saved_ucmd;
void SaveNPCGlobals()
{
_saved_NPC = NPC;
_saved_NPCInfo = NPCInfo;
_saved_client = client;
memcpy( &_saved_ucmd, &ucmd, sizeof( usercmd_t ) );
}
void RestoreNPCGlobals()
{
NPC = _saved_NPC;
NPCInfo = _saved_NPCInfo;
client = _saved_client;
memcpy( &ucmd, &_saved_ucmd, sizeof( usercmd_t ) );
}
//We MUST do this, other funcs were using NPC illegally when "self" wasn't the global NPC
void ClearNPCGlobals( void )
{
NPC = NULL;
NPCInfo = NULL;
client = NULL;
}
//===============
extern qboolean showBBoxes;
vec3_t NPCDEBUG_RED = {1.0, 0.0, 0.0};
vec3_t NPCDEBUG_GREEN = {0.0, 1.0, 0.0};
vec3_t NPCDEBUG_BLUE = {0.0, 0.0, 1.0};
vec3_t NPCDEBUG_LIGHT_BLUE = {0.3f, 0.7f, 1.0};
extern void CG_Cube( vec3_t mins, vec3_t maxs, vec3_t color, float alpha );
extern void CG_Line( vec3_t start, vec3_t end, vec3_t color, float alpha );
extern void CG_Cylinder( vec3_t start, vec3_t end, float radius, vec3_t color );
void NPC_ShowDebugInfo (void)
{
if ( showBBoxes )
{
gentity_t *found = NULL;