-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp_view.cpp
1446 lines (1195 loc) · 43.5 KB
/
p_view.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) ZeniMax Media Inc.
// Licensed under the GNU General Public License 2.0.
#include "g_local.h"
#include "monsters/m_player.h"
#include "bots/bot_includes.h"
static gentity_t *current_player;
static gclient_t *current_client;
static vec3_t forward, right, up;
float xyspeed;
float bobmove;
int bobcycle, bobcycle_run; // odd cycles are right foot going forward
float bobfracsin; // sinf(bobfrac*M_PI)
/*
===============
SkipViewModifiers
===============
*/
static inline bool SkipViewModifiers() {
if (g_skip_view_modifiers->integer && g_cheats->integer)
return true;
// don't do bobbing, etc on grapple
if (current_client->grapple_ent &&
current_client->grapple_state > GRAPPLE_STATE_FLY) {
return true;
}
// spectator mode
if (!ClientIsPlaying(current_client))
return true;
return false;
}
/*
===============
G_CalcRoll
===============
*/
static float G_CalcRoll(const vec3_t &angles, const vec3_t &velocity) {
if (SkipViewModifiers()) {
return 0.0f;
}
float sign;
float side;
float value;
side = velocity.dot(right);
sign = side < 0 ? -1.f : 1.f;
side = fabsf(side);
value = g_rollangle->value;
if (side < g_rollspeed->value)
side = side * value / g_rollspeed->value;
else
side = value;
return side * sign;
}
/*
===============
P_DamageFeedback
Handles color blends and view kicks
===============
*/
void P_DamageFeedback(gentity_t *player) {
gclient_t *client;
float side;
float realcount, count, kick;
vec3_t v;
int l;
constexpr vec3_t armor_color = { 1.0, 1.0, 1.0 };
constexpr vec3_t power_color = { 0.0, 1.0, 0.0 };
constexpr vec3_t bcolor = { 1.0, 0.0, 0.0 };
client = player->client;
// flash the backgrounds behind the status numbers
int16_t want_flashes = 0;
if (client->damage_blood)
want_flashes |= 1;
if (client->damage_armor && !(player->flags & FL_GODMODE))
want_flashes |= 2;
if (want_flashes) {
client->flash_time = level.time + 100_ms;
client->ps.stats[STAT_FLASHES] = want_flashes;
} else if (client->flash_time < level.time)
client->ps.stats[STAT_FLASHES] = 0;
// total points of damage shot at the player this frame
count = (float)(client->damage_blood + client->damage_armor + client->damage_parmor);
if (count == 0)
return; // didn't take any damage
// start a pain animation if still in the player model
if (client->anim_priority < ANIM_PAIN && player->s.modelindex == MODELINDEX_PLAYER) {
static int i;
client->anim_priority = ANIM_PAIN;
if (client->ps.pmove.pm_flags & PMF_DUCKED) {
player->s.frame = FRAME_crpain1 - 1;
client->anim_end = FRAME_crpain4;
} else {
i = (i + 1) % 3;
switch (i) {
case 0:
player->s.frame = FRAME_pain101 - 1;
client->anim_end = FRAME_pain104;
break;
case 1:
player->s.frame = FRAME_pain201 - 1;
client->anim_end = FRAME_pain204;
break;
case 2:
player->s.frame = FRAME_pain301 - 1;
client->anim_end = FRAME_pain304;
break;
}
}
client->anim_time = 0_ms;
}
realcount = count;
// if we took health damage, do a minimum clamp
if (client->damage_blood) {
if (count < 10)
count = 10; // always make a visible effect
} else {
if (count > 2)
count = 2; // don't go too deep
}
// play an appropriate pain sound
if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE)) {
player->pain_debounce_time = level.time + 700_ms;
constexpr const char *pain_sounds[] = {
"*pain25_1.wav",
"*pain25_2.wav",
"*pain50_1.wav",
"*pain50_2.wav",
"*pain75_1.wav",
"*pain75_2.wav",
"*pain100_1.wav",
"*pain100_2.wav",
};
if (player->health < 25)
l = 0;
else if (player->health < 50)
l = 2;
else if (player->health < 75)
l = 4;
else
l = 6;
if (brandom())
l |= 1;
gi.sound(player, CHAN_VOICE, gi.soundindex(pain_sounds[l]), 1, ATTN_NORM, 0);
// Paril: pain noises alert monsters
PlayerNoise(player, player->s.origin, PNOISE_SELF);
}
// the total alpha of the blend is always proportional to count
if (client->damage_alpha < 0)
client->damage_alpha = 0;
// [Paril-KEX] tweak the values to rely less on this
// and more on damage indicators
if (client->damage_blood || (client->damage_alpha + count * 0.06f) < 0.15f) {
client->damage_alpha += count * 0.06f;
if (client->damage_alpha < 0.06f)
client->damage_alpha = 0.06f;
if (client->damage_alpha > 0.4f)
client->damage_alpha = 0.4f; // don't go too saturated
}
// mix in colors
v = {};
if (client->damage_parmor)
v += power_color * (client->damage_parmor / realcount);
if (client->damage_blood)
v += bcolor * max(15.0f, (client->damage_blood / realcount));
if (client->damage_armor)
v += armor_color * (client->damage_armor / realcount);
client->damage_blend = v.normalized();
//
// calculate view angle kicks
//
kick = (float)abs(client->damage_knockback);
if (kick && player->health > 0) // kick of 0 means no view adjust at all
{
kick = kick * 100 / player->health;
if (kick < count * 0.5f)
kick = count * 0.5f;
if (kick > 50)
kick = 50;
v = client->damage_from - player->s.origin;
v.normalize();
side = v.dot(right);
client->v_dmg_roll = kick * side * 0.3f;
side = -v.dot(forward);
client->v_dmg_pitch = kick * side * 0.3f;
client->v_dmg_time = level.time + DAMAGE_TIME();
}
// [Paril-KEX] send view indicators
if (client->num_damage_indicators) {
gi.WriteByte(svc_damage);
gi.WriteByte(client->num_damage_indicators);
for (size_t i = 0; i < client->num_damage_indicators; i++) {
auto &indicator = client->damage_indicators[i];
// encode total damage into 5 bits
uint8_t encoded = std::clamp((indicator.health + indicator.power + indicator.armor) / 3, 1, 0x1F);
// encode types in the latter 3 bits
if (indicator.health)
encoded |= 0x20;
if (indicator.armor)
encoded |= 0x40;
if (indicator.power)
encoded |= 0x80;
gi.WriteByte(encoded);
gi.WriteDir((player->s.origin - indicator.from).normalized());
}
gi.unicast(player, false);
}
//
// clear totals
//
client->damage_blood = 0;
client->damage_armor = 0;
client->damage_parmor = 0;
client->damage_knockback = 0;
client->num_damage_indicators = 0;
}
/*
===============
G_CalcViewOffset
Auto pitching on slopes?
fall from 128: 400 = 160000
fall from 256: 580 = 336400
fall from 384: 720 = 518400
fall from 512: 800 = 640000
fall from 640: 960 =
damage = deltavelocity*deltavelocity * 0.0001
===============
*/
static void G_CalcViewOffset(gentity_t *ent) {
float bob;
float ratio;
float delta;
vec3_t v;
//===================================
// base angles
vec3_t &angles = ent->client->ps.kick_angles;
// if dead, fix the angle and don't add any kick
if (ent->deadflag && ClientIsPlaying(ent->client)) {
angles = {};
if (ent->flags & FL_SAM_RAIMI) {
ent->client->ps.viewangles[ROLL] = 0;
ent->client->ps.viewangles[PITCH] = 0;
} else {
ent->client->ps.viewangles[ROLL] = 40;
ent->client->ps.viewangles[PITCH] = -15;
}
ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;
} else if (!ent->client->pers.bob_skip && !SkipViewModifiers()) {
// add angles based on weapon kick
angles = P_CurrentKickAngles(ent);
// add angles based on damage kick
if (ent->client->v_dmg_time > level.time) {
// [Paril-KEX] 100ms of slack is added to account for
// visual difference in higher tickrates
gtime_t diff = ent->client->v_dmg_time - level.time;
// slack time remaining
if (DAMAGE_TIME_SLACK()) {
if (diff > DAMAGE_TIME() - DAMAGE_TIME_SLACK())
ratio = (DAMAGE_TIME() - diff).seconds() / DAMAGE_TIME_SLACK().seconds();
else
ratio = diff.seconds() / (DAMAGE_TIME() - DAMAGE_TIME_SLACK()).seconds();
} else
ratio = diff.seconds() / (DAMAGE_TIME() - DAMAGE_TIME_SLACK()).seconds();
angles[PITCH] += ratio * ent->client->v_dmg_pitch;
angles[ROLL] += ratio * ent->client->v_dmg_roll;
}
// add pitch based on fall kick
if (ent->client->fall_time > level.time) {
// [Paril-KEX] 100ms of slack is added to account for
// visual difference in higher tickrates
gtime_t diff = ent->client->fall_time - level.time;
// slack time remaining
if (DAMAGE_TIME_SLACK()) {
if (diff > FALL_TIME() - DAMAGE_TIME_SLACK())
ratio = (FALL_TIME() - diff).seconds() / DAMAGE_TIME_SLACK().seconds();
else
ratio = diff.seconds() / (FALL_TIME() - DAMAGE_TIME_SLACK()).seconds();
} else
ratio = diff.seconds() / (FALL_TIME() - DAMAGE_TIME_SLACK()).seconds();
angles[PITCH] += ratio * ent->client->fall_value;
}
// add angles based on velocity
if (!ent->client->pers.bob_skip && !SkipViewModifiers()) {
delta = ent->velocity.dot(forward);
angles[PITCH] += delta * run_pitch->value;
delta = ent->velocity.dot(right);
angles[ROLL] += delta * run_roll->value;
// add angles based on bob
delta = bobfracsin * bob_pitch->value * xyspeed;
if ((ent->client->ps.pmove.pm_flags & PMF_DUCKED) && ent->groundentity)
delta *= 6; // crouching
delta = min(delta, 1.2f);
angles[PITCH] += delta;
delta = bobfracsin * bob_roll->value * xyspeed;
if ((ent->client->ps.pmove.pm_flags & PMF_DUCKED) && ent->groundentity)
delta *= 6; // crouching
delta = min(delta, 1.2f);
if (bobcycle & 1)
delta = -delta;
angles[ROLL] += delta;
}
// add earthquake angles
if (ent->client->quake_time > level.time) {
float factor = min(1.0f, (ent->client->quake_time.seconds() / level.time.seconds()) * 0.25f);
angles.x += crandom_open() * factor;
angles.z += crandom_open() * factor;
angles.y += crandom_open() * factor;
}
}
// [Paril-KEX] clamp angles
for (int i = 0; i < 3; i++)
angles[i] = clamp(angles[i], -31.f, 31.f);
//===================================
// base origin
v = {};
// add fall height
if (!ent->client->pers.bob_skip && !SkipViewModifiers()) {
if (ent->client->fall_time > level.time) {
// [Paril-KEX] 100ms of slack is added to account for
// visual difference in higher tickrates
gtime_t diff = ent->client->fall_time - level.time;
// slack time remaining
if (DAMAGE_TIME_SLACK()) {
if (diff > FALL_TIME() - DAMAGE_TIME_SLACK())
ratio = (FALL_TIME() - diff).seconds() / DAMAGE_TIME_SLACK().seconds();
else
ratio = diff.seconds() / (FALL_TIME() - DAMAGE_TIME_SLACK()).seconds();
} else
ratio = diff.seconds() / (FALL_TIME() - DAMAGE_TIME_SLACK()).seconds();
v[2] -= ratio * ent->client->fall_value * 0.4f;
}
// add bob height
bob = bobfracsin * xyspeed * bob_up->value;
if (bob > 6)
bob = 6;
// gi.DebugGraph (bob *2, 255);
v[2] += bob;
}
// add kick offset
if (!ent->client->pers.bob_skip && !SkipViewModifiers())
v += P_CurrentKickOrigin(ent);
// absolutely bound offsets
// so the view can never be outside the player box
if (v[0] < -14)
v[0] = -14;
else if (v[0] > 14)
v[0] = 14;
if (v[1] < -14)
v[1] = -14;
else if (v[1] > 14)
v[1] = 14;
if (v[2] < -22)
v[2] = -22;
else if (v[2] > 30)
v[2] = 30;
ent->client->ps.viewoffset = v;
}
/*
==============
G_CalcGunOffset
==============
*/
static void G_CalcGunOffset(gentity_t *ent) {
int i;
if (ent->client->pers.weapon &&
!((ent->client->pers.weapon->id == IT_WEAPON_PLASMABEAM || ent->client->pers.weapon->id == IT_WEAPON_GRAPPLE) && ent->client->weaponstate == WEAPON_FIRING)
&& !SkipViewModifiers()) {
// gun angles from bobbing
ent->client->ps.gunangles[ROLL] = xyspeed * bobfracsin * 0.005f;
ent->client->ps.gunangles[YAW] = xyspeed * bobfracsin * 0.01f;
if (bobcycle & 1) {
ent->client->ps.gunangles[ROLL] = -ent->client->ps.gunangles[ROLL];
ent->client->ps.gunangles[YAW] = -ent->client->ps.gunangles[YAW];
}
ent->client->ps.gunangles[PITCH] = xyspeed * bobfracsin * 0.005f;
vec3_t viewangles_delta = ent->client->oldviewangles - ent->client->ps.viewangles;
for (i = 0; i < 3; i++)
ent->client->slow_view_angles[i] += viewangles_delta[i];
// gun angles from delta movement
for (i = 0; i < 3; i++) {
float &d = ent->client->slow_view_angles[i];
if (!d)
continue;
if (d > 180)
d -= 360;
if (d < -180)
d += 360;
if (d > 45)
d = 45;
if (d < -45)
d = -45;
// [Sam-KEX] Apply only half-delta. Makes the weapons look less detatched from the player.
if (i == ROLL)
ent->client->ps.gunangles[i] += (0.1f * d) * 0.5f;
else
ent->client->ps.gunangles[i] += (0.2f * d) * 0.5f;
float reduction_factor = viewangles_delta[i] ? 0.05f : 0.15f;
if (d > 0)
d = max(0.f, d - gi.frame_time_ms * reduction_factor);
else if (d < 0)
d = min(0.f, d + gi.frame_time_ms * reduction_factor);
}
// [Paril-KEX] cl_rollhack
ent->client->ps.gunangles[ROLL] = -ent->client->ps.gunangles[ROLL];
} else {
for (i = 0; i < 3; i++)
ent->client->ps.gunangles[i] = 0;
}
// gun height
ent->client->ps.gunoffset = {};
// gun_x / gun_y / gun_z are development tools
for (i = 0; i < 3; i++) {
ent->client->ps.gunoffset[i] += forward[i] * (gun_y->value);
ent->client->ps.gunoffset[i] += right[i] * gun_x->value;
ent->client->ps.gunoffset[i] += up[i] * (-gun_z->value);
}
}
/*
=============
G_CalcBlend
=============
*/
static void G_CalcBlend(gentity_t *ent) {
gtime_t remaining;
ent->client->ps.damage_blend = ent->client->ps.screen_blend = {};
// add for powerups
if (ent->client->pu_time_quad > level.time) {
remaining = ent->client->pu_time_quad - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage2.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(0, 0, 1, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_duelfire > level.time) {
remaining = ent->client->pu_time_duelfire - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/quadfire2.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(1, 0.2f, 0.5f, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_double > level.time) {
remaining = ent->client->pu_time_double - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/ddamage2.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(0.9f, 0.7f, 0, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_protection > level.time) {
remaining = ent->client->pu_time_protection - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(1, 1, 0, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_invisibility > level.time) {
remaining = ent->client->pu_time_invisibility - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(0.8f, 0.8f, 0.8f, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_regeneration > level.time) {
remaining = ent->client->pu_time_regeneration - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
} else if (ent->client->pu_time_enviro > level.time) {
remaining = ent->client->pu_time_enviro - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(0, 1, 0, 0.08f, ent->client->ps.screen_blend);
} else if (ent->client->pu_time_rebreather > level.time) {
remaining = ent->client->pu_time_rebreather - level.time;
if (remaining.milliseconds() == 3000) // beginning to fade
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
if (G_PowerUpExpiringRelative(remaining))
G_AddBlend(0.4f, 1, 0.4f, 0.04f, ent->client->ps.screen_blend);
}
if (ent->client->nuke_time > level.time) {
float brightness = (ent->client->nuke_time - level.time).seconds() / 2.0f;
G_AddBlend(1, 1, 1, brightness, ent->client->ps.screen_blend);
}
if ((ClientIsPredator(ent->client) && g_predator_ir->integer) || ent->client->ir_time > level.time) {
remaining = ent->client->ir_time - level.time;
if (G_PowerUpExpiringRelative(remaining)) {
ent->client->ps.rdflags |= RDF_IRGOGGLES;
G_AddBlend(1, 0, 0, 0.2f, ent->client->ps.screen_blend);
} else
ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
} else {
ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
}
// add for damage
if (ent->client->damage_alpha > 0)
G_AddBlend(ent->client->damage_blend[0], ent->client->damage_blend[1], ent->client->damage_blend[2], ent->client->damage_alpha, ent->client->ps.damage_blend);
// [Paril-KEX] drowning visual indicator
if (ent->air_finished < level.time + 9_sec) {
constexpr vec3_t drown_color = { 0.1f, 0.1f, 0.2f };
constexpr float max_drown_alpha = 0.75f;
float alpha = (ent->air_finished < level.time) ? 1 : (1.f - ((ent->air_finished - level.time).seconds() / 9.0f));
G_AddBlend(drown_color[0], drown_color[1], drown_color[2], min(alpha, max_drown_alpha), ent->client->ps.damage_blend);
}
// drop the damage value
ent->client->damage_alpha -= gi.frame_time_s * 0.6f;
if (ent->client->damage_alpha < 0)
ent->client->damage_alpha = 0;
// drop the bonus value
ent->client->bonus_alpha -= gi.frame_time_s;
if (ent->client->bonus_alpha < 0)
ent->client->bonus_alpha = 0;
}
/*
=============
P_WorldEffects
=============
*/
static void P_WorldEffects() {
bool breather, envirosuit, protection;
water_level_t waterlevel, old_waterlevel;
if (current_player->movetype == MOVETYPE_FREECAM) {
current_player->air_finished = level.time + 12_sec; // don't need air
return;
}
waterlevel = current_player->waterlevel;
old_waterlevel = current_client->old_waterlevel;
current_client->old_waterlevel = waterlevel;
breather = current_client->pu_time_rebreather > level.time;
envirosuit = current_client->pu_time_enviro > level.time;
protection = current_client->pu_time_protection > level.time;
//
// if just entered a water volume, play a sound
//
if (!old_waterlevel && waterlevel) {
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
if (current_player->watertype & CONTENTS_LAVA)
gi.sound(current_player, CHAN_BODY, gi.soundindex("player/lava_in.wav"), 1, ATTN_NORM, 0);
else if (current_player->watertype & CONTENTS_SLIME)
gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
else if (current_player->watertype & CONTENTS_WATER)
gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
current_player->flags |= FL_INWATER;
// clear damage_debounce, so the pain sound will play immediately
current_player->damage_debounce_time = level.time - 1_sec;
}
//
// if just completely exited a water volume, play a sound
//
if (old_waterlevel && !waterlevel) {
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
current_player->flags &= ~FL_INWATER;
}
//
// check for head just going under water
//
if (old_waterlevel != WATER_UNDER && waterlevel == WATER_UNDER) {
gi.sound(current_player, CHAN_BODY, gi.soundindex("player/watr_un.wav"), 1, ATTN_NORM, 0);
}
//
// check for head just coming out of water
//
if (current_player->health > 0 && old_waterlevel == WATER_UNDER && waterlevel != WATER_UNDER) {
if (current_player->air_finished < level.time) { // gasp for air
gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/gasp1.wav"), 1, ATTN_NORM, 0);
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
} else if (current_player->air_finished < level.time + 11_sec) { // just break surface
gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/gasp2.wav"), 1, ATTN_NORM, 0);
}
}
//
// check for drowning
//
if (waterlevel == WATER_UNDER) {
// breather or envirosuit give air
if (breather || envirosuit) {
current_player->air_finished = level.time + 10_sec;
if (((current_client->pu_time_rebreather - level.time).milliseconds() % 2500) == 0) {
if (!current_client->breather_sound)
gi.sound(current_player, CHAN_AUTO, gi.soundindex("player/u_breath1.wav"), 1, ATTN_NORM, 0);
else
gi.sound(current_player, CHAN_AUTO, gi.soundindex("player/u_breath2.wav"), 1, ATTN_NORM, 0);
current_client->breather_sound ^= 1;
PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
// FIXME: release a bubble?
}
}
// if out of air, start drowning
if (current_player->air_finished < level.time) { // drown!
if (current_player->client->next_drown_time < level.time && current_player->health > 0) {
current_player->client->next_drown_time = level.time + 1_sec;
// take more damage the longer underwater
current_player->dmg += 2;
if (current_player->dmg > 15)
current_player->dmg = 15;
// play a gurp sound instead of a normal pain sound
if (current_player->health <= current_player->dmg)
gi.sound(current_player, CHAN_VOICE, gi.soundindex("*drown1.wav"), 1, ATTN_NORM, 0); // [Paril-KEX]
else if (brandom())
gi.sound(current_player, CHAN_VOICE, gi.soundindex("*gurp1.wav"), 1, ATTN_NORM, 0);
else
gi.sound(current_player, CHAN_VOICE, gi.soundindex("*gurp2.wav"), 1, ATTN_NORM, 0);
current_player->pain_debounce_time = level.time;
T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, current_player->dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
}
}
// Paril: almost-drowning sounds
else if (current_player->air_finished <= level.time + 3_sec) {
if (current_player->client->next_drown_time < level.time) {
gi.sound(current_player, CHAN_VOICE, gi.soundindex(fmt::format("player/wade{}.wav", 1 + ((int32_t)level.time.seconds() % 3)).c_str()), 1, ATTN_NORM, 0);
current_player->client->next_drown_time = level.time + 1_sec;
}
}
} else {
current_player->air_finished = level.time + 12_sec;
current_player->dmg = 2;
}
//
// check for sizzle damage
//
if (waterlevel && (current_player->watertype & (CONTENTS_LAVA | CONTENTS_SLIME)) && current_player->slime_debounce_time <= level.time) {
if (current_player->watertype & CONTENTS_LAVA) {
if (current_player->health > 0 && current_player->pain_debounce_time <= level.time) {
if (brandom())
gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/burn1.wav"), 1, ATTN_NORM, 0);
else
gi.sound(current_player, CHAN_VOICE, gi.soundindex("player/burn2.wav"), 1, ATTN_NORM, 0);
if (envirosuit || protection)
gi.sound(current_player, CHAN_AUX, gi.soundindex("items/protect3.wav"), 1, ATTN_NORM, 0);
current_player->pain_debounce_time = level.time + 1_sec;
}
int dmg = ((envirosuit || protection) ? 1 : 3) * waterlevel; // take 1/3 damage with envirosuit/protection
T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, dmg, 0, DAMAGE_NONE, MOD_LAVA);
current_player->slime_debounce_time = level.time + 10_hz;
}
if (current_player->watertype & CONTENTS_SLIME) {
if (!envirosuit && !protection) { // no damage from slime with envirosuit/protection
T_Damage(current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1 * waterlevel, 0, DAMAGE_NONE, MOD_SLIME);
current_player->slime_debounce_time = level.time + 10_hz;
} else {
if (current_player->health > 0 && current_player->pain_debounce_time <= level.time) {
gi.sound(current_player, CHAN_AUX, gi.soundindex("items/protect3.wav"), 1, ATTN_NORM, 0);
current_player->pain_debounce_time = level.time + 1_sec;
}
}
}
}
}
/*
===============
G_SetClientEffects
===============
*/
static void G_SetClientEffects(gentity_t *ent) {
int pa_type;
ent->s.effects = EF_NONE;
ent->s.renderfx &= RF_STAIR_STEP;
ent->s.renderfx |= RF_IR_VISIBLE;
ent->s.alpha = 1.0;
if (ent->health <= 0 || ent->client->eliminated || level.intermission_time)
return;
if (ent->flags & FL_FLASHLIGHT)
ent->s.effects |= EF_FLASHLIGHT;
if (ent->flags & FL_DISGUISED)
ent->s.renderfx |= RF_USE_DISGUISE;
if (ent->powerarmor_time > level.time) {
pa_type = PowerArmorType(ent);
if (pa_type == IT_POWER_SCREEN) {
ent->s.effects |= EF_POWERSCREEN;
} else if (pa_type == IT_POWER_SHIELD) {
ent->s.effects |= EF_COLOR_SHELL;
ent->s.renderfx |= RF_SHELL_GREEN;
}
}
if (ent->client->pu_regen_time_blip > level.time) {
ent->s.effects |= EF_COLOR_SHELL;
ent->s.renderfx |= RF_SHELL_RED;
}
if (ent->client->pu_time_quad > level.time)
if (G_PowerUpExpiring(ent->client->pu_time_quad))
ent->s.effects |= EF_QUAD;
if (ent->client->pu_time_protection > level.time)
if (G_PowerUpExpiring(ent->client->pu_time_protection))
ent->s.effects |= EF_PENT;
if (ent->client->pu_time_duelfire > level.time)
if (G_PowerUpExpiring(ent->client->pu_time_duelfire))
ent->s.effects |= EF_DUALFIRE;
if (ent->client->pu_time_double > level.time)
if (G_PowerUpExpiring(ent->client->pu_time_double))
ent->s.effects |= EF_DOUBLE;
if ((ent->client->owned_sphere) && (ent->client->owned_sphere->spawnflags == SF_SPHERE_DEFENDER))
ent->s.effects |= EF_HALF_DAMAGE;
if (ent->client->tracker_pain_time > level.time)
ent->s.effects |= EF_TRACKERTRAIL;
if (ClientIsPredator(ent->client) || ent->client->pu_time_invisibility > level.time) {
if (ent->client->invisibility_fade_time <= level.time)
ent->s.alpha = 0.05f;
else {
float x = (ent->client->invisibility_fade_time - level.time).seconds() / INVISIBILITY_TIME.seconds();
ent->s.alpha = std::clamp(x, 0.05f, 0.2f);
}
}
}
/*
===============
G_SetClientEvent
===============
*/
static void G_SetClientEvent(gentity_t *ent) {
if (ent->s.event)
return;
if (ent->client->ps.pmove.pm_flags & PMF_ON_LADDER) {
if (g_ladder_steps->integer > 1 || (g_ladder_steps->integer == 1 && !deathmatch->integer)) {
if (current_client->last_ladder_sound < level.time &&
(current_client->last_ladder_pos - ent->s.origin).length() > 48.f) {
ent->s.event = EV_LADDER_STEP;
current_client->last_ladder_pos = ent->s.origin;
current_client->last_ladder_sound = level.time + LADDER_SOUND_TIME;
}
}
} else if (ent->groundentity && xyspeed > 225) {
if ((int)(current_client->bobtime + bobmove) != bobcycle_run)
ent->s.event = EV_FOOTSTEP;
}
}
/*
===============
G_SetClientSound
===============
*/
static void G_SetClientSound(gentity_t *ent) {
// help beep (no more than three times)
if (ent->client->pers.helpchanged && ent->client->pers.helpchanged <= 3 && ent->client->pers.help_time < level.time) {
if (ent->client->pers.helpchanged == 1) // [KEX] haleyjd: once only
gi.sound(ent, CHAN_AUTO, gi.soundindex("misc/pc_up.wav"), 1, ATTN_STATIC, 0);
ent->client->pers.helpchanged++;
ent->client->pers.help_time = level.time + 5_sec;
}
// reset defaults
ent->s.sound = 0;
ent->s.loop_attenuation = 0;
ent->s.loop_volume = 0;
if (ent->waterlevel && (ent->watertype & (CONTENTS_LAVA | CONTENTS_SLIME))) {
ent->s.sound = snd_fry;
return;
}
if (ent->deadflag || !ClientIsPlaying(ent->client) || ent->client->eliminated)
return;
if (ent->client->weapon_sound)
ent->s.sound = ent->client->weapon_sound;
else if (ent->client->pers.weapon) {
if (ent->client->pers.weapon->id == IT_WEAPON_RAILGUN)
ent->s.sound = gi.soundindex("weapons/rg_hum.wav");
else if (ent->client->pers.weapon->id == IT_WEAPON_BFG)
ent->s.sound = gi.soundindex("weapons/bfg_hum.wav");
else if (ent->client->pers.weapon->id == IT_WEAPON_PLASMABEAM)
ent->s.sound = gi.soundindex("weapons/traploop.wav");
else if (ent->client->pers.weapon->id == IT_WEAPON_PHALANX)
ent->s.sound = gi.soundindex("weapons/phaloop.wav");
}
// [Paril-KEX] if no other sound is playing, play appropriate grapple sounds
if (!ent->s.sound && ent->client->grapple_ent) {
if (ent->client->grapple_state == GRAPPLE_STATE_PULL)
ent->s.sound = gi.soundindex("weapons/grapple/grpull.wav");
else if (ent->client->grapple_state == GRAPPLE_STATE_FLY)
ent->s.sound = gi.soundindex("weapons/grapple/grfly.wav");
else if (ent->client->grapple_state == GRAPPLE_STATE_HANG)
ent->s.sound = gi.soundindex("weapons/grapple/grhang.wav");
}
// weapon sounds play at a higher attn
ent->s.loop_attenuation = ATTN_NORM;
}
/*
===============
G_SetClientFrame
===============
*/
void G_SetClientFrame(gentity_t *ent) {
gclient_t *client;
bool duck, run;
if (ent->s.modelindex != MODELINDEX_PLAYER)
return; // not in the player model
client = ent->client;
duck = client->ps.pmove.pm_flags & PMF_DUCKED ? true : false;
run = xyspeed ? true : false;
// check for stand/duck and stop/go transitions
if (duck != client->anim_duck && client->anim_priority < ANIM_DEATH)
goto newanim;
if (run != client->anim_run && client->anim_priority == ANIM_BASIC)
goto newanim;
if (!ent->groundentity && client->anim_priority <= ANIM_WAVE)
goto newanim;
if (client->anim_time > level.time)
return;
else if ((client->anim_priority & ANIM_REVERSED) && (ent->s.frame > client->anim_end)) {
if (client->anim_time <= level.time) {
ent->s.frame--;
client->anim_time = level.time + 10_hz;
}
return;
} else if (!(client->anim_priority & ANIM_REVERSED) && (ent->s.frame < client->anim_end)) {
// continue an animation
if (client->anim_time <= level.time) {
ent->s.frame++;
client->anim_time = level.time + 10_hz;
}
return;
}
if (client->anim_priority == ANIM_DEATH)
return; // stay there
if (client->anim_priority == ANIM_JUMP) {
if (!ent->groundentity)
return; // stay there
ent->client->anim_priority = ANIM_WAVE;
if (duck) {
ent->s.frame = FRAME_jump6;
ent->client->anim_end = FRAME_jump4;
ent->client->anim_priority |= ANIM_REVERSED;
} else {
ent->s.frame = FRAME_jump3;
ent->client->anim_end = FRAME_jump6;
}
ent->client->anim_time = level.time + 10_hz;
return;
}
newanim:
// return to either a running or standing frame
client->anim_priority = ANIM_BASIC;
client->anim_duck = duck;
client->anim_run = run;
client->anim_time = level.time + 10_hz;
if (!ent->groundentity) {
// if on grapple, don't go into jump frame, go into standing
// frame
if (client->grapple_ent) {
if (duck) {
ent->s.frame = FRAME_crstnd01;
client->anim_end = FRAME_crstnd19;
} else {
ent->s.frame = FRAME_stand01;
client->anim_end = FRAME_stand40;
}
} else {
client->anim_priority = ANIM_JUMP;
if (duck) {
if (ent->s.frame != FRAME_crwalk2)
ent->s.frame = FRAME_crwalk1;
client->anim_end = FRAME_crwalk2;
} else {
if (ent->s.frame != FRAME_jump2)
ent->s.frame = FRAME_jump1;
client->anim_end = FRAME_jump2;
}
}