Debian Codegraph @

code/game/bg_pmove.c

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // bg_pmove.c -- both games player movement code
24 // takes a playerstate and a usercmd as input and returns a modifed playerstate
25
26 #include "../qcommon/q_shared.h"
27 #include "bg_public.h"
28 #include "bg_local.h"
29
30 pmove_t *pm;
31 pml_t pml;
32
33 // movement parameters
34 float pm_stopspeed = 100.0f;
35 float pm_duckScale = 0.25f;
36 float pm_swimScale = 0.50f;
37 float pm_wadeScale = 0.70f;
38
39 float pm_accelerate = 10.0f;
40 float pm_airaccelerate = 1.0f;
41 float pm_wateraccelerate = 4.0f;
42 float pm_flyaccelerate = 8.0f;
43
44 float pm_friction = 6.0f;
45 float pm_waterfriction = 1.0f;
46 float pm_flightfriction = 3.0f;
47 float pm_spectatorfriction = 5.0f;
48
49 int c_pmove = 0;
50
51 /*
52 ===============
53 PM_AddEvent
54
55 ===============
56 */
57 void PM_AddEvent( int newEvent ) {
58 BG_AddPredictableEventToPlayerstate( newEvent, 0, pm->ps );
59 }
60
61 /*
62 ===============
63 PM_AddTouchEnt
64 ===============
65 */
66 void PM_AddTouchEnt( int entityNum ) {
67 int i;
68
69 if ( entityNum == ENTITYNUM_WORLD ) {
70 return;
71 }
72 if ( pm->numtouch == MAXTOUCH ) {
73 return;
74 }
75
76 // see if it is already added
77 for ( i = 0 ; i < pm->numtouch ; i++ ) {
78 if ( pm->touchents[ i ] == entityNum ) {
79 return;
80 }
81 }
82
83 // add it
84 pm->touchents[pm->numtouch] = entityNum;
85 pm->numtouch++;
86 }
87
88 /*
89 ===================
90 PM_StartTorsoAnim
91 ===================
92 */
93 static void PM_StartTorsoAnim( int anim ) {
94 if ( pm->ps->pm_type >= PM_DEAD ) {
95 return;
96 }
97 pm->ps->torsoAnim = ( ( pm->ps->torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT )
98 | anim;
99 }
100 static void PM_StartLegsAnim( int anim ) {
101 if ( pm->ps->pm_type >= PM_DEAD ) {
102 return;
103 }
104 if ( pm->ps->legsTimer > 0 ) {
105 return; // a high priority animation is running
106 }
107 pm->ps->legsAnim = ( ( pm->ps->legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT )
108 | anim;
109 }
110
111 static void PM_ContinueLegsAnim( int anim ) {
112 if ( ( pm->ps->legsAnim & ~ANIM_TOGGLEBIT ) == anim ) {
113 return;
114 }
115 if ( pm->ps->legsTimer > 0 ) {
116 return; // a high priority animation is running
117 }
118 PM_StartLegsAnim( anim );
119 }
120
121 static void PM_ContinueTorsoAnim( int anim ) {
122 if ( ( pm->ps->torsoAnim & ~ANIM_TOGGLEBIT ) == anim ) {
123 return;
124 }
125 if ( pm->ps->torsoTimer > 0 ) {
126 return; // a high priority animation is running
127 }
128 PM_StartTorsoAnim( anim );
129 }
130
131 static void PM_ForceLegsAnim( int anim ) {
132 pm->ps->legsTimer = 0;
133 PM_StartLegsAnim( anim );
134 }
135
136
137 /*
138 ==================
139 PM_ClipVelocity
140
141 Slide off of the impacting surface
142 ==================
143 */
144 void PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce ) {
145 float backoff;
146 float change;
147 int i;
148
149 backoff = DotProduct (in, normal);
150
151 if ( backoff < 0 ) {
152 backoff *= overbounce;
153 } else {
154 backoff /= overbounce;
155 }
156
157 for ( i=0 ; i<3 ; i++ ) {
158 change = normal[i]*backoff;
159 out[i] = in[i] - change;
160 }
161 }
162
163
164 /*
165 ==================
166 PM_Friction
167
168 Handles both ground friction and water friction
169 ==================
170 */
171 static void PM_Friction( void ) {
172 vec3_t vec;
173 float *vel;
174 float speed, newspeed, control;
175 float drop;
176
177 vel = pm->ps->velocity;
178
179 VectorCopy( vel, vec );
180 if ( pml.walking ) {
181 vec[2] = 0; // ignore slope movement
182 }
183
184 speed = VectorLength(vec);
185 if (speed < 1) {
186 vel[0] = 0;
187 vel[1] = 0; // allow sinking underwater
188 // FIXME: still have z friction underwater?
189 return;
190 }
191
192 drop = 0;
193
194 // apply ground friction
195 if ( pm->waterlevel <= 1 ) {
196 if ( pml.walking && !(pml.groundTrace.surfaceFlags & SURF_SLICK) ) {
197 // if getting knocked back, no friction
198 if ( ! (pm->ps->pm_flags & PMF_TIME_KNOCKBACK) ) {
199 control = speed < pm_stopspeed ? pm_stopspeed : speed;
200 drop += control*pm_friction*pml.frametime;
201 }
202 }
203 }
204
205 // apply water friction even if just wading
206 if ( pm->waterlevel ) {
207 drop += speed*pm_waterfriction*pm->waterlevel*pml.frametime;
208 }
209
210 // apply flying friction
211 if ( pm->ps->powerups[PW_FLIGHT]) {
212 drop += speed*pm_flightfriction*pml.frametime;
213 }
214
215 if ( pm->ps->pm_type == PM_SPECTATOR) {
216 drop += speed*pm_spectatorfriction*pml.frametime;
217 }
218
219 // scale the velocity
220 newspeed = speed - drop;
221 if (newspeed < 0) {
222 newspeed = 0;
223 }
224 newspeed /= speed;
225
226 vel[0] = vel[0] * newspeed;
227 vel[1] = vel[1] * newspeed;
228 vel[2] = vel[2] * newspeed;
229 }
230
231
232 /*
233 ==============
234 PM_Accelerate
235
236 TODO: bunny hoping
237
238 Handles user intended acceleration
239 ==============
240 */
241 static void PM_Accelerate( vec3_t wishdir, float wishspeed, float accel ) {
242 if(! (pm->pmove_flags & DF_NO_BUNNY) ) {
243 //#if 1
244
245 // q2 style
246 int i;
247 float addspeed, accelspeed, currentspeed;
248
249 currentspeed = DotProduct (pm->ps->velocity, wishdir);
250 addspeed = wishspeed - currentspeed;
251 if (addspeed <= 0) {
252 return;
253 }
254 accelspeed = accel*pml.frametime*wishspeed;
255 if (accelspeed > addspeed) {
256 accelspeed = addspeed;
257 }
258
259 for (i=0 ; i<3 ; i++) {
260 pm->ps->velocity[i] += accelspeed*wishdir[i];
261 }
262 } else {
263 //#else
264 // proper way (avoids strafe jump maxspeed bug), but feels bad
265 vec3_t wishVelocity;
266 vec3_t pushDir;
267 float pushLen;
268 float canPush;
269
270 VectorScale( wishdir, wishspeed, wishVelocity );
271 VectorSubtract( wishVelocity, pm->ps->velocity, pushDir );
272 pushLen = VectorNormalize( pushDir );
273
274 canPush = accel*pml.frametime*wishspeed;
275 if (canPush > pushLen) {
276 canPush = pushLen;
277 }
278
279 VectorMA( pm->ps->velocity, canPush, pushDir, pm->ps->velocity );
280 }
281 //#endif
282 }
283
284
285
286 /*
287 ============
288 PM_CmdScale
289
290 Returns the scale factor to apply to cmd movements
291 This allows the clients to use axial -127 to 127 values for all directions
292 without getting a sqrt(2) distortion in speed.
293 ============
294 */
295 static float PM_CmdScale( usercmd_t *cmd ) {
296 int max;
297 float total;
298 float scale;
299
300 max = abs( cmd->forwardmove );
301 if ( abs( cmd->rightmove ) > max ) {
302 max = abs( cmd->rightmove );
303 }
304 if ( abs( cmd->upmove ) > max ) {
305 max = abs( cmd->upmove );
306 }
307 if ( !max ) {
308 return 0;
309 }
310
311 total = sqrt( cmd->forwardmove * cmd->forwardmove
312 + cmd->rightmove * cmd->rightmove + cmd->upmove * cmd->upmove );
313 scale = (float)pm->ps->speed * max / ( 127.0 * total );
314
315 return scale;
316 }
317
318
319 /*
320 ================
321 PM_SetMovementDir
322
323 Determine the rotation of the legs reletive
324 to the facing dir
325 ================
326 */
327 static void PM_SetMovementDir( void ) {
328 if ( pm->cmd.forwardmove || pm->cmd.rightmove ) {
329 if ( pm->cmd.rightmove == 0 && pm->cmd.forwardmove > 0 ) {
330 pm->ps->movementDir = 0;
331 } else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove > 0 ) {
332 pm->ps->movementDir = 1;
333 } else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove == 0 ) {
334 pm->ps->movementDir = 2;
335 } else if ( pm->cmd.rightmove < 0 && pm->cmd.forwardmove < 0 ) {
336 pm->ps->movementDir = 3;
337 } else if ( pm->cmd.rightmove == 0 && pm->cmd.forwardmove < 0 ) {
338 pm->ps->movementDir = 4;
339 } else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove < 0 ) {
340 pm->ps->movementDir = 5;
341 } else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove == 0 ) {
342 pm->ps->movementDir = 6;
343 } else if ( pm->cmd.rightmove > 0 && pm->cmd.forwardmove > 0 ) {
344 pm->ps->movementDir = 7;
345 }
346 } else {
347 // if they aren't actively going directly sideways,
348 // change the animation to the diagonal so they
349 // don't stop too crooked
350 if ( pm->ps->movementDir == 2 ) {
351 pm->ps->movementDir = 1;
352 } else if ( pm->ps->movementDir == 6 ) {
353 pm->ps->movementDir = 7;
354 }
355 }
356 }
357
358
359 /*
360 =============
361 PM_CheckJump
362 =============
363 */
364 static qboolean PM_CheckJump( void ) {
365
366
367 if ( pm->ps->pm_flags & PMF_RESPAWNED ) {
368 return qfalse; // don't allow jump until all buttons are up
369 }
370
371 if ( pm->cmd.upmove < 10 ) {
372 // not holding jump
373 return qfalse;
374 }
375
376
377 // must wait for jump to be released
378 if ( pm->ps->pm_flags & PMF_JUMP_HELD ) {
379 // clear upmove so cmdscale doesn't lower running speed
380 pm->cmd.upmove = 0;
381 return qfalse;
382 }
383
384
385
386
387 pml.groundPlane = qfalse; // jumping away
388 pml.walking = qfalse;
389 pm->ps->pm_flags |= PMF_JUMP_HELD;
390
391 pm->ps->groundEntityNum = ENTITYNUM_NONE;
392 pm->ps->velocity[2] = JUMP_VELOCITY;
393 PM_AddEvent( EV_JUMP );
394
395 if ( pm->cmd.forwardmove >= 0 ) {
396 PM_ForceLegsAnim( LEGS_JUMP );
397 pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
398 } else {
399 PM_ForceLegsAnim( LEGS_JUMPB );
400 pm->ps->pm_flags |= PMF_BACKWARDS_JUMP;
401 }
402
403 return qtrue;
404 }
405
406 /*
407 =============
408 PM_CheckWaterJump
409 =============
410 */
411 static qboolean PM_CheckWaterJump( void ) {
412 vec3_t spot;
413 int cont;
414 vec3_t flatforward;
415
416 if (pm->ps->pm_time) {
417 return qfalse;
418 }
419
420 // check for water jump
421 if ( pm->waterlevel != 2 ) {
422 return qfalse;
423 }
424
425 flatforward[0] = pml.forward[0];
426 flatforward[1] = pml.forward[1];
427 flatforward[2] = 0;
428 VectorNormalize (flatforward);
429
430 VectorMA (pm->ps->origin, 30, flatforward, spot);
431 spot[2] += 4;
432 cont = pm->pointcontents (spot, pm->ps->clientNum );
433 if ( !(cont & CONTENTS_SOLID) ) {
434 return qfalse;
435 }
436
437 spot[2] += 16;
438 cont = pm->pointcontents (spot, pm->ps->clientNum );
439 if ( cont & (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_BODY) ) {
440 return qfalse;
441 }
442
443 // jump out of water
444 VectorScale (pml.forward, 200, pm->ps->velocity);
445 pm->ps->velocity[2] = 350;
446
447 pm->ps->pm_flags |= PMF_TIME_WATERJUMP;
448 pm->ps->pm_time = 2000;
449
450 return qtrue;
451 }
452
453 //============================================================================
454
455
456 /*
457 ===================
458 PM_WaterJumpMove
459
460 Flying out of the water
461 ===================
462 */
463 static void PM_WaterJumpMove( void ) {
464 // waterjump has no control, but falls
465
466 PM_StepSlideMove( qtrue );
467
468 pm->ps->velocity[2] -= pm->ps->gravity * pml.frametime;
469 if (pm->ps->velocity[2] < 0) {
470 // cancel as soon as we are falling down again
471 pm->ps->pm_flags &= ~PMF_ALL_TIMES;
472 pm->ps->pm_time = 0;
473 }
474 }
475
476 /*
477 ===================
478 PM_WaterMove
479
480 ===================
481 */
482 static void PM_WaterMove( void ) {
483 int i;
484 vec3_t wishvel;
485 float wishspeed;
486 vec3_t wishdir;
487 float scale;
488 float vel;
489
490 if ( PM_CheckWaterJump() ) {
491 PM_WaterJumpMove();
492 return;
493 }
494 #if 0
495 // jump = head for surface
496 if ( pm->cmd.upmove >= 10 ) {
497 if (pm->ps->velocity[2] > -300) {
498 if ( pm->watertype == CONTENTS_WATER ) {
499 pm->ps->velocity[2] = 100;
500 } else if (pm->watertype == CONTENTS_SLIME) {
501 pm->ps->velocity[2] = 80;
502 } else {
503 pm->ps->velocity[2] = 50;
504 }
505 }
506 }
507 #endif
508 PM_Friction ();
509
510 scale = PM_CmdScale( &pm->cmd );
511 //
512 // user intentions
513 //
514 if ( !scale ) {
515 wishvel[0] = 0;
516 wishvel[1] = 0;
517 wishvel[2] = -60; // sink towards bottom
518 } else {
519 for (i=0 ; i<3 ; i++)
520 wishvel[i] = scale * pml.forward[i]*pm->cmd.forwardmove + scale * pml.right[i]*pm->cmd.rightmove;
521
522 wishvel[2] += scale * pm->cmd.upmove;
523 }
524
525 VectorCopy (wishvel, wishdir);
526 wishspeed = VectorNormalize(wishdir);
527
528 if ( wishspeed > pm->ps->speed * pm_swimScale ) {
529 wishspeed = pm->ps->speed * pm_swimScale;
530 }
531
532 PM_Accelerate (wishdir, wishspeed, pm_wateraccelerate);
533
534 // make sure we can go up slopes easily under water
535 if ( pml.groundPlane && DotProduct( pm->ps->velocity, pml.groundTrace.plane.normal ) < 0 ) {
536 vel = VectorLength(pm->ps->velocity);
537 // slide along the ground plane
538 PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal,
539 pm->ps->velocity, OVERCLIP );
540
541 VectorNormalize(pm->ps->velocity);
542 VectorScale(pm->ps->velocity, vel, pm->ps->velocity);
543 }
544
545 PM_SlideMove( qfalse );
546 }
547
548 /*
549 ===================
550 PM_InvulnerabilityMove
551
552 Only with the invulnerability powerup
553 ===================
554 */
555 static void PM_InvulnerabilityMove( void ) {
556 pm->cmd.forwardmove = 0;
557 pm->cmd.rightmove = 0;
558 pm->cmd.upmove = 0;
559 VectorClear(pm->ps->velocity);
560 }
561
562 /*
563 ===================
564 PM_FlyMove
565
566 Only with the flight powerup
567 ===================
568 */
569 static void PM_FlyMove( void ) {
570 int i;
571 vec3_t wishvel;
572 float wishspeed;
573 vec3_t wishdir;
574 float scale;
575
576 // normal slowdown
577 PM_Friction ();
578
579 scale = PM_CmdScale( &pm->cmd );
580 //
581 // user intentions
582 //
583 if ( !scale ) {
584 wishvel[0] = 0;
585 wishvel[1] = 0;
586 wishvel[2] = 0;
587 } else {
588 for (i=0 ; i<3 ; i++) {
589 wishvel[i] = scale * pml.forward[i]*pm->cmd.forwardmove + scale * pml.right[i]*pm->cmd.rightmove;
590 }
591
592 wishvel[2] += scale * pm->cmd.upmove;
593 }
594
595 VectorCopy (wishvel, wishdir);
596 wishspeed = VectorNormalize(wishdir);
597
598 PM_Accelerate (wishdir, wishspeed, pm_flyaccelerate);
599
600 PM_StepSlideMove( qfalse );
601 }
602
603
604 /*
605 ===================
606 PM_AirMove
607
608 ===================
609 */
610 static void PM_AirMove( void ) {
611 int i;
612 vec3_t wishvel;
613 float fmove, smove;
614 vec3_t wishdir;
615 float wishspeed;
616 float scale;
617 usercmd_t cmd;
618
619 PM_Friction();
620
621 fmove = pm->cmd.forwardmove;
622 smove = pm->cmd.rightmove;
623
624 cmd = pm->cmd;
625 scale = PM_CmdScale( &cmd );
626
627 // set the movementDir so clients can rotate the legs for strafing
628 PM_SetMovementDir();
629
630 // project moves down to flat plane
631 pml.forward[2] = 0;
632 pml.right[2] = 0;
633 VectorNormalize (pml.forward);
634 VectorNormalize (pml.right);
635
636 for ( i = 0 ; i < 2 ; i++ ) {
637 wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove;
638 }
639 wishvel[2] = 0;
640
641 VectorCopy (wishvel, wishdir);
642 wishspeed = VectorNormalize(wishdir);
643 wishspeed *= scale;
644
645 // not on ground, so little effect on velocity
646 PM_Accelerate (wishdir, wishspeed, pm_airaccelerate);
647
648 // we may have a ground plane that is very steep, even
649 // though we don't have a groundentity
650 // slide along the steep plane
651 if ( pml.groundPlane ) {
652 PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal,
653 pm->ps->velocity, OVERCLIP );
654 }
655
656 #if 0
657 //ZOID: If we are on the grapple, try stair-stepping
658 //this allows a player to use the grapple to pull himself
659 //over a ledge
660 if (pm->ps->pm_flags & PMF_GRAPPLE_PULL)
661 PM_StepSlideMove ( qtrue );
662 else
663 PM_SlideMove ( qtrue );
664 #endif
665
666 PM_StepSlideMove ( qtrue );
667 }
668
669 /*
670 ===================
671 PM_GrappleMove
672
673 ===================
674 */
675 static void PM_GrappleMove( void ) {
676 vec3_t vel, v;
677 float vlen;
678
679 VectorScale(pml.forward, -16, v);
680 VectorAdd(pm->ps->grapplePoint, v, v);
681 VectorSubtract(v, pm->ps->origin, vel);
682 vlen = VectorLength(vel);
683 VectorNormalize( vel );
684
685 if (vlen <= 100)
686 VectorScale(vel, 10 * vlen, vel);
687 else
688 VectorScale(vel, 800, vel);
689
690 VectorCopy(vel, pm->ps->velocity);
691
692 pml.groundPlane = qfalse;
693 }
694
695 /*
696 ===================
697 PM_WalkMove
698
699 ===================
700 */
701 static void PM_WalkMove( void ) {
702 int i;
703 vec3_t wishvel;
704 float fmove, smove;
705 vec3_t wishdir;
706 float wishspeed;
707 float scale;
708 usercmd_t cmd;
709 float accelerate;
710 float vel;
711
712 if ( pm->waterlevel > 2 && DotProduct( pml.forward, pml.groundTrace.plane.normal ) > 0 ) {
713 // begin swimming
714 PM_WaterMove();
715 return;
716 }
717
718
719 if ( PM_CheckJump () ) {
720 // jumped away
721 if ( pm->waterlevel > 1 ) {
722 PM_WaterMove();
723 } else {
724 PM_AirMove();
725 }
726 return;
727 }
728
729 PM_Friction ();
730
731 fmove = pm->cmd.forwardmove;
732 smove = pm->cmd.rightmove;
733
734 cmd = pm->cmd;
735 scale = PM_CmdScale( &cmd );
736
737 // set the movementDir so clients can rotate the legs for strafing
738 PM_SetMovementDir();
739
740 // project moves down to flat plane
741 pml.forward[2] = 0;
742 pml.right[2] = 0;
743
744 // project the forward and right directions onto the ground plane
745 PM_ClipVelocity (pml.forward, pml.groundTrace.plane.normal, pml.forward, OVERCLIP );
746 PM_ClipVelocity (pml.right, pml.groundTrace.plane.normal, pml.right, OVERCLIP );
747 //
748 VectorNormalize (pml.forward);
749 VectorNormalize (pml.right);
750
751 for ( i = 0 ; i < 3 ; i++ ) {
752 wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove;
753 }
754 // when going up or down slopes the wish velocity should Not be zero
755 // wishvel[2] = 0;
756
757 VectorCopy (wishvel, wishdir);
758 wishspeed = VectorNormalize(wishdir);
759 wishspeed *= scale;
760
761 // clamp the speed lower if ducking
762 if ( pm->ps->pm_flags & PMF_DUCKED ) {
763 if ( wishspeed > pm->ps->speed * pm_duckScale ) {
764 wishspeed = pm->ps->speed * pm_duckScale;
765 }
766 }
767
768 // clamp the speed lower if wading or walking on the bottom
769 if ( pm->waterlevel ) {
770 float waterScale;
771
772 waterScale = pm->waterlevel / 3.0;
773 waterScale = 1.0 - ( 1.0 - pm_swimScale ) * waterScale;
774 if ( wishspeed > pm->ps->speed * waterScale ) {
775 wishspeed = pm->ps->speed * waterScale;
776 }
777 }
778
779 // when a player gets hit, they temporarily lose
780 // full control, which allows them to be moved a bit
781 if ( ( pml.groundTrace.surfaceFlags & SURF_SLICK ) || pm->ps->pm_flags & PMF_TIME_KNOCKBACK ) {
782 accelerate = pm_airaccelerate;
783 } else {
784 accelerate = pm_accelerate;
785 }
786
787 PM_Accelerate (wishdir, wishspeed, accelerate);
788
789 //Com_Printf("velocity = %1.1f %1.1f %1.1f\n", pm->ps->velocity[0], pm->ps->velocity[1], pm->ps->velocity[2]);
790 //Com_Printf("velocity1 = %1.1f\n", VectorLength(pm->ps->velocity));
791
792 if ( ( pml.groundTrace.surfaceFlags & SURF_SLICK ) || pm->ps->pm_flags & PMF_TIME_KNOCKBACK ) {
793 pm->ps->velocity[2] -= pm->ps->gravity * pml.frametime;
794 } else {
795 // don't reset the z velocity for slopes
796 // pm->ps->velocity[2] = 0;
797 }
798
799 vel = VectorLength(pm->ps->velocity);
800
801 // slide along the ground plane
802 PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal,
803 pm->ps->velocity, OVERCLIP );
804
805 // don't decrease velocity when going up or down a slope
806 VectorNormalize(pm->ps->velocity);
807 VectorScale(pm->ps->velocity, vel, pm->ps->velocity);
808
809 // don't do anything if standing still
810 if (!pm->ps->velocity[0] && !pm->ps->velocity[1]) {
811 return;
812 }
813
814 PM_StepSlideMove( qfalse );
815
816 //Com_Printf("velocity2 = %1.1f\n", VectorLength(pm->ps->velocity));
817
818 }
819
820
821 /*
822 ==============
823 PM_DeadMove
824 ==============
825 */
826 static void PM_DeadMove( void ) {
827 float forward;
828
829 if ( !pml.walking ) {
830 return;
831 }
832
833 // extra friction
834
835 forward = VectorLength (pm->ps->velocity);
836 forward -= 20;
837 if ( forward <= 0 ) {
838 VectorClear (pm->ps->velocity);
839 } else {
840 VectorNormalize (pm->ps->velocity);
841 VectorScale (pm->ps->velocity, forward, pm->ps->velocity);
842 }
843 }
844
845
846 /*
847 ===============
848 PM_NoclipMove
849 ===============
850 */
851 static void PM_NoclipMove( void ) {
852 float speed, drop, friction, control, newspeed;
853 int i;
854 vec3_t wishvel;
855 float fmove, smove;
856 vec3_t wishdir;
857 float wishspeed;
858 float scale;
859
860 pm->ps->viewheight = DEFAULT_VIEWHEIGHT;
861
862 // friction
863
864 speed = VectorLength (pm->ps->velocity);
865 if (speed < 1)
866 {
867 VectorCopy (vec3_origin, pm->ps->velocity);
868 }
869 else
870 {
871 drop = 0;
872
873 friction = pm_friction*1.5; // extra friction
874 control = speed < pm_stopspeed ? pm_stopspeed : speed;
875 drop += control*friction*pml.frametime;
876
877 // scale the velocity
878 newspeed = speed - drop;
879 if (newspeed < 0)
880 newspeed = 0;
881 newspeed /= speed;
882
883 VectorScale (pm->ps->velocity, newspeed, pm->ps->velocity);
884 }
885
886 // accelerate
887 scale = PM_CmdScale( &pm->cmd );
888
889 fmove = pm->cmd.forwardmove;
890 smove = pm->cmd.rightmove;
891
892 for (i=0 ; i<3 ; i++)
893 wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove;
894 wishvel[2] += pm->cmd.upmove;
895
896 VectorCopy (wishvel, wishdir);
897 wishspeed = VectorNormalize(wishdir);
898 wishspeed *= scale;
899
900 PM_Accelerate( wishdir, wishspeed, pm_accelerate );
901
902 // move
903 VectorMA (pm->ps->origin, pml.frametime, pm->ps->velocity, pm->ps->origin);
904 }
905
906 //============================================================================
907
908 /*
909 ================
910 PM_FootstepForSurface
911
912 Returns an event number apropriate for the groundsurface
913 ================
914 */
915 static int PM_FootstepForSurface( void ) {
916 if ( pml.groundTrace.surfaceFlags & SURF_NOSTEPS ) {
917 return 0;
918 }
919 if ( pml.groundTrace.surfaceFlags & SURF_METALSTEPS ) {
920 return EV_FOOTSTEP_METAL;
921 }
922 return EV_FOOTSTEP;
923 }
924
925
926 /*
927 =================
928 PM_CrashLand
929
930 Check for hard landings that generate sound events
931 =================
932 */
933 static void PM_CrashLand( void ) {
934 float delta;
935 float dist;
936 float vel, acc;
937 float t;
938 float a, b, c, den;
939
940 // decide which landing animation to use
941 if ( pm->ps->pm_flags & PMF_BACKWARDS_JUMP ) {
942 PM_ForceLegsAnim( LEGS_LANDB );
943 } else {
944 PM_ForceLegsAnim( LEGS_LAND );
945 }
946
947 pm->ps->legsTimer = TIMER_LAND;
948
949 // calculate the exact velocity on landing
950 dist = pm->ps->origin[2] - pml.previous_origin[2];
951 vel = pml.previous_velocity[2];
952 acc = -pm->ps->gravity;
953
954 a = acc / 2;
955 b = vel;
956 c = -dist;
957
958 den = b * b - 4 * a * c;
959 if ( den < 0 ) {
960 return;
961 }
962 t = (-b - sqrt( den ) ) / ( 2 * a );
963
964 delta = vel + t * acc;
965 delta = delta*delta * 0.0001;
966
967 // ducking while falling doubles damage
968 if ( pm->ps->pm_flags & PMF_DUCKED ) {
969 delta *= 2;
970 }
971
972 // never take falling damage if completely underwater
973 if ( pm->waterlevel == 3 ) {
974 return;
975 }
976
977 // reduce falling damage if there is standing water
978 if ( pm->waterlevel == 2 ) {
979 delta *= 0.25;
980 }
981 if ( pm->waterlevel == 1 ) {
982 delta *= 0.5;
983 }
984
985 if ( delta < 1 ) {
986 return;
987 }
988
989 // create a local entity event to play the sound
990
991 // SURF_NODAMAGE is used for bounce pads where you don't ever
992 // want to take damage or play a crunch sound
993 if ( !(pml.groundTrace.surfaceFlags & SURF_NODAMAGE) ) {
994 if ( delta > 60 ) {
995 PM_AddEvent( EV_FALL_FAR );
996 } else if ( delta > 40 ) {
997 // this is a pain grunt, so don't play it if dead
998 if ( pm->ps->stats[STAT_HEALTH] > 0 ) {
999 PM_AddEvent( EV_FALL_MEDIUM );
1000 }
1001 } else if ( delta > 7 ) {
1002 PM_AddEvent( EV_FALL_SHORT );
1003 } else {
1004 PM_AddEvent( PM_FootstepForSurface() );
1005 }
1006 }
1007
1008 // start footstep cycle over
1009 pm->ps->bobCycle = 0;
1010 }
1011
1012 /*
1013 =============
1014 PM_CheckStuck
1015 =============
1016 */
1017 /*
1018 void PM_CheckStuck(void) {
1019 trace_t trace;
1020
1021 pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, pm->ps->origin, pm->ps->clientNum, pm->tracemask);
1022 if (trace.allsolid) {
1023 //int shit = qtrue;
1024 }
1025 }
1026 */
1027
1028 /*
1029 =============
1030 PM_CorrectAllSolid
1031 =============
1032 */
1033 static int PM_CorrectAllSolid( trace_t *trace ) {
1034 int i, j, k;
1035 vec3_t point;
1036
1037 if ( pm->debugLevel ) {
1038 Com_Printf("%i:allsolid\n", c_pmove);
1039 }
1040
1041 // jitter around
1042 for (i = -1; i <= 1; i++) {
1043 for (j = -1; j <= 1; j++) {
1044 for (k = -1; k <= 1; k++) {
1045 VectorCopy(pm->ps->origin, point);
1046 point[0] += (float) i;
1047 point[1] += (float) j;
1048 point[2] += (float) k;
1049 pm->trace (trace, point, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
1050 if ( !trace->allsolid ) {
1051 point[0] = pm->ps->origin[0];
1052 point[1] = pm->ps->origin[1];
1053 point[2] = pm->ps->origin[2] - 0.25;
1054
1055 pm->trace (trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
1056 pml.groundTrace = *trace;
1057 return qtrue;
1058 }
1059 }
1060 }
1061 }
1062
1063 pm->ps->groundEntityNum = ENTITYNUM_NONE;
1064 pml.groundPlane = qfalse;
1065 pml.walking = qfalse;
1066
1067 return qfalse;
1068 }
1069
1070
1071 /*
1072 =============
1073 PM_GroundTraceMissed
1074
1075 The ground trace didn't hit a surface, so we are in freefall
1076 =============
1077 */
1078 static void PM_GroundTraceMissed( void ) {
1079 trace_t trace;
1080 vec3_t point;
1081
1082 if ( pm->ps->groundEntityNum != ENTITYNUM_NONE ) {
1083 // we just transitioned into freefall
1084 if ( pm->debugLevel ) {
1085 Com_Printf("%i:lift\n", c_pmove);
1086 }
1087
1088 // if they aren't in a jumping animation and the ground is a ways away, force into it
1089 // if we didn't do the trace, the player would be backflipping down staircases
1090 VectorCopy( pm->ps->origin, point );
1091 point[2] -= 64;
1092
1093 pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
1094 if ( trace.fraction == 1.0 ) {
1095 if ( pm->cmd.forwardmove >= 0 ) {
1096 PM_ForceLegsAnim( LEGS_JUMP );
1097 pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
1098 } else {
1099 PM_ForceLegsAnim( LEGS_JUMPB );
1100 pm->ps->pm_flags |= PMF_BACKWARDS_JUMP;
1101 }
1102 }
1103 }
1104
1105 pm->ps->groundEntityNum = ENTITYNUM_NONE;
1106 pml.groundPlane = qfalse;
1107 pml.walking = qfalse;
1108 }
1109
1110
1111 /*
1112 =============
1113 PM_GroundTrace
1114 =============
1115 */
1116 static void PM_GroundTrace( void ) {
1117 vec3_t point;
1118 trace_t trace;
1119
1120 point[0] = pm->ps->origin[0];
1121 point[1] = pm->ps->origin[1];
1122 point[2] = pm->ps->origin[2] - 0.25;
1123
1124 pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
1125 pml.groundTrace = trace;
1126
1127 // do something corrective if the trace starts in a solid...
1128 if ( trace.allsolid ) {
1129 if ( !PM_CorrectAllSolid(&trace) )
1130 return;
1131 }
1132
1133 // if the trace didn't hit anything, we are in free fall
1134 if ( trace.fraction == 1.0 ) {
1135 PM_GroundTraceMissed();
1136 pml.groundPlane = qfalse;
1137 pml.walking = qfalse;
1138 return;
1139 }
1140
1141 // check if getting thrown off the ground
1142 if ( pm->ps->velocity[2] > 0 && DotProduct( pm->ps->velocity, trace.plane.normal ) > 10 ) {
1143 if ( pm->debugLevel ) {
1144 Com_Printf("%i:kickoff\n", c_pmove);
1145 }
1146 // go into jump animation
1147 if ( pm->cmd.forwardmove >= 0 ) {
1148 PM_ForceLegsAnim( LEGS_JUMP );
1149 pm->ps->pm_flags &= ~PMF_BACKWARDS_JUMP;
1150 } else {
1151 PM_ForceLegsAnim( LEGS_JUMPB );
1152 pm->ps->pm_flags |= PMF_BACKWARDS_JUMP;
1153 }
1154
1155 pm->ps->groundEntityNum = ENTITYNUM_NONE;
1156 pml.groundPlane = qfalse;
1157 pml.walking = qfalse;
1158 return;
1159 }
1160
1161 // slopes that are too steep will not be considered onground
1162 if ( trace.plane.normal[2] < MIN_WALK_NORMAL ) {
1163 if ( pm->debugLevel ) {
1164 Com_Printf("%i:steep\n", c_pmove);
1165 }
1166 // FIXME: if they can't slide down the slope, let them
1167 // walk (sharp crevices)
1168 pm->ps->groundEntityNum = ENTITYNUM_NONE;
1169 pml.groundPlane = qtrue;
1170 pml.walking = qfalse;
1171 return;
1172 }
1173
1174 pml.groundPlane = qtrue;
1175 pml.walking = qtrue;
1176
1177 // hitting solid ground will end a waterjump
1178 if (pm->ps->pm_flags & PMF_TIME_WATERJUMP)
1179 {
1180 pm->ps->pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND);
1181 pm->ps->pm_time = 0;
1182 }
1183
1184 if ( pm->ps->groundEntityNum == ENTITYNUM_NONE ) {
1185 // just hit the ground
1186 if ( pm->debugLevel ) {
1187 Com_Printf("%i:Land\n", c_pmove);
1188 }
1189
1190 PM_CrashLand();
1191
1192 // don't do landing time if we were just going down a slope
1193 if ( pml.previous_velocity[2] < -200 ) {
1194 // don't allow another jump for a little while
1195 pm->ps->pm_flags |= PMF_TIME_LAND;
1196 pm->ps->pm_time = 250;
1197 }
1198 }
1199
1200 pm->ps->groundEntityNum = trace.entityNum;
1201
1202 // don't reset the z velocity for slopes
1203 // pm->ps->velocity[2] = 0;
1204
1205 PM_AddTouchEnt( trace.entityNum );
1206 }
1207
1208
1209 /*
1210 =============
1211 PM_SetWaterLevel FIXME: avoid this twice? certainly if not moving
1212 =============
1213 */
1214 static void PM_SetWaterLevel( void ) {
1215 vec3_t point;
1216 int cont;
1217 int sample1;
1218 int sample2;
1219
1220 //
1221 // get waterlevel, accounting for ducking
1222 //
1223 pm->waterlevel = 0;
1224 pm->watertype = 0;
1225
1226 point[0] = pm->ps->origin[0];
1227 point[1] = pm->ps->origin[1];
1228 point[2] = pm->ps->origin[2] + MINS_Z + 1;
1229 cont = pm->pointcontents( point, pm->ps->clientNum );
1230
1231 if ( cont & MASK_WATER ) {
1232 sample2 = pm->ps->viewheight - MINS_Z;
1233 sample1 = sample2 / 2;
1234
1235 pm->watertype = cont;
1236 pm->waterlevel = 1;
1237 point[2] = pm->ps->origin[2] + MINS_Z + sample1;
1238 cont = pm->pointcontents (point, pm->ps->clientNum );
1239 if ( cont & MASK_WATER ) {
1240 pm->waterlevel = 2;
1241 point[2] = pm->ps->origin[2] + MINS_Z + sample2;
1242 cont = pm->pointcontents (point, pm->ps->clientNum );
1243 if ( cont & MASK_WATER ){
1244 pm->waterlevel = 3;
1245 }
1246 }
1247 }
1248
1249 }
1250
1251 /*
1252 ==============
1253 PM_CheckDuck
1254
1255 Sets mins, maxs, and pm->ps->viewheight
1256 ==============
1257 */
1258 static void PM_CheckDuck (void)
1259 {
1260 trace_t trace;
1261
1262 if ( pm->ps->powerups[PW_INVULNERABILITY] ) {
1263 if ( pm->ps->pm_flags & PMF_INVULEXPAND ) {
1264 // invulnerability sphere has a 42 units radius
1265 VectorSet( pm->mins, -42, -42, -42 );
1266 VectorSet( pm->maxs, 42, 42, 42 );
1267 }
1268 else {
1269 VectorSet( pm->mins, -15, -15, MINS_Z );
1270 VectorSet( pm->maxs, 15, 15, 16 );
1271 }
1272 pm->ps->pm_flags |= PMF_DUCKED;
1273 pm->ps->viewheight = CROUCH_VIEWHEIGHT;
1274 return;
1275 }
1276 pm->ps->pm_flags &= ~PMF_INVULEXPAND;
1277
1278 pm->mins[0] = -15;
1279 pm->mins[1] = -15;
1280
1281 pm->maxs[0] = 15;
1282 pm->maxs[1] = 15;
1283
1284 pm->mins[2] = MINS_Z;
1285
1286 if (pm->ps->pm_type == PM_DEAD)
1287 {
1288 pm->maxs[2] = -8;
1289 pm->ps->viewheight = DEAD_VIEWHEIGHT;
1290 return;
1291 }
1292
1293 if (pm->cmd.upmove < 0)
1294 { // duck
1295 pm->ps->pm_flags |= PMF_DUCKED;
1296 }
1297 else
1298 { // stand up if possible
1299 if (pm->ps->pm_flags & PMF_DUCKED)
1300 {
1301 // try to stand up
1302 pm->maxs[2] = 32;
1303 pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, pm->ps->origin, pm->ps->clientNum, pm->tracemask );
1304 if (!trace.allsolid)
1305 pm->ps->pm_flags &= ~PMF_DUCKED;
1306 }
1307 }
1308
1309 if (pm->ps->pm_flags & PMF_DUCKED)
1310 {
1311 pm->maxs[2] = 16;
1312 pm->ps->viewheight = CROUCH_VIEWHEIGHT;
1313 }
1314 else
1315 {
1316 pm->maxs[2] = 32;
1317 pm->ps->viewheight = DEFAULT_VIEWHEIGHT;
1318 }
1319 }
1320
1321
1322
1323 //===================================================================
1324
1325
1326 /*
1327 ===============
1328 PM_Footsteps
1329 ===============
1330 */
1331 static void PM_Footsteps( void ) {
1332 float bobmove;
1333 int old;
1334 qboolean footstep;
1335
1336 //
1337 // calculate speed and cycle to be used for
1338 // all cyclic walking effects
1339 //
1340 pm->xyspeed = sqrt( pm->ps->velocity[0] * pm->ps->velocity[0]
1341 + pm->ps->velocity[1] * pm->ps->velocity[1] );
1342
1343 if ( pm->ps->groundEntityNum == ENTITYNUM_NONE ) {
1344
1345 if ( pm->ps->powerups[PW_INVULNERABILITY] ) {
1346 PM_ContinueLegsAnim( LEGS_IDLECR );
1347 }
1348 // airborne leaves position in cycle intact, but doesn't advance
1349 if ( pm->waterlevel > 1 ) {
1350 PM_ContinueLegsAnim( LEGS_SWIM );
1351 }
1352 return;
1353 }
1354
1355 // if not trying to move
1356 if ( !pm->cmd.forwardmove && !pm->cmd.rightmove ) {
1357 if ( pm->xyspeed < 5 ) {
1358 pm->ps->bobCycle = 0; // start at beginning of cycle again
1359 if ( pm->ps->pm_flags & PMF_DUCKED ) {
1360 PM_ContinueLegsAnim( LEGS_IDLECR );
1361 } else {
1362 PM_ContinueLegsAnim( LEGS_IDLE );
1363 }
1364 }
1365 return;
1366 }
1367
1368
1369 footstep = qfalse;
1370
1371 if ( pm->ps->pm_flags & PMF_DUCKED ) {
1372 bobmove = 0.5; // ducked characters bob much faster
1373 if ( pm->ps->pm_flags & PMF_BACKWARDS_RUN ) {
1374 PM_ContinueLegsAnim( LEGS_BACKCR );
1375 }
1376 else {
1377 PM_ContinueLegsAnim( LEGS_WALKCR );
1378 }
1379 // ducked characters never play footsteps
1380 /*
1381 } else if ( pm->ps->pm_flags & PMF_BACKWARDS_RUN ) {
1382 if ( !( pm->cmd.buttons & BUTTON_WALKING ) ) {
1383 bobmove = 0.4; // faster speeds bob faster
1384 footstep = qtrue;
1385 } else {
1386 bobmove = 0.3;
1387 }
1388 PM_ContinueLegsAnim( LEGS_BACK );
1389 */
1390 } else {
1391 if ( !( pm->cmd.buttons & BUTTON_WALKING ) ) {
1392 bobmove = 0.4f; // faster speeds bob faster
1393 if ( pm->ps->pm_flags & PMF_BACKWARDS_RUN ) {
1394 PM_ContinueLegsAnim( LEGS_BACK );
1395 }
1396 else {
1397 PM_ContinueLegsAnim( LEGS_RUN );
1398 }
1399 footstep = qtrue;
1400 } else {
1401 bobmove = 0.3f; // walking bobs slow
1402 if ( pm->ps->pm_flags & PMF_BACKWARDS_RUN ) {
1403 PM_ContinueLegsAnim( LEGS_BACKWALK );
1404 }
1405 else {
1406 PM_ContinueLegsAnim( LEGS_WALK );
1407 }
1408 }
1409 }
1410
1411 // check for footstep / splash sounds
1412 old = pm->ps->bobCycle;
1413 pm->ps->bobCycle = (int)( old + bobmove * pml.msec ) & 255;
1414
1415 // if we just crossed a cycle boundary, play an apropriate footstep event
1416 if ( ( ( old + 64 ) ^ ( pm->ps->bobCycle + 64 ) ) & 128 ) {
1417 if ( pm->waterlevel == 0 ) {
1418 // on ground will only play sounds if running
1419 if ( footstep && !pm->noFootsteps ) {
1420 PM_AddEvent( PM_FootstepForSurface() );
1421 }
1422 } else if ( pm->waterlevel == 1 ) {
1423 // splashing
1424 PM_AddEvent( EV_FOOTSPLASH );
1425 } else if ( pm->waterlevel == 2 ) {
1426 // wading / swimming at surface
1427 PM_AddEvent( EV_SWIM );
1428 } else if ( pm->waterlevel == 3 ) {
1429 // no sound when completely underwater
1430
1431 }
1432 }
1433 }
1434
1435 /*
1436 ==============
1437 PM_WaterEvents
1438
1439 Generate sound events for entering and leaving water
1440 ==============
1441 */
1442 static void PM_WaterEvents( void ) { // FIXME?
1443 //
1444 // if just entered a water volume, play a sound
1445 //
1446 if (!pml.previous_waterlevel && pm->waterlevel) {
1447 PM_AddEvent( EV_WATER_TOUCH );
1448 }
1449
1450 //
1451 // if just completely exited a water volume, play a sound
1452 //
1453 if (pml.previous_waterlevel && !pm->waterlevel) {
1454 PM_AddEvent( EV_WATER_LEAVE );
1455 }
1456
1457 //
1458 // check for head just going under water
1459 //
1460 if (pml.previous_waterlevel != 3 && pm->waterlevel == 3) {
1461 PM_AddEvent( EV_WATER_UNDER );
1462 }
1463
1464 //
1465 // check for head just coming out of water
1466 //
1467 if (pml.previous_waterlevel == 3 && pm->waterlevel != 3) {
1468 PM_AddEvent( EV_WATER_CLEAR );
1469 }
1470 }
1471
1472
1473 /*
1474 ===============
1475 PM_BeginWeaponChange
1476 ===============
1477 */
1478 static void PM_BeginWeaponChange( int weapon ) {
1479 if ( weapon <= WP_NONE || weapon >= WP_NUM_WEAPONS ) {
1480 return;
1481 }
1482
1483 if ( !( pm->ps->stats[STAT_WEAPONS] & ( 1 << weapon ) ) ) {
1484 return;
1485 }
1486
1487 if ( pm->ps->weaponstate == WEAPON_DROPPING ) {
1488 return;
1489 }
1490
1491 if(pm->pmove_flags & DF_INSTANT_WEAPON_CHANGE)
1492 {
1493 pm->ps->weaponstate = WEAPON_DROPPING;
1494 } else
1495 {
1496 PM_AddEvent( EV_CHANGE_WEAPON );
1497 pm->ps->weaponstate = WEAPON_DROPPING;
1498 pm->ps->weaponTime += 200;
1499 PM_StartTorsoAnim( TORSO_DROP );
1500 }
1501 }
1502
1503
1504 /*
1505 ===============
1506 PM_FinishWeaponChange
1507 ===============
1508 */
1509 static void PM_FinishWeaponChange( void ) {
1510 int weapon;
1511
1512 weapon = pm->cmd.weapon;
1513 if ( weapon < WP_NONE || weapon >= WP_NUM_WEAPONS ) {
1514 weapon = WP_NONE;
1515 }
1516
1517 if ( !( pm->ps->stats[STAT_WEAPONS] & ( 1 << weapon ) ) ) {
1518 weapon = WP_NONE;
1519 }
1520
1521 pm->ps->weapon = weapon;
1522 pm->ps->weaponstate = WEAPON_RAISING;
1523 if(! (pm->pmove_flags & DF_INSTANT_WEAPON_CHANGE))
1524 {
1525 pm->ps->weaponTime += 250;
1526 PM_StartTorsoAnim( TORSO_RAISE );
1527 }
1528 }
1529
1530
1531 /*
1532 ==============
1533 PM_TorsoAnimation
1534
1535 ==============
1536 */
1537 static void PM_TorsoAnimation( void ) {
1538 if ( pm->ps->weaponstate == WEAPON_READY ) {
1539 if ( pm->ps->weapon == WP_GAUNTLET ) {
1540 PM_ContinueTorsoAnim( TORSO_STAND2 );
1541 } else {
1542 PM_ContinueTorsoAnim( TORSO_STAND );
1543 }
1544 return;
1545 }
1546 }
1547
1548
1549 /*
1550 ==============
1551 PM_Weapon
1552
1553 Generates weapon events and modifes the weapon counter
1554
1555 Elimination TODO:
1556 Make this thing stop during warmup (done)
1557 ==============
1558 */
1559 static void PM_Weapon( void ) {
1560 int addTime;
1561
1562 // don't allow attack until all buttons are up
1563 if ( pm->ps->pm_flags & PMF_RESPAWNED ) {
1564 return;
1565 }
1566
1567 // ignore if spectator
1568 if ( pm->ps->persistant[PERS_TEAM] == TEAM_SPECTATOR || pm->ps->pm_type == PM_SPECTATOR) {
1569 return;
1570 }
1571
1572 // check for dead player
1573 if ( pm->ps->stats[STAT_HEALTH] <= 0 ) {
1574 pm->ps->weapon = WP_NONE;
1575 return;
1576 }
1577
1578 // check for item using
1579 if ( pm->cmd.buttons & BUTTON_USE_HOLDABLE ) {
1580 if ( ! ( pm->ps->pm_flags & PMF_USE_ITEM_HELD ) ) {
1581 if ( bg_itemlist[pm->ps->stats[STAT_HOLDABLE_ITEM]].giTag == HI_MEDKIT
1582 && pm->ps->stats[STAT_HEALTH] >= (pm->ps->stats[STAT_MAX_HEALTH] + 25) ) {
1583 // don't use medkit if at max health
1584 } else {
1585 pm->ps->pm_flags |= PMF_USE_ITEM_HELD;
1586 PM_AddEvent( EV_USE_ITEM0 + bg_itemlist[pm->ps->stats[STAT_HOLDABLE_ITEM]].giTag );
1587 pm->ps->stats[STAT_HOLDABLE_ITEM] = 0;
1588 }
1589 return;
1590 }
1591 } else {
1592 pm->ps->pm_flags &= ~PMF_USE_ITEM_HELD;
1593 }
1594
1595
1596 // make weapon function
1597 if ( pm->ps->weaponTime > 0 ) {
1598 pm->ps->weaponTime -= pml.msec;
1599 }
1600
1601 // check for weapon change
1602 // can't change if weapon is firing, but can change
1603 // again if lowering or raising
1604 if ( pm->ps->weaponTime <= 0 || pm->ps->weaponstate != WEAPON_FIRING ) {
1605 if ( pm->ps->weapon != pm->cmd.weapon ) {
1606 PM_BeginWeaponChange( pm->cmd.weapon );
1607 }
1608 }
1609
1610 if ( pm->ps->weaponTime > 0 ) {
1611 return;
1612 }
1613
1614 // change weapon if time
1615 if ( pm->ps->weaponstate == WEAPON_DROPPING ) {
1616 PM_FinishWeaponChange();
1617 return;
1618 }
1619
1620 if ( pm->ps->weaponstate == WEAPON_RAISING ) {
1621 pm->ps->weaponstate = WEAPON_READY;
1622 if ( pm->ps->weapon == WP_GAUNTLET ) {
1623 PM_StartTorsoAnim( TORSO_STAND2 );
1624 } else {
1625 PM_StartTorsoAnim( TORSO_STAND );
1626 }
1627 return;
1628 }
1629
1630 // check for fire
1631 if ( ! (pm->cmd.buttons & BUTTON_ATTACK) ) {
1632 pm->ps->weaponTime = 0;
1633 pm->ps->weaponstate = WEAPON_READY;
1634 return;
1635 }
1636
1637 // start the animation even if out of ammo
1638 if ( pm->ps->weapon == WP_GAUNTLET ) {
1639 // the guantlet only "fires" when it actually hits something
1640 if ( !pm->gauntletHit ) {
1641 pm->ps->weaponTime = 0;
1642 pm->ps->weaponstate = WEAPON_READY;
1643 return;
1644 }
1645 PM_StartTorsoAnim( TORSO_ATTACK2 );
1646 } else {
1647 PM_StartTorsoAnim( TORSO_ATTACK );
1648 }
1649
1650 pm->ps->weaponstate = WEAPON_FIRING;
1651
1652 // check for out of ammo
1653 if ( ! pm->ps->ammo[ pm->ps->weapon ] ) {
1654 PM_AddEvent( EV_NOAMMO );
1655 pm->ps->weaponTime += 500;
1656 return;
1657 }
1658
1659 // take an ammo away if not infinite, 999 or up
1660 if ( !(pm->ps->ammo[ pm->ps->weapon ] == -1 || pm->ps->ammo[ pm->ps->weapon ] >=999 )) {
1661 pm->ps->ammo[ pm->ps->weapon ]--;
1662 }
1663
1664 // fire weapon
1665 PM_AddEvent( EV_FIRE_WEAPON );
1666
1667 switch( pm->ps->weapon ) {
1668 default:
1669 case WP_GAUNTLET:
1670 addTime = 400;
1671 break;
1672 case WP_LIGHTNING:
1673 addTime = 50;
1674 break;
1675 case WP_SHOTGUN:
1676 addTime = 1000;
1677 break;
1678 case WP_MACHINEGUN:
1679 addTime = 100;
1680 break;
1681 case WP_GRENADE_LAUNCHER:
1682 addTime = 800;
1683 break;
1684 case WP_ROCKET_LAUNCHER:
1685 addTime = 800;
1686 break;
1687 case WP_PLASMAGUN:
1688 addTime = 100;
1689 break;
1690 case WP_RAILGUN:
1691 addTime = 1500;
1692 break;
1693 case WP_BFG:
1694 addTime = 200;
1695 break;
1696 case WP_GRAPPLING_HOOK:
1697 addTime = 400;
1698 break;
1699 case WP_NAILGUN:
1700 addTime = 1000;
1701 break;
1702 case WP_PROX_LAUNCHER:
1703 addTime = 800;
1704 break;
1705 case WP_CHAINGUN:
1706 addTime = 30;
1707 break;
1708 }
1709
1710 if( bg_itemlist[pm->ps->stats[STAT_PERSISTANT_POWERUP]].giTag == PW_SCOUT ) {
1711 addTime /= 1.5;
1712 }
1713 else
1714 if( bg_itemlist[pm->ps->stats[STAT_PERSISTANT_POWERUP]].giTag == PW_AMMOREGEN ) {
1715 addTime /= 1.3;
1716 }
1717 else
1718 if ( pm->ps->powerups[PW_HASTE] ) {
1719 addTime /= 1.3;
1720 }
1721
1722 pm->ps->weaponTime += addTime;
1723 }
1724
1725 /*
1726 ================
1727 PM_Animate
1728 ================
1729 */
1730
1731 static void PM_Animate( void ) {
1732 if ( pm->cmd.buttons & BUTTON_GESTURE ) {
1733 if ( pm->ps->torsoTimer == 0 ) {
1734 PM_StartTorsoAnim( TORSO_GESTURE );
1735 pm->ps->torsoTimer = TIMER_GESTURE;
1736 PM_AddEvent( EV_TAUNT );
1737 }
1738 } else if ( pm->cmd.buttons & BUTTON_GETFLAG ) {
1739 if ( pm->ps->torsoTimer == 0 ) {
1740 PM_StartTorsoAnim( TORSO_GETFLAG );
1741 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1742 }
1743 } else if ( pm->cmd.buttons & BUTTON_GUARDBASE ) {
1744 if ( pm->ps->torsoTimer == 0 ) {
1745 PM_StartTorsoAnim( TORSO_GUARDBASE );
1746 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1747 }
1748 } else if ( pm->cmd.buttons & BUTTON_PATROL ) {
1749 if ( pm->ps->torsoTimer == 0 ) {
1750 PM_StartTorsoAnim( TORSO_PATROL );
1751 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1752 }
1753 } else if ( pm->cmd.buttons & BUTTON_FOLLOWME ) {
1754 if ( pm->ps->torsoTimer == 0 ) {
1755 PM_StartTorsoAnim( TORSO_FOLLOWME );
1756 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1757 }
1758 } else if ( pm->cmd.buttons & BUTTON_AFFIRMATIVE ) {
1759 if ( pm->ps->torsoTimer == 0 ) {
1760 PM_StartTorsoAnim( TORSO_AFFIRMATIVE);
1761 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1762 }
1763 } else if ( pm->cmd.buttons & BUTTON_NEGATIVE ) {
1764 if ( pm->ps->torsoTimer == 0 ) {
1765 PM_StartTorsoAnim( TORSO_NEGATIVE );
1766 pm->ps->torsoTimer = 600; //TIMER_GESTURE;
1767 }
1768 }
1769 }
1770
1771
1772 /*
1773 ================
1774 PM_DropTimers
1775 ================
1776 */
1777 static void PM_DropTimers( void ) {
1778 // drop misc timing counter
1779 if ( pm->ps->pm_time ) {
1780 if ( pml.msec >= pm->ps->pm_time ) {
1781 pm->ps->pm_flags &= ~PMF_ALL_TIMES;
1782 pm->ps->pm_time = 0;
1783 } else {
1784 pm->ps->pm_time -= pml.msec;
1785 }
1786 }
1787
1788 // drop animation counter
1789 if ( pm->ps->legsTimer > 0 ) {
1790 pm->ps->legsTimer -= pml.msec;
1791 if ( pm->ps->legsTimer < 0 ) {
1792 pm->ps->legsTimer = 0;
1793 }
1794 }
1795
1796 if ( pm->ps->torsoTimer > 0 ) {
1797 pm->ps->torsoTimer -= pml.msec;
1798 if ( pm->ps->torsoTimer < 0 ) {
1799 pm->ps->torsoTimer = 0;
1800 }
1801 }
1802 }
1803
1804 /*
1805 ================
1806 PM_UpdateViewAngles
1807
1808 This can be used as another entry point when only the viewangles
1809 are being updated isntead of a full move
1810 ================
1811 */
1812 void PM_UpdateViewAngles( playerState_t *ps, const usercmd_t *cmd ) {
1813 short temp;
1814 int i;
1815
1816 if ( ps->pm_type == PM_INTERMISSION || ps->pm_type == PM_SPINTERMISSION) {
1817 return; // no view changes at all
1818 }
1819
1820 if ( ps->pm_type != PM_SPECTATOR && ps->stats[STAT_HEALTH] <= 0 ) {
1821 return; // no view changes at all
1822 }
1823
1824 // circularly clamp the angles with deltas
1825 for (i=0 ; i<3 ; i++) {
1826 temp = cmd->angles[i] + ps->delta_angles[i];
1827 if ( i == PITCH ) {
1828 // don't let the player look up or down more than 90 degrees
1829 if ( temp > 16000 ) {
1830 ps->delta_angles[i] = 16000 - cmd->angles[i];
1831 temp = 16000;
1832 } else if ( temp < -16000 ) {
1833 ps->delta_angles[i] = -16000 - cmd->angles[i];
1834 temp = -16000;
1835 }
1836 }
1837 ps->viewangles[i] = SHORT2ANGLE(temp);
1838 }
1839
1840 }
1841
1842
1843 /*
1844 ================
1845 PmoveSingle
1846
1847 ================
1848 */
1849 void trap_SnapVector( float *v );
1850
1851 void PmoveSingle (pmove_t *pmove) {
1852 pm = pmove;
1853
1854 // this counter lets us debug movement problems with a journal
1855 // by setting a conditional breakpoint fot the previous frame
1856 c_pmove++;
1857
1858 // clear results
1859 pm->numtouch = 0;
1860 pm->watertype = 0;
1861 pm->waterlevel = 0;
1862
1863 if ( pm->ps->stats[STAT_HEALTH] <= 0 ) {
1864 pm->tracemask &= ~CONTENTS_BODY; // corpses can fly through bodies
1865 }
1866
1867 // make sure walking button is clear if they are running, to avoid
1868 // proxy no-footsteps cheats
1869 if ( abs( pm->cmd.forwardmove ) > 64 || abs( pm->cmd.rightmove ) > 64 ) {
1870 pm->cmd.buttons &= ~BUTTON_WALKING;
1871 }
1872
1873 // set the talk balloon flag
1874 if ( pm->cmd.buttons & BUTTON_TALK ) {
1875 pm->ps->eFlags |= EF_TALK;
1876 } else {
1877 pm->ps->eFlags &= ~EF_TALK;
1878 }
1879
1880 // set the firing flag for continuous beam weapons
1881 if ( !(pm->ps->pm_flags & PMF_RESPAWNED) && pm->ps->pm_type != PM_INTERMISSION && pm->ps->pm_type != PM_NOCLIP
1882 && ( pm->cmd.buttons & BUTTON_ATTACK ) && pm->ps->ammo[ pm->ps->weapon ] ) {
1883 pm->ps->eFlags |= EF_FIRING;
1884 } else {
1885 pm->ps->eFlags &= ~EF_FIRING;
1886 }
1887
1888 // clear the respawned flag if attack and use are cleared
1889 if ( pm->ps->stats[STAT_HEALTH] > 0 &&
1890 !( pm->cmd.buttons & (BUTTON_ATTACK | BUTTON_USE_HOLDABLE) ) ) {
1891 pm->ps->pm_flags &= ~PMF_RESPAWNED;
1892 }
1893
1894 // if talk button is down, dissallow all other input
1895 // this is to prevent any possible intercept proxy from
1896 // adding fake talk balloons
1897 if ( pmove->cmd.buttons & BUTTON_TALK ) {
1898 // keep the talk button set tho for when the cmd.serverTime > 66 msec
1899 // and the same cmd is used multiple times in Pmove
1900 pmove->cmd.buttons = BUTTON_TALK;
1901 pmove->cmd.forwardmove = 0;
1902 pmove->cmd.rightmove = 0;
1903 pmove->cmd.upmove = 0;
1904 }
1905
1906 // clear all pmove local vars
1907 memset (&pml, 0, sizeof(pml));
1908
1909 // determine the time
1910 pml.msec = pmove->cmd.serverTime - pm->ps->commandTime;
1911 if ( pml.msec < 1 ) {
1912 pml.msec = 1;
1913 } else if ( pml.msec > 200 ) {
1914 pml.msec = 200;
1915 }
1916 pm->ps->commandTime = pmove->cmd.serverTime;
1917
1918 // save old org in case we get stuck
1919 VectorCopy (pm->ps->origin, pml.previous_origin);
1920
1921 // save old velocity for crashlanding
1922 VectorCopy (pm->ps->velocity, pml.previous_velocity);
1923
1924 pml.frametime = pml.msec * 0.001;
1925
1926 // update the viewangles
1927 PM_UpdateViewAngles( pm->ps, &pm->cmd );
1928
1929 AngleVectors (pm->ps->viewangles, pml.forward, pml.right, pml.up);
1930
1931 if ( pm->cmd.upmove < 10 ) {
1932 // not holding jump
1933 pm->ps->pm_flags &= ~PMF_JUMP_HELD;
1934 }
1935
1936 // decide if backpedaling animations should be used
1937 if ( pm->cmd.forwardmove < 0 ) {
1938 pm->ps->pm_flags |= PMF_BACKWARDS_RUN;
1939 } else if ( pm->cmd.forwardmove > 0 || ( pm->cmd.forwardmove == 0 && pm->cmd.rightmove ) ) {
1940 pm->ps->pm_flags &= ~PMF_BACKWARDS_RUN;
1941 }
1942
1943 if ( pm->ps->pm_type >= PM_DEAD ) {
1944 pm->cmd.forwardmove = 0;
1945 pm->cmd.rightmove = 0;
1946 pm->cmd.upmove = 0;
1947 }
1948
1949 if ( pm->ps->pm_type == PM_SPECTATOR ) {
1950 PM_CheckDuck ();
1951 PM_FlyMove ();
1952 PM_DropTimers ();
1953 return;
1954 }
1955
1956 if ( pm->ps->pm_type == PM_NOCLIP ) {
1957 PM_NoclipMove ();
1958 PM_DropTimers ();
1959 return;
1960 }
1961
1962 if (pm->ps->pm_type == PM_FREEZE) {
1963 return; // no movement at all
1964 }
1965
1966 if ( pm->ps->pm_type == PM_INTERMISSION || pm->ps->pm_type == PM_SPINTERMISSION) {
1967 return; // no movement at all
1968 }
1969
1970 // set watertype, and waterlevel
1971 PM_SetWaterLevel();
1972 pml.previous_waterlevel = pmove->waterlevel;
1973
1974 // set mins, maxs, and viewheight
1975 PM_CheckDuck ();
1976
1977 // set groundentity
1978 PM_GroundTrace();
1979
1980 if ( pm->ps->pm_type == PM_DEAD ) {
1981 PM_DeadMove ();
1982 }
1983
1984 PM_DropTimers();
1985
1986 if ( pm->ps->powerups[PW_INVULNERABILITY] ) {
1987 PM_InvulnerabilityMove();
1988 } else
1989 if ( pm->ps->powerups[PW_FLIGHT] ) {
1990 // flight powerup doesn't allow jump and has different friction
1991 PM_FlyMove();
1992 } else if (pm->ps->pm_flags & PMF_GRAPPLE_PULL) {
1993 PM_GrappleMove();
1994 // We can wiggle a bit
1995 PM_AirMove();
1996 } else if (pm->ps->pm_flags & PMF_TIME_WATERJUMP) {
1997 PM_WaterJumpMove();
1998 } else if ( pm->waterlevel > 1 ) {
1999 // swimming
2000 PM_WaterMove();
2001 } else if ( pml.walking ) {
2002 // walking on ground
2003 PM_WalkMove();
2004 } else {
2005 // airborne
2006 PM_AirMove();
2007 }
2008
2009 PM_Animate();
2010
2011 // set groundentity, watertype, and waterlevel
2012 PM_GroundTrace();
2013 PM_SetWaterLevel();
2014
2015 // weapons
2016 if(!(pm->ps->pm_flags & PMF_ELIMWARMUP))
2017 PM_Weapon();
2018
2019 // torso animation
2020 PM_TorsoAnimation();
2021
2022 // footstep events / legs animations
2023 PM_Footsteps();
2024
2025 // entering / leaving water splashes
2026 PM_WaterEvents();
2027
2028 // snap some parts of playerstate to save network bandwidth
2029 //But only if pmove_float is not enabled
2030 if(!(pm->pmove_float))
2031 trap_SnapVector( pm->ps->velocity );
2032 }
2033
2034
2035 /*
2036 ================
2037 Pmove
2038
2039 Can be called by either the server or the client
2040 ================
2041 */
2042 void Pmove (pmove_t *pmove) {
2043 int finalTime;
2044
2045 finalTime = pmove->cmd.serverTime;
2046
2047 if ( finalTime < pmove->ps->commandTime ) {
2048 return; // should not happen
2049 }
2050
2051 if ( finalTime > pmove->ps->commandTime + 1000 ) {
2052 pmove->ps->commandTime = finalTime - 1000;
2053 }
2054
2055 pmove->ps->pmove_framecount = (pmove->ps->pmove_framecount+1) & ((1<<PS_PMOVEFRAMECOUNTBITS)-1);
2056
2057 // chop the move up if it is too long, to prevent framerate
2058 // dependent behavior
2059 while ( pmove->ps->commandTime != finalTime ) {
2060 int msec;
2061
2062 msec = finalTime - pmove->ps->commandTime;
2063
2064 if ( pmove->pmove_fixed ) {
2065 if ( msec > pmove->pmove_msec ) {
2066 msec = pmove->pmove_msec;
2067 }
2068 }
2069 else {
2070 if ( msec > 66 ) {
2071 msec = 66;
2072 }
2073 }
2074 pmove->cmd.serverTime = pmove->ps->commandTime + msec;
2075 PmoveSingle( pmove );
2076
2077 if ( pmove->ps->pm_flags & PMF_JUMP_HELD ) {
2078 pmove->cmd.upmove = 20;
2079 }
2080 }
2081
2082 //PM_CheckStuck();
2083
2084 }
2085