-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpmove.c
849 lines (676 loc) · 21.2 KB
/
pmove.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: pmove.c,v 1.20 2007-10-07 16:21:10 tonik Exp $
*/
#include "quakedef.h"
#include "pmove.h"
movevars_t movevars;
playermove_t pmove;
static float pm_frametime;
static vec3_t pm_forward, pm_right;
vec3_t player_mins = {-16, -16, -24};
vec3_t player_maxs = {16, 16, 32};
#define STEPSIZE 18
#define MIN_STEP_NORMAL 0.7 // roughly 45 degrees
#define pm_flyfriction 4
#define BLOCKED_FLOOR 1
#define BLOCKED_STEP 2
#define BLOCKED_OTHER 4
#define BLOCKED_ANY 7
void PM_Init (void) { }
// Add an entity to touch list, discarding duplicates
static void PM_AddTouchedEnt (int num) {
int i;
if (pmove.numtouch == sizeof(pmove.touchindex)/sizeof(pmove.touchindex[0]))
return;
for (i = 0; i < pmove.numtouch; i++)
if (pmove.touchindex[i] == num)
return; // already added
pmove.touchindex[pmove.numtouch] = num;
pmove.numtouch++;
}
//Slide off of the impacting object
//returns the blocked flags (1 = floor, 2 = step / wall)
#define STOP_EPSILON 0.1
void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) {
float backoff, change;
int i;
backoff = DotProduct (in, normal) * overbounce;
for (i = 0; i < 3; i++) {
change = normal[i] * backoff;
out[i] = in[i] - change;
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
out[i] = 0;
}
}
//The basic solid body movement clip that slides along multiple planes
#define MAX_CLIP_PLANES 5
int PM_SlideMove (void) {
int bumpcount, numbumps, i, j, blocked, numplanes;
vec3_t dir, planes[MAX_CLIP_PLANES], primal_velocity, original_velocity, end;
float d, time_left;
trace_t trace;
numbumps = 4;
blocked = 0;
VectorCopy (pmove.velocity, original_velocity);
VectorCopy (pmove.velocity, primal_velocity);
numplanes = 0;
time_left = pm_frametime;
for (bumpcount = 0; bumpcount < numbumps; bumpcount++) {
VectorMA(pmove.origin, time_left, pmove.velocity, end);
trace = PM_PlayerTrace (pmove.origin, end);
if (trace.startsolid || trace.allsolid) {
// entity is trapped in another solid
VectorClear (pmove.velocity);
return 3;
}
if (trace.fraction > 0) {
// actually covered some distance
VectorCopy (trace.endpos, pmove.origin);
numplanes = 0;
}
if (trace.fraction == 1)
break; // moved the entire distance
// save entity for contact
PM_AddTouchedEnt (trace.e.entnum);
if (trace.plane.normal[2] >= MIN_STEP_NORMAL)
blocked |= BLOCKED_FLOOR;
else if (!trace.plane.normal[2])
blocked |= BLOCKED_STEP;
else
blocked |= BLOCKED_OTHER;
time_left -= time_left * trace.fraction;
// cliped to another plane
if (numplanes >= MAX_CLIP_PLANES) {
// this shouldn't really happen
VectorClear (pmove.velocity);
break;
}
VectorCopy (trace.plane.normal, planes[numplanes]);
numplanes++;
// modify original_velocity so it parallels all of the clip planes
for (i = 0; i < numplanes; i++) {
PM_ClipVelocity (original_velocity, planes[i], pmove.velocity, 1);
for (j = 0; j < numplanes; j++) {
if (j != i) {
if (DotProduct (pmove.velocity, planes[j]) < 0)
break; // not ok
}
}
if (j == numplanes)
break;
}
if (i != numplanes) {
// go along this plane
} else {
// go along the crease
if (numplanes != 2) {
VectorClear (pmove.velocity);
break;
}
CrossProduct (planes[0], planes[1], dir);
d = DotProduct (dir, pmove.velocity);
VectorScale (dir, d, pmove.velocity);
}
// if velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
if (DotProduct (pmove.velocity, primal_velocity) <= 0) {
VectorClear (pmove.velocity);
break;
}
}
if (pmove.waterjumptime)
VectorCopy (primal_velocity, pmove.velocity);
return blocked;
}
//Each intersection will try to step over the obstruction instead of sliding along it.
int PM_StepSlideMove (qbool in_air) {
vec3_t dest;
trace_t trace;
vec3_t original, originalvel, down, up, downvel;
float downdist, updist;
int blocked;
float stepsize;
// try sliding forward both on ground and up 16 pixels
// take the move that goes farthest
VectorCopy (pmove.origin, original);
VectorCopy (pmove.velocity, originalvel);
blocked = PM_SlideMove ();
if (!blocked)
return blocked; // moved the entire distance
if (in_air) {
// don't let us step up unless it's indeed a step we bumped in
// (that is, there's solid ground below)
float *org;
if (!(blocked & BLOCKED_STEP))
return blocked;
org = (originalvel[2] < 0) ? pmove.origin : original;
VectorCopy (org, dest);
dest[2] -= STEPSIZE;
trace = PM_PlayerTrace (org, dest);
if (trace.fraction == 1 || trace.plane.normal[2] < MIN_STEP_NORMAL)
return blocked;
// adjust stepsize, otherwise it would be possible to walk up a
// a step higher than STEPSIZE
stepsize = STEPSIZE - (org[2] - trace.endpos[2]);
} else {
stepsize = STEPSIZE;
}
VectorCopy (pmove.origin, down);
VectorCopy (pmove.velocity, downvel);
VectorCopy (original, pmove.origin);
VectorCopy (originalvel, pmove.velocity);
// move up a stair height
VectorCopy (pmove.origin, dest);
dest[2] += stepsize;
trace = PM_PlayerTrace (pmove.origin, dest);
if (!trace.startsolid && !trace.allsolid)
VectorCopy (trace.endpos, pmove.origin);
if (in_air && originalvel[2] < 0)
pmove.velocity[2] = 0;
PM_SlideMove ();
// press down the stepheight
VectorCopy (pmove.origin, dest);
dest[2] -= stepsize;
trace = PM_PlayerTrace (pmove.origin, dest);
if (trace.fraction != 1 && trace.plane.normal[2] < MIN_STEP_NORMAL)
goto usedown;
if (!trace.startsolid && !trace.allsolid)
VectorCopy (trace.endpos, pmove.origin);
if (pmove.origin[2] < original[2])
goto usedown;
VectorCopy (pmove.origin, up);
// decide which one went farther
downdist = (down[0] - original[0]) * (down[0] - original[0])
+ (down[1] - original[1]) * (down[1] - original[1]);
updist = (up[0] - original[0]) * (up[0] - original[0])
+ (up[1] - original[1]) * (up[1] - original[1]);
if (downdist >= updist) {
usedown:
VectorCopy (down, pmove.origin);
VectorCopy (downvel, pmove.velocity);
return blocked;
}
// copy z value from slide move
pmove.velocity[2] = downvel[2];
if (!pmove.onground && pmove.waterlevel < 2 && (blocked & BLOCKED_STEP)) {
float scale;
// in pm_airstep mode, walking up a 16 unit high step
// will kill 16% of horizontal velocity
scale = 1 - 0.01*(pmove.origin[2] - original[2]);
pmove.velocity[0] *= scale;
pmove.velocity[1] *= scale;
}
return blocked;
}
//Handles both ground friction and water friction
void PM_Friction (void) {
float speed, newspeed, control, friction, drop;
vec3_t start, stop;
trace_t trace;
if (pmove.waterjumptime)
return;
speed = VectorLength(pmove.velocity);
if (speed < 1) {
pmove.velocity[0] = pmove.velocity[1] = 0;
if (pmove.pm_type == PM_FLY)
pmove.velocity[2] = 0;
return;
}
if (pmove.waterlevel >= 2) {
// apply water friction, even if in fly mode
drop = speed * movevars.waterfriction * pmove.waterlevel * pm_frametime;
} else if (pmove.pm_type == PM_FLY) {
// apply flymode friction
drop = speed * pm_flyfriction * pm_frametime;
} else if (pmove.onground) {
// apply ground friction
friction = movevars.friction;
// if the leading edge is over a dropoff, increase friction
start[0] = stop[0] = pmove.origin[0] + pmove.velocity[0]/speed*16;
start[1] = stop[1] = pmove.origin[1] + pmove.velocity[1]/speed*16;
start[2] = pmove.origin[2] + player_mins[2];
stop[2] = start[2] - 34;
trace = PM_PlayerTrace (start, stop);
if (trace.fraction == 1)
friction *= 2;
control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
drop = control * friction * pm_frametime;
}
else
return; // in air, no friction
// scale the velocity
newspeed = speed - drop;
newspeed = max(newspeed, 0);
newspeed /= speed;
VectorScale (pmove.velocity, newspeed, pmove.velocity);
}
void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel) {
float addspeed, accelspeed, currentspeed;
if (pmove.pm_type == PM_DEAD)
return;
if (pmove.waterjumptime)
return;
currentspeed = DotProduct (pmove.velocity, wishdir);
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
return;
accelspeed = accel * pm_frametime * wishspeed;
if (accelspeed > addspeed)
accelspeed = addspeed;
VectorMA(pmove.velocity, accelspeed, wishdir, pmove.velocity);
}
#ifdef EXPERIMENTAL_SHOW_ACCELERATION
qbool player_in_air = false;
float cosinus_val = 0.f;
qbool flag_player_pmove;
#endif
void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel) {
float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
float originalspeed = 0.0, newspeed = 0.0, speedcap = 0.0;
if (pmove.pm_type == PM_DEAD)
return;
if (pmove.waterjumptime)
return;
if (movevars.bunnyspeedcap > 0)
originalspeed = sqrt(pmove.velocity[0] * pmove.velocity[0] + pmove.velocity[1] * pmove.velocity[1]);
wishspd = min(wishspd, 30);
currentspeed = DotProduct (pmove.velocity, wishdir);
addspeed = wishspd - currentspeed;
#ifdef EXPERIMENTAL_SHOW_ACCELERATION
if(flag_player_pmove)
{
cosinus_val = 0.f;
originalspeed = sqrt(pmove.velocity[0] * pmove.velocity[0] + pmove.velocity[1] * pmove.velocity[1]);
if(originalspeed > 1.f) cosinus_val = currentspeed / originalspeed;
player_in_air = true;
}
#endif
if (addspeed <= 0)
return;
accelspeed = accel * wishspeed * pm_frametime;
accelspeed = min(accelspeed, addspeed);
VectorMA(pmove.velocity, accelspeed, wishdir, pmove.velocity);
if (movevars.bunnyspeedcap > 0) {
newspeed = sqrt(pmove.velocity[0] * pmove.velocity[0] + pmove.velocity[1] * pmove.velocity[1]);
if (newspeed > originalspeed) {
speedcap = movevars.maxspeed * movevars.bunnyspeedcap;
if (newspeed > speedcap) {
if (originalspeed < speedcap)
originalspeed = speedcap;
pmove.velocity[0] *= originalspeed / newspeed;
pmove.velocity[1] *= originalspeed / newspeed;
}
}
}
}
void PM_WaterMove (void) {
int i;
vec3_t wishvel, wishdir;
float wishspeed;
// user intentions
for (i = 0; i < 3; i++)
wishvel[i] = pm_forward[i] * pmove.cmd.forwardmove + pm_right[i] * pmove.cmd.sidemove;
if (pmove.pm_type != PM_FLY && !pmove.cmd.forwardmove && !pmove.cmd.sidemove && !pmove.cmd.upmove)
wishvel[2] -= 60; // drift towards bottom
else
wishvel[2] += pmove.cmd.upmove;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
if (wishspeed > movevars.maxspeed) {
VectorScale (wishvel, movevars.maxspeed/wishspeed, wishvel);
wishspeed = movevars.maxspeed;
}
wishspeed *= 0.7;
// water acceleration
PM_Accelerate (wishdir, wishspeed, movevars.wateraccelerate);
PM_StepSlideMove (false);
}
void PM_FlyMove (void) {
int i;
vec3_t wishvel, wishdir;
float wishspeed;
for (i = 0; i < 3; i++)
wishvel[i] = pm_forward[i] * pmove.cmd.forwardmove + pm_right[i] * pmove.cmd.sidemove;
wishvel[2] += pmove.cmd.upmove;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
if (wishspeed > movevars.maxspeed) {
VectorScale (wishvel, movevars.maxspeed/wishspeed, wishvel);
wishspeed = movevars.maxspeed;
}
PM_Accelerate (wishdir, wishspeed, movevars.accelerate);
PM_StepSlideMove (false);
}
void PM_AirMove (void) {
int i;
vec3_t wishvel, wishdir;
float fmove, smove, wishspeed;
fmove = pmove.cmd.forwardmove;
smove = pmove.cmd.sidemove;
pm_forward[2] = 0;
pm_right[2] = 0;
VectorNormalize (pm_forward);
VectorNormalize (pm_right);
for (i = 0; i < 2; i++)
wishvel[i] = pm_forward[i] * fmove + pm_right[i] * smove;
wishvel[2] = 0;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
// clamp to server defined max speed
if (wishspeed > movevars.maxspeed) {
VectorScale (wishvel, movevars.maxspeed/wishspeed, wishvel);
wishspeed = movevars.maxspeed;
}
if (pmove.onground) {
if (movevars.slidefix)
{
pmove.velocity[2] = min(pmove.velocity[2], 0); // bound above by 0
PM_Accelerate (wishdir, wishspeed, movevars.accelerate);
// add gravity
pmove.velocity[2] -= movevars.entgravity * movevars.gravity * pm_frametime;
}
else
{
pmove.velocity[2] = 0;
PM_Accelerate (wishdir, wishspeed, movevars.accelerate);
}
if (!pmove.velocity[0] && !pmove.velocity[1]) {
pmove.velocity[2] = 0;
return;
}
PM_StepSlideMove(false);
} else {
int blocked;
// not on ground, so little effect on velocity
PM_AirAccelerate (wishdir, wishspeed, movevars.accelerate);
// add gravity
pmove.velocity[2] -= movevars.entgravity * movevars.gravity * pm_frametime;
if (movevars.airstep)
blocked = PM_StepSlideMove (true);
else
blocked = PM_SlideMove ();
if (movevars.pground)
{
if (blocked & BLOCKED_FLOOR)
pmove.onground = true;
}
}
}
plane_t groundplane;
void PM_CategorizePosition (void) {
vec3_t point;
int cont;
trace_t trace;
// if the player hull point one unit down is solid, the player is on ground
// see if standing on something solid
point[0] = pmove.origin[0];
point[1] = pmove.origin[1];
point[2] = pmove.origin[2] - 1;
if (pmove.velocity[2] > 180) {
pmove.onground = false;
} else if (!movevars.pground || pmove.onground) {
trace = PM_PlayerTrace (pmove.origin, point);
if (trace.fraction == 1 || trace.plane.normal[2] < MIN_STEP_NORMAL) {
pmove.onground = false;
} else {
pmove.onground = true;
pmove.groundent = trace.e.entnum;
groundplane = trace.plane;
pmove.waterjumptime = 0;
}
// standing on an entity other than the world
if (trace.e.entnum > 0)
PM_AddTouchedEnt (trace.e.entnum);
}
// get waterlevel
pmove.waterlevel = 0;
pmove.watertype = CONTENTS_EMPTY;
point[2] = pmove.origin[2] + player_mins[2] + 1;
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER) {
pmove.watertype = cont;
pmove.waterlevel = 1;
point[2] = pmove.origin[2] + (player_mins[2] + player_maxs[2]) * 0.5;
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER) {
pmove.waterlevel = 2;
point[2] = pmove.origin[2] + 22;
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER)
pmove.waterlevel = 3;
}
}
if (!movevars.pground) {
if (pmove.onground && pmove.pm_type != PM_FLY && pmove.waterlevel < 2) {
// snap to ground so that we can't jump higher than we're supposed to
if (!trace.startsolid && !trace.allsolid)
VectorCopy (trace.endpos, pmove.origin);
}
}
}
void PM_CheckJump (void) {
if (pmove.pm_type == PM_FLY)
return;
if (pmove.pm_type == PM_DEAD) {
pmove.jump_held = true; // don't jump on respawn
return;
}
if (!(pmove.cmd.buttons & BUTTON_JUMP)) {
pmove.jump_held = false;
return;
}
if (pmove.waterjumptime)
return;
if (pmove.waterlevel >= 2) {
// swimming, not jumping
pmove.onground = false;
if (pmove.watertype == CONTENTS_WATER)
pmove.velocity[2] = 100;
else if (pmove.watertype == CONTENTS_SLIME)
pmove.velocity[2] = 80;
else
pmove.velocity[2] = 50;
return;
}
if (!pmove.onground)
return; // in air, so no effect
if (pmove.jump_held && !pmove.jump_msec)
return; // don't pogo stick
if (!movevars.pground) {
// check for jump bug
// groundplane normal was set in the call to PM_CategorizePosition
if (pmove.velocity[2] < 0 && DotProduct(pmove.velocity, groundplane.normal) < -0.1) {
// pmove.velocity is pointing into the ground, clip it
PM_ClipVelocity (pmove.velocity, groundplane.normal, pmove.velocity, 1);
}
}
pmove.onground = false;
pmove.velocity[2] += 270;
if (movevars.ktjump > 0) {
if (movevars.ktjump > 1)
movevars.ktjump = 1;
if (pmove.velocity[2] < 270)
pmove.velocity[2] = pmove.velocity[2] * (1 - movevars.ktjump) + 270 * movevars.ktjump;
}
pmove.jump_held = true; // don't jump again until released
pmove.jump_msec = pmove.cmd.msec;
}
void PM_CheckWaterJump (void) {
vec3_t spot;
int cont;
vec3_t flatforward;
if (pmove.waterjumptime)
return;
// don't hop out if we just jumped in
if (pmove.velocity[2] < -180)
return;
// see if near an edge
flatforward[0] = pm_forward[0];
flatforward[1] = pm_forward[1];
flatforward[2] = 0;
VectorNormalize (flatforward);
VectorMA (pmove.origin, 24, flatforward, spot);
spot[2] += 8;
cont = PM_PointContents_AllBSPs (spot);
if (cont != CONTENTS_SOLID)
return;
spot[2] += 24;
cont = PM_PointContents_AllBSPs (spot);
if (cont != CONTENTS_EMPTY)
return;
// jump out of water
VectorScale (flatforward, 50, pmove.velocity);
pmove.velocity[2] = 310;
pmove.waterjumptime = 2; // safety net
pmove.jump_held = true; // don't jump again until released
}
//If pmove.origin is in a solid position,
//try nudging slightly on all axis to
//allow for the cut precision of the net coordinates
void PM_NudgePosition (void) {
vec3_t base;
int x, y, z, i;
static int sign[3] = {0, -1, 1};
VectorCopy (pmove.origin, base);
for (i = 0; i < 3; i++)
pmove.origin[i] = ((int) (pmove.origin[i] * 8)) * 0.125;
for (z = 0; z <= 2; z++) {
for (y = 0; y <= 2; y++) {
for (x = 0; x <= 2; x++) {
pmove.origin[0] = base[0] + (sign[x] * 0.125);
pmove.origin[1] = base[1] + (sign[y] * 0.125);
pmove.origin[2] = base[2] + (sign[z] * 0.125);
if (PM_TestPlayerPosition (pmove.origin))
return;
}
}
}
// some maps spawn the player several units into the ground
for (z=1 ; z<=18 ; z++)
{
pmove.origin[0] = base[0];
pmove.origin[1] = base[1];
pmove.origin[2] = base[2] + z;
if (PM_TestPlayerPosition(pmove.origin))
return;
}
VectorCopy (base, pmove.origin);
}
void PM_SpectatorMove (void) {
float speed, drop, friction, control, newspeed, currentspeed, addspeed, accelspeed, fmove, smove, wishspeed;
int i;
vec3_t wishvel, wishdir;
// friction
speed = VectorLength (pmove.velocity);
if (speed < 1) {
VectorClear (pmove.velocity);
} else {
friction = movevars.friction * 1.5; // extra friction
control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
drop = control * friction * pm_frametime;
// scale the velocity
newspeed = speed - drop;
if (newspeed < 0)
newspeed = 0;
newspeed /= speed;
VectorScale (pmove.velocity, newspeed, pmove.velocity);
}
// accelerate
fmove = pmove.cmd.forwardmove;
smove = pmove.cmd.sidemove;
VectorNormalize (pm_forward);
VectorNormalize (pm_right);
for (i = 0; i < 3; i++)
wishvel[i] = pm_forward[i] * fmove + pm_right[i] * smove;
wishvel[2] += pmove.cmd.upmove;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize(wishdir);
// clamp to server defined max speed
if (wishspeed > movevars.spectatormaxspeed) {
VectorScale (wishvel, movevars.spectatormaxspeed / wishspeed, wishvel);
wishspeed = movevars.spectatormaxspeed;
}
currentspeed = DotProduct(pmove.velocity, wishdir);
addspeed = wishspeed - currentspeed;
// Buggy QW spectator mode, kept for compatibility
if (pmove.pm_type == PM_OLD_SPECTATOR) {
if (addspeed <= 0)
return;
}
if (addspeed > 0) {
accelspeed = movevars.accelerate * pm_frametime * wishspeed;
accelspeed = min(accelspeed, addspeed);
VectorMA(pmove.velocity, accelspeed, wishdir, pmove.velocity);
}
// move
VectorMA (pmove.origin, pm_frametime, pmove.velocity, pmove.origin);
}
//Returns with origin, angles, and velocity modified in place.
//Numtouch and touchindex[] will be set if any of the physents were contacted during the move.
void PM_PlayerMove (void)
{
#ifdef EXPERIMENTAL_SHOW_ACCELERATION
if(flag_player_pmove) player_in_air = false;
#endif
pm_frametime = pmove.cmd.msec * 0.001;
pmove.numtouch = 0;
if (pmove.pm_type == PM_NONE || pmove.pm_type == PM_LOCK) {
PM_CategorizePosition ();
return;
}
// take angles directly from command
VectorCopy (pmove.cmd.angles, pmove.angles);
AngleVectors (pmove.angles, pm_forward, pm_right, NULL);
if (pmove.pm_type == PM_SPECTATOR || pmove.pm_type == PM_OLD_SPECTATOR) {
PM_SpectatorMove ();
pmove.onground = false;
return;
}
PM_NudgePosition ();
// set onground, watertype, and waterlevel
PM_CategorizePosition ();
if (pmove.waterlevel == 2 && pmove.pm_type != PM_FLY)
PM_CheckWaterJump ();
if (pmove.velocity[2] < 0 || pmove.pm_type == PM_DEAD)
pmove.waterjumptime = 0;
if (pmove.waterjumptime)
{
pmove.waterjumptime -= pm_frametime;
if (pmove.waterjumptime < 0)
pmove.waterjumptime = 0;
}
if (pmove.jump_msec) {
pmove.jump_msec += pmove.cmd.msec;
if (pmove.jump_msec > 50)
pmove.jump_msec = 0;
}
PM_CheckJump ();
PM_Friction ();
if (pmove.waterlevel >= 2)
PM_WaterMove ();
else if (pmove.pm_type == PM_FLY)
PM_FlyMove ();
else
PM_AirMove ();
// set onground, watertype, and waterlevel for final spot
PM_CategorizePosition ();
if (!movevars.pground) {
// this is to make sure landing sound is not played twice
// and falling damage is calculated correctly
if (pmove.onground && pmove.velocity[2] < -300
&& DotProduct(pmove.velocity, groundplane.normal) < -0.1)
PM_ClipVelocity (pmove.velocity, groundplane.normal, pmove.velocity, 1);
}
}