-
Notifications
You must be signed in to change notification settings - Fork 655
Expand file tree
/
Copy pathbg_pmove.c
More file actions
11239 lines (10120 loc) · 293 KB
/
bg_pmove.c
File metadata and controls
11239 lines (10120 loc) · 293 KB
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) 1999 - 2005, Id Software, Inc.
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
// bg_pmove.c -- both games player movement code
// takes a playerstate and a usercmd as input and returns a modifed playerstate
#include "qcommon/q_shared.h"
#include "bg_public.h"
#include "bg_local.h"
#include "ghoul2/G2.h"
#ifdef _GAME
#include "g_local.h"
#elif _CGAME
#include "cgame/cg_local.h"
#elif UI_BUILD
#include "ui/ui_local.h"
#endif
#define MAX_WEAPON_CHARGE_TIME 5000
#ifdef _GAME
extern void G_CheapWeaponFire(int entNum, int ev);
extern qboolean TryGrapple(gentity_t *ent); //g_cmds.c
#endif // _GAME
extern qboolean BG_FullBodyTauntAnim( int anim );
extern float PM_WalkableGroundDistance(void);
extern qboolean PM_GroundSlideOkay( float zNormal );
extern saberInfo_t *BG_MySaber( int clientNum, int saberNum );
pmove_t *pm;
pml_t pml;
bgEntity_t *pm_entSelf = NULL;
bgEntity_t *pm_entVeh = NULL;
qboolean gPMDoSlowFall = qfalse;
qboolean pm_cancelOutZoom = qfalse;
// movement parameters
float pm_stopspeed = 100.0f;
float pm_duckScale = 0.50f;
float pm_swimScale = 0.50f;
float pm_wadeScale = 0.70f;
float pm_vehicleaccelerate = 36.0f;
float pm_accelerate = 10.0f;
float pm_airaccelerate = 1.0f;
float pm_wateraccelerate = 4.0f;
float pm_flyaccelerate = 8.0f;
float pm_friction = 6.0f;
float pm_waterfriction = 1.0f;
float pm_flightfriction = 3.0f;
float pm_spectatorfriction = 5.0f;
int c_pmove = 0;
float forceSpeedLevels[4] =
{
1, //rank 0?
1.25,
1.5,
1.75
};
int forcePowerNeeded[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS] =
{
{ //nothing should be usable at rank 0..
999,//FP_HEAL,//instant
999,//FP_LEVITATION,//hold/duration
999,//FP_SPEED,//duration
999,//FP_PUSH,//hold/duration
999,//FP_PULL,//hold/duration
999,//FP_TELEPATHY,//instant
999,//FP_GRIP,//hold/duration
999,//FP_LIGHTNING,//hold/duration
999,//FP_RAGE,//duration
999,//FP_PROTECT,//duration
999,//FP_ABSORB,//duration
999,//FP_TEAM_HEAL,//instant
999,//FP_TEAM_FORCE,//instant
999,//FP_DRAIN,//hold/duration
999,//FP_SEE,//duration
999,//FP_SABER_OFFENSE,
999,//FP_SABER_DEFENSE,
999//FP_SABERTHROW,
//NUM_FORCE_POWERS
},
{
65,//FP_HEAL,//instant //was 25, but that was way too little
10,//FP_LEVITATION,//hold/duration
50,//FP_SPEED,//duration
20,//FP_PUSH,//hold/duration
20,//FP_PULL,//hold/duration
20,//FP_TELEPATHY,//instant
30,//FP_GRIP,//hold/duration
1,//FP_LIGHTNING,//hold/duration
50,//FP_RAGE,//duration
50,//FP_PROTECT,//duration
50,//FP_ABSORB,//duration
50,//FP_TEAM_HEAL,//instant
50,//FP_TEAM_FORCE,//instant
20,//FP_DRAIN,//hold/duration
20,//FP_SEE,//duration
0,//FP_SABER_OFFENSE,
2,//FP_SABER_DEFENSE,
20//FP_SABERTHROW,
//NUM_FORCE_POWERS
},
{
60,//FP_HEAL,//instant
10,//FP_LEVITATION,//hold/duration
50,//FP_SPEED,//duration
20,//FP_PUSH,//hold/duration
20,//FP_PULL,//hold/duration
20,//FP_TELEPATHY,//instant
30,//FP_GRIP,//hold/duration
1,//FP_LIGHTNING,//hold/duration
50,//FP_RAGE,//duration
25,//FP_PROTECT,//duration
25,//FP_ABSORB,//duration
33,//FP_TEAM_HEAL,//instant
33,//FP_TEAM_FORCE,//instant
20,//FP_DRAIN,//hold/duration
20,//FP_SEE,//duration
0,//FP_SABER_OFFENSE,
1,//FP_SABER_DEFENSE,
20//FP_SABERTHROW,
//NUM_FORCE_POWERS
},
{
50,//FP_HEAL,//instant //You get 5 points of health.. for 50 force points!
10,//FP_LEVITATION,//hold/duration
50,//FP_SPEED,//duration
20,//FP_PUSH,//hold/duration
20,//FP_PULL,//hold/duration
20,//FP_TELEPATHY,//instant
60,//FP_GRIP,//hold/duration
1,//FP_LIGHTNING,//hold/duration
50,//FP_RAGE,//duration
10,//FP_PROTECT,//duration
10,//FP_ABSORB,//duration
25,//FP_TEAM_HEAL,//instant
25,//FP_TEAM_FORCE,//instant
20,//FP_DRAIN,//hold/duration
20,//FP_SEE,//duration
0,//FP_SABER_OFFENSE,
0,//FP_SABER_DEFENSE,
20//FP_SABERTHROW,
//NUM_FORCE_POWERS
}
};
float forceJumpHeight[NUM_FORCE_POWER_LEVELS] =
{
32,//normal jump (+stepheight+crouchdiff = 66)
96,//(+stepheight+crouchdiff = 130)
192,//(+stepheight+crouchdiff = 226)
384//(+stepheight+crouchdiff = 418)
};
float forceJumpStrength[NUM_FORCE_POWER_LEVELS] =
{
JUMP_VELOCITY,//normal jump
420,
590,
840
};
static qboolean BG_FixWaterJump(void) {
#if defined(_GAME)
return !!g_fixWaterJump.integer;
#elif defined(_CGAME)
const char *cs = CG_ConfigString(CS_LEGACY_FIXES);
const uint32_t legacyFixes = strtoul(cs, NULL, 0);
return !!(legacyFixes & (1 << LEGACYFIX_WATERJUMP));
#endif
}
//rww - Get a pointer to the bgEntity by the index
bgEntity_t *PM_BGEntForNum( int num )
{
bgEntity_t *ent;
if (!pm)
{
assert(!"You cannot call PM_BGEntForNum outside of pm functions!");
return NULL;
}
if (!pm->baseEnt)
{
assert(!"Base entity address not set");
return NULL;
}
if (!pm->entSize)
{
assert(!"sizeof(ent) is 0, impossible (not set?)");
return NULL;
}
assert(num >= 0 && num < MAX_GENTITIES);
ent = (bgEntity_t *)((byte *)pm->baseEnt + pm->entSize*(num));
return ent;
}
qboolean BG_SabersOff( playerState_t *ps )
{
if ( !ps->saberHolstered )
{
return qfalse;
}
if ( ps->fd.saberAnimLevelBase == SS_DUAL
|| ps->fd.saberAnimLevelBase == SS_STAFF )
{
if ( ps->saberHolstered < 2 )
{
return qfalse;
}
}
return qtrue;
}
qboolean BG_KnockDownable(playerState_t *ps)
{
if (!ps)
{ //just for safety
return qfalse;
}
if (ps->m_iVehicleNum)
{ //riding a vehicle, don't knock me down
return qfalse;
}
if (ps->emplacedIndex)
{ //using emplaced gun or eweb, can't be knocked down
return qfalse;
}
//ok, I guess?
return qtrue;
}
//hacky assumption check, assume any client non-humanoid is a rocket trooper
static QINLINE qboolean PM_IsRocketTrooper(void)
{
/*
if (pm->ps->clientNum < MAX_CLIENTS &&
pm->gametype == GT_SIEGE &&
pm->nonHumanoid)
{
return qtrue;
}
*/
return qfalse;
}
int PM_GetSaberStance(void)
{
int anim = BOTH_STAND2;
saberInfo_t *saber1 = BG_MySaber( pm->ps->clientNum, 0 );
saberInfo_t *saber2 = BG_MySaber( pm->ps->clientNum, 1 );
if (!pm->ps->saberEntityNum)
{ //lost it
return BOTH_STAND1;
}
if ( BG_SabersOff( pm->ps ) )
{
return BOTH_STAND1;
}
if ( saber1
&& saber1->readyAnim != -1 )
{
return saber1->readyAnim;
}
if ( saber2
&& saber2->readyAnim != -1 )
{
return saber2->readyAnim;
}
if ( saber1
&& saber2
&& !pm->ps->saberHolstered )
{//dual sabers, both on
return BOTH_SABERDUAL_STANCE;
}
switch ( pm->ps->fd.saberAnimLevel )
{
case SS_DUAL:
anim = BOTH_SABERDUAL_STANCE;
break;
case SS_STAFF:
anim = BOTH_SABERSTAFF_STANCE;
break;
case SS_FAST:
case SS_TAVION:
anim = BOTH_SABERFAST_STANCE;
break;
case SS_STRONG:
anim = BOTH_SABERSLOW_STANCE;
break;
case SS_NONE:
case SS_MEDIUM:
case SS_DESANN:
default:
anim = BOTH_STAND2;
break;
}
return anim;
}
qboolean PM_DoSlowFall(void)
{
if ( ( (pm->ps->legsAnim) == BOTH_WALL_RUN_RIGHT || (pm->ps->legsAnim) == BOTH_WALL_RUN_LEFT ) && pm->ps->legsTimer > 500 )
{
return qtrue;
}
return qfalse;
}
//begin vehicle functions crudely ported from sp -rww
/*
====================================================================
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 PM_pitch_roll_for_slope( bgEntity_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( pm->ps->origin, startspot );
startspot[2] += pm->mins[2] + 4;
VectorCopy( startspot, endspot );
endspot[2] -= 300;
pm->trace( &trace, pm->ps->origin, 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 ( VectorCompare( vec3_origin, trace.plane.normal ) )
return;
VectorCopy( trace.plane.normal, slope );
}
else
{
VectorCopy( pass_slope, slope );
}
if ( forwhom->s.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( pm->ps->viewangles, 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 )
{
float oldmins2;
pm->ps->viewangles[PITCH] = dot * pitch;
pm->ps->viewangles[ROLL] = ((1-Q_fabs(dot)) * pitch * mod);
oldmins2 = pm->mins[2];
pm->mins[2] = -24 + 12 * fabs(pm->ps->viewangles[PITCH])/180.0f;
//FIXME: if it gets bigger, move up
if ( oldmins2 > pm->mins[2] )
{//our mins is now lower, need to move up
//FIXME: trace?
pm->ps->origin[2] += (oldmins2 - pm->mins[2]);
//forwhom->currentOrigin[2] = forwhom->client->ps.origin[2];
//trap->linkentity( forwhom );
}
}
/*
else
{
forwhom->currentAngles[PITCH] = dot * pitch;
forwhom->currentAngles[ROLL] = ((1-Q_fabs(dot)) * pitch * mod);
}
*/
}
#define FLY_NONE 0
#define FLY_NORMAL 1
#define FLY_VEHICLE 2
#define FLY_HOVER 3
static int pm_flying = FLY_NONE;
void PM_SetSpecialMoveValues (void)
{
bgEntity_t *pEnt;
if (pm->ps->clientNum < MAX_CLIENTS)
{ //we know that real players aren't vehs
pm_flying = FLY_NONE;
return;
}
//default until we decide otherwise
pm_flying = FLY_NONE;
pEnt = pm_entSelf;
if ( pEnt )
{
if ( (pm->ps->eFlags2&EF2_FLYING) )// pm->gent->client->moveType == MT_FLYSWIM )
{
pm_flying = FLY_NORMAL;
}
else if ( pEnt->s.NPC_class == CLASS_VEHICLE )
{
if ( pEnt->m_pVehicle->m_pVehicleInfo->type == VH_FIGHTER )
{
pm_flying = FLY_VEHICLE;
}
else if ( pEnt->m_pVehicle->m_pVehicleInfo->hoverHeight > 0 )
{
pm_flying = FLY_HOVER;
}
}
}
}
static void PM_SetVehicleAngles( vec3_t normal )
{
bgEntity_t *pEnt = pm_entSelf;
Vehicle_t *pVeh;
vec3_t vAngles;
float vehicleBankingSpeed;
float pitchBias;
int i;
if ( !pEnt || pEnt->s.NPC_class != CLASS_VEHICLE )
{
return;
}
pVeh = pEnt->m_pVehicle;
//float curVehicleBankingSpeed;
vehicleBankingSpeed = (pVeh->m_pVehicleInfo->bankingSpeed*32.0f)*pml.frametime;//0.25f
if ( vehicleBankingSpeed <= 0
|| ( pVeh->m_pVehicleInfo->pitchLimit == 0 && pVeh->m_pVehicleInfo->rollLimit == 0 ) )
{//don't bother, this vehicle doesn't bank
return;
}
//FIXME: do 3 traces to define a plane and use that... smoothes it out some, too...
//pitch_roll_for_slope( pm->gent, normal, vAngles );
//FIXME: maybe have some pitch control in water and/or air?
if ( pVeh->m_pVehicleInfo->type == VH_FIGHTER )
{
pitchBias = 0.0f;
}
else
{
//FIXME: gravity does not matter in SPACE!!!
//center of gravity affects pitch in air/water (FIXME: what about roll?)
pitchBias = 90.0f*pVeh->m_pVehicleInfo->centerOfGravity[0];//if centerOfGravity is all the way back (-1.0f), vehicle pitches up 90 degrees when in air
}
VectorClear( vAngles );
if ( pm->waterlevel > 0 )
{//in water
//view pitch has some influence when in water
//FIXME: take center of gravity into account?
vAngles[PITCH] += (pm->ps->viewangles[PITCH]-vAngles[PITCH])*0.75f + (pitchBias*0.5);
}
else if ( normal )
{//have a valid surface below me
PM_pitch_roll_for_slope( pEnt, normal, vAngles );
if ( (pml.groundTrace.contents&(CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) )
{//on water
//view pitch has some influence when on a fluid surface
//FIXME: take center of gravity into account
vAngles[PITCH] += (pm->ps->viewangles[PITCH]-vAngles[PITCH])*0.5f + (pitchBias*0.5f);
}
}
else
{//in air, let pitch match view...?
//FIXME: take center of gravity into account
vAngles[PITCH] = pm->ps->viewangles[PITCH]*0.5f + pitchBias;
//don't bank so fast when in the air
vehicleBankingSpeed *= (0.125f*pml.frametime);
}
//NOTE: if angles are flat and we're moving through air (not on ground),
// then pitch/bank?
if ( pVeh->m_pVehicleInfo->rollLimit > 0 )
{
//roll when banking
vec3_t velocity;
float speed;
VectorCopy( pm->ps->velocity, velocity );
velocity[2] = 0.0f;
speed = VectorNormalize( velocity );
if ( speed > 32.0f || speed < -32.0f )
{
vec3_t rt, tempVAngles;
float side;
float dp;
// Magic number fun! Speed is used for banking, so modulate the speed by a sine wave
//FIXME: this banks too early
speed *= sin( (150 + pml.frametime) * 0.003 );
// Clamp to prevent harsh rolling
if ( speed > 60 )
speed = 60;
VectorCopy( pVeh->m_vOrientation, tempVAngles );
tempVAngles[ROLL] = 0;
AngleVectors( tempVAngles, NULL, rt, NULL );
dp = DotProduct( velocity, rt );
side = speed * dp;
vAngles[ROLL] -= side;
}
}
//cap
if ( pVeh->m_pVehicleInfo->pitchLimit != -1 )
{
if ( vAngles[PITCH] > pVeh->m_pVehicleInfo->pitchLimit )
{
vAngles[PITCH] = pVeh->m_pVehicleInfo->pitchLimit;
}
else if ( vAngles[PITCH] < -pVeh->m_pVehicleInfo->pitchLimit )
{
vAngles[PITCH] = -pVeh->m_pVehicleInfo->pitchLimit;
}
}
if ( vAngles[ROLL] > pVeh->m_pVehicleInfo->rollLimit )
{
vAngles[ROLL] = pVeh->m_pVehicleInfo->rollLimit;
}
else if ( vAngles[ROLL] < -pVeh->m_pVehicleInfo->rollLimit )
{
vAngles[ROLL] = -pVeh->m_pVehicleInfo->rollLimit;
}
//do it
for ( i = 0; i < 3; i++ )
{
if ( i == YAW )
{//yawing done elsewhere
continue;
}
//bank faster the higher the difference is
/*
else if ( i == PITCH )
{
curVehicleBankingSpeed = vehicleBankingSpeed*fabs(AngleNormalize180(AngleSubtract( vAngles[PITCH], pVeh->m_vOrientation[PITCH] )))/(g_vehicleInfo[pm->ps->vehicleIndex].pitchLimit/2.0f);
}
else if ( i == ROLL )
{
curVehicleBankingSpeed = vehicleBankingSpeed*fabs(AngleNormalize180(AngleSubtract( vAngles[ROLL], pVeh->m_vOrientation[ROLL] )))/(g_vehicleInfo[pm->ps->vehicleIndex].rollLimit/2.0f);
}
if ( curVehicleBankingSpeed )
*/
{
if ( pVeh->m_vOrientation[i] >= vAngles[i] + vehicleBankingSpeed )
{
pVeh->m_vOrientation[i] -= vehicleBankingSpeed;
}
else if ( pVeh->m_vOrientation[i] <= vAngles[i] - vehicleBankingSpeed )
{
pVeh->m_vOrientation[i] += vehicleBankingSpeed;
}
else
{
pVeh->m_vOrientation[i] = vAngles[i];
}
}
}
}
void BG_VehicleTurnRateForSpeed( Vehicle_t *pVeh, float speed, float *mPitchOverride, float *mYawOverride )
{
if ( pVeh && pVeh->m_pVehicleInfo )
{
float speedFrac = 1.0f;
if ( pVeh->m_pVehicleInfo->speedDependantTurning )
{
if ( pVeh->m_LandTrace.fraction >= 1.0f
|| pVeh->m_LandTrace.plane.normal[2] < MIN_LANDING_SLOPE )
{
speedFrac = (speed/(pVeh->m_pVehicleInfo->speedMax*0.75f));
if ( speedFrac < 0.25f )
{
speedFrac = 0.25f;
}
else if ( speedFrac > 1.0f )
{
speedFrac = 1.0f;
}
}
}
if ( pVeh->m_pVehicleInfo->mousePitch )
{
*mPitchOverride = pVeh->m_pVehicleInfo->mousePitch*speedFrac;
}
if ( pVeh->m_pVehicleInfo->mouseYaw )
{
*mYawOverride = pVeh->m_pVehicleInfo->mouseYaw*speedFrac;
}
}
}
// Following couple things don't belong in the DLL namespace!
#ifdef _GAME
#if !defined(MACOS_X) && !defined(__GCC__) && !defined(__GNUC__)
typedef struct gentity_s gentity_t;
#endif
gentity_t *G_PlayEffectID( const int fxID, vec3_t org, vec3_t ang );
#endif
static void PM_GroundTraceMissed( void );
void PM_HoverTrace( void )
{
Vehicle_t *pVeh;
float hoverHeight;
vec3_t point, vAng, fxAxis[3];
trace_t *trace;
float relativeWaterLevel;
bgEntity_t *pEnt = pm_entSelf;
if ( !pEnt || pEnt->s.NPC_class != CLASS_VEHICLE )
{
return;
}
pVeh = pEnt->m_pVehicle;
hoverHeight = pVeh->m_pVehicleInfo->hoverHeight;
trace = &pml.groundTrace;
pml.groundPlane = qfalse;
//relativeWaterLevel = (pm->ps->waterheight - (pm->ps->origin[2]+pm->mins[2]));
relativeWaterLevel = pm->waterlevel; //I.. guess this works
if ( pm->waterlevel && relativeWaterLevel >= 0 )
{//in water
if ( pVeh->m_pVehicleInfo->bouyancy <= 0.0f )
{//sink like a rock
}
else
{//rise up
float floatHeight = (pVeh->m_pVehicleInfo->bouyancy * ((pm->maxs[2]-pm->mins[2])*0.5f)) - (hoverHeight*0.5f);//1.0f should make you float half-in, half-out of water
if ( relativeWaterLevel > floatHeight )
{//too low, should rise up
pm->ps->velocity[2] += (relativeWaterLevel - floatHeight) * pVeh->m_fTimeModifier;
}
}
//if ( pm->ps->waterheight < pm->ps->origin[2]+pm->maxs[2] )
if (pm->waterlevel <= 1)
{//part of us is sticking out of water
if ( fabs(pm->ps->velocity[0]) + fabs(pm->ps->velocity[1]) > 100 )
{//moving at a decent speed
if ( Q_irand( pml.frametime, 100 ) >= 50 )
{//splash
vec3_t wakeOrg;
vAng[PITCH] = vAng[ROLL] = 0;
vAng[YAW] = pVeh->m_vOrientation[YAW];
AngleVectors( vAng, fxAxis[2], fxAxis[1], fxAxis[0] );
VectorCopy( pm->ps->origin, wakeOrg );
//wakeOrg[2] = pm->ps->waterheight;
if (pm->waterlevel >= 2)
{
wakeOrg[2] = pm->ps->origin[2]+16;
}
else
{
wakeOrg[2] = pm->ps->origin[2];
}
#ifdef _GAME //yeah, this is kind of crappy and makes no use of prediction whatsoever
if ( pVeh->m_pVehicleInfo->iWakeFX )
{
//G_PlayEffectID( pVeh->m_pVehicleInfo->iWakeFX, wakeOrg, fxAxis[0] );
//tempent use bad!
G_AddEvent((gentity_t *)pEnt, EV_PLAY_EFFECT_ID, pVeh->m_pVehicleInfo->iWakeFX);
}
#endif
}
}
}
}
else
{
int traceContents;
float minNormal = pVeh->m_pVehicleInfo->maxSlope;
point[0] = pm->ps->origin[0];
point[1] = pm->ps->origin[1];
point[2] = pm->ps->origin[2] - hoverHeight;
//FIXME: check for water, too? If over water, go slower and make wave effect
// If *in* water, go really slow and use bouyancy stat to determine how far below surface to float
//NOTE: if bouyancy is 2.0f or higher, you float over water like it's solid ground.
// if it's 1.0f, you sink halfway into water. If it's 0, you sink...
traceContents = pm->tracemask;
if ( pVeh->m_pVehicleInfo->bouyancy >= 2.0f )
{//sit on water
traceContents |= (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA);
}
pm->trace( trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, traceContents );
if (trace->plane.normal[0] > 0.5f || trace->plane.normal[0] < -0.5f ||
trace->plane.normal[1] > 0.5f || trace->plane.normal[1] < -0.5f)
{ //steep slanted hill, don't go up it.
float d = fabs(trace->plane.normal[0]);
float e = fabs(trace->plane.normal[1]);
if (e > d)
{
d = e;
}
pm->ps->velocity[2] = -300.0f*d;
}
else if ( trace->plane.normal[2] >= minNormal )
{//not a steep slope, so push us up
if ( trace->fraction < 1.0f )
{//push up off ground
float hoverForce = pVeh->m_pVehicleInfo->hoverStrength;
if ( trace->fraction > 0.5f )
{
pm->ps->velocity[2] += (1.0f-trace->fraction)*hoverForce*pVeh->m_fTimeModifier;
}
else
{
pm->ps->velocity[2] += (0.5f-(trace->fraction*trace->fraction))*hoverForce*2.0f*pVeh->m_fTimeModifier;
}
if ( (trace->contents&(CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) )
{//hovering on water, make a spash if moving
if ( fabs(pm->ps->velocity[0]) + fabs(pm->ps->velocity[1]) > 100 )
{//moving at a decent speed
if ( Q_irand( pml.frametime, 100 ) >= 50 )
{//splash
vAng[PITCH] = vAng[ROLL] = 0;
vAng[YAW] = pVeh->m_vOrientation[YAW];
AngleVectors( vAng, fxAxis[2], fxAxis[1], fxAxis[0] );
#ifdef _GAME
if ( pVeh->m_pVehicleInfo->iWakeFX )
{
G_PlayEffectID( pVeh->m_pVehicleInfo->iWakeFX, trace->endpos, fxAxis[0] );
}
#endif
}
}
}
pml.groundPlane = qtrue;
}
}
}
if ( pml.groundPlane )
{
PM_SetVehicleAngles( pml.groundTrace.plane.normal );
// We're on the ground.
pVeh->m_ulFlags &= ~VEH_FLYING;
pVeh->m_vAngularVelocity = 0.0f;
}
else
{
PM_SetVehicleAngles( NULL );
// We're flying in the air.
pVeh->m_ulFlags |= VEH_FLYING;
//groundTrace
if (pVeh->m_vAngularVelocity==0.0f)
{
pVeh->m_vAngularVelocity = pVeh->m_vOrientation[YAW] - pVeh->m_vPrevOrientation[YAW];
if (pVeh->m_vAngularVelocity<-15.0f)
{
pVeh->m_vAngularVelocity = -15.0f;
}
if (pVeh->m_vAngularVelocity> 15.0f)
{
pVeh->m_vAngularVelocity = 15.0f;
}
}
//pVeh->m_vAngularVelocity *= 0.95f; // Angular Velocity Decays Over Time
if (pVeh->m_vAngularVelocity > 0.0f)
{
pVeh->m_vAngularVelocity -= pml.frametime;
if (pVeh->m_vAngularVelocity < 0.0f)
{
pVeh->m_vAngularVelocity = 0.0f;
}
}
else if (pVeh->m_vAngularVelocity < 0.0f)
{
pVeh->m_vAngularVelocity += pml.frametime;
if (pVeh->m_vAngularVelocity > 0.0f)
{
pVeh->m_vAngularVelocity = 0.0f;
}
}
}
PM_GroundTraceMissed();
}
//end vehicle functions crudely ported from sp -rww
/*
===============
PM_AddEvent
===============
*/
void PM_AddEvent( int newEvent ) {
BG_AddPredictableEventToPlayerstate( newEvent, 0, pm->ps );
}
void PM_AddEventWithParm( int newEvent, int parm )
{
BG_AddPredictableEventToPlayerstate( newEvent, parm, pm->ps );
}
/*
===============
PM_AddTouchEnt
===============
*/
void PM_AddTouchEnt( int entityNum ) {
int i;
if ( entityNum == ENTITYNUM_WORLD ) {
return;
}
if ( pm->numtouch >= MAXTOUCH ) {
return;
}
// see if it is already added
for ( i = 0 ; i < pm->numtouch ; i++ ) {
if ( pm->touchents[ i ] == entityNum ) {
return;
}
}
// add it
pm->touchents[pm->numtouch++] = entityNum;
}
/*
==================
PM_ClipVelocity
Slide off of the impacting surface
==================
*/
void PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce ) {
float backoff;
float change;
float oldInZ;
int i;
if ( (pm->ps->pm_flags&PMF_STUCK_TO_WALL) )
{//no sliding!
VectorCopy( in, out );
return;
}
oldInZ = in[2];
backoff = DotProduct (in, normal);
if ( backoff < 0 ) {
backoff *= overbounce;
} else {
backoff /= overbounce;
}
for ( i=0 ; i<3 ; i++ ) {
change = normal[i]*backoff;
out[i] = in[i] - change;
}
if ( pm->stepSlideFix )
{
if ( pm->ps->clientNum < MAX_CLIENTS//normal player
&& pm->ps->groundEntityNum != ENTITYNUM_NONE//on the ground
&& normal[2] < MIN_WALK_NORMAL )//sliding against a steep slope
{//if walking on the ground, don't slide up slopes that are too steep to walk on
out[2] = oldInZ;
}
}
}
/*
==================
PM_Friction
Handles both ground friction and water friction
==================
*/
static void PM_Friction( void ) {
vec3_t vec;
float *vel;
float speed, newspeed, control;
float drop;
bgEntity_t *pEnt = NULL;
vel = pm->ps->velocity;
VectorCopy( vel, vec );
if ( pml.walking ) {
vec[2] = 0; // ignore slope movement
}
speed = VectorLength(vec);
if (speed < 1) {
vel[0] = 0;
vel[1] = 0; // allow sinking underwater
if (pm->ps->pm_type == PM_SPECTATOR)
{
vel[2] = 0;
}