/
cg_players.c
3395 lines (2932 loc) · 85.7 KB
/
cg_players.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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012-2018 ET:Legacy team <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*/
/**
* @file cg_players.c
* @brief Handle the media and animation for player entities
*/
#include "cg_local.h"
#define SWING_RIGHT 1.f
#define SWING_LEFT 2.f
extern const char *cg_skillRewards[SK_NUM_SKILLS][NUM_SKILL_LEVELS - 1];
/**
* @brief CG_EntOnFire
* @param[in] cent
* @return
*/
qboolean CG_EntOnFire(centity_t *cent)
{
// don't display on respawn
if (cent->currentState.powerups & (1 << PW_INVULNERABLE))
{
return qfalse;
}
if (cent->currentState.number == cg.snap->ps.clientNum && cent->currentState.eType != ET_CORPSE)
{
// the player is always starting out on fire, which is easily seen in cinematics
// so make sure onFireStart is not 0
return (cg.snap->ps.onFireStart
&& (cg.snap->ps.onFireStart < cg.time)
&& ((cg.snap->ps.onFireStart + 2000) > cg.time));
}
else
{
return ((cent->currentState.onFireStart < cg.time) &&
(cent->currentState.onFireEnd > cg.time));
}
}
/**
* @brief CG_IsCrouchingAnim
* @param[in] animModelInfo
* @param[in] animNum
* @return
*/
qboolean CG_IsCrouchingAnim(animModelInfo_t *animModelInfo, int animNum)
{
animation_t *anim;
// FIXME: make compatible with new scripting
animNum &= ~ANIM_TOGGLEBIT;
anim = BG_GetAnimationForIndex(animModelInfo, animNum);
if (anim->movetype & ((1 << ANIM_MT_IDLECR) | (1 << ANIM_MT_WALKCR) | (1 << ANIM_MT_WALKCRBK)))
{
return qtrue;
}
return qfalse;
}
/**
* @brief CG_CustomSound
* @param clientNum - unused
* @param[in] soundName
* @return
*/
sfxHandle_t CG_CustomSound(int clientNum, const char *soundName)
{
if (soundName[0] != '*')
{
return trap_S_RegisterSound(soundName, qfalse);
}
return 0;
}
/*
=============================================================================
CLIENT INFO
=============================================================================
*/
/**
* @brief Load it now, taking the disk hits.
* This will usually be deferred to a safe time
* @param clientNum
*/
static void CG_LoadClientInfo(int clientNum)
{
int i;
// reset any existing players and bodies, because they might be in bad
// frames for this new model
for (i = 0 ; i < MAX_GENTITIES ; i++)
{
if (cg_entities[i].currentState.clientNum == clientNum && cg_entities[i].currentState.eType == ET_PLAYER)
{
CG_ResetPlayerEntity(&cg_entities[i]);
}
}
}
/**
* @brief CG_ParseTeamXPs
* @param[in] n
*/
void CG_ParseTeamXPs(int n)
{
int i, j;
char *cs = (char *)CG_ConfigString(CS_AXIS_MAPS_XP + n);
const char *token;
for (i = 0; i < MAX_MAPS_PER_CAMPAIGN; i++)
{
for (j = 0; j < SK_NUM_SKILLS; j++)
{
token = COM_ParseExt(&cs, qfalse);
if (!token[0])
{
return;
}
if (n == 0)
{
cgs.tdbAxisMapsXP[j][i] = atoi(token);
}
else
{
cgs.tdbAlliedMapsXP[j][i] = atoi(token);
}
}
}
}
void CG_LimboPanel_SendSetupMsg(qboolean forceteam);
/**
* @brief CG_NewClientInfo
* @param[in] clientNum
*/
void CG_NewClientInfo(int clientNum)
{
clientInfo_t *ci = &cgs.clientinfo[clientNum];
clientInfo_t newInfo;
const char *configstring;
const char *v;
configstring = CG_ConfigString(clientNum + CS_PLAYERS);
if (!*configstring)
{
Com_Memset(ci, 0, sizeof(*ci));
return; // player just left
}
// build into a temp buffer so the defer checks can use
// the old value
Com_Memset(&newInfo, 0, sizeof(newInfo));
// grabbing some older stuff, if it's a new client, tinfo will update within one second anyway, otherwise you get the health thing flashing red
// NOTE: why are we bothering to do all this setting up of a new clientInfo_t anyway? it was all for deffered clients iirc, which we dont have
VectorCopy(ci->location, newInfo.location);
newInfo.health = ci->health;
newInfo.fireteamData = ci->fireteamData;
newInfo.clientNum = clientNum;
newInfo.selected = ci->selected;
// isolate the player's name
v = Info_ValueForKey(configstring, "n");
Q_strncpyz(newInfo.name, v, sizeof(newInfo.name));
Q_strncpyz(newInfo.cleanname, v, sizeof(newInfo.cleanname));
Q_CleanStr(newInfo.cleanname);
// bot skill
v = Info_ValueForKey(configstring, "skill");
newInfo.botSkill = atoi(v);
// team
v = Info_ValueForKey(configstring, "t");
newInfo.team = (team_t)(atoi(v));
// class
v = Info_ValueForKey(configstring, "c");
newInfo.cls = atoi(v);
// latched class
v = Info_ValueForKey(configstring, "lc");
newInfo.latchedcls = atoi(v);
// rank
v = Info_ValueForKey(configstring, "r");
newInfo.rank = atoi(v);
// fireteam
v = Info_ValueForKey(configstring, "f");
newInfo.fireteam = atoi(v);
v = Info_ValueForKey(configstring, "m");
if (*v)
{
int i;
char buf[2];
buf[1] = '\0';
for (i = 0; i < SK_NUM_SKILLS; i++)
{
buf[0] = *v;
newInfo.medals[i] = atoi(buf);
v++;
}
}
v = Info_ValueForKey(configstring, "ch");
if (*v)
{
newInfo.character = cgs.gameCharacters[atoi(v)];
}
v = Info_ValueForKey(configstring, "s");
if (*v)
{
int i;
for (i = 0; i < SK_NUM_SKILLS; i++)
{
char skill[2];
skill[0] = v[i];
skill[1] = '\0';
newInfo.skill[i] = atoi(skill);
}
}
// disguise clientNum
v = Info_ValueForKey(configstring, "dn");
newInfo.disguiseClientNum = atoi(v);
// weapon and latchedweapon ( FIXME: make these more secure )
v = Info_ValueForKey(configstring, "w");
newInfo.weapon = atoi(v);
v = Info_ValueForKey(configstring, "lw");
newInfo.latchedweapon = atoi(v);
v = Info_ValueForKey(configstring, "sw");
newInfo.secondaryweapon = atoi(v);
v = Info_ValueForKey(configstring, "lsw");
newInfo.latchedsecondaryweapon = atoi(v);
v = Info_ValueForKey(configstring, "ref");
newInfo.refStatus = atoi(v);
v = Info_ValueForKey(configstring, "sc");
newInfo.shoutcaster = atoi(v);
// Detect rank/skill changes client side.
// Make sure we have some valid clientinfo, otherwise people are thrown
// into spectator on map starts.
if (clientNum == cg.clientNum && cgs.clientinfo[cg.clientNum].team > 0)
{
int i;
if (newInfo.team != cgs.clientinfo[cg.clientNum].team)
{
if (cgs.autoFireteamCreateEndTime != cg.time + 20000)
{
cgs.autoFireteamCreateEndTime = 0;
}
if (cgs.autoFireteamJoinEndTime != cg.time + 20000)
{
cgs.autoFireteamJoinEndTime = 0;
}
}
#ifdef FEATURE_EDV
if (newInfo.rank > cgs.clientinfo[cg.clientNum].rank && !cgs.demoCamera.renderingFreeCam && !cgs.demoCamera.renderingWeaponCam)
#else
if (newInfo.rank > cgs.clientinfo[cg.clientNum].rank)
#endif
{
CG_SoundPlaySoundScript(GetRankTableData(cgs.clientinfo[cg.clientNum].team, newInfo.rank)->soundNames, NULL, -1, qtrue);
if (!(cg_popupBigFilter.integer & POPUP_BIG_FILTER_RANK))
{
CG_AddPMItemBig(PM_RANK, va(CG_TranslateString("Promoted to rank %s!"), GetRankTableData(cgs.clientinfo[cg.clientNum].team, newInfo.rank)->names), rankicons[newInfo.rank][cgs.clientinfo[cg.clientNum].team == TEAM_AXIS ? 1 : 0][0].shader);
}
}
// Make sure primary class and primary weapons are correct for
// subsequent calls to CG_LimboPanel_SendSetupMsg
CG_LimboPanel_Setup();
for (i = 0; i < SK_NUM_SKILLS; i++)
{
if (newInfo.skill[i] > cgs.clientinfo[cg.clientNum].skill[i])
{
// NOTE: slick hack so that funcs we call use the new value now
cgs.clientinfo[cg.clientNum].skill[i] = newInfo.skill[i];
if (newInfo.skill[i] == 4 && (i == SK_HEAVY_WEAPONS || i == SK_LIGHT_WEAPONS))
{
bg_playerclass_t *classinfo;
classinfo = BG_GetPlayerClassInfo(cgs.clientinfo[cg.clientNum].team, cgs.clientinfo[cg.clientNum].cls);
// Only select new weapon if using the first weapon (pistol 0)
if (cgs.ccSelectedSecondaryWeapon == classinfo->classSecondaryWeapons[0].weapon)
{
CG_LimboPanel_SetDefaultWeapon(SECONDARY_SLOT);
CG_LimboPanel_SendSetupMsg(qfalse);
}
}
#ifdef FEATURE_EDV
if (!cgs.demoCamera.renderingFreeCam && !cgs.demoCamera.renderingWeaponCam)
{
#endif
if (!(cg_popupBigFilter.integer & POPUP_BIG_FILTER_SKILL))
{
CG_AddPMItemBig(PM_SKILL, va(CG_TranslateString("Increased %s skill to level %i!"), CG_TranslateString(GetSkillTableData(i)->skillNames), newInfo.skill[i]), cgs.media.skillPics[i]);
}
CG_PriorityCenterPrint(va(CG_TranslateString("You have been rewarded with %s"), CG_TranslateString(cg_skillRewards[i][newInfo.skill[i] - 1])), 400, cg_fontScaleCP.value, 99999);
#ifdef FEATURE_EDV
}
#endif
}
}
if (newInfo.team != cgs.clientinfo[cg.clientNum].team)
{
// clear these
Com_Memset(cg.artilleryRequestPos, 0, sizeof(cg.artilleryRequestPos));
Com_Memset(cg.artilleryRequestTime, 0, sizeof(cg.artilleryRequestTime));
}
trap_Cvar_Set("authLevel", va("%i", newInfo.refStatus));
if (newInfo.refStatus != ci->refStatus)
{
if (newInfo.refStatus <= RL_NONE)
{
const char *info = CG_ConfigString(CS_SERVERINFO);
trap_Cvar_Set("cg_ui_voteFlags", Info_ValueForKey(info, "voteFlags"));
CG_Printf("[cgnotify]^3*** You have been stripped of your referee status! ***\n");
}
else
{
trap_Cvar_Set("cg_ui_voteFlags", "0");
CG_Printf("[cgnotify]^2*** You have been authorized \"%s\" status ***\n", ((newInfo.refStatus == RL_RCON) ? "rcon" : "referee"));
CG_Printf("Type: ^3ref^7 (by itself) for a list of referee commands.\n");
}
}
if (newInfo.shoutcaster != ci->shoutcaster)
{
if (newInfo.shoutcaster <= 0)
{
const char *info = CG_ConfigString(CS_SERVERINFO);
CG_Printf("[cgnotify]^3*** You have been stripped of your shoutcaster status! ***\n");
}
else
{
CG_Printf("[cgnotify]^2*** You have been authorized \"shoutcaster\" status ***\n");
}
}
}
// passing the clientNum since that's all we need, and we
// can't calculate it properly from the clientinfo
CG_LoadClientInfo(clientNum);
// replace whatever was there with the new one
newInfo.infoValid = qtrue;
*ci = newInfo;
// make sure we have a character set
if (!ci->character)
{
ci->character = BG_GetCharacter(ci->team, ci->cls);
}
// need to resort the fireteam list, in case ranks etc have changed
CG_SortClientFireteam();
}
/*
=============================================================================
PLAYER ANIMATION
=============================================================================
*/
/**
* @brief CG_PlayerClassForClientinfo
* @param[in] ci
* @param[in] cent
* @return
*/
bg_playerclass_t *CG_PlayerClassForClientinfo(clientInfo_t *ci, centity_t *cent)
{
int team, cls;
if (cent && cent->currentState.eType == ET_CORPSE)
{
return BG_GetPlayerClassInfo(cent->currentState.modelindex, cent->currentState.modelindex2);
}
if (cent && (cent->currentState.powerups & (1 << PW_OPS_DISGUISED)))
{
team = ci->team == TEAM_AXIS ? TEAM_ALLIES : TEAM_AXIS;
// fixed incorrect class determination (was & 6, should be & 7)
cls = (cent->currentState.powerups >> PW_OPS_CLASS_1) & 7;
return BG_GetPlayerClassInfo(team, cls);
}
return BG_GetPlayerClassInfo(ci->team, ci->cls);
}
/**
* @brief CG_SetLerpFrameAnimation
* @param cent
* @param ci
* @param lf
* @param newAnimation
* @note May include ANIM_TOGGLEBIT
*/
static void CG_SetLerpFrameAnimation(centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int newAnimation)
{
animation_t *anim;
bg_character_t *character;
character = CG_CharacterForClientinfo(ci, cent);
if (!character)
{
CG_Printf("Warning: CG_SetLerpFrameAnimation w/o character.\n");
return;
}
lf->animationNumber = newAnimation;
newAnimation &= ~ANIM_TOGGLEBIT;
if (newAnimation < 0 || newAnimation >= character->animModelInfo->numAnimations)
{
CG_Error("CG_SetLerpFrameAnimation: Bad animation number: %i\n", newAnimation);
}
anim = character->animModelInfo->animations[newAnimation];
lf->animation = anim;
lf->animationTime = lf->frameTime + anim->initialLerp;
if (cg_debugAnim.integer == 1)
{
CG_Printf("Anim: %i, %s\n", newAnimation, character->animModelInfo->animations[newAnimation]->name);
}
}
/**
* @brief Sets cg.snap, cg.oldFrame, and cg.backlerp
* cg.time should be between oldFrameTime and frameTime after exit
* @param[in] cent
* @param[in] ci
* @param[in,out] lf
* @param[in] newAnimation
* @param[in] speedScale
*/
void CG_RunLerpFrame(centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale)
{
// debugging tool to get no animations
if (cg_animSpeed.integer == 0)
{
lf->oldFrame = lf->frame = 0;
lf->backlerp = 0;
return;
}
// see if the animation sequence is switching
if (ci && (newAnimation != lf->animationNumber || !lf->animation))
{
CG_SetLerpFrameAnimation(cent, ci, lf, newAnimation);
}
// if we have passed the current frame, move it to
// oldFrame and calculate a new frame
if (cg.time >= lf->frameTime)
{
animation_t *anim;
int f;
lf->oldFrame = lf->frame;
lf->oldFrameTime = lf->frameTime;
lf->oldFrameModel = lf->frameModel;
// get the next frame based on the animation
anim = lf->animation;
if (!anim || !anim->frameLerp)
{
CG_Printf("Warning: CG_RunLerpFrame w/o animation.\n");
return; // shouldn't happen
}
if (cg.time < lf->animationTime)
{
lf->frameTime = lf->animationTime; // initial lerp
}
else
{
lf->frameTime = lf->oldFrameTime + anim->frameLerp;
}
f = (lf->frameTime - lf->animationTime) / anim->frameLerp;
f *= speedScale; // adjust for haste, etc
if (f >= anim->numFrames)
{
f -= anim->numFrames;
if (anim->loopFrames)
{
f %= anim->loopFrames;
f += anim->numFrames - anim->loopFrames;
}
else
{
f = anim->numFrames - 1;
// the animation is stuck at the end, so it
// can immediately transition to another sequence
lf->frameTime = cg.time;
}
}
lf->frame = anim->firstFrame + f;
lf->frameModel = anim->mdxFile;
if (cg.time > lf->frameTime)
{
lf->frameTime = cg.time;
if (cg_debugAnim.integer)
{
CG_Printf("Clamp lf->frameTime\n");
}
}
}
if (lf->frameTime > cg.time + 200)
{
lf->frameTime = cg.time;
}
if (lf->oldFrameTime > cg.time)
{
lf->oldFrameTime = cg.time;
}
// calculate current lerp value
if (lf->frameTime == lf->oldFrameTime)
{
lf->backlerp = 0;
}
else
{
lf->backlerp = 1.0f - (float)(cg.time - lf->oldFrameTime) / (lf->frameTime - lf->oldFrameTime);
}
}
/**
* @brief CG_ClearLerpFrame
* @param[in] cent
* @param[in] ci
* @param[in,out] lf
* @param animationNumber
*/
static void CG_ClearLerpFrame(centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int animationNumber)
{
lf->frameTime = lf->oldFrameTime = cg.time;
CG_SetLerpFrameAnimation(cent, ci, lf, animationNumber);
if (lf->animation)
{
lf->oldFrame = lf->frame = lf->animation->firstFrame;
lf->oldFrameModel = lf->frameModel = lf->animation->mdxFile;
}
}
/**
* @brief CG_SetLerpFrameAnimationRate
* @param[in] cent
* @param[in] ci
* @param[in,out] lf
* @param[in] newAnimation
* @note May include ANIM_TOGGLEBIT
*/
void CG_SetLerpFrameAnimationRate(centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int newAnimation)
{
animation_t *anim, *oldanim;
int oldAnimNum; // oldAnimTime
qboolean firstAnim = qfalse;
bg_character_t *character;
character = CG_CharacterForClientinfo(ci, cent);
if (!character)
{
CG_Printf("Warning: CG_SetLerpFrameAnimationRate w/o character.\n");
return;
}
// oldAnimTime = lf->animationTime;
oldanim = lf->animation;
oldAnimNum = lf->animationNumber;
if (!lf->animation)
{
firstAnim = qtrue;
}
lf->animationNumber = newAnimation;
newAnimation &= ~ANIM_TOGGLEBIT;
if (newAnimation < 0 || newAnimation >= character->animModelInfo->numAnimations)
{
CG_Error("CG_SetLerpFrameAnimationRate: Bad animation number: %i\n", newAnimation);
}
anim = character->animModelInfo->animations[newAnimation];
lf->animation = anim;
lf->animationTime = lf->frameTime + anim->initialLerp;
if (!(anim->flags & ANIMFL_FIRINGANIM) || (lf != ¢->pe.torso))
{
int transitionMin = -1;
if ((lf == ¢->pe.legs) && (CG_IsCrouchingAnim(character->animModelInfo, newAnimation) != CG_IsCrouchingAnim(character->animModelInfo, oldAnimNum)))
{
if (anim->moveSpeed || (anim->movetype & ((1 << ANIM_MT_TURNLEFT) | (1 << ANIM_MT_TURNRIGHT)))) // if unknown movetype, go there faster
{
transitionMin = lf->frameTime + 200; // slowly raise/drop
}
else
{
transitionMin = lf->frameTime + 350; // slowly raise/drop
}
}
else if (anim->moveSpeed)
{
transitionMin = lf->frameTime + 120; // always do some lerping (?)
}
else // not moving, so take your time
{
transitionMin = lf->frameTime + 170; // always do some lerping (?)
}
if (oldanim && oldanim->animBlend) //transitionMin < lf->frameTime + oldanim->animBlend) {
{
transitionMin = lf->frameTime + oldanim->animBlend;
lf->animationTime = transitionMin;
}
else
{
// slow down transitions according to speed
if (anim->moveSpeed && lf->animSpeedScale < 1.0f)
{
lf->animationTime += anim->initialLerp;
}
if (lf->animationTime < transitionMin)
{
lf->animationTime = transitionMin;
}
}
}
// if first anim, go immediately
if (firstAnim)
{
lf->frameTime = cg.time - 1;
lf->animationTime = cg.time - 1;
lf->frame = anim->firstFrame;
lf->frameModel = anim->mdxFile;
}
if (cg_debugAnim.integer == 1) // extra debug info
{
CG_Printf("Anim: %i, %s\n", newAnimation, character->animModelInfo->animations[newAnimation]->name);
}
}
#define ANIM_SCALEMAX_LOW 1.1f
#define ANIM_SCALEMAX_HIGH 1.6f
#define ANIM_SPEEDMAX_LOW 100
#define ANIM_SPEEDMAX_HIGH 20
/**
* @brief Sets cg.snap, cg.oldFrame, and cg.backlerp
* cg.time should be between oldFrameTime and frameTime after exit
* @param[in] ci
* @param[in,out] lf
* @param[in] newAnimation
* @param[in] cent
* @param[in] recursion
*/
void CG_RunLerpFrameRate(clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, centity_t *cent, int recursion)
{
animation_t *anim, *oldAnim;
animation_t *otherAnim = NULL;
qboolean isLadderAnim;
// debugging tool to get no animations
if (cg_animSpeed.integer == 0)
{
lf->oldFrame = lf->frame = 0;
lf->backlerp = 0.f;
return;
}
isLadderAnim = lf->animation && (lf->animation->flags & ANIMFL_LADDERANIM);
oldAnim = lf->animation;
// see if the animation sequence is switching
if (newAnimation != lf->animationNumber || !lf->animation)
{
CG_SetLerpFrameAnimationRate(cent, ci, lf, newAnimation);
// make sure the animation is valid from CG_SetLerpFrameAnimationRate due to character absent
if (!lf->animation)
{
CG_Printf("Warning: CG_RunLerpFrameRate w/o animation.\n");
return; // shouldn't happen
}
}
// make sure the animation speed is updated when possible
anim = lf->animation;
// force last frame for corpses
if (cent->currentState.eType == ET_CORPSE)
{
lf->oldFrame = lf->frame = anim->firstFrame + anim->numFrames - 1;
lf->oldFrameModel = lf->frameModel = anim->mdxFile;
lf->backlerp = 0;
return;
}
if (anim->moveSpeed && lf->oldFrameSnapshotTime)
{
// calculate the speed at which we moved over the last frame
if (cg.latestSnapshotTime != lf->oldFrameSnapshotTime && cg.nextSnap)
{
float moveSpeed;
if (cent->currentState.number == cg.snap->ps.clientNum)
{
if (isLadderAnim) // only use Z axis for speed
{
lf->oldFramePos[0] = cent->lerpOrigin[0];
lf->oldFramePos[1] = cent->lerpOrigin[1];
}
else // only use x/y axis
{
lf->oldFramePos[2] = cent->lerpOrigin[2];
}
moveSpeed = Distance(cent->lerpOrigin, lf->oldFramePos) / ((float)(cg.time - lf->oldFrameTime) / 1000.0f);
}
else
{
if (isLadderAnim) // only use Z axis for speed
{
lf->oldFramePos[0] = cent->currentState.pos.trBase[0];
lf->oldFramePos[1] = cent->currentState.pos.trBase[1];
}
moveSpeed = Distance(cent->lerpOrigin, lf->oldFramePos) / ((float)(cg.time - lf->oldFrameTime) / 1000.0f);
}
// convert it to a factor of this animation's movespeed
lf->animSpeedScale = moveSpeed / (float)anim->moveSpeed;
lf->oldFrameSnapshotTime = cg.latestSnapshotTime;
}
}
else
{
// move at normal speed
lf->animSpeedScale = 1.0f;
lf->oldFrameSnapshotTime = cg.latestSnapshotTime;
}
// adjust with manual setting (pain anims)
lf->animSpeedScale *= cent->pe.animSpeed;
// if we have passed the current frame, move it to
// oldFrame and calculate a new frame
if (cg.time >= lf->frameTime)
{
int f;
lf->oldFrame = lf->frame;
lf->oldFrameTime = lf->frameTime;
lf->oldFrameModel = lf->frameModel;
VectorCopy(cent->lerpOrigin, lf->oldFramePos);
// restrict the speed range
if (lf->animSpeedScale < 0.25f) // if it's too slow, then a really slow spped, combined with a sudden take-off, can leave them playing a really slow frame while they a moving really fast
{
if (lf->animSpeedScale < 0.01f && isLadderAnim)
{
lf->animSpeedScale = 0.0f;
}
else
{
lf->animSpeedScale = 0.25f;
}
}
else if (lf->animSpeedScale > ANIM_SCALEMAX_LOW)
{
if (!(anim->flags & ANIMFL_LADDERANIM))
{
// allow slower anims to speed up more than faster anims
if (anim->moveSpeed > ANIM_SPEEDMAX_LOW)
{
lf->animSpeedScale = ANIM_SCALEMAX_LOW;
}
else if (anim->moveSpeed < ANIM_SPEEDMAX_HIGH)
{
if (lf->animSpeedScale > ANIM_SCALEMAX_HIGH)
{
lf->animSpeedScale = ANIM_SCALEMAX_HIGH;
}
}
else
{
lf->animSpeedScale = ANIM_SCALEMAX_HIGH - (ANIM_SCALEMAX_HIGH - ANIM_SCALEMAX_LOW) * (float)(anim->moveSpeed - ANIM_SPEEDMAX_HIGH) / (float)(ANIM_SPEEDMAX_LOW - ANIM_SPEEDMAX_HIGH);
}
}
else if (lf->animSpeedScale > 4)
{
lf->animSpeedScale = 4.0f;
}
}
if (lf == ¢->pe.legs)
{
otherAnim = cent->pe.torso.animation;
}
else if (lf == ¢->pe.torso)
{
otherAnim = cent->pe.legs.animation;
}
// get the next frame based on the animation
if (lf->animSpeedScale == 0.f)
{
// stopped on the ladder, so stay on the same frame
f = lf->frame - anim->firstFrame;
lf->frameTime += anim->frameLerp; // don't wait too long before starting to move again
}
else if (lf->oldAnimationNumber != lf->animationNumber &&
(!anim->moveSpeed || lf->oldFrame < anim->firstFrame || lf->oldFrame >= anim->firstFrame + anim->numFrames)) // Ridah, added this so walking frames don't always get reset to 0, which can happen in the middle of a walking anim, which looks wierd
{
lf->frameTime = lf->animationTime; // initial lerp
if (oldAnim && anim->moveSpeed) // keep locomotions going continuously
{
f = (lf->frame - oldAnim->firstFrame) + 1;
while (f < 0)
{
f += anim->numFrames;
}
}
else
{
f = 0;
}
}
else if ((lf == ¢->pe.legs) && otherAnim && !(anim->flags & ANIMFL_FIRINGANIM) && ((lf->animationNumber & ~ANIM_TOGGLEBIT) == (cent->pe.torso.animationNumber & ~ANIM_TOGGLEBIT)) && (!anim->moveSpeed))
{
// legs should synch with torso
f = cent->pe.torso.frame - otherAnim->firstFrame;
if (f >= anim->numFrames || f < 0)
{
f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim)
}
lf->frameTime = cent->pe.torso.frameTime;
}
else if ((lf == ¢->pe.torso) && otherAnim && !(anim->flags & ANIMFL_FIRINGANIM) && ((lf->animationNumber & ~ANIM_TOGGLEBIT) == (cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT)) && (otherAnim->moveSpeed))
{
// torso needs to sync with legs
f = cent->pe.legs.frame - otherAnim->firstFrame;
if (f >= anim->numFrames || f < 0)
{
f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim)
}
lf->frameTime = cent->pe.legs.frameTime;
}
else
{
lf->frameTime = lf->oldFrameTime + (int)((float)anim->frameLerp * (1.0f / lf->animSpeedScale));
if (lf->frameTime < cg.time)
{
lf->frameTime = cg.time;
}
// check for skipping frames (eg. death anims play in slo-mo if low framerate)
if (anim->flags & ANIMFL_REVERSED)
{
if (cg.time > lf->frameTime && !anim->moveSpeed)
{
f = (anim->numFrames - 1) - ((lf->frame - anim->firstFrame) - (1 + (cg.time - lf->frameTime) / anim->frameLerp));
}
else
{
f = (anim->numFrames - 1) - ((lf->frame - anim->firstFrame) - 1);
}
}
else
{
if (cg.time > lf->frameTime && !anim->moveSpeed)
{
f = (lf->frame - anim->firstFrame) + 1 + (cg.time - lf->frameTime) / anim->frameLerp;
}
else
{
f = (lf->frame - anim->firstFrame) + 1;
}
}
if (f < 0)
{
f = 0;
}
}
//f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp;
if (f >= anim->numFrames)
{
f -= anim->numFrames;
if (anim->loopFrames)
{
f %= anim->loopFrames;
f += anim->numFrames - anim->loopFrames;
}
else
{
f = anim->numFrames - 1;
// the animation is stuck at the end, so it
// can immediately transition to another sequence
lf->frameTime = cg.time;
}
}
if (anim->flags & ANIMFL_REVERSED)
{
lf->frame = anim->firstFrame + anim->numFrames - 1 - f;
lf->frameModel = anim->mdxFile;
}
else
{
lf->frame = anim->firstFrame + f;
lf->frameModel = anim->mdxFile;
}
if (cg.time > lf->frameTime)
{
// run the frame again until we move ahead of the current time, fixes walking speeds for zombie
if (/*!anim->moveSpeed ||*/ recursion > 4)
{
lf->frameTime = cg.time;
}
else
{
CG_RunLerpFrameRate(ci, lf, newAnimation, cent, recursion + 1);