-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathFighterNPC.c
1751 lines (1602 loc) · 52.8 KB
/
FighterNPC.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
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
// leave this line at the top for all g_xxxx.cpp files...
#include "g_headers.h"
//seems to be a compiler bug, it doesn't clean out the #ifdefs between dif-compiles
//or something, so the headers spew errors on these defs from the previous compile.
//this fixes that. -rww
#ifdef _JK2MP
//get rid of all the crazy defs we added for this file
#undef currentAngles
#undef currentOrigin
#undef mins
#undef maxs
#undef legsAnimTimer
#undef torsoAnimTimer
#undef bool
#undef false
#undef true
#undef sqrtf
#undef Q_flrand
#undef MOD_EXPLOSIVE
#endif
#ifdef _JK2 //SP does not have this preprocessor for game like MP does
#ifndef _JK2MP
#define _JK2MP
#endif
#endif
#ifndef _JK2MP //if single player
#ifndef QAGAME //I don't think we have a QAGAME define
#define QAGAME //but define it cause in sp we're always in the game
#endif
#endif
#ifdef QAGAME //including game headers on cgame is FORBIDDEN ^_^
#include "g_local.h"
#elif defined _JK2MP
#include "bg_public.h"
#endif
#ifndef _JK2MP
#include "g_functions.h"
#include "g_vehicles.h"
#else
#include "bg_vehicles.h"
#endif
#ifdef _JK2MP
//this is really horrible, but it works! just be sure not to use any locals or anything
//with these names (exluding bool, false, true). -rww
#define currentAngles r.currentAngles
#define currentOrigin r.currentOrigin
#define mins r.mins
#define maxs r.maxs
#define legsAnimTimer legsTimer
#define torsoAnimTimer torsoTimer
#define bool qboolean
#define false qfalse
#define true qtrue
#define sqrtf sqrt
#define Q_flrand flrand
#define MOD_EXPLOSIVE MOD_SUICIDE
#else
#define bgEntity_t gentity_t
#endif
extern float DotToSpot( vec3_t spot, vec3_t from, vec3_t fromAngles );
#ifdef QAGAME //SP or gameside MP
extern vmCvar_t cg_thirdPersonAlpha;
extern vec3_t playerMins;
extern vec3_t playerMaxs;
extern cvar_t *g_speederControlScheme;
extern void ChangeWeapon( gentity_t *ent, int newWeapon );
extern void PM_SetAnim(pmove_t *pm,int setAnimParts,int anim,int setAnimFlags, int blendTime);
extern int PM_AnimLength( int index, animNumber_t anim );
extern void G_VehicleTrace( trace_t *results, const vec3_t start, const vec3_t tMins, const vec3_t tMaxs, const vec3_t end, int passEntityNum, int contentmask );
#endif
extern qboolean BG_UnrestrainedPitchRoll( playerState_t *ps, Vehicle_t *pVeh );
#ifdef _JK2MP
#include "../namespace_begin.h"
extern void BG_SetAnim(playerState_t *ps, animation_t *animations, int setAnimParts,int anim,int setAnimFlags, int blendTime);
extern int BG_GetTime(void);
#endif
extern void BG_ExternThisSoICanRecompileInDebug( Vehicle_t *pVeh, playerState_t *riderPS );
//this stuff has got to be predicted, so..
bool BG_FighterUpdate(Vehicle_t *pVeh, const usercmd_t *pUcmd, vec3_t trMins, vec3_t trMaxs, float gravity,
void (*traceFunc)( trace_t *results, const vec3_t start, const vec3_t lmins, const vec3_t lmaxs, const vec3_t end, int passEntityNum, int contentMask ))
{
vec3_t bottom;
playerState_t *parentPS;
qboolean isDead = qfalse;
#ifdef QAGAME //don't do this on client
// Make sure the riders are not visible or collidable.
pVeh->m_pVehicleInfo->Ghost( pVeh, pVeh->m_pPilot );
#endif
#ifdef _JK2MP
parentPS = pVeh->m_pParentEntity->playerState;
#else
parentPS = &pVeh->m_pParentEntity->client->ps;
#endif
if (!parentPS)
{
Com_Error(ERR_DROP, "NULL PS in BG_FighterUpdate (%s)", pVeh->m_pVehicleInfo->name);
return false;
}
// If we have a pilot, take out gravity (it's a flying craft...).
if ( pVeh->m_pPilot )
{
parentPS->gravity = 0;
#ifndef _JK2MP //don't need this flag in mp, I.. guess
pVeh->m_pParentEntity->svFlags |= SVF_CUSTOM_GRAVITY;
#endif
}
else
{
#ifndef _JK2MP //don't need this flag in mp, I.. guess
pVeh->m_pParentEntity->svFlags &= ~SVF_CUSTOM_GRAVITY;
#else //in MP set grav back to normal gravity
if (pVeh->m_pVehicleInfo->gravity)
{
parentPS->gravity = pVeh->m_pVehicleInfo->gravity;
}
else
{ //it doesn't have gravity specified apparently
parentPS->gravity = gravity;
}
#endif
}
#ifdef _JK2MP
isDead = (qboolean)((parentPS->eFlags&EF_DEAD)!=0);
#else
isDead = (parentPS->stats[STAT_HEALTH] <= 0 );
#endif
/*
if ( isDead ||
(pVeh->m_pVehicleInfo->surfDestruction &&
pVeh->m_iRemovedSurfaces ) )
{//can't land if dead or spiralling out of control
pVeh->m_LandTrace.fraction = 1.0f;
pVeh->m_LandTrace.contents = pVeh->m_LandTrace.surfaceFlags = 0;
VectorClear( pVeh->m_LandTrace.plane.normal );
pVeh->m_LandTrace.allsolid = qfalse;
pVeh->m_LandTrace.startsolid = qfalse;
}
else
{
*/
//argh, no, I need to have a way to see when they impact the ground while damaged. -rww
// Check to see if the fighter has taken off yet (if it's a certain height above ground).
VectorCopy( parentPS->origin, bottom );
bottom[2] -= pVeh->m_pVehicleInfo->landingHeight;
traceFunc( &pVeh->m_LandTrace, parentPS->origin, trMins, trMaxs, bottom, pVeh->m_pParentEntity->s.number, (MASK_NPCSOLID&~CONTENTS_BODY) );
//}
return true;
}
#ifdef QAGAME //ONLY in SP or on server, not cgame
// Like a think or move command, this updates various vehicle properties.
static bool Update( Vehicle_t *pVeh, const usercmd_t *pUcmd )
{
assert(pVeh->m_pParentEntity);
if (!BG_FighterUpdate(pVeh, pUcmd, ((gentity_t *)pVeh->m_pParentEntity)->mins,
((gentity_t *)pVeh->m_pParentEntity)->maxs,
#ifdef _JK2MP
g_gravity.value,
#else
g_gravity->value,
#endif
G_VehicleTrace))
{
return false;
}
if ( !g_vehicleInfo[VEHICLE_BASE].Update( pVeh, pUcmd ) )
{
return false;
}
return true;
}
// Board this Vehicle (get on). The first entity to board an empty vehicle becomes the Pilot.
static bool Board( Vehicle_t *pVeh, bgEntity_t *pEnt )
{
if ( !g_vehicleInfo[VEHICLE_BASE].Board( pVeh, pEnt ) )
return false;
// Set the board wait time (they won't be able to do anything, including getting off, for this amount of time).
pVeh->m_iBoarding = level.time + 1500;
return true;
}
// Eject an entity from the vehicle.
static bool Eject( Vehicle_t *pVeh, bgEntity_t *pEnt, qboolean forceEject )
{
if ( g_vehicleInfo[VEHICLE_BASE].Eject( pVeh, pEnt, forceEject ) )
{
return true;
}
return false;
}
#endif //end game-side only
//method of decrementing the given angle based on the given taking variable frame times into account
static float PredictedAngularDecrement(float scale, float timeMod, float originalAngle)
{
float fixedBaseDec = originalAngle*0.05f;
float r = 0.0f;
if (fixedBaseDec < 0.0f)
{
fixedBaseDec = -fixedBaseDec;
}
fixedBaseDec *= (1.0f+(1.0f-scale));
if (fixedBaseDec < 0.1f)
{ //don't increment in incredibly small fractions, it would eat up unnecessary bandwidth.
fixedBaseDec = 0.1f;
}
fixedBaseDec *= (timeMod*0.1f);
if (originalAngle > 0.0f)
{ //subtract
r = (originalAngle-fixedBaseDec);
if (r < 0.0f)
{
r = 0.0f;
}
}
else if (originalAngle < 0.0f)
{ //add
r = (originalAngle+fixedBaseDec);
if (r > 0.0f)
{
r = 0.0f;
}
}
return r;
}
#ifdef QAGAME//only do this check on GAME side, because if it's CGAME, it's being predicted, and it's only predicted if the local client is the driver
qboolean FighterIsInSpace( gentity_t *gParent )
{
if ( gParent
&& gParent->client
&& gParent->client->inSpaceIndex
&& gParent->client->inSpaceIndex < ENTITYNUM_WORLD )
{
return qtrue;
}
return qfalse;
}
#endif
qboolean FighterOverValidLandingSurface( Vehicle_t *pVeh )
{
if ( pVeh->m_LandTrace.fraction < 1.0f //ground present
&& pVeh->m_LandTrace.plane.normal[2] >= MIN_LANDING_SLOPE )//flat enough
//FIXME: also check for a certain surface flag ... "landing zones"?
{
return qtrue;
}
return qfalse;
}
qboolean FighterIsLanded( Vehicle_t *pVeh, playerState_t *parentPS )
{
if ( FighterOverValidLandingSurface( pVeh )
&& !parentPS->speed )//stopped
{
return qtrue;
}
return qfalse;
}
qboolean FighterIsLanding( Vehicle_t *pVeh, playerState_t *parentPS )
{
if ( FighterOverValidLandingSurface( pVeh )
#ifdef QAGAME//only do this check on GAME side, because if it's CGAME, it's being predicted, and it's only predicted if the local client is the driver
&& pVeh->m_pVehicleInfo->Inhabited( pVeh )//has to have a driver in order to be capable of landing
#endif
&& (pVeh->m_ucmd.forwardmove < 0||pVeh->m_ucmd.upmove<0) //decelerating or holding crouch button
&& parentPS->speed <= MIN_LANDING_SPEED )//going slow enough to start landing - was using pVeh->m_pVehicleInfo->speedIdle, but that's still too fast
{
return qtrue;
}
return qfalse;
}
qboolean FighterIsLaunching( Vehicle_t *pVeh, playerState_t *parentPS )
{
if ( FighterOverValidLandingSurface( pVeh )
#ifdef QAGAME//only do this check on GAME side, because if it's CGAME, it's being predicted, and it's only predicted if the local client is the driver
&& pVeh->m_pVehicleInfo->Inhabited( pVeh )//has to have a driver in order to be capable of landing
#endif
&& pVeh->m_ucmd.upmove > 0 //trying to take off
&& parentPS->speed <= 200.0f )//going slow enough to start landing - was using pVeh->m_pVehicleInfo->speedIdle, but that's still too fast
{
return qtrue;
}
return qfalse;
}
qboolean FighterSuspended( Vehicle_t *pVeh, playerState_t *parentPS )
{
#ifdef QAGAME//only do this check on GAME side, because if it's CGAME, it's being predicted, and it's only predicted if the local client is the driver
if (!pVeh->m_pPilot//empty
&& !parentPS->speed//not moving
&& pVeh->m_ucmd.forwardmove <= 0//not trying to go forward for whatever reason
&& pVeh->m_pParentEntity != NULL
&& (((gentity_t *)pVeh->m_pParentEntity)->spawnflags&2) )//SUSPENDED spawnflag is on
{
return qtrue;
}
return qfalse;
#elif CGAME
return qfalse;
#endif
}
#ifdef CGAME
extern void trap_S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ); //cg_syscalls.c
extern sfxHandle_t trap_S_RegisterSound( const char *sample); //cg_syscalls.c
#endif
//MP RULE - ALL PROCESSMOVECOMMANDS FUNCTIONS MUST BE BG-COMPATIBLE!!!
//If you really need to violate this rule for SP, then use ifdefs.
//By BG-compatible, I mean no use of game-specific data - ONLY use
//stuff available in the MP bgEntity (in SP, the bgEntity is #defined
//as a gentity, but the MP-compatible access restrictions are based
//on the bgEntity structure in the MP codebase) -rww
// ProcessMoveCommands the Vehicle.
#define FIGHTER_MIN_TAKEOFF_FRACTION 0.7f
static void ProcessMoveCommands( Vehicle_t *pVeh )
{
/************************************************************************************/
/* BEGIN Here is where we move the vehicle (forward or back or whatever). BEGIN */
/************************************************************************************/
//Client sets ucmds and such for speed alterations
float speedInc, speedIdleDec, speedIdle, speedIdleAccel, speedMin, speedMax;
bgEntity_t *parent = pVeh->m_pParentEntity;
qboolean isLandingOrLaunching = qfalse;
#ifndef _JK2MP//SP
int curTime = level.time;
#elif QAGAME//MP GAME
int curTime = level.time;
#elif CGAME//MP CGAME
//FIXME: pass in ucmd? Not sure if this is reliable...
int curTime = pm->cmd.serverTime;
#endif
#ifdef _JK2MP
playerState_t *parentPS = parent->playerState;
#else
playerState_t *parentPS = &parent->client->ps;
#endif
#ifdef _JK2MP
if ( parentPS->hyperSpaceTime
&& curTime - parentPS->hyperSpaceTime < HYPERSPACE_TIME )
{//Going to Hyperspace
//totally override movement
float timeFrac = ((float)(curTime-parentPS->hyperSpaceTime))/HYPERSPACE_TIME;
if ( timeFrac < HYPERSPACE_TELEPORT_FRAC )
{//for first half, instantly jump to top speed!
if ( !(parentPS->eFlags2&EF2_HYPERSPACE) )
{//waiting to face the right direction, do nothing
parentPS->speed = 0.0f;
}
else
{
if ( parentPS->speed < HYPERSPACE_SPEED )
{//just started hyperspace
//MIKE: This is going to play the sound twice for the predicting client, I suggest using
//a predicted event or only doing it game-side. -rich
#ifdef QAGAME//MP GAME-side
//G_EntitySound( ((gentity_t *)(pVeh->m_pParentEntity)), CHAN_LOCAL, pVeh->m_pVehicleInfo->soundHyper );
#elif CGAME//MP CGAME-side
trap_S_StartSound( NULL, pm->ps->clientNum, CHAN_LOCAL, pVeh->m_pVehicleInfo->soundHyper );
#endif
}
parentPS->speed = HYPERSPACE_SPEED;
}
}
else
{//slow from top speed to 200...
parentPS->speed = 200.0f + ((1.0f-timeFrac)*(1.0f/HYPERSPACE_TELEPORT_FRAC)*(HYPERSPACE_SPEED-200.0f));
//don't mess with acceleration, just pop to the high velocity
if ( VectorLength( parentPS->velocity ) < parentPS->speed )
{
VectorScale( parentPS->moveDir, parentPS->speed, parentPS->velocity );
}
}
return;
}
#endif
if ( pVeh->m_iDropTime >= curTime )
{//no speed, just drop
parentPS->speed = 0.0f;
parentPS->gravity = 800;
return;
}
isLandingOrLaunching = (FighterIsLanding( pVeh, parentPS )||FighterIsLaunching( pVeh, parentPS ));
// If we are hitting the ground, just allow the fighter to go up and down.
if ( isLandingOrLaunching//going slow enough to start landing
&& (pVeh->m_ucmd.forwardmove<=0||pVeh->m_LandTrace.fraction<=FIGHTER_MIN_TAKEOFF_FRACTION) )//not trying to accelerate away already (or: you are trying to, but not high enough off the ground yet)
{//FIXME: if start to move forward and fly over something low while still going relatively slow, you may try to land even though you don't mean to...
//float fInvFrac = 1.0f - pVeh->m_LandTrace.fraction;
if ( pVeh->m_ucmd.upmove > 0 )
{
#ifdef _JK2MP
if ( parentPS->velocity[2] <= 0
&& pVeh->m_pVehicleInfo->soundTakeOff )
{//taking off for the first time
#ifdef QAGAME//MP GAME-side
G_EntitySound( ((gentity_t *)(pVeh->m_pParentEntity)), CHAN_AUTO, pVeh->m_pVehicleInfo->soundTakeOff );
#endif
}
#endif
parentPS->velocity[2] += pVeh->m_pVehicleInfo->acceleration * pVeh->m_fTimeModifier;// * ( /*fInvFrac **/ 1.5f );
}
else if ( pVeh->m_ucmd.upmove < 0 )
{
parentPS->velocity[2] -= pVeh->m_pVehicleInfo->acceleration * pVeh->m_fTimeModifier;// * ( /*fInvFrac **/ 1.8f );
}
else if ( pVeh->m_ucmd.forwardmove < 0 )
{
if ( pVeh->m_LandTrace.fraction != 0.0f )
{
parentPS->velocity[2] -= pVeh->m_pVehicleInfo->acceleration * pVeh->m_fTimeModifier;
}
if ( pVeh->m_LandTrace.fraction <= FIGHTER_MIN_TAKEOFF_FRACTION )
{
//pVeh->m_pParentEntity->client->ps.velocity[0] *= pVeh->m_LandTrace.fraction;
//pVeh->m_pParentEntity->client->ps.velocity[1] *= pVeh->m_LandTrace.fraction;
//remember to always base this stuff on the time modifier! otherwise, you create
//framerate-dependancy issues and break prediction in MP -rww
//parentPS->velocity[2] *= pVeh->m_LandTrace.fraction;
//it's not an angle, but hey
parentPS->velocity[2] = PredictedAngularDecrement(pVeh->m_LandTrace.fraction, pVeh->m_fTimeModifier*5.0f, parentPS->velocity[2]);
parentPS->speed = 0;
}
}
// Make sure they don't pitch as they near the ground.
//pVeh->m_vOrientation[PITCH] *= 0.7f;
pVeh->m_vOrientation[PITCH] = PredictedAngularDecrement(0.7f, pVeh->m_fTimeModifier*10.0f, pVeh->m_vOrientation[PITCH]);
return;
}
if ( (pVeh->m_ucmd.upmove > 0) && pVeh->m_pVehicleInfo->turboSpeed )
{
if ((curTime - pVeh->m_iTurboTime)>pVeh->m_pVehicleInfo->turboRecharge)
{
pVeh->m_iTurboTime = (curTime + pVeh->m_pVehicleInfo->turboDuration);
if (pVeh->m_pVehicleInfo->iTurboStartFX)
{
int i;
for (i=0; i<MAX_VEHICLE_EXHAUSTS; i++)
{
if (pVeh->m_iExhaustTag[i]==-1)
{
break;
}
#ifndef _JK2MP//SP
G_PlayEffect(pVeh->m_pVehicleInfo->iTurboStartFX, pVeh->m_pParentEntity->playerModel, pVeh->m_iExhaustTag[i], pVeh->m_pParentEntity->s.number, pVeh->m_pParentEntity->currentOrigin );
#else
//TODO: MP Play Effect?
#endif
}
}
//NOTE: turbo sound can't be part of effect if effect is played on every muzzle!
if ( pVeh->m_pVehicleInfo->soundTurbo )
{
#ifndef _JK2MP//SP
G_SoundIndexOnEnt( pVeh->m_pParentEntity, CHAN_AUTO, pVeh->m_pVehicleInfo->soundTurbo );
#elif QAGAME//MP GAME-side
G_EntitySound( ((gentity_t *)(pVeh->m_pParentEntity)), CHAN_AUTO, pVeh->m_pVehicleInfo->soundTurbo );
#elif CGAME//MP CGAME-side
//trap_S_StartSound( NULL, pVeh->m_pParentEntity->s.number, CHAN_AUTO, pVeh->m_pVehicleInfo->soundTurbo );
#endif
}
}
}
speedInc = pVeh->m_pVehicleInfo->acceleration * pVeh->m_fTimeModifier;
if ( curTime < pVeh->m_iTurboTime )
{//going turbo speed
speedMax = pVeh->m_pVehicleInfo->turboSpeed;
//double our acceleration
speedInc *= 2.0f;
//force us to move forward
pVeh->m_ucmd.forwardmove = 127;
#ifdef _JK2MP//SP can cheat and just check m_iTurboTime directly... :)
//add flag to let cgame know to draw the iTurboFX effect
parentPS->eFlags |= EF_JETPACK_ACTIVE;
#endif
}
/*
//FIXME: if turbotime is up and we're waiting for it to recharge, should our max speed drop while we recharge?
else if ( (curTime - pVeh->m_iTurboTime)<3000 )
{//still waiting for the recharge
speedMax = pVeh->m_pVehicleInfo->speedMax*0.75;
}
*/
else
{//normal max speed
speedMax = pVeh->m_pVehicleInfo->speedMax;
#ifdef _JK2MP//SP can cheat and just check m_iTurboTime directly... :)
if ( (parentPS->eFlags&EF_JETPACK_ACTIVE) )
{//stop cgame from playing the turbo exhaust effect
parentPS->eFlags &= ~EF_JETPACK_ACTIVE;
}
#endif
}
speedIdleDec = pVeh->m_pVehicleInfo->decelIdle * pVeh->m_fTimeModifier;
speedIdle = pVeh->m_pVehicleInfo->speedIdle;
speedIdleAccel = pVeh->m_pVehicleInfo->accelIdle * pVeh->m_fTimeModifier;
speedMin = pVeh->m_pVehicleInfo->speedMin;
if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_BACK_HEAVY)) )
{//engine has taken heavy damage
speedMax *= 0.8f;//at 80% speed
}
else if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_BACK_LIGHT)) )
{//engine has taken light damage
speedMax *= 0.6f;//at 60% speed
}
if (pVeh->m_iRemovedSurfaces
|| parentPS->electrifyTime>=curTime)
{ //go out of control
parentPS->speed += speedInc;
//Why set forwardmove? PMove code doesn't use it... does it?
pVeh->m_ucmd.forwardmove = 127;
}
#ifdef QAGAME //well, the thing is always going to be inhabited if it's being predicted!
else if ( FighterSuspended( pVeh, parentPS ) )
{
parentPS->speed = 0;
pVeh->m_ucmd.forwardmove = 0;
}
else if ( !pVeh->m_pVehicleInfo->Inhabited( pVeh )
&& parentPS->speed > 0 )
{//pilot jumped out while we were moving forward (not landing or landed) so just keep the throttle locked
//Why set forwardmove? PMove code doesn't use it... does it?
pVeh->m_ucmd.forwardmove = 127;
}
#endif
else if ( ( parentPS->speed || parentPS->groundEntityNum == ENTITYNUM_NONE ||
pVeh->m_ucmd.forwardmove || pVeh->m_ucmd.upmove > 0 ) && pVeh->m_LandTrace.fraction >= 0.05f )
{
if ( pVeh->m_ucmd.forwardmove > 0 && speedInc )
{
parentPS->speed += speedInc;
pVeh->m_ucmd.forwardmove = 127;
}
else if ( pVeh->m_ucmd.forwardmove < 0
|| pVeh->m_ucmd.upmove < 0 )
{//decelerating or braking
if ( pVeh->m_ucmd.upmove < 0 )
{//braking (trying to land?), slow down faster
if ( pVeh->m_ucmd.forwardmove )
{//decelerator + brakes
speedInc += pVeh->m_pVehicleInfo->braking;
speedIdleDec += pVeh->m_pVehicleInfo->braking;
}
else
{//just brakes
speedInc = speedIdleDec = pVeh->m_pVehicleInfo->braking;
}
}
if ( parentPS->speed > speedIdle )
{
parentPS->speed -= speedInc;
}
else if ( parentPS->speed > speedMin )
{
if ( FighterOverValidLandingSurface( pVeh ) )
{//there's ground below us and we're trying to slow down, slow down faster
parentPS->speed -= speedInc;
}
else
{
parentPS->speed -= speedIdleDec;
if ( parentPS->speed < MIN_LANDING_SPEED )
{//unless you can land, don't drop below the landing speed!!! This way you can't come to a dead stop in mid-air
parentPS->speed = MIN_LANDING_SPEED;
}
}
}
if ( pVeh->m_pVehicleInfo->type == VH_FIGHTER )
{
pVeh->m_ucmd.forwardmove = 127;
}
else if ( speedMin >= 0 )
{
pVeh->m_ucmd.forwardmove = 0;
}
}
//else not accel, decel or braking
else if ( pVeh->m_pVehicleInfo->throttleSticks )
{//we're using a throttle that sticks at current speed
if ( parentPS->speed <= MIN_LANDING_SPEED )
{//going less than landing speed
if ( FighterOverValidLandingSurface( pVeh ) )
{//close to ground and not going very fast
//slow to a stop if within landing height and not accel/decel/braking
if ( parentPS->speed > 0 )
{//slow down
parentPS->speed -= speedIdleDec;
}
else if ( parentPS->speed < 0 )
{//going backwards, slow down
parentPS->speed += speedIdleDec;
}
}
else
{//not over a valid landing surf, but going too slow
//speed up to idle speed if not over a valid landing surf and not accel/decel/braking
if ( parentPS->speed < speedIdle )
{
parentPS->speed += speedIdleAccel;
if ( parentPS->speed > speedIdle )
{
parentPS->speed = speedIdle;
}
}
}
}
}
else
{//then speed up or slow down to idle speed
//accelerate to cruising speed only, otherwise, just coast
// If they've launched, apply some constant motion.
if ( (pVeh->m_LandTrace.fraction >= 1.0f //no ground
|| pVeh->m_LandTrace.plane.normal[2] < MIN_LANDING_SLOPE )//or can't land on ground below us
&& speedIdle > 0 )
{//not above ground and have an idle speed
//float fSpeed = pVeh->m_pParentEntity->client->ps.speed;
if ( parentPS->speed < speedIdle )
{
parentPS->speed += speedIdleAccel;
if ( parentPS->speed > speedIdle )
{
parentPS->speed = speedIdle;
}
}
else if ( parentPS->speed > 0 )
{//slow down
parentPS->speed -= speedIdleDec;
if ( parentPS->speed < speedIdle )
{
parentPS->speed = speedIdle;
}
}
}
else//either close to ground or no idle speed
{//slow to a stop if no idle speed or within landing height and not accel/decel/braking
if ( parentPS->speed > 0 )
{//slow down
parentPS->speed -= speedIdleDec;
}
else if ( parentPS->speed < 0 )
{//going backwards, slow down
parentPS->speed += speedIdleDec;
}
}
}
}
else
{
if ( pVeh->m_ucmd.forwardmove < 0 )
{
pVeh->m_ucmd.forwardmove = 0;
}
if ( pVeh->m_ucmd.upmove < 0 )
{
pVeh->m_ucmd.upmove = 0;
}
#ifndef _JK2MP
if ( !pVeh->m_pVehicleInfo->strafePerc || (!g_speederControlScheme->value && !pVeh->m_pParentEntity->s.number) )
{//if in a strafe-capable vehicle, clear strafing unless using alternate control scheme
pVeh->m_ucmd.rightmove = 0;
}
#endif
}
#if 1//This is working now, but there are some transitional jitters... Rich?
//STRAFING==============================================================================
if ( pVeh->m_pVehicleInfo->strafePerc
#ifdef QAGAME//only do this check on GAME side, because if it's CGAME, it's being predicted, and it's only predicted if the local client is the driver
&& pVeh->m_pVehicleInfo->Inhabited( pVeh )//has to have a driver in order to be capable of landing
#endif
&& !pVeh->m_iRemovedSurfaces
&& parentPS->electrifyTime<curTime
&& (pVeh->m_LandTrace.fraction >= 1.0f//no grounf
||pVeh->m_LandTrace.plane.normal[2] < MIN_LANDING_SLOPE//can't land here
||parentPS->speed>MIN_LANDING_SPEED)//going too fast to land
&& pVeh->m_ucmd.rightmove )
{//strafe
vec3_t vAngles, vRight;
float strafeSpeed = (pVeh->m_pVehicleInfo->strafePerc*speedMax)*5.0f;
VectorCopy( pVeh->m_vOrientation, vAngles );
vAngles[PITCH] = vAngles[ROLL] = 0;
AngleVectors( vAngles, NULL, vRight, NULL );
if ( pVeh->m_ucmd.rightmove > 0 )
{//strafe right
//FIXME: this will probably make it possible to cheat and
// go faster than max speed if you keep turning and strafing...
if ( pVeh->m_fStrafeTime > -MAX_STRAFE_TIME )
{//can strafe right for 2 seconds
float curStrafeSpeed = DotProduct( parentPS->velocity, vRight );
if ( curStrafeSpeed > 0.0f )
{//if > 0, already strafing right
strafeSpeed -= curStrafeSpeed;//so it doesn't add up
}
if ( strafeSpeed > 0 )
{
VectorMA( parentPS->velocity, strafeSpeed*pVeh->m_fTimeModifier, vRight, parentPS->velocity );
}
pVeh->m_fStrafeTime -= 50*pVeh->m_fTimeModifier;
}
}
else
{//strafe left
if ( pVeh->m_fStrafeTime < MAX_STRAFE_TIME )
{//can strafe left for 2 seconds
float curStrafeSpeed = DotProduct( parentPS->velocity, vRight );
if ( curStrafeSpeed < 0.0f )
{//if < 0, already strafing left
strafeSpeed += curStrafeSpeed;//so it doesn't add up
}
if ( strafeSpeed > 0 )
{
VectorMA( parentPS->velocity, -strafeSpeed*pVeh->m_fTimeModifier, vRight, parentPS->velocity );
}
pVeh->m_fStrafeTime += 50*pVeh->m_fTimeModifier;
}
}
//strafing takes away from forward speed? If so, strafePerc above should use speedMax
//parentPS->speed *= (1.0f-pVeh->m_pVehicleInfo->strafePerc);
}
else//if ( pVeh->m_fStrafeTime )
{
if ( pVeh->m_fStrafeTime > 0 )
{
pVeh->m_fStrafeTime -= 50*pVeh->m_fTimeModifier;
if ( pVeh->m_fStrafeTime < 0 )
{
pVeh->m_fStrafeTime = 0.0f;
}
}
else if ( pVeh->m_fStrafeTime < 0 )
{
pVeh->m_fStrafeTime += 50*pVeh->m_fTimeModifier;
if ( pVeh->m_fStrafeTime > 0 )
{
pVeh->m_fStrafeTime = 0.0f;
}
}
}
//STRAFING==============================================================================
#endif
if ( parentPS->speed > speedMax )
{
parentPS->speed = speedMax;
}
else if ( parentPS->speed < speedMin )
{
parentPS->speed = speedMin;
}
#ifdef QAGAME//FIXME: get working in GAME and CGAME
if ((pVeh->m_vOrientation[PITCH]*0.1f) > 10.0f)
{ //pitched downward, increase speed more and more based on our tilt
if ( FighterIsInSpace( (gentity_t *)parent ) )
{//in space, do nothing with speed base on pitch...
}
else
{
//really should only do this when on a planet
float mult = pVeh->m_vOrientation[PITCH]*0.1f;
if (mult < 1.0f)
{
mult = 1.0f;
}
parentPS->speed = PredictedAngularDecrement(mult, pVeh->m_fTimeModifier*10.0f, parentPS->speed);
}
}
if (pVeh->m_iRemovedSurfaces
|| parentPS->electrifyTime>=curTime)
{ //going down
if ( FighterIsInSpace( (gentity_t *)parent ) )
{//we're in a valid trigger_space brush
//simulate randomness
if ( !(parent->s.number&3) )
{//even multiple of 3, don't do anything
parentPS->gravity = 0;
}
else if ( !(parent->s.number&2) )
{//even multiple of 2, go up
parentPS->gravity = -500.0f;
parentPS->velocity[2] = 80.0f;
}
else
{//odd number, go down
parentPS->gravity = 500.0f;
parentPS->velocity[2] = -80.0f;
}
}
else
{//over a planet
parentPS->gravity = 500.0f;
parentPS->velocity[2] = -80.0f;
}
}
else if ( FighterSuspended( pVeh, parentPS ) )
{
parentPS->gravity = 0;
}
else if ( (!parentPS->speed||parentPS->speed < speedIdle) && pVeh->m_ucmd.upmove <= 0 )
{//slowing down or stopped and not trying to take off
if ( FighterIsInSpace( (gentity_t *)parent ) )
{//we're in space, stopping doesn't make us drift downward
if ( FighterOverValidLandingSurface( pVeh ) )
{//well, there's something below us to land on, so go ahead and lower us down to it
parentPS->gravity = (speedIdle - parentPS->speed)/4;
}
}
else
{//over a planet
parentPS->gravity = (speedIdle - parentPS->speed)/4;
}
}
else
{
parentPS->gravity = 0;
}
#else//FIXME: get above checks working in GAME and CGAME
parentPS->gravity = 0;
#endif
/********************************************************************************/
/* END Here is where we move the vehicle (forward or back or whatever). END */
/********************************************************************************/
}
extern void BG_VehicleTurnRateForSpeed( Vehicle_t *pVeh, float speed, float *mPitchOverride, float *mYawOverride );
static void FighterWingMalfunctionCheck( Vehicle_t *pVeh, playerState_t *parentPS )
{
float mPitchOverride = 1.0f;
float mYawOverride = 1.0f;
BG_VehicleTurnRateForSpeed( pVeh, parentPS->speed, &mPitchOverride, &mYawOverride );
//check right wing damage
if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_RIGHT_HEAVY)) )
{//right wing has taken heavy damage
pVeh->m_vOrientation[ROLL] += (sin( pVeh->m_ucmd.serverTime*0.001 )+1.0f)*pVeh->m_fTimeModifier*mYawOverride*50.0f;
}
else if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_RIGHT_LIGHT)) )
{//right wing has taken light damage
pVeh->m_vOrientation[ROLL] += (sin( pVeh->m_ucmd.serverTime*0.001 )+1.0f)*pVeh->m_fTimeModifier*mYawOverride*12.5f;
}
//check left wing damage
if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_LEFT_HEAVY)) )
{//left wing has taken heavy damage
pVeh->m_vOrientation[ROLL] -= (sin( pVeh->m_ucmd.serverTime*0.001 )+1.0f)*pVeh->m_fTimeModifier*mYawOverride*50.0f;
}
else if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_LEFT_LIGHT)) )
{//left wing has taken light damage
pVeh->m_vOrientation[ROLL] -= (sin( pVeh->m_ucmd.serverTime*0.001 )+1.0f)*pVeh->m_fTimeModifier*mYawOverride*12.5f;
}
}
static void FighterNoseMalfunctionCheck( Vehicle_t *pVeh, playerState_t *parentPS )
{
float mPitchOverride = 1.0f;
float mYawOverride = 1.0f;
BG_VehicleTurnRateForSpeed( pVeh, parentPS->speed, &mPitchOverride, &mYawOverride );
//check nose damage
if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_FRONT_HEAVY)) )
{//nose has taken heavy damage
//pitch up and down over time
pVeh->m_vOrientation[PITCH] += sin( pVeh->m_ucmd.serverTime*0.001 )*pVeh->m_fTimeModifier*mPitchOverride*50.0f;
}
else if ( (parentPS->brokenLimbs&(1<<SHIPSURF_DAMAGE_FRONT_LIGHT)) )
{//nose has taken heavy damage
//pitch up and down over time
pVeh->m_vOrientation[PITCH] += sin( pVeh->m_ucmd.serverTime*0.001 )*pVeh->m_fTimeModifier*mPitchOverride*20.0f;
}
}
static void FighterDamageRoutine( Vehicle_t *pVeh, bgEntity_t *parent, playerState_t *parentPS, playerState_t *riderPS, qboolean isDead )
{
if ( !pVeh->m_iRemovedSurfaces )
{//still in one piece
if ( pVeh->m_pParentEntity && isDead )
{//death spiral
pVeh->m_ucmd.upmove = 0;
//FIXME: don't bias toward pitching down when not in space
/*
if ( FighterIsInSpace( pVeh->m_pParentEntity ) )
{
}
else
*/
if ( !(pVeh->m_pParentEntity->s.number%3) )
{//NOT everyone should do this
pVeh->m_vOrientation[PITCH] += pVeh->m_fTimeModifier;
if ( !BG_UnrestrainedPitchRoll( riderPS, pVeh ) )
{
if ( pVeh->m_vOrientation[PITCH] > 60.0f )
{
pVeh->m_vOrientation[PITCH] = 60.0f;
}
}
}
else if ( !(pVeh->m_pParentEntity->s.number%2) )
{
pVeh->m_vOrientation[PITCH] -= pVeh->m_fTimeModifier;
if ( !BG_UnrestrainedPitchRoll( riderPS, pVeh ) )
{
if ( pVeh->m_vOrientation[PITCH] > -60.0f )
{
pVeh->m_vOrientation[PITCH] = -60.0f;
}
}
}
if ( (pVeh->m_pParentEntity->s.number%2) )
{
pVeh->m_vOrientation[YAW] += pVeh->m_fTimeModifier;
pVeh->m_vOrientation[ROLL] += pVeh->m_fTimeModifier*4.0f;
}
else
{
pVeh->m_vOrientation[YAW] -= pVeh->m_fTimeModifier;
pVeh->m_vOrientation[ROLL] -= pVeh->m_fTimeModifier*4.0f;
}
}
return;
}
//if we get into here we have at least one broken piece
pVeh->m_ucmd.upmove = 0;
//if you're off the ground and not suspended, pitch down
//FIXME: not in space!
if ( pVeh->m_LandTrace.fraction >= 0.1f )
{
if ( !FighterSuspended( pVeh, parentPS ) )
{
//pVeh->m_ucmd.forwardmove = 0;
//FIXME: don't bias towards pitching down when in space...
if ( !(pVeh->m_pParentEntity->s.number%2) )
{//NOT everyone should do this
pVeh->m_vOrientation[PITCH] += pVeh->m_fTimeModifier;
if ( !BG_UnrestrainedPitchRoll( riderPS, pVeh ) )