1 #include "csqcmodel_hooks.qh"
3 #include <client/mutators/_mod.qh>
4 #include <client/player_skeleton.qh>
5 #include <client/weapons/projectile.qh>
6 #include <common/animdecide.qh>
7 #include <common/effects/all.inc>
8 #include <common/effects/all.qh>
9 #include <common/ent_cs.qh>
10 #include <common/gamemodes/_mod.qh>
11 #include <common/mapinfo.qh>
12 #include <common/physics/movetypes/movetypes.qh>
13 #include <common/physics/player.qh>
14 #include <common/viewloc.qh>
15 #include <lib/csqcmodel/cl_model.qh>
16 #include <lib/csqcmodel/cl_player.qh>
17 #include <lib/csqcmodel/interpolate.qh>
28 void CSQCModel_LOD_Apply(entity this, bool isplayer)
30 int detailreduction = ((isplayer) ? autocvar_cl_playerdetailreduction : autocvar_cl_modeldetailreduction);
33 if(this.lodmodelindex0 != this.modelindex && this.lodmodelindex1 != this.modelindex && this.lodmodelindex2 != this.modelindex)
35 string modelname = this.model;
38 vector mi = this.mins;
39 vector ma = this.maxs;
42 this.lodmodelindex0 = this.modelindex;
43 this.lodmodelindex1 = this.modelindex;
44 this.lodmodelindex2 = this.modelindex;
46 // FIXME: this only supports 3-letter extensions
47 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
53 this.lodmodelindex2 = this.lodmodelindex1 = this.modelindex;
56 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
62 this.lodmodelindex2 = this.modelindex;
65 _setmodel(this, modelname); // make everything normal again
66 setsize(this, mi, ma);
70 if(detailreduction <= 0)
72 if(detailreduction <= -2)
73 this.modelindex = this.lodmodelindex2;
74 else if(detailreduction <= -1)
75 this.modelindex = this.lodmodelindex1;
77 this.modelindex = this.lodmodelindex0;
81 float distance = vlen(((isplayer) ? this.origin : NearestPointOnBox(this, view_origin)) - view_origin); // TODO: perhaps it should just use NearestPointOnBox all the time, player hitbox can potentially be huge
82 float dist1 = (this.loddistance1 > 0) ? this.loddistance1 : autocvar_cl_loddistance1;
83 float dist2 = (this.loddistance2 > 0) ? this.loddistance2 : autocvar_cl_loddistance2;
84 float f = (distance * current_viewzoom + 100.0) * detailreduction;
85 f *= 1.0 / bound(0.01, view_quality, 1);
87 this.modelindex = this.lodmodelindex2;
89 this.modelindex = this.lodmodelindex1;
91 this.modelindex = this.lodmodelindex0;
95 // FEATURE: forcemodel and model color selection (MUST be called BEFORE LOD!)
96 string forceplayermodels_model;
97 bool forceplayermodels_modelisgoodmodel;
98 int forceplayermodels_modelindex;
99 int forceplayermodels_skin;
101 string forceplayermodels_mymodel;
102 bool forceplayermodels_myisgoodmodel;
103 int forceplayermodels_mymodelindex;
105 bool forceplayermodels_attempted;
107 .string forceplayermodels_savemodel;
108 .int forceplayermodels_savemodelindex;
109 .int forceplayermodels_saveskin;
110 .int forceplayermodels_savecolormap;
112 .string forceplayermodels_isgoodmodel_mdl;
113 .bool forceplayermodels_isgoodmodel;
115 string forceplayermodels_goodmodel;
116 int forceplayermodels_goodmodelindex;
120 void CSQCPlayer_ModelAppearance_PreUpdate(entity this)
122 this.model = this.forceplayermodels_savemodel;
123 this.modelindex = this.forceplayermodels_savemodelindex;
124 this.skin = this.forceplayermodels_saveskin;
125 this.colormap = this.forceplayermodels_savecolormap;
127 void CSQCPlayer_ModelAppearance_PostUpdate(entity this)
129 this.forceplayermodels_savemodel = this.model;
130 this.forceplayermodels_savemodelindex = this.modelindex;
131 this.forceplayermodels_saveskin = this.skin;
132 this.forceplayermodels_savecolormap = this.colormap;
134 if(this.forceplayermodels_savemodel != this.forceplayermodels_isgoodmodel_mdl)
136 this.forceplayermodels_isgoodmodel = fexists(this.forceplayermodels_savemodel);
137 this.forceplayermodels_isgoodmodel_mdl = this.forceplayermodels_savemodel;
138 if(!this.forceplayermodels_isgoodmodel)
139 LOG_INFOF("Warning: missing model %s has been used", this.forceplayermodels_savemodel);
142 void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer)
144 int cm = this.forceplayermodels_savecolormap;
145 cm = (cm >= 1024) ? cm : (entcs_GetClientColors(cm - 1) + 1024);
147 if(MUTATOR_CALLHOOK(ForcePlayermodels_Skip, this, islocalplayer))
148 goto skipforcemodels;
151 // which one is ALWAYS good?
152 if (!forceplayermodels_goodmodel)
155 precache_model(cvar_defstring("_cl_playermodel"));
156 _setmodel(e, cvar_defstring("_cl_playermodel"));
157 forceplayermodels_goodmodel = e.model;
158 forceplayermodels_goodmodelindex = e.modelindex;
162 // first, try finding it from the server
163 if(this.forceplayermodels_savemodelindex && this.forceplayermodels_savemodel != "null")
167 if(!isdemo()) // this is mainly cheat protection; not needed for demos
169 // trust server's idea of "own player model"
170 forceplayermodels_modelisgoodmodel = this.forceplayermodels_isgoodmodel;
171 forceplayermodels_model = this.forceplayermodels_savemodel;
172 forceplayermodels_modelindex = this.forceplayermodels_savemodelindex;
173 forceplayermodels_skin = this.forceplayermodels_saveskin;
174 forceplayermodels_attempted = 1;
179 // forcemodel finding
180 if(!forceplayermodels_attempted)
182 forceplayermodels_attempted = 1;
184 // only if this failed, find it out on our own
186 precache_model(autocvar__cl_playermodel);
187 _setmodel(e, autocvar__cl_playermodel); // this is harmless, see below
188 forceplayermodels_modelisgoodmodel = fexists(e.model);
189 forceplayermodels_model = e.model;
190 forceplayermodels_modelindex = e.modelindex;
191 forceplayermodels_skin = autocvar__cl_playerskin;
195 if(autocvar_cl_forcemyplayermodel != "" && autocvar_cl_forcemyplayermodel != forceplayermodels_mymodel)
198 _setmodel(e, autocvar_cl_forcemyplayermodel); // this is harmless, see below
199 forceplayermodels_myisgoodmodel = fexists(e.model);
200 forceplayermodels_mymodel = e.model;
201 forceplayermodels_mymodelindex = e.modelindex;
209 isfriend = (cm == 1024 + 17 * myteam);
211 isfriend = islocalplayer;
213 if(autocvar_cl_forcemyplayermodel != "" && forceplayermodels_myisgoodmodel && isfriend)
215 this.model = forceplayermodels_mymodel;
216 this.modelindex = forceplayermodels_mymodelindex;
217 this.skin = autocvar_cl_forcemyplayerskin;
219 else if(autocvar_cl_forceplayermodels && forceplayermodels_modelisgoodmodel)
221 this.model = forceplayermodels_model;
222 this.modelindex = forceplayermodels_modelindex;
223 this.skin = forceplayermodels_skin;
225 else if(this.forceplayermodels_isgoodmodel)
227 this.model = this.forceplayermodels_savemodel;
228 this.modelindex = this.forceplayermodels_savemodelindex;
229 this.skin = this.forceplayermodels_saveskin;
233 this.model = forceplayermodels_goodmodel;
234 this.modelindex = forceplayermodels_goodmodelindex;
235 this.skin = this.forceplayermodels_saveskin;
238 LABEL(skipforcemodels)
240 if(MUTATOR_CALLHOOK(ForcePlayercolors_Skip, this, islocalplayer))
241 goto skipforcecolors;
243 bool forceplayercolors_enabled = false;
244 #define fpc autocvar_cl_forceplayercolors
247 if ((myteam != NUM_SPECTATOR) && (fpc == 1 || fpc == 2 || fpc == 3 || fpc == 5))
248 forceplayercolors_enabled = true;
252 if ((team_count == 2) && (myteam != NUM_SPECTATOR) && (fpc == 2 || fpc == 4 || fpc == 5))
253 forceplayercolors_enabled = true;
257 if (fpc == 1 || fpc == 2)
258 forceplayercolors_enabled = true;
261 // forceplayercolors too
264 // own team's color is never forced
265 int forcecolor_friend = 0, forcecolor_enemy = 0;
268 if(autocvar_cl_forcemyplayercolors)
269 forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors;
271 if(forceplayercolors_enabled)
272 forcecolor_enemy = 1024 + autocvar__cl_color;
274 if(forcecolor_enemy && !forcecolor_friend)
276 // only enemy color is forced?
277 // verify it is not equal to the friend color
278 if(forcecolor_enemy == 1024 + 17 * myteam)
279 forcecolor_enemy = 0;
282 if(forcecolor_friend && !forcecolor_enemy)
284 // only friend color is forced?
285 // verify it is not equal to the enemy color
286 for(tm = teams.sort_next; tm; tm = tm.sort_next)
287 // note: we even compare against our own team.
288 // if we rejected because we matched our OWN team color,
289 // this is not bad; we then simply keep our color as is
291 if(forcecolor_friend == 1024 + 17 * tm.team)
292 forcecolor_friend = 0;
295 if(cm == 1024 + 17 * myteam)
297 if(forcecolor_friend)
298 this.colormap = forcecolor_friend;
303 this.colormap = forcecolor_enemy;
306 else // if(!teamplay)
308 if(autocvar_cl_forcemyplayercolors && islocalplayer)
309 this.colormap = 1024 + autocvar_cl_forcemyplayercolors;
310 else if (autocvar_cl_forceuniqueplayercolors && !islocalplayer && !gametype.m_1v1)
312 // Assign each enemy unique colors
313 // pick colors from 0 to 14 since 15 is the rainbow color
314 // pl01 0 1, pl02 1 2, ..., pl14 13 14, pl15 14 0
315 // pl16 0 2, pl17 1 3, ..., pl29 13 0, pl30 14 1
316 int num = this.entnum - 1;
318 int q = floor(num / 15);
319 int c2 = (c1 + 1 + q) % 15;
320 this.colormap = 1024 + (c1 << 4) + c2;
322 else if(forceplayercolors_enabled)
323 this.colormap = player_localnum + 1;
326 LABEL(skipforcecolors)
328 if((this.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST) && !autocvar_cl_respawn_ghosts_keepcolors)
330 this.glowmod = '0 0 0';
335 // GLOWMOD AND DEATH FADING
336 if(this.colormap > 0)
337 this.glowmod = colormapPaletteColor(((this.colormap >= 1024) ? this.colormap : entcs_GetClientColors(this.colormap - 1)) & 0x0F, true);
339 this.glowmod = '1 1 1';
341 if(autocvar_cl_deathglow > 0)
343 if(this.csqcmodel_isdead)
345 float min_factor = bound(0, autocvar_cl_deathglow_min, 1);
346 if(this.colormap > 0)
348 float glow_fade = bound(0, 1 - (time - this.death_time) / autocvar_cl_deathglow, 1);
349 this.glowmod *= (min_factor + glow_fade * (1 - min_factor));
350 if (this.glowmod == '0 0 0')
351 this.glowmod.x = 0.000001;
355 // don't let the engine increase player's glowmod
356 if (autocvar_r_hdr_glowintensity > 1)
357 this.glowmod /= autocvar_r_hdr_glowintensity;
359 //printf("CSQCPlayer_ModelAppearance_Apply(): state = %s, colormap = %f, glowmod = %s\n", (this.csqcmodel_isdead ? "DEAD" : "ALIVE"), this.colormap, vtos(this.glowmod));
362 // FEATURE: fallback frames
363 .int csqcmodel_saveframe;
364 .int csqcmodel_saveframe2;
365 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
366 .int csqcmodel_saveframe3;
367 .int csqcmodel_saveframe4;
369 .int csqcmodel_framecount;
371 #define IS_DEAD_FRAME(f) ((f) == 0 || (f) == 1)
372 void CSQCPlayer_FallbackFrame_PreUpdate(entity this)
374 this.frame = this.csqcmodel_saveframe;
375 this.frame2 = this.csqcmodel_saveframe2;
376 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
377 this.frame3 = this.csqcmodel_saveframe3;
378 this.frame4 = this.csqcmodel_saveframe4;
381 void CSQCPlayer_FallbackFrame_PostUpdate(entity this, bool isnew)
383 this.csqcmodel_saveframe = this.frame;
384 this.csqcmodel_saveframe2 = this.frame2;
385 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
386 this.csqcmodel_saveframe3 = this.frame3;
387 this.csqcmodel_saveframe4 = this.frame4;
390 // hack for death animations: set their frametime to zero in case a
394 #define FIX_FRAMETIME(f,ft) MACRO_BEGIN \
395 if(IS_DEAD_FRAME(this.f) && this.ft != 0 && this.death_time != 0) \
396 this.ft = this.death_time; \
398 FIX_FRAMETIME(frame, frame1time);
399 FIX_FRAMETIME(frame2, frame2time);
400 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
401 FIX_FRAMETIME(frame3, frame3time);
402 FIX_FRAMETIME(frame4, frame4time);
405 this.csqcmodel_isdead = IS_DEAD_FRAME(this.frame);
407 void CSQCPlayer_AnimDecide_PostUpdate(entity this, bool isnew)
409 this.csqcmodel_isdead = boolean(this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
411 int CSQCPlayer_FallbackFrame(entity this, int f)
414 if(frameduration(this.modelindex, f) > 0)
415 return f; // goooooood
416 if(frameduration(this.modelindex, 1) <= 0)
417 return f; // this is a static model. We can't fix it if we wanted to
420 case 23: return 11; // anim_melee -> anim_shoot
421 case 24: return 4; // anim_duckwalkbackwards -> anim_duckwalk
422 case 25: return 4; // anim_duckwalkstrafeleft -> anim_duckwalk
423 case 26: return 4; // anim_duckwalkstraferight -> anim_duckwalk
424 case 27: return 4; // anim_duckwalkforwardright -> anim_duckwalk
425 case 28: return 4; // anim_duckwalkforwardleft -> anim_duckwalk
426 case 29: return 4; // anim_duckwalkbackright -> anim_duckwalk
427 case 30: return 4; // anim_duckwalkbackleft -> anim_duckwalk
429 LOG_DEBUGF("Frame %d missing in model %s, and we have no fallback - FAIL!", f, this.model);
432 void CSQCPlayer_FallbackFrame_Apply(entity this)
434 this.frame = CSQCPlayer_FallbackFrame(this, this.frame);
435 this.frame2 = CSQCPlayer_FallbackFrame(this, this.frame2);
436 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
437 this.frame3 = CSQCPlayer_FallbackFrame(this, this.frame3);
438 this.frame4 = CSQCPlayer_FallbackFrame(this, this.frame4);
442 // FEATURE: auto tag_index
444 .int tag_entity_lastmodelindex;
446 void CSQCModel_AutoTagIndex_Apply(entity this)
448 if(this.tag_entity && wasfreed(this.tag_entity))
449 this.tag_entity = NULL;
451 MUTATOR_CALLHOOK(TagIndex_Update, this);
453 if(this.tag_networkentity)
457 if(this.tag_entity.entnum != this.tag_networkentity)
459 this.tag_entity = findfloat(NULL, entnum, this.tag_networkentity);
463 // recursive predraw call to fix issues with forcemodels and LOD if bone indexes mismatch
464 if(this.tag_entity.classname == "ENT_CLIENT_MODEL")
466 CSQCModel_Hook_PreDraw(this.tag_entity, (this.tag_entity.isplayermodel & ISPLAYER_CLIENT));
469 if(this.tag_entity.modelindex != this.tag_entity_lastmodelindex)
471 this.tag_entity_lastmodelindex = this.tag_entity.modelindex;
478 // the best part is: IT EXISTS
479 if(substring(this.model, 0, 14) == "models/weapons")
481 if(substring(this.tag_entity.model, 0, 14) == "models/weapons")
483 this.tag_index = gettagindex(this.tag_entity, "weapon");
485 this.tag_index = gettagindex(this.tag_entity, "tag_weapon");
488 // we need to prevent this from 'appening
489 this.tag_entity = NULL;
491 LOG_TRACE("h_ model lacks weapon attachment, but v_ model is attached to it");
494 else if((this.tag_entity.isplayermodel & ISPLAYER_MODEL))
496 skeleton_loadinfo(this.tag_entity);
497 this.tag_index = this.tag_entity.bone_weapon;
501 if(substring(this.tag_entity.model, 0, 14) == "models/weapons")
503 this.tag_index = gettagindex(this.tag_entity, "shot");
505 this.tag_index = gettagindex(this.tag_entity, "tag_shot");
508 MUTATOR_CALLHOOK(TagIndex_Apply, this);
512 // damn, see you next frame
519 void CSQCModel_Effects_PreUpdate(entity this)
521 this.effects = this.csqcmodel_effects;
522 this.modelflags = this.csqcmodel_modelflags;
523 this.traileffect = this.csqcmodel_traileffect;
525 void Reset_ArcBeam();
526 void CSQCModel_Effects_PostUpdate(entity this)
528 if (this == csqcplayer) {
529 if (this.csqcmodel_teleported) {
533 this.csqcmodel_effects = this.effects;
534 this.csqcmodel_modelflags = this.modelflags;
535 this.csqcmodel_traileffect = this.traileffect;
538 if(this.csqcmodel_teleported)
539 Projectile_ResetTrail(this, this.origin);
542 void CSQCModel_Effects_Apply(entity this)
544 int eff = this.csqcmodel_effects & ~CSQCMODEL_EF_RESPAWNGHOST;
545 int tref = this.csqcmodel_traileffect;
547 this.renderflags &= ~(RF_DEPTHHACK | RF_ADDITIVE | RF_FULLBRIGHT | EF_NOSHADOW | RF_USEAXIS);
549 this.traileffect = 0;
551 if(eff & EF_BRIGHTFIELD)
552 tref = EFFECT_TR_NEXUIZPLASMA.m_id;
553 // ignoring EF_MUZZLEFLASH
554 if(eff & EF_BRIGHTLIGHT)
555 adddynamiclight(this.origin, 400, '3 3 3');
556 if(eff & EF_DIMLIGHT)
557 adddynamiclight(this.origin, 200, '1.5 1.5 1.5');
558 if((eff & EF_NODRAW) || (this.alpha < 0))
560 if(eff & EF_ADDITIVE)
561 this.renderflags |= RF_ADDITIVE;
563 adddynamiclight(this.origin, 200, '0.15 0.15 1.5');
565 adddynamiclight(this.origin, 200, '1.5 0.15 0.15');
566 // ignoring EF_NOGUNBOB
567 if(eff & EF_FULLBRIGHT)
568 this.renderflags |= RF_FULLBRIGHT;
571 boxparticles(particleeffectnum(EFFECT_EF_FLAME), this, this.absmin, this.absmax, this.velocity, this.velocity, bound(0, frametime, 0.1), 0);
572 //pointparticles(EFFECT_EF_FLAME, this.origin, '0 0 0', bound(0, frametime, 0.1));
576 boxparticles(particleeffectnum(EFFECT_ARC_LIGHTNING), this, this.absmin, this.absmax, '0 0 0', '0 0 0', bound(0, frametime, 0.1), 0);
577 //pointparticles(EFFECT_ARC_LIGHTNING, this.origin, '0 0 0', bound(0, frametime, 0.1));
579 if(eff & EF_STARDUST)
581 boxparticles(particleeffectnum(EFFECT_EF_STARDUST), this, this.absmin, this.absmax, this.velocity, this.velocity, bound(0, frametime, 0.1), 0);
582 //pointparticles(EFFECT_EF_STARDUST, this.origin, '0 0 0', bound(0, frametime, 0.1));
584 if(eff & EF_NOSHADOW)
585 this.renderflags |= RF_NOSHADOW;
586 if(eff & EF_NODEPTHTEST)
587 this.renderflags |= RF_DEPTHHACK;
588 // ignoring EF_SELECTABLE
589 if(eff & EF_DOUBLESIDED)
590 this.effects |= EF_DOUBLESIDED;
591 if(eff & EF_NOSELFSHADOW)
592 this.effects |= EF_NOSELFSHADOW;
593 if(eff & EF_DYNAMICMODELLIGHT)
594 this.renderflags |= RF_DYNAMICMODELLIGHT;
595 // ignoring EF_UNUSED18, EF_UNUSED19, EF_RESTARTANIM_BIT, EF_TELEPORT_BIT, EF_LOWPRECISION
596 if(this.csqcmodel_modelflags & MF_ROCKET)
597 tref = EFFECT_TR_ROCKET.m_id;
598 if(this.csqcmodel_modelflags & MF_GRENADE)
599 tref = EFFECT_TR_GRENADE.m_id;
600 if(this.csqcmodel_modelflags & MF_GIB)
601 tref = EFFECT_TR_BLOOD.m_id;
602 if(this.csqcmodel_modelflags & MF_ROTATE)
604 // This will be hard to replace with MAKE_VECTORS because it's called as part of the predraw function
605 // as documented in csprogs.h in the engine. The globals can then be read in many places in the engine.
606 // However MF_ROTATE is currently only used in one place - might be possible to get rid of it entirely.
607 this.renderflags |= RF_USEAXIS;
608 makevectors(this.angles + '0 100 0' * fmod(time, 3.6));
610 if(this.csqcmodel_modelflags & MF_TRACER)
611 tref = EFFECT_TR_WIZSPIKE.m_id;
612 if(this.csqcmodel_modelflags & MF_ZOMGIB)
613 tref = EFFECT_TR_SLIGHTBLOOD.m_id;
614 if(this.csqcmodel_modelflags & MF_TRACER2)
615 tref = EFFECT_TR_KNIGHTSPIKE.m_id;
616 if(this.csqcmodel_modelflags & MF_TRACER3)
617 tref = EFFECT_TR_VORESPIKE.m_id;
619 this.traileffect = tref;
622 Projectile_DrawTrail(this, this.origin);
624 Projectile_ResetTrail(this, this.origin);
626 if(this.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST)
627 this.renderflags |= RF_ADDITIVE;
628 // also special in CSQCPlayer_GlowMod_Apply
630 if(this.csqcmodel_modelflags & MF_ROCKET)
632 if(!this.snd_looping)
634 sound(this, CH_TRIGGER_SINGLE, SND_JETPACK_FLY, VOL_BASE, autocvar_cl_jetpack_attenuation);
635 this.snd_looping = CH_TRIGGER_SINGLE;
642 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation);
643 this.snd_looping = 0;
649 .int csqcmodel_predraw_run;
651 .int anim_frame1time;
653 .int anim_frame2time;
655 .int anim_saveframe1time;
656 .int anim_saveframe2;
657 .int anim_saveframe2time;
658 .int anim_prev_pmove_flags;
659 void CSQCModel_Hook_PreDraw(entity this, bool isplayer)
661 if(this.csqcmodel_predraw_run == framecount)
663 this.csqcmodel_predraw_run = framecount;
665 if(!this.modelindex || this.model == "null")
668 if(this.snd_looping > 0)
670 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation);
671 this.snd_looping = 0;
676 this.drawmask = MASK_NORMAL;
678 if((this.isplayermodel & ISPLAYER_MODEL) && this.drawmask) // this checks if it's a player MODEL!
680 CSQCPlayer_ModelAppearance_Apply(this, (this.isplayermodel & ISPLAYER_LOCAL));
681 CSQCModel_LOD_Apply(this, true);
685 skeleton_loadinfo(this);
686 bool doblend = (this.bone_upperbody >= 0);
687 CSQCPlayer_FallbackFrame_Apply(this);
690 skeleton_from_frames(this, this.csqcmodel_isdead);
694 free_skeleton_from_frames(this);
695 // just in case, clear these (we're animating in frame and frame3)
702 // we know that frame3 and frame4 fields, used by InterpolateAnimation, are left alone - but that is all we know!
703 skeleton_loadinfo(this);
704 bool doblend = (this.bone_upperbody >= 0);
706 if(this == csqcplayer)
708 if(IS_ONGROUND(this))
710 this.anim_prev_pmove_flags = this.flags;
711 if(this.flags & FL_DUCKED)
712 animdecide_setstate(this, this.anim_state | ANIMSTATE_DUCK, false);
713 else if(this.anim_state & ANIMSTATE_DUCK)
714 animdecide_setstate(this, this.anim_state - ANIMSTATE_DUCK, false);
718 tracebox(this.origin + '0 0 1', this.mins, this.maxs, this.origin - '0 0 4', MOVE_NORMAL, this);
719 if(trace_startsolid || trace_fraction < 1)
721 // predicted clients handle smoothing in the prediction code
722 this.origin = CSQCModel_ApplyStairSmoothing(this, onground, this.origin);
724 animdecide_load_if_needed(this);
725 animdecide_setimplicitstate(this, onground);
726 animdecide_setframes(this, doblend, anim_frame, anim_frame1time, anim_frame2, anim_frame2time);
728 if(this.anim_saveframe != this.anim_frame || this.anim_saveframe1time != this.anim_frame1time)
729 sf |= CSQCMODEL_PROPERTY_FRAME;
730 if(this.anim_saveframe2 != this.anim_frame2 || this.anim_saveframe2time != this.anim_frame2time)
731 sf |= CSQCMODEL_PROPERTY_FRAME2;
732 this.anim_saveframe = this.anim_frame;
733 this.anim_saveframe1time = this.anim_frame1time;
734 this.anim_saveframe2 = this.anim_frame2;
735 this.anim_saveframe2time = this.anim_frame2time;
736 // Note: we always consider lerpfrac "changed", as it uses fixed values every time anyway.
737 // This ensures that .frame etc. are always written.
738 CSQCModel_InterpolateAnimation_2To4_PreNote(this, sf | CSQCMODEL_PROPERTY_LERPFRAC);
739 this.lerpfrac = (doblend ? 0.5 : 0);
740 this.frame = this.anim_frame;
741 this.frame1time = this.anim_frame1time;
742 this.frame2 = this.anim_frame2;
743 this.frame2time = this.anim_frame2time;
744 CSQCModel_InterpolateAnimation_2To4_Note(this, sf | CSQCMODEL_PROPERTY_LERPFRAC, false);
745 CSQCModel_InterpolateAnimation_2To4_Do(this);
748 skeleton_from_frames(this, this.csqcmodel_isdead);
752 free_skeleton_from_frames(this);
753 // just in case, clear these (we're animating in frame and frame3)
760 CSQCModel_LOD_Apply(this, false);
762 CSQCModel_AutoTagIndex_Apply(this);
764 CSQCModel_Effects_Apply(this);
767 void CSQCModel_Hook_PreUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
769 // interpolate v_angle
770 this.iflags |= IFLAG_V_ANGLE_X;
771 // revert to values from server
772 CSQCModel_Effects_PreUpdate(this);
773 if((this.isplayermodel & ISPLAYER_MODEL))
776 CSQCPlayer_FallbackFrame_PreUpdate(this);
777 CSQCPlayer_ModelAppearance_PreUpdate(this);
781 void CSQCModel_Hook_PostUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
783 // is it a player model? (shared state)
784 bool is_playermodel = (substring(this.model, 0, 14) == "models/player/" || substring(this.model, 0, 17) == "models/ok_player/" ||
785 (substring(this.model, 0, 16) == "models/monsters/" && (this.isplayermodel & BIT(1))));
786 this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_MODEL, is_playermodel);
787 this.csqcmodel_isdead = false; // workaround for dead players who become a spectator
789 // save values set by server
790 if((this.isplayermodel & ISPLAYER_MODEL))
792 CSQCPlayer_ModelAppearance_PostUpdate(this);
794 CSQCPlayer_AnimDecide_PostUpdate(this, isnew);
796 CSQCPlayer_FallbackFrame_PostUpdate(this, isnew);
798 CSQCModel_Effects_PostUpdate(this);