-
Notifications
You must be signed in to change notification settings - Fork 631
/
pm_shared.c
3367 lines (2793 loc) · 79.2 KB
/
pm_shared.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include <assert.h>
#include "mathlib.h"
#include "const.h"
#include "usercmd.h"
#include "pm_defs.h"
#include "pm_shared.h"
#include "pm_movevars.h"
#include "pm_debug.h"
#include <stdio.h> // NULL
#include <math.h> // sqrt
#include <string.h> // strcpy
#include <stdlib.h> // atoi
#include <ctype.h> // isspace
#ifdef CLIENT_DLL
// Spectator Mode
int iJumpSpectator;
#ifndef DISABLE_JUMP_ORIGIN
float vJumpOrigin[3];
float vJumpAngles[3];
#else
extern float vJumpOrigin[3];
extern float vJumpAngles[3];
#endif
#endif
static int pm_shared_initialized = 0;
#pragma warning( disable : 4305 )
typedef enum {mod_brush, mod_sprite, mod_alias, mod_studio} modtype_t;
playermove_t *pmove = NULL;
typedef struct
{
int planenum;
short children[2]; // negative numbers are contents
} dclipnode_t;
typedef struct mplane_s
{
vec3_t normal; // surface normal
float dist; // closest appoach to origin
byte type; // for texture axis selection and fast side tests
byte signbits; // signx + signy<<1 + signz<<1
byte pad[2];
} mplane_t;
typedef struct hull_s
{
dclipnode_t *clipnodes;
mplane_t *planes;
int firstclipnode;
int lastclipnode;
vec3_t clip_mins;
vec3_t clip_maxs;
} hull_t;
// Ducking time
#define TIME_TO_DUCK 0.4
#define VEC_DUCK_HULL_MIN -18
#define VEC_DUCK_HULL_MAX 18
#define VEC_DUCK_VIEW 12
#define PM_DEAD_VIEWHEIGHT -8
#define MAX_CLIMB_SPEED 200
#define STUCK_MOVEUP 1
#define STUCK_MOVEDOWN -1
#define VEC_HULL_MIN -36
#define VEC_HULL_MAX 36
#define VEC_VIEW 28
#define STOP_EPSILON 0.1
#define CTEXTURESMAX 512 // max number of textures loaded
#define CBTEXTURENAMEMAX 13 // only load first n chars of name
#define CHAR_TEX_CONCRETE 'C' // texture types
#define CHAR_TEX_METAL 'M'
#define CHAR_TEX_DIRT 'D'
#define CHAR_TEX_VENT 'V'
#define CHAR_TEX_GRATE 'G'
#define CHAR_TEX_TILE 'T'
#define CHAR_TEX_SLOSH 'S'
#define CHAR_TEX_WOOD 'W'
#define CHAR_TEX_COMPUTER 'P'
#define CHAR_TEX_GLASS 'Y'
#define CHAR_TEX_FLESH 'F'
#define STEP_CONCRETE 0 // default step sound
#define STEP_METAL 1 // metal floor
#define STEP_DIRT 2 // dirt, sand, rock
#define STEP_VENT 3 // ventillation duct
#define STEP_GRATE 4 // metal grating
#define STEP_TILE 5 // floor tiles
#define STEP_SLOSH 6 // shallow liquid puddle
#define STEP_WADE 7 // wading in liquid
#define STEP_LADDER 8 // climbing ladder
#define PLAYER_FATAL_FALL_SPEED 1024// approx 60 feet
#define PLAYER_MAX_SAFE_FALL_SPEED 580// approx 20 feet
#define DAMAGE_FOR_FALL_SPEED (float) 100 / ( PLAYER_FATAL_FALL_SPEED - PLAYER_MAX_SAFE_FALL_SPEED )// damage per unit per second.
#define PLAYER_MIN_BOUNCE_SPEED 200
#define PLAYER_FALL_PUNCH_THRESHHOLD (float)350 // won't punch player's screen/make scrape noise unless player falling at least this fast.
#define PLAYER_LONGJUMP_SPEED 350 // how fast we longjump
#define PLAYER_DUCKING_MULTIPLIER 0.333
// double to float warning
#pragma warning(disable : 4244)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
// up / down
#define PITCH 0
// left / right
#define YAW 1
// fall over
#define ROLL 2
#define MAX_CLIENTS 32
#define CONTENTS_CURRENT_0 -9
#define CONTENTS_CURRENT_90 -10
#define CONTENTS_CURRENT_180 -11
#define CONTENTS_CURRENT_270 -12
#define CONTENTS_CURRENT_UP -13
#define CONTENTS_CURRENT_DOWN -14
#define CONTENTS_TRANSLUCENT -15
static vec3_t rgv3tStuckTable[54];
static int rgStuckLast[MAX_CLIENTS][2];
// Texture names
static int gcTextures = 0;
static char grgszTextureName[CTEXTURESMAX][CBTEXTURENAMEMAX];
static char grgchTextureType[CTEXTURESMAX];
int g_onladder = 0;
void PM_SwapTextures( int i, int j )
{
char chTemp;
char szTemp[ CBTEXTURENAMEMAX ];
strcpy( szTemp, grgszTextureName[ i ] );
chTemp = grgchTextureType[ i ];
strcpy( grgszTextureName[ i ], grgszTextureName[ j ] );
grgchTextureType[ i ] = grgchTextureType[ j ];
strcpy( grgszTextureName[ j ], szTemp );
grgchTextureType[ j ] = chTemp;
}
void PM_SortTextures( void )
{
// Bubble sort, yuck, but this only occurs at startup and it's only 512 elements...
//
int i, j;
for ( i = 0 ; i < gcTextures; i++ )
{
for ( j = i + 1; j < gcTextures; j++ )
{
if ( stricmp( grgszTextureName[ i ], grgszTextureName[ j ] ) > 0 )
{
// Swap
//
PM_SwapTextures( i, j );
}
}
}
}
void PM_InitTextureTypes()
{
char buffer[512];
int i, j;
byte *pMemFile;
int fileSize, filePos;
static qboolean bTextureTypeInit = false;
if ( bTextureTypeInit )
return;
memset(&(grgszTextureName[0][0]), 0, CTEXTURESMAX * CBTEXTURENAMEMAX);
memset(grgchTextureType, 0, CTEXTURESMAX);
gcTextures = 0;
memset(buffer, 0, 512);
fileSize = pmove->COM_FileSize( "sound/materials.txt" );
pMemFile = pmove->COM_LoadFile( "sound/materials.txt", 5, NULL );
if ( !pMemFile )
return;
filePos = 0;
// for each line in the file...
while ( pmove->memfgets( pMemFile, fileSize, &filePos, buffer, 511 ) != NULL && (gcTextures < CTEXTURESMAX) )
{
// skip whitespace
i = 0;
while(buffer[i] && isspace(buffer[i]))
i++;
if (!buffer[i])
continue;
// skip comment lines
if (buffer[i] == '/' || !isalpha(buffer[i]))
continue;
// get texture type
grgchTextureType[gcTextures] = toupper(buffer[i++]);
// skip whitespace
while(buffer[i] && isspace(buffer[i]))
i++;
if (!buffer[i])
continue;
// get sentence name
j = i;
while (buffer[j] && !isspace(buffer[j]))
j++;
if (!buffer[j])
continue;
// null-terminate name and save in sentences array
j = min (j, CBTEXTURENAMEMAX-1+i);
buffer[j] = 0;
strcpy(&(grgszTextureName[gcTextures++][0]), &(buffer[i]));
}
// Must use engine to free since we are in a .dll
pmove->COM_FreeFile ( pMemFile );
PM_SortTextures();
bTextureTypeInit = true;
}
char PM_FindTextureType( char *name )
{
int left, right, pivot;
int val;
assert( pm_shared_initialized );
left = 0;
right = gcTextures - 1;
while ( left <= right )
{
pivot = ( left + right ) / 2;
val = strnicmp( name, grgszTextureName[ pivot ], CBTEXTURENAMEMAX-1 );
if ( val == 0 )
{
return grgchTextureType[ pivot ];
}
else if ( val > 0 )
{
left = pivot + 1;
}
else if ( val < 0 )
{
right = pivot - 1;
}
}
return CHAR_TEX_CONCRETE;
}
void PM_PlayStepSound( int step, float fvol )
{
static int iSkipStep = 0;
int irand;
vec3_t hvel;
pmove->iStepLeft = !pmove->iStepLeft;
if ( !pmove->runfuncs )
{
return;
}
irand = pmove->RandomLong(0,1) + ( pmove->iStepLeft * 2 );
// FIXME mp_footsteps needs to be a movevar
if ( pmove->multiplayer && !pmove->movevars->footsteps )
return;
VectorCopy( pmove->velocity, hvel );
hvel[2] = 0.0;
if ( pmove->multiplayer && ( !g_onladder && Length( hvel ) <= 220 ) )
return;
// irand - 0,1 for right foot, 2,3 for left foot
// used to alternate left and right foot
// FIXME, move to player state
switch (step)
{
default:
case STEP_CONCRETE:
switch (irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_step1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_step3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_step2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_step4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_METAL:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_DIRT:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_VENT:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_GRATE:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_TILE:
if ( !pmove->RandomLong(0,4) )
irand = 4;
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 4: pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile5.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_SLOSH:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_WADE:
if ( iSkipStep == 0 )
{
iSkipStep++;
break;
}
if ( iSkipStep++ == 3 )
{
iSkipStep = 0;
}
switch (irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
case STEP_LADDER:
switch(irand)
{
// right foot
case 0: pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder1.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 1: pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder3.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
// left foot
case 2: pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder2.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
case 3: pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder4.wav", fvol, ATTN_NORM, 0, PITCH_NORM ); break;
}
break;
}
}
int PM_MapTextureTypeStepType(char chTextureType)
{
switch (chTextureType)
{
default:
case CHAR_TEX_CONCRETE: return STEP_CONCRETE;
case CHAR_TEX_METAL: return STEP_METAL;
case CHAR_TEX_DIRT: return STEP_DIRT;
case CHAR_TEX_VENT: return STEP_VENT;
case CHAR_TEX_GRATE: return STEP_GRATE;
case CHAR_TEX_TILE: return STEP_TILE;
case CHAR_TEX_SLOSH: return STEP_SLOSH;
}
}
/*
====================
PM_CatagorizeTextureType
Determine texture info for the texture we are standing on.
====================
*/
void PM_CatagorizeTextureType( void )
{
vec3_t start, end;
const char *pTextureName;
VectorCopy( pmove->origin, start );
VectorCopy( pmove->origin, end );
// Straight down
end[2] -= 64;
// Fill in default values, just in case.
pmove->sztexturename[0] = '\0';
pmove->chtexturetype = CHAR_TEX_CONCRETE;
pTextureName = pmove->PM_TraceTexture( pmove->onground, start, end );
if ( !pTextureName )
return;
// strip leading '-0' or '+0~' or '{' or '!'
if (*pTextureName == '-' || *pTextureName == '+')
pTextureName += 2;
if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ')
pTextureName++;
// '}}'
strcpy( pmove->sztexturename, pTextureName);
pmove->sztexturename[ CBTEXTURENAMEMAX - 1 ] = 0;
// get texture type
pmove->chtexturetype = PM_FindTextureType( pmove->sztexturename );
}
void PM_UpdateStepSound( void )
{
int fWalking;
float fvol;
vec3_t knee;
vec3_t feet;
vec3_t center;
float height;
float speed;
float velrun;
float velwalk;
float flduck;
int fLadder;
int step;
if ( pmove->flTimeStepSound > 0 )
return;
if ( pmove->flags & FL_FROZEN )
return;
PM_CatagorizeTextureType();
speed = Length( pmove->velocity );
// determine if we are on a ladder
fLadder = ( pmove->movetype == MOVETYPE_FLY );// IsOnLadder();
// UNDONE: need defined numbers for run, walk, crouch, crouch run velocities!!!!
if ( ( pmove->flags & FL_DUCKING) || fLadder )
{
velwalk = 60; // These constants should be based on cl_movespeedkey * cl_forwardspeed somehow
velrun = 80; // UNDONE: Move walking to server
flduck = 100;
}
else
{
velwalk = 120;
velrun = 210;
flduck = 0;
}
// If we're on a ladder or on the ground, and we're moving fast enough,
// play step sound. Also, if pmove->flTimeStepSound is zero, get the new
// sound right away - we just started moving in new level.
if ( (fLadder || ( pmove->onground != -1 ) ) &&
( Length( pmove->velocity ) > 0.0 ) &&
( speed >= velwalk || !pmove->flTimeStepSound ) )
{
fWalking = speed < velrun;
VectorCopy( pmove->origin, center );
VectorCopy( pmove->origin, knee );
VectorCopy( pmove->origin, feet );
height = pmove->player_maxs[ pmove->usehull ][ 2 ] - pmove->player_mins[ pmove->usehull ][ 2 ];
knee[2] = pmove->origin[2] - 0.3 * height;
feet[2] = pmove->origin[2] - 0.5 * height;
// find out what we're stepping in or on...
if (fLadder)
{
step = STEP_LADDER;
fvol = 0.35;
pmove->flTimeStepSound = 350;
}
else if ( pmove->PM_PointContents ( knee, NULL ) == CONTENTS_WATER )
{
step = STEP_WADE;
fvol = 0.65;
pmove->flTimeStepSound = 600;
}
else if ( pmove->PM_PointContents ( feet, NULL ) == CONTENTS_WATER )
{
step = STEP_SLOSH;
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
}
else
{
// find texture under player, if different from current texture,
// get material type
step = PM_MapTextureTypeStepType( pmove->chtexturetype );
switch ( pmove->chtexturetype )
{
default:
case CHAR_TEX_CONCRETE:
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_METAL:
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_DIRT:
fvol = fWalking ? 0.25 : 0.55;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_VENT:
fvol = fWalking ? 0.4 : 0.7;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_GRATE:
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_TILE:
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
case CHAR_TEX_SLOSH:
fvol = fWalking ? 0.2 : 0.5;
pmove->flTimeStepSound = fWalking ? 400 : 300;
break;
}
}
pmove->flTimeStepSound += flduck; // slower step time if ducking
// play the sound
// 35% volume if ducking
if ( pmove->flags & FL_DUCKING )
{
fvol *= 0.35;
}
PM_PlayStepSound( step, fvol );
}
}
/*
================
PM_AddToTouched
Add's the trace result to touch list, if contact is not already in list.
================
*/
qboolean PM_AddToTouched(pmtrace_t tr, vec3_t impactvelocity)
{
int i;
for (i = 0; i < pmove->numtouch; i++)
{
if (pmove->touchindex[i].ent == tr.ent)
break;
}
if (i != pmove->numtouch) // Already in list.
return false;
VectorCopy( impactvelocity, tr.deltavelocity );
if (pmove->numtouch >= MAX_PHYSENTS)
pmove->Con_DPrintf("Too many entities were touched!\n");
pmove->touchindex[pmove->numtouch++] = tr;
return true;
}
/*
================
PM_CheckVelocity
See if the player has a bogus velocity value.
================
*/
void PM_CheckVelocity ()
{
int i;
//
// bound velocity
//
for (i=0 ; i<3 ; i++)
{
// See if it's bogus.
if (IS_NAN(pmove->velocity[i]))
{
pmove->Con_Printf ("PM Got a NaN velocity %i\n", i);
pmove->velocity[i] = 0;
}
if (IS_NAN(pmove->origin[i]))
{
pmove->Con_Printf ("PM Got a NaN origin on %i\n", i);
pmove->origin[i] = 0;
}
// Bound it.
if (pmove->velocity[i] > pmove->movevars->maxvelocity)
{
pmove->Con_DPrintf ("PM Got a velocity too high on %i\n", i);
pmove->velocity[i] = pmove->movevars->maxvelocity;
}
else if (pmove->velocity[i] < -pmove->movevars->maxvelocity)
{
pmove->Con_DPrintf ("PM Got a velocity too low on %i\n", i);
pmove->velocity[i] = -pmove->movevars->maxvelocity;
}
}
}
/*
==================
PM_ClipVelocity
Slide off of the impacting object
returns the blocked flags:
0x01 == floor
0x02 == step / wall
==================
*/
int PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
{
float backoff;
float change;
float angle;
int i, blocked;
angle = normal[ 2 ];
blocked = 0x00; // Assume unblocked.
if (angle > 0) // If the plane that is blocking us has a positive z component, then assume it's a floor.
blocked |= 0x01; //
if (!angle) // If the plane has no Z, it is vertical (wall/step)
blocked |= 0x02; //
// Determine how far along plane to slide based on incoming direction.
// Scale by overbounce factor.
backoff = DotProduct (in, normal) * overbounce;
for (i=0 ; i<3 ; i++)
{
change = normal[i]*backoff;
out[i] = in[i] - change;
// If out velocity is too small, zero it out.
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
out[i] = 0;
}
// Return blocking flags.
return blocked;
}
void PM_AddCorrectGravity ()
{
float ent_gravity;
if ( pmove->waterjumptime )
return;
if (pmove->gravity)
ent_gravity = pmove->gravity;
else
ent_gravity = 1.0;
// Add gravity so they'll be in the correct position during movement
// yes, this 0.5 looks wrong, but it's not.
pmove->velocity[2] -= (ent_gravity * pmove->movevars->gravity * 0.5 * pmove->frametime );
pmove->velocity[2] += pmove->basevelocity[2] * pmove->frametime;
pmove->basevelocity[2] = 0;
PM_CheckVelocity();
}
void PM_FixupGravityVelocity ()
{
float ent_gravity;
if ( pmove->waterjumptime )
return;
if (pmove->gravity)
ent_gravity = pmove->gravity;
else
ent_gravity = 1.0;
// Get the correct velocity for the end of the dt
pmove->velocity[2] -= (ent_gravity * pmove->movevars->gravity * pmove->frametime * 0.5 );
PM_CheckVelocity();
}
/*
============
PM_FlyMove
The basic solid body movement clip that slides along multiple planes
============
*/
int PM_FlyMove (void)
{
int bumpcount, numbumps;
vec3_t dir;
float d;
int numplanes;
vec3_t planes[MAX_CLIP_PLANES];
vec3_t primal_velocity, original_velocity;
vec3_t new_velocity;
int i, j;
pmtrace_t trace;
vec3_t end;
float time_left, allFraction;
int blocked;
numbumps = 4; // Bump up to four times
blocked = 0; // Assume not blocked
numplanes = 0; // and not sliding along any planes
VectorCopy (pmove->velocity, original_velocity); // Store original velocity
VectorCopy (pmove->velocity, primal_velocity);
allFraction = 0;
time_left = pmove->frametime; // Total time for this movement operation.
for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++)
{
if (!pmove->velocity[0] && !pmove->velocity[1] && !pmove->velocity[2])
break;
// Assume we can move all the way from the current origin to the
// end point.
for (i=0 ; i<3 ; i++)
end[i] = pmove->origin[i] + time_left * pmove->velocity[i];
// See if we can make it from origin to end point.
trace = pmove->PM_PlayerTrace (pmove->origin, end, PM_NORMAL, -1 );
allFraction += trace.fraction;
// If we started in a solid object, or we were in solid space
// the whole way, zero out our velocity and return that we
// are blocked by floor and wall.
if (trace.allsolid)
{ // entity is trapped in another solid
VectorCopy (vec3_origin, pmove->velocity);
//Con_DPrintf("Trapped 4\n");
return 4;
}
// If we moved some portion of the total distance, then
// copy the end position into the pmove->origin and
// zero the plane counter.
if (trace.fraction > 0)
{ // actually covered some distance
VectorCopy (trace.endpos, pmove->origin);
VectorCopy (pmove->velocity, original_velocity);
numplanes = 0;
}
// If we covered the entire distance, we are done
// and can return.
if (trace.fraction == 1)
break; // moved the entire distance
//if (!trace.ent)
// Sys_Error ("PM_PlayerTrace: !trace.ent");
// Save entity that blocked us (since fraction was < 1.0)
// for contact
// Add it if it's not already in the list!!!
PM_AddToTouched(trace, pmove->velocity);
// If the plane we hit has a high z component in the normal, then
// it's probably a floor
if (trace.plane.normal[2] > 0.7)
{
blocked |= 1; // floor
}
// If the plane has a zero z component in the normal, then it's a
// step or wall
if (!trace.plane.normal[2])
{
blocked |= 2; // step / wall
//Con_DPrintf("Blocked by %i\n", trace.ent);
}
// Reduce amount of pmove->frametime left by total time left * fraction
// that we covered.
time_left -= time_left * trace.fraction;
// Did we run out of planes to clip against?
if (numplanes >= MAX_CLIP_PLANES)
{ // this shouldn't really happen
// Stop our movement if so.
VectorCopy (vec3_origin, pmove->velocity);
//Con_DPrintf("Too many planes 4\n");
break;
}
// Set up next clipping plane
VectorCopy (trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
if ( pmove->movetype == MOVETYPE_WALK &&
((pmove->onground == -1) || (pmove->friction != 1)) ) // relfect player velocity
{
for ( i = 0; i < numplanes; i++ )
{
if ( planes[i][2] > 0.7 )
{// floor or slope
PM_ClipVelocity( original_velocity, planes[i], new_velocity, 1 );
VectorCopy( new_velocity, original_velocity );
}
else
PM_ClipVelocity( original_velocity, planes[i], new_velocity, 1.0 + pmove->movevars->bounce * (1-pmove->friction) );
}
VectorCopy( new_velocity, pmove->velocity );
VectorCopy( new_velocity, original_velocity );
}
else
{
for (i=0 ; i<numplanes ; i++)
{
PM_ClipVelocity (
original_velocity,
planes[i],
pmove->velocity,
1);
for (j=0 ; j<numplanes ; j++)
if (j != i)
{
// Are we now moving against this plane?
if (DotProduct (pmove->velocity, planes[j]) < 0)
break; // not ok
}
if (j == numplanes) // Didn't have to clip, so we're ok
break;
}
// Did we go all the way through plane set
if (i != numplanes)
{ // go along this plane
// pmove->velocity is set in clipping call, no need to set again.
;
}
else
{ // go along the crease
if (numplanes != 2)
{
//Con_Printf ("clip velocity, numplanes == %i\n",numplanes);
VectorCopy (vec3_origin, pmove->velocity);
//Con_DPrintf("Trapped 4\n");
break;
}
CrossProduct (planes[0], planes[1], dir);
d = DotProduct (dir, pmove->velocity);
VectorScale (dir, d, pmove->velocity );
}
//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
if (DotProduct (pmove->velocity, primal_velocity) <= 0)
{
//Con_DPrintf("Back\n");
VectorCopy (vec3_origin, pmove->velocity);
break;
}
}
}
if ( allFraction == 0 )
{
VectorCopy (vec3_origin, pmove->velocity);
//Con_DPrintf( "Don't stick\n" );
}
return blocked;
}
/*
==============
PM_Accelerate
==============
*/
void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
{
int i;
float addspeed, accelspeed, currentspeed;
// Dead player's don't accelerate
if (pmove->dead)
return;
// If waterjumping, don't accelerate
if (pmove->waterjumptime)
return;
// See if we are changing direction a bit
currentspeed = DotProduct (pmove->velocity, wishdir);