forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbg_pmove.cpp
8994 lines (8286 loc) · 243 KB
/
bg_pmove.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
/*
===========================================================================
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
// define GAME_INCLUDE so that g_public.h does not define the
// short, server-visible gclient_t and gentity_t structures,
// because we define the full size ones in this file
#define GAME_INCLUDE
#include "../../code/qcommon/q_shared.h"
#include "b_local.h"
#include "g_shared.h"
#include "bg_local.h"
#include "g_local.h"
#include "g_functions.h"
#include "anims.h"
#include "../cgame/cg_local.h" // yeah I know this is naughty, but we're shipping soon...
#include "wp_saber.h"
#include <float.h>
extern qboolean G_DoDismemberment( gentity_t *self, vec3_t point, int mod, int damage, int hitLoc, qboolean force = qfalse );
extern qboolean G_EntIsUnlockedDoor( int entityNum );
extern qboolean G_EntIsDoor( int entityNum );
extern qboolean InFront( vec3_t spot, vec3_t from, vec3_t fromAngles, float threshHold = 0.0f );
extern void G_AddVoiceEvent( gentity_t *self, int event, int speakDebounceTime );
extern qboolean Q3_TaskIDPending( gentity_t *ent, taskID_t taskType );
extern void WP_SaberInitBladeData( gentity_t *ent );
extern qboolean WP_SaberLose( gentity_t *self, vec3_t throwDir );
extern void G_SoundOnEnt( gentity_t *ent, soundChannel_t channel, const char *soundPath );
extern int Jedi_ReCalcParryTime( gentity_t *self, evasionType_t evasionType );
extern qboolean PM_HasAnimation( gentity_t *ent, int animation );
extern int PM_SaberAnimTransitionAnim( int curmove, int newmove );
extern saberMoveName_t PM_AttackMoveForQuad( int quad );
extern qboolean PM_SaberInTransition( int move );
extern qboolean PM_SaberInTransitionAny( int move );
extern qboolean PM_SaberInBounce( int move );
extern qboolean PM_SaberInSpecialAttack( int anim );
extern qboolean PM_SaberInAttack( int move );
extern qboolean PM_InAnimForSaberMove( int anim, int saberMove );
extern int PM_SaberBounceForAttack( int move );
extern int PM_SaberAttackForMovement( int forwardmove, int rightmove, int move );
extern int PM_BrokenParryForParry( int move );
extern int PM_KnockawayForParry( int move );
extern qboolean PM_SaberInParry( int move );
extern qboolean PM_SaberInKnockaway( int move );
extern qboolean PM_SaberInBrokenParry( int move );
extern qboolean PM_SaberInReflect( int move );
extern qboolean PM_SaberInIdle( int move );
extern qboolean PM_SaberInStart( int move );
extern qboolean PM_SaberKataDone( int curmove, int newmove );
extern qboolean PM_SaberInSpecial( int move );
extern qboolean PM_InDeathAnim ( void );
extern qboolean PM_StandingAnim( int anim );
extern int PM_SaberFlipOverAttackMove( void );
extern int PM_SaberJumpAttackMove( void );
qboolean PM_InKnockDown( playerState_t *ps );
qboolean PM_InKnockDownOnGround( playerState_t *ps );
qboolean PM_InGetUp( playerState_t *ps );
qboolean PM_InRoll( playerState_t *ps );
qboolean PM_SpinningSaberAnim( int anim );
qboolean PM_GettingUpFromKnockDown( float standheight, float crouchheight );
qboolean PM_SpinningAnim( int anim );
qboolean PM_FlippingAnim( int anim );
qboolean PM_PainAnim( int anim );
qboolean PM_RollingAnim( int anim );
qboolean PM_SwimmingAnim( int anim );
extern int parryDebounce[];
extern qboolean player_locked;
extern qboolean MatrixMode;
qboolean waterForceJump;
extern cvar_t *g_timescale;
static void PM_SetWaterLevelAtPoint( vec3_t org, int *waterlevel, int *watertype );
#define FLY_NONE 0
#define FLY_NORMAL 1
#define FLY_VEHICLE 2
#define FLY_HOVER 3
int Flying = FLY_NONE;
pmove_t *pm;
pml_t pml;
// movement parameters
const float pm_stopspeed = 100.0f;
const float pm_duckScale = 0.50f;
const float pm_swimScale = 0.50f;
float pm_ladderScale = 0.7f;
const float pm_accelerate = 12.0f;
const float pm_airaccelerate = 4.0f;
const float pm_wateraccelerate = 4.0f;
const float pm_flyaccelerate = 8.0f;
const float pm_friction = 6.0f;
const float pm_waterfriction = 1.0f;
const float pm_flightfriction = 3.0f;
const float pm_frictionModifier = 3.0f; //Used for "careful" mode (when pressing use)
const float pm_airDecelRate = 1.35f; //Used for air decelleration away from current movement velocity
int c_pmove = 0;
extern void PM_SetTorsoAnimTimer( gentity_t *ent, int *torsoAnimTimer, int time );
extern void PM_SetLegsAnimTimer( gentity_t *ent, int *legsAnimTimer, int time );
//extern void PM_SetAnim(pmove_t *pm,int setAnimParts,int anim,int setAnimFlags);
extern void PM_TorsoAnimation( void );
extern int PM_TorsoAnimForFrame( gentity_t *ent, int torsoFrame );
extern int PM_AnimLength( int index, animNumber_t anim );
extern qboolean PM_InDeathAnim ( void );
extern qboolean PM_InOnGroundAnim ( playerState_t *ps );
extern weaponInfo_t cg_weapons[MAX_WEAPONS];
extern int PM_PickAnim( gentity_t *self, int minAnim, int maxAnim );
extern void DoImpact( gentity_t *self, gentity_t *other, qboolean damageSelf );
#define PHASER_RECHARGE_TIME 100
extern saberMoveName_t transitionMove[Q_NUM_QUADS][Q_NUM_QUADS];
extern qboolean G_ControlledByPlayer( gentity_t *self );
qboolean PM_ControlledByPlayer( void )
{
return G_ControlledByPlayer( pm->gent );
}
/*
===============
PM_AddEvent
===============
*/
void PM_AddEvent( int newEvent )
{
AddEventToPlayerstate( newEvent, 0, pm->ps );
}
/*
===============
qboolean PM_ClientImpact( int otherEntityNum, qboolean damageSelf )
===============
*/
qboolean PM_ClientImpact( int otherEntityNum, qboolean damageSelf )
{
gentity_t *traceEnt;
if ( !pm->gent )
{
return qfalse;
}
if( (VectorLength( pm->ps->velocity )*(pm->gent->mass/10)) >= 100 && pm->ps->lastOnGround+100<level.time )//was 300 ||(other->material>=MAT_GLASS&&pm->gent->lastImpact+100<=level.time))
{
DoImpact( pm->gent, &g_entities[otherEntityNum], damageSelf );
}
if ( otherEntityNum >= ENTITYNUM_WORLD )
{
return qfalse;
}
traceEnt = &g_entities[otherEntityNum];
if ( !traceEnt || !(traceEnt->contents&pm->tracemask) )
{//it's dead or not in my way anymore
return qtrue;
}
return qfalse;
}
/*
===============
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->numtouch++;
}
/*
==================
PM_ClipVelocity
Slide off of the impacting surface
This will pull you down onto slopes if heading away from
them and push you up them as you go up them.
Also stops you when you hit walls.
==================
*/
void PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce ) {
float backoff;
float change;
int i;
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;
}
}
/*
==================
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, friction = pm->ps->friction;
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
// FIXME: still have z friction underwater?
return;
}
drop = 0;
// apply ground friction, even if on ladder
if ( Flying != FLY_NORMAL )
{
if ( (pm->watertype & CONTENTS_LADDER) || pm->waterlevel <= 1 )
{
if ( (pm->watertype & CONTENTS_LADDER) || (pml.walking && !(pml.groundTrace.surfaceFlags & SURF_SLICK)) )
{
// if getting knocked back, no friction
if ( !(pm->ps->pm_flags & PMF_TIME_KNOCKBACK) && !(pm->ps->pm_flags & PMF_TIME_NOFRICTION) )
{
//If the use key is pressed. slow the player more quickly
if ( pm->cmd.buttons & BUTTON_USE )
friction *= pm_frictionModifier;
control = speed < pm_stopspeed ? pm_stopspeed : speed;
drop += control*friction*pml.frametime;
}
}
}
}
if ( Flying == FLY_VEHICLE )
{
if ( !(pm->ps->pm_flags & PMF_TIME_KNOCKBACK) && !(pm->ps->pm_flags & PMF_TIME_NOFRICTION) )
{
control = speed < pm_stopspeed ? pm_stopspeed : speed;
drop += control*friction*pml.frametime;
}
}
// apply water friction even if just wading
if ( !waterForceJump )
{
if ( pm->waterlevel && !(pm->watertype & CONTENTS_LADDER))
{
drop += speed*pm_waterfriction*pm->waterlevel*pml.frametime;
}
}
// apply flying friction
if ( pm->ps->pm_type == PM_SPECTATOR )
{
drop += speed*pm_flightfriction*pml.frametime;
}
// scale the velocity
newspeed = speed - drop;
if (newspeed < 0)
newspeed = 0;
newspeed /= speed;
vel[0] = vel[0] * newspeed;
vel[1] = vel[1] * newspeed;
vel[2] = vel[2] * newspeed;
}
/*
==============
PM_Accelerate
Handles user intended acceleration
==============
*/
static void PM_Accelerate( vec3_t wishdir, float wishspeed, float accel )
{
int i;
float addspeed, accelspeed, currentspeed;
currentspeed = DotProduct (pm->ps->velocity, wishdir);
addspeed = wishspeed - currentspeed;
if (addspeed <= 0) {
return;
}
accelspeed = ( accel * pml.frametime ) * wishspeed;
if (accelspeed > addspeed) {
accelspeed = addspeed;
}
for (i=0 ; i<3 ; i++) {
pm->ps->velocity[i] += accelspeed * wishdir[i];
}
}
/*
============
PM_CmdScale
Returns the scale factor to apply to cmd movements
This allows the clients to use axial -127 to 127 values for all directions
without getting a sqrt(2) distortion in speed.
============
*/
static float PM_CmdScale( usercmd_t *cmd )
{
int max;
float total;
float scale;
max = abs( cmd->forwardmove );
if ( abs( cmd->rightmove ) > max ) {
max = abs( cmd->rightmove );
}
if ( abs( cmd->upmove ) > max ) {
max = abs( cmd->upmove );
}
if ( !max ) {
return 0;
}
total = sqrt((double)( ( cmd->forwardmove * cmd->forwardmove )
+ ( cmd->rightmove * cmd->rightmove )
+ ( cmd->upmove * cmd->upmove ) ));
scale = (float) pm->ps->speed * max / ( 127.0f * total );
return scale;
}
/*
================
PM_SetMovementDir
Determine the rotation of the legs reletive
to the facing dir
================
*/
static void PM_SetMovementDir( void ) {
if ( pm->cmd.forwardmove || pm->cmd.rightmove ) {
if ( pm->cmd.rightmove == 0 && pm->cmd.forwardmove > 0 ) {
pm->ps->movementDir = 0;
} else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove > 0 ) {
pm->ps->movementDir = 1;
} else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove == 0 ) {
pm->ps->movementDir = 2;
} else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove < 0 ) {
pm->ps->movementDir = 3;
} else if ( pm->cmd.rightmove == 0 && pm->cmd.forwardmove < 0 ) {
pm->ps->movementDir = 4;
} else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove < 0 ) {
pm->ps->movementDir = 5;
} else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove == 0 ) {
pm->ps->movementDir = 6;
} else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove > 0 ) {
pm->ps->movementDir = 7;
}
} else {
// if they aren't actively going directly sideways,
// change the animation to the diagonal so they
// don't stop too crooked
if ( pm->ps->movementDir == 2 ) {
pm->ps->movementDir = 1;
} else if ( pm->ps->movementDir == 6 ) {
pm->ps->movementDir = 7;
}
}
}
/*
=============
PM_CheckJump
=============
*/
#define METROID_JUMP 1
qboolean PM_InSpecialJump( int anim )
{
switch ( anim )
{
case BOTH_WALL_RUN_RIGHT:
case BOTH_WALL_RUN_RIGHT_STOP:
case BOTH_WALL_RUN_RIGHT_FLIP:
case BOTH_WALL_RUN_LEFT:
case BOTH_WALL_RUN_LEFT_STOP:
case BOTH_WALL_RUN_LEFT_FLIP:
case BOTH_WALL_FLIP_RIGHT:
case BOTH_WALL_FLIP_LEFT:
case BOTH_FLIP_BACK1:
case BOTH_FLIP_BACK2:
case BOTH_FLIP_BACK3:
case BOTH_WALL_FLIP_BACK1:
case BOTH_BUTTERFLY_LEFT:
case BOTH_BUTTERFLY_RIGHT:
case BOTH_FJSS_TR_BL:
case BOTH_FJSS_TL_BR:
case BOTH_FORCELEAP2_T__B_:
case BOTH_JUMPFLIPSLASHDOWN1://#
case BOTH_JUMPFLIPSTABDOWN://#
case BOTH_ARIAL_LEFT:
case BOTH_ARIAL_RIGHT:
case BOTH_ARIAL_F1:
case BOTH_CARTWHEEL_LEFT:
case BOTH_CARTWHEEL_RIGHT:
return qtrue;
}
return qfalse;
}
extern void CG_PlayerLockedWeaponSpeech( int jumping );
qboolean PM_ForceJumpingUp( gentity_t *gent )
{
if ( !gent || !gent->client )
{
return qfalse;
}
if ( gent->NPC )
{//this is ONLY for the player
if ( player
&& player->client
&& player->client->ps.viewEntity == gent->s.number )
{//okay to jump if an NPC controlled by the player
}
else
{
return qfalse;
}
}
if ( !(gent->client->ps.forcePowersActive&(1<<FP_LEVITATION)) && gent->client->ps.forceJumpCharge )
{//already jumped and let go
return qfalse;
}
if ( PM_InSpecialJump( gent->client->ps.legsAnim ) )
{
return qfalse;
}
if ( PM_InKnockDown( &gent->client->ps ) )
{
return qfalse;
}
if ( !gent->s.number && in_camera )
{//player can't use force powers in cinematic
return qfalse;
}
if ( gent->client->ps.groundEntityNum == ENTITYNUM_NONE //in air
&& ( /*(gent->client->ps.waterHeightLevel==WHL_SHOULDERS&&gent->client->usercmd.upmove>0) ||*/ ((gent->client->ps.pm_flags&PMF_JUMPING)&&gent->client->ps.velocity[2] > 0) )//jumped & going up or at water surface
&& gent->client->ps.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0 //force-jump capable
&& !(gent->client->ps.pm_flags&PMF_TRIGGER_PUSHED) )//not pushed by a trigger
{
if( gent->flags & FL_LOCK_PLAYER_WEAPONS ) // yes this locked weapons check also includes force powers, if we need a separate check later I'll make one
{
CG_PlayerLockedWeaponSpeech( qtrue );
return qfalse;
}
return qtrue;
}
return qfalse;
}
static void PM_JumpForDir( void )
{
int anim = BOTH_JUMP1;
if ( pm->cmd.forwardmove > 0 )
{
anim = BOTH_JUMP1;
pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
}
else if ( pm->cmd.forwardmove < 0 )
{
anim = BOTH_JUMPBACK1;
pm->ps->pm_flags |= PMF_BACKWARDS_JUMP;
}
else if ( pm->cmd.rightmove > 0 )
{
anim = BOTH_JUMPRIGHT1;
pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
}
else if ( pm->cmd.rightmove < 0 )
{
anim = BOTH_JUMPLEFT1;
pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
}
else
{
anim = BOTH_JUMP1;
pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
}
if(!PM_InDeathAnim())
{
PM_SetAnim(pm,SETANIM_LEGS,anim,SETANIM_FLAG_OVERRIDE, 100); // Only blend over 100ms
}
}
extern qboolean WP_ForcePowerAvailable( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
extern void WP_ForcePowerDrain( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
qboolean PM_GentCantJump( gentity_t *gent )
{//FIXME: ugh, hacky, set a flag on NPC or something, please...
if ( gent && gent->client &&
( gent->client->NPC_class == CLASS_ATST ||
gent->client->NPC_class == CLASS_GONK ||
gent->client->NPC_class == CLASS_MARK1 ||
gent->client->NPC_class == CLASS_MARK2 ||
gent->client->NPC_class == CLASS_MOUSE ||
gent->client->NPC_class == CLASS_PROBE ||
gent->client->NPC_class == CLASS_PROTOCOL ||
gent->client->NPC_class == CLASS_R2D2 ||
gent->client->NPC_class == CLASS_R5D2 ||
gent->client->NPC_class == CLASS_SEEKER ||
gent->client->NPC_class == CLASS_REMOTE ||
gent->client->NPC_class == CLASS_SENTRY ) )
{
return qtrue;
}
return qfalse;
}
static qboolean PM_CheckJump( void )
{
//Don't allow jump until all buttons are up
if ( pm->ps->pm_flags & PMF_RESPAWNED ) {
return qfalse;
}
if ( PM_InKnockDown( pm->ps ) || PM_InRoll( pm->ps ) )
{//in knockdown
return qfalse;
}
if ( PM_GentCantJump( pm->gent ) )
{
return qfalse;
}
/*
if ( pm->cmd.buttons & BUTTON_FORCEJUMP )
{
pm->ps->pm_flags |= PMF_JUMP_HELD;
}
*/
#if METROID_JUMP
if ( pm->waterlevel < 3 )//|| (pm->ps->waterHeightLevel==WHL_SHOULDERS&&pm->cmd.upmove>0) )
{
if ( pm->ps->gravity > 0 )
{//can't do this in zero-G
//FIXME: still able to pogo-jump...
if ( PM_ForceJumpingUp( pm->gent ) && (pm->ps->pm_flags&PMF_JUMP_HELD) )//||pm->ps->waterHeightLevel==WHL_SHOULDERS) )
{//force jumping && holding jump
/*
if ( !pm->ps->forceJumpZStart && (pm->ps->waterHeightLevel==WHL_SHOULDERS&&pm->cmd.upmove>0) )
{
pm->ps->forceJumpZStart = pm->ps->origin[2];
}
*/
float curHeight = pm->ps->origin[2] - pm->ps->forceJumpZStart;
//check for max force jump level and cap off & cut z vel
if ( ( curHeight<=forceJumpHeight[0] ||//still below minimum jump height
(pm->ps->forcePower&&pm->cmd.upmove>=10) ) &&////still have force power available and still trying to jump up
curHeight < forceJumpHeight[pm->ps->forcePowerLevel[FP_LEVITATION]] )//still below maximum jump height
{//can still go up
//FIXME: after a certain amount of time of held jump, play force jump sound and flip if a dir is being held
//FIXME: if hit a wall... should we cut velocity or allow them to slide up it?
//FIXME: constantly drain force power at a rate by which the usage for maximum height would use up the full cost of force jump
if ( curHeight > forceJumpHeight[0] )
{//passed normal jump height *2?
if ( !(pm->ps->forcePowersActive&(1<<FP_LEVITATION)) )//haven't started forcejump yet
{
//start force jump
pm->ps->forcePowersActive |= (1<<FP_LEVITATION);
if ( pm->gent )
{
G_SoundOnEnt( pm->gent, CHAN_BODY, "sound/weapons/force/jump.wav" );
}
//play flip
//FIXME: do this only when they stop the jump (below) or when they're just about to hit the peak of the jump
if ((pm->cmd.forwardmove || pm->cmd.rightmove) && //pushing in a dir
//pm->ps->legsAnim != BOTH_ARIAL_F1 &&//not already flipping
pm->ps->legsAnim != BOTH_FLIP_F &&
pm->ps->legsAnim != BOTH_FLIP_B &&
pm->ps->legsAnim != BOTH_FLIP_R &&
pm->ps->legsAnim != BOTH_FLIP_L
&& cg.renderingThirdPerson//third person only
&& !cg.zoomMode )//not zoomed in
{//FIXME: this could end up playing twice if the jump is very long...
int anim = BOTH_FORCEINAIR1;
int parts = SETANIM_BOTH;
if ( pm->cmd.forwardmove > 0 )
{
/*
if ( pm->ps->forcePowerLevel[FP_LEVITATION] < FORCE_LEVEL_2 )
{
anim = BOTH_ARIAL_F1;
}
else
*/
{
anim = BOTH_FLIP_F;
}
}
else if ( pm->cmd.forwardmove < 0 )
{
anim = BOTH_FLIP_B;
}
else if ( pm->cmd.rightmove > 0 )
{
anim = BOTH_FLIP_R;
}
else if ( pm->cmd.rightmove < 0 )
{
anim = BOTH_FLIP_L;
}
if ( pm->ps->weaponTime )
{//FIXME: really only care if we're in a saber attack anim...
parts = SETANIM_LEGS;
}
PM_SetAnim( pm, parts, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
}
else if ( pm->ps->forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_1 )
{//FIXME: really want to know how far off ground we are, probably...
vec3_t facingFwd, facingRight, facingAngles = {0, pm->ps->viewangles[YAW], 0};
int anim = -1;
AngleVectors( facingAngles, facingFwd, facingRight, NULL );
float dotR = DotProduct( facingRight, pm->ps->velocity );
float dotF = DotProduct( facingFwd, pm->ps->velocity );
if ( fabs(dotR) > fabs(dotF) * 1.5 )
{
if ( dotR > 150 )
{
anim = BOTH_FORCEJUMPRIGHT1;
}
else if ( dotR < -150 )
{
anim = BOTH_FORCEJUMPLEFT1;
}
}
else
{
if ( dotF > 150 )
{
anim = BOTH_FORCEJUMP1;
}
else if ( dotF < -150 )
{
anim = BOTH_FORCEJUMPBACK1;
}
}
if ( anim != -1 )
{
int parts = SETANIM_BOTH;
if ( pm->ps->weaponTime )
{//FIXME: really only care if we're in a saber attack anim...
parts = SETANIM_LEGS;
}
PM_SetAnim( pm, parts, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
}
}
}
else
{
if ( !pm->ps->legsAnimTimer )
{//not in the middle of a legsAnim
int anim = pm->ps->legsAnim;
int newAnim = -1;
switch ( anim )
{
case BOTH_FORCEJUMP1:
newAnim = BOTH_FORCELAND1;//BOTH_FORCEINAIR1;
break;
case BOTH_FORCEJUMPBACK1:
newAnim = BOTH_FORCELANDBACK1;//BOTH_FORCEINAIRBACK1;
break;
case BOTH_FORCEJUMPLEFT1:
newAnim = BOTH_FORCELANDLEFT1;//BOTH_FORCEINAIRLEFT1;
break;
case BOTH_FORCEJUMPRIGHT1:
newAnim = BOTH_FORCELANDRIGHT1;//BOTH_FORCEINAIRRIGHT1;
break;
}
if ( newAnim != -1 )
{
int parts = SETANIM_BOTH;
if ( pm->ps->weaponTime )
{//FIXME: really only care if we're in a saber attack anim...
parts = SETANIM_LEGS;
}
PM_SetAnim( pm, parts, newAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
}
}
}
}
//need to scale this down, start with height velocity (based on max force jump height) and scale down to regular jump vel
pm->ps->velocity[2] = (forceJumpHeight[pm->ps->forcePowerLevel[FP_LEVITATION]]-curHeight)/forceJumpHeight[pm->ps->forcePowerLevel[FP_LEVITATION]]*forceJumpStrength[pm->ps->forcePowerLevel[FP_LEVITATION]];//JUMP_VELOCITY;
pm->ps->velocity[2] /= 10;
pm->ps->velocity[2] += JUMP_VELOCITY;
pm->ps->pm_flags |= PMF_JUMP_HELD;
}
else if ( curHeight > forceJumpHeight[0] && curHeight < forceJumpHeight[pm->ps->forcePowerLevel[FP_LEVITATION]] - forceJumpHeight[0] )
{//still have some headroom, don't totally stop it
if ( pm->ps->velocity[2] > JUMP_VELOCITY )
{
pm->ps->velocity[2] = JUMP_VELOCITY;
}
}
else
{
pm->ps->velocity[2] = 0;
}
pm->cmd.upmove = 0;
return qfalse;
}
}
}
#endif
//Not jumping
if ( pm->cmd.upmove < 10 ) {
return qfalse;
}
// must wait for jump to be released
if ( pm->ps->pm_flags & PMF_JUMP_HELD )
{
// clear upmove so cmdscale doesn't lower running speed
pm->cmd.upmove = 0;
return qfalse;
}
if ( pm->ps->gravity <= 0 )
{//in low grav, you push in the dir you're facing as long as there is something behind you to shove off of
vec3_t forward, back;
trace_t trace;
AngleVectors( pm->ps->viewangles, forward, NULL, NULL );
VectorMA( pm->ps->origin, -8, forward, back );
pm->trace( &trace, pm->ps->origin, pm->mins, pm->maxs, back, pm->ps->clientNum, pm->tracemask, G2_NOCOLLIDE, 0 );
pm->cmd.upmove = 0;
if ( trace.fraction < 1.0f )
{
VectorMA( pm->ps->velocity, JUMP_VELOCITY/2, forward, pm->ps->velocity );
//FIXME: kicking off wall anim? At least check what anim we're in?
PM_SetAnim(pm,SETANIM_LEGS,BOTH_FORCEJUMP1,SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD|SETANIM_FLAG_RESTART);
}
else
{//else no surf close enough to push off of
return qfalse;
}
if ( pm->ps->groundEntityNum == ENTITYNUM_NONE )
{//need to set some things and return
//Jumping
pm->ps->forceJumpZStart = 0;
pml.groundPlane = qfalse;
pml.walking = qfalse;
pm->ps->pm_flags |= (PMF_JUMPING|PMF_JUMP_HELD);
pm->ps->groundEntityNum = ENTITYNUM_NONE;
pm->ps->jumpZStart = pm->ps->origin[2];
if ( pm->gent )
{
if ( !Q3_TaskIDPending( pm->gent, TID_CHAN_VOICE ) )
{
PM_AddEvent( EV_JUMP );
}
}
else
{
PM_AddEvent( EV_JUMP );
}
return qtrue;
}//else no surf close enough to push off of
}
else if ( pm->cmd.upmove > 0 && pm->waterlevel < 2
&& pm->ps->forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0
&& !(pm->ps->pm_flags&PMF_JUMP_HELD)
//&& !PM_InKnockDown( pm->ps )
&& pm->gent && WP_ForcePowerAvailable( pm->gent, FP_LEVITATION, 0 )
&& ((pm->ps->clientNum&&!PM_ControlledByPlayer())||((!pm->ps->clientNum||PM_ControlledByPlayer()) && cg.renderingThirdPerson && !cg.zoomMode && !(pm->gent->flags&FL_LOCK_PLAYER_WEAPONS) )) )// yes this locked weapons check also includes force powers, if we need a separate check later I'll make one
{
if ( pm->gent->NPC && pm->gent->NPC->rank != RANK_CREWMAN && pm->gent->NPC->rank <= RANK_LT_JG )
{//reborn who are not acrobats can't do any of these acrobatics
}
else if ( pm->ps->groundEntityNum != ENTITYNUM_NONE )
{//on the ground
//check for left-wall and right-wall special jumps
int anim = -1;
float vertPush = 0;
if ( pm->cmd.rightmove > 0 && pm->ps->forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_1 )
{//strafing right
if ( pm->cmd.forwardmove > 0 )
{//wall-run
vertPush = forceJumpStrength[FORCE_LEVEL_2]/2.0f;
anim = BOTH_WALL_RUN_RIGHT;
}
else if ( pm->cmd.forwardmove == 0 )
{//wall-flip
vertPush = forceJumpStrength[FORCE_LEVEL_2]/2.25f;
anim = BOTH_WALL_FLIP_RIGHT;
}
}
else if ( pm->cmd.rightmove < 0 && pm->ps->forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_1 )
{//strafing left
if ( pm->cmd.forwardmove > 0 )
{//wall-run
vertPush = forceJumpStrength[FORCE_LEVEL_2]/2.0f;
anim = BOTH_WALL_RUN_LEFT;
}
else if ( pm->cmd.forwardmove == 0 )
{//wall-flip
vertPush = forceJumpStrength[FORCE_LEVEL_2]/2.25f;
anim = BOTH_WALL_FLIP_LEFT;
}
}
else if ( pm->ps->clientNum && !PM_ControlledByPlayer() && pm->cmd.forwardmove > 0 && pm->ps->forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_1 )
{//run up wall, flip backwards
if ( VectorLengthSquared( pm->ps->velocity ) > 40000 /*200*200*/)
{//have to be moving... FIXME: make sure it's opposite the wall... or at least forward?
vertPush = forceJumpStrength[FORCE_LEVEL_2]/2.25f;
anim = BOTH_WALL_FLIP_BACK1;
}
}
else if ( pm->cmd.forwardmove < 0 && !(pm->cmd.buttons&BUTTON_ATTACK) )//pm->ps->clientNum &&
{//double-tap back-jump does backflip
if ( pm->ps->velocity[2] >= 0 )
{//must be going up already
vertPush = JUMP_VELOCITY;
anim = PM_PickAnim( pm->gent, BOTH_FLIP_BACK1, BOTH_FLIP_BACK3 );
}
}
else if ( VectorLengthSquared( pm->ps->velocity ) < 256 /*16 squared*/)
{//not moving
if ( pm->ps->weapon == WP_SABER && (pm->cmd.buttons & BUTTON_ATTACK) && pm->ps->saberAnimLevel == FORCE_LEVEL_2 )
{
/*
//Only tavion does these now
if ( pm->ps->clientNum && Q_irand( 0, 1 ) )
{//butterfly... FIXME: does direction matter?
vertPush = JUMP_VELOCITY;
if ( Q_irand( 0, 1 ) )
{
anim = BOTH_BUTTERFLY_LEFT;
}
else
{
anim = BOTH_BUTTERFLY_RIGHT;
}
}
else
*/if ( pm->ps->clientNum && !PM_ControlledByPlayer() )//NOTE: pretty much useless, so player never does these
{//jump-spin FIXME: does direction matter?
vertPush = forceJumpStrength[FORCE_LEVEL_2]/1.5f;
anim = Q_irand( BOTH_FJSS_TR_BL, BOTH_FJSS_TL_BR );
}
}
}
if ( anim != -1 && PM_HasAnimation( pm->gent, anim ) )
{
vec3_t fwd, right, traceto, mins = {pm->mins[0],pm->mins[1],0}, maxs = {pm->maxs[0],pm->maxs[1],24}, fwdAngles = {0, pm->ps->viewangles[YAW], 0};
trace_t trace;
qboolean doTrace = qfalse;
int contents = CONTENTS_SOLID;
AngleVectors( fwdAngles, fwd, right, NULL );
//trace-check for a wall, if necc.
switch ( anim )
{
case BOTH_WALL_FLIP_LEFT:
//contents |= CONTENTS_BODY;
//NOTE: purposely falls through to next case!
case BOTH_WALL_RUN_LEFT:
doTrace = qtrue;
VectorMA( pm->ps->origin, -16, right, traceto );
break;
case BOTH_WALL_FLIP_RIGHT:
//contents |= CONTENTS_BODY;
//NOTE: purposely falls through to next case!
case BOTH_WALL_RUN_RIGHT:
doTrace = qtrue;
VectorMA( pm->ps->origin, 16, right, traceto );
break;
case BOTH_WALL_FLIP_BACK1:
//contents |= CONTENTS_BODY;
doTrace = qtrue;
VectorMA( pm->ps->origin, 16, fwd, traceto );
break;
}
vec3_t idealNormal;
if ( doTrace )
{
//FIXME: all these jump ones should check for head clearance
pm->trace( &trace, pm->ps->origin, mins, maxs, traceto, pm->ps->clientNum, contents, G2_NOCOLLIDE, 0 );
VectorSubtract( pm->ps->origin, traceto, idealNormal );
VectorNormalize( idealNormal );
if ( anim == BOTH_WALL_FLIP_LEFT )
{//sigh.. check for bottomless pit to the right
trace_t trace2;
vec3_t start;
VectorMA( pm->ps->origin, 128, right, traceto );
pm->trace( &trace2, pm->ps->origin, mins, maxs, traceto, pm->ps->clientNum, contents, G2_NOCOLLIDE, 0 );
if ( !trace2.allsolid && !trace2.startsolid )
{
VectorCopy( trace2.endpos, traceto );
VectorCopy( traceto, start );
traceto[2] -= 384;
pm->trace( &trace2, start, mins, maxs, traceto, pm->ps->clientNum, contents, G2_NOCOLLIDE, 0 );