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);
210 else if(ISGAMETYPE(BR))
211 isfriend = br_isSameSquad(this.entnum);
213 isfriend = islocalplayer;
215 if(autocvar_cl_forcemyplayermodel != "" && forceplayermodels_myisgoodmodel && isfriend)
217 this.model = forceplayermodels_mymodel;
218 this.modelindex = forceplayermodels_mymodelindex;
219 this.skin = autocvar_cl_forcemyplayerskin;
221 else if(autocvar_cl_forceplayermodels && forceplayermodels_modelisgoodmodel)
223 this.model = forceplayermodels_model;
224 this.modelindex = forceplayermodels_modelindex;
225 this.skin = forceplayermodels_skin;
227 else if(this.forceplayermodels_isgoodmodel)
229 this.model = this.forceplayermodels_savemodel;
230 this.modelindex = this.forceplayermodels_savemodelindex;
231 this.skin = this.forceplayermodels_saveskin;
235 this.model = forceplayermodels_goodmodel;
236 this.modelindex = forceplayermodels_goodmodelindex;
237 this.skin = this.forceplayermodels_saveskin;
240 LABEL(skipforcemodels)
242 if(MUTATOR_CALLHOOK(ForcePlayercolors_Skip, this, islocalplayer))
243 goto skipforcecolors;
245 bool forceplayercolors_enabled = false;
246 #define fpc autocvar_cl_forceplayercolors
249 if ((myteam != NUM_SPECTATOR) && (fpc == 1 || fpc == 2 || fpc == 3 || fpc == 5))
250 forceplayercolors_enabled = true;
254 if ((team_count == 2) && (myteam != NUM_SPECTATOR) && (fpc == 2 || fpc == 4 || fpc == 5))
255 forceplayercolors_enabled = true;
257 else if (ISGAMETYPE(BR))
259 if (br_inSquad() && (fpc == 2 || fpc == 5))
260 forceplayercolors_enabled = true;
264 if (fpc == 1 || fpc == 2)
265 forceplayercolors_enabled = true;
268 // forceplayercolors too
269 if(teamplay || ISGAMETYPE(BR))
271 // own team's color is never forced
272 int forcecolor_friend = 0, forcecolor_enemy = 0;
275 if(autocvar_cl_forcemyplayercolors)
276 forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors;
278 if(forceplayercolors_enabled)
279 forcecolor_enemy = 1024 + autocvar__cl_color;
281 if(!ISGAMETYPE(BR) && forcecolor_enemy && !forcecolor_friend)
283 // only enemy color is forced?
284 // verify it is not equal to the friend color
285 if(forcecolor_enemy == 1024 + 17 * myteam)
286 forcecolor_enemy = 0;
289 if(!ISGAMETYPE(BR) && forcecolor_friend && !forcecolor_enemy)
291 // only friend color is forced?
292 // verify it is not equal to the enemy color
293 for(tm = teams.sort_next; tm; tm = tm.sort_next)
294 // note: we even compare against our own team.
295 // if we rejected because we matched our OWN team color,
296 // this is not bad; we then simply keep our color as is
298 if(forcecolor_friend == 1024 + 17 * tm.team)
299 forcecolor_friend = 0;
302 if((!ISGAMETYPE(BR) && (cm == 1024 + 17 * myteam)) || (ISGAMETYPE(BR) && br_isSameSquad(this.entnum)))
304 if(forcecolor_friend)
305 this.colormap = forcecolor_friend;
310 this.colormap = forcecolor_enemy;
313 else // if(!teamplay)
315 if(autocvar_cl_forcemyplayercolors && islocalplayer)
316 this.colormap = 1024 + autocvar_cl_forcemyplayercolors;
317 else if (autocvar_cl_forceuniqueplayercolors && !islocalplayer && !gametype.m_1v1)
319 // Assign each enemy unique colors
320 // pick colors from 0 to 14 since 15 is the rainbow color
321 // pl01 0 1, pl02 1 2, ..., pl14 13 14, pl15 14 0
322 // pl16 0 2, pl17 1 3, ..., pl29 13 0, pl30 14 1
323 int num = this.entnum - 1;
325 int q = floor(num / 15);
326 int c2 = (c1 + 1 + q) % 15;
327 this.colormap = 1024 + (c1 << 4) + c2;
329 else if(forceplayercolors_enabled)
330 this.colormap = player_localnum + 1;
333 LABEL(skipforcecolors)
335 if((this.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST) && !autocvar_cl_respawn_ghosts_keepcolors)
337 this.glowmod = '0 0 0';
342 // GLOWMOD AND DEATH FADING
343 if(this.colormap > 0)
344 this.glowmod = colormapPaletteColor(((this.colormap >= 1024) ? this.colormap : entcs_GetClientColors(this.colormap - 1)) & 0x0F, true);
346 this.glowmod = '1 1 1';
348 if(autocvar_cl_deathglow > 0)
350 if(this.csqcmodel_isdead)
352 float min_factor = bound(0, autocvar_cl_deathglow_min, 1);
353 if(this.colormap > 0)
355 float glow_fade = bound(0, 1 - (time - this.death_time) / autocvar_cl_deathglow, 1);
356 this.glowmod *= (min_factor + glow_fade * (1 - min_factor));
357 if (this.glowmod == '0 0 0')
358 this.glowmod.x = 0.000001;
362 // don't let the engine increase player's glowmod
363 if (autocvar_r_hdr_glowintensity > 1)
364 this.glowmod /= autocvar_r_hdr_glowintensity;
366 //printf("CSQCPlayer_ModelAppearance_Apply(): state = %s, colormap = %f, glowmod = %s\n", (this.csqcmodel_isdead ? "DEAD" : "ALIVE"), this.colormap, vtos(this.glowmod));
369 // FEATURE: fallback frames
370 .int csqcmodel_saveframe;
371 .int csqcmodel_saveframe2;
372 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
373 .int csqcmodel_saveframe3;
374 .int csqcmodel_saveframe4;
376 .int csqcmodel_framecount;
378 #define IS_DEAD_FRAME(f) ((f) == 0 || (f) == 1)
379 void CSQCPlayer_FallbackFrame_PreUpdate(entity this)
381 this.frame = this.csqcmodel_saveframe;
382 this.frame2 = this.csqcmodel_saveframe2;
383 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
384 this.frame3 = this.csqcmodel_saveframe3;
385 this.frame4 = this.csqcmodel_saveframe4;
388 void CSQCPlayer_FallbackFrame_PostUpdate(entity this, bool isnew)
390 this.csqcmodel_saveframe = this.frame;
391 this.csqcmodel_saveframe2 = this.frame2;
392 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
393 this.csqcmodel_saveframe3 = this.frame3;
394 this.csqcmodel_saveframe4 = this.frame4;
397 // hack for death animations: set their frametime to zero in case a
401 #define FIX_FRAMETIME(f,ft) MACRO_BEGIN \
402 if(IS_DEAD_FRAME(this.f) && this.ft != 0 && this.death_time != 0) \
403 this.ft = this.death_time; \
405 FIX_FRAMETIME(frame, frame1time);
406 FIX_FRAMETIME(frame2, frame2time);
407 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
408 FIX_FRAMETIME(frame3, frame3time);
409 FIX_FRAMETIME(frame4, frame4time);
412 this.csqcmodel_isdead = IS_DEAD_FRAME(this.frame);
414 void CSQCPlayer_AnimDecide_PostUpdate(entity this, bool isnew)
416 this.csqcmodel_isdead = boolean(this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
418 int CSQCPlayer_FallbackFrame(entity this, int f)
421 if(frameduration(this.modelindex, f) > 0)
422 return f; // goooooood
423 if(frameduration(this.modelindex, 1) <= 0)
424 return f; // this is a static model. We can't fix it if we wanted to
427 case 23: return 11; // anim_melee -> anim_shoot
428 case 24: return 4; // anim_duckwalkbackwards -> anim_duckwalk
429 case 25: return 4; // anim_duckwalkstrafeleft -> anim_duckwalk
430 case 26: return 4; // anim_duckwalkstraferight -> anim_duckwalk
431 case 27: return 4; // anim_duckwalkforwardright -> anim_duckwalk
432 case 28: return 4; // anim_duckwalkforwardleft -> anim_duckwalk
433 case 29: return 4; // anim_duckwalkbackright -> anim_duckwalk
434 case 30: return 4; // anim_duckwalkbackleft -> anim_duckwalk
436 LOG_DEBUGF("Frame %d missing in model %s, and we have no fallback - FAIL!", f, this.model);
439 void CSQCPlayer_FallbackFrame_Apply(entity this)
441 this.frame = CSQCPlayer_FallbackFrame(this, this.frame);
442 this.frame2 = CSQCPlayer_FallbackFrame(this, this.frame2);
443 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
444 this.frame3 = CSQCPlayer_FallbackFrame(this, this.frame3);
445 this.frame4 = CSQCPlayer_FallbackFrame(this, this.frame4);
449 // FEATURE: auto tag_index
451 .int tag_entity_lastmodelindex;
453 void CSQCModel_AutoTagIndex_Apply(entity this)
455 if(this.tag_entity && wasfreed(this.tag_entity))
456 this.tag_entity = NULL;
458 MUTATOR_CALLHOOK(TagIndex_Update, this);
460 if(this.tag_networkentity)
464 if(this.tag_entity.entnum != this.tag_networkentity)
466 this.tag_entity = findfloat(NULL, entnum, this.tag_networkentity);
470 // recursive predraw call to fix issues with forcemodels and LOD if bone indexes mismatch
471 if(this.tag_entity.classname == "ENT_CLIENT_MODEL")
473 CSQCModel_Hook_PreDraw(this.tag_entity, (this.tag_entity.isplayermodel & ISPLAYER_CLIENT));
476 if(this.tag_entity.modelindex != this.tag_entity_lastmodelindex)
478 this.tag_entity_lastmodelindex = this.tag_entity.modelindex;
485 // the best part is: IT EXISTS
486 if(substring(this.model, 0, 14) == "models/weapons")
488 if(substring(this.tag_entity.model, 0, 14) == "models/weapons")
490 this.tag_index = gettagindex(this.tag_entity, "weapon");
492 this.tag_index = gettagindex(this.tag_entity, "tag_weapon");
495 // we need to prevent this from 'appening
496 this.tag_entity = NULL;
498 LOG_TRACE("h_ model lacks weapon attachment, but v_ model is attached to it");
501 else if((this.tag_entity.isplayermodel & ISPLAYER_MODEL))
503 skeleton_loadinfo(this.tag_entity);
504 this.tag_index = this.tag_entity.bone_weapon;
508 if(substring(this.tag_entity.model, 0, 14) == "models/weapons")
510 this.tag_index = gettagindex(this.tag_entity, "shot");
512 this.tag_index = gettagindex(this.tag_entity, "tag_shot");
515 MUTATOR_CALLHOOK(TagIndex_Apply, this);
519 // damn, see you next frame
526 void CSQCModel_Effects_PreUpdate(entity this)
528 this.effects = this.csqcmodel_effects;
529 this.modelflags = this.csqcmodel_modelflags;
530 this.traileffect = this.csqcmodel_traileffect;
532 void Reset_ArcBeam();
533 void CSQCModel_Effects_PostUpdate(entity this)
535 if (this == csqcplayer) {
536 if (this.csqcmodel_teleported) {
540 this.csqcmodel_effects = this.effects;
541 this.csqcmodel_modelflags = this.modelflags;
542 this.csqcmodel_traileffect = this.traileffect;
545 if(this.csqcmodel_teleported)
546 Projectile_ResetTrail(this, this.origin);
549 void CSQCModel_Effects_Apply(entity this)
551 int eff = this.csqcmodel_effects & ~CSQCMODEL_EF_RESPAWNGHOST;
552 int tref = this.csqcmodel_traileffect;
554 this.renderflags &= ~(RF_DEPTHHACK | RF_ADDITIVE | RF_FULLBRIGHT | EF_NOSHADOW | RF_USEAXIS);
556 this.traileffect = 0;
558 if(eff & EF_BRIGHTFIELD)
559 tref = EFFECT_TR_NEXUIZPLASMA.m_id;
560 // ignoring EF_MUZZLEFLASH
561 if(eff & EF_BRIGHTLIGHT)
562 adddynamiclight(this.origin, 400, '3 3 3');
563 if(eff & EF_DIMLIGHT)
564 adddynamiclight(this.origin, 200, '1.5 1.5 1.5');
565 if((eff & EF_NODRAW) || (this.alpha < 0))
567 if(eff & EF_ADDITIVE)
568 this.renderflags |= RF_ADDITIVE;
570 adddynamiclight(this.origin, 200, '0.15 0.15 1.5');
572 adddynamiclight(this.origin, 200, '1.5 0.15 0.15');
573 // ignoring EF_NOGUNBOB
574 if(eff & EF_FULLBRIGHT)
575 this.renderflags |= RF_FULLBRIGHT;
578 boxparticles(particleeffectnum(EFFECT_EF_FLAME), this, this.absmin, this.absmax, this.velocity, this.velocity, bound(0, frametime, 0.1), 0);
579 //pointparticles(EFFECT_EF_FLAME, this.origin, '0 0 0', bound(0, frametime, 0.1));
583 boxparticles(particleeffectnum(EFFECT_ARC_LIGHTNING), this, this.absmin, this.absmax, '0 0 0', '0 0 0', bound(0, frametime, 0.1), 0);
584 //pointparticles(EFFECT_ARC_LIGHTNING, this.origin, '0 0 0', bound(0, frametime, 0.1));
586 if(eff & EF_STARDUST)
588 boxparticles(particleeffectnum(EFFECT_EF_STARDUST), this, this.absmin, this.absmax, this.velocity, this.velocity, bound(0, frametime, 0.1), 0);
589 //pointparticles(EFFECT_EF_STARDUST, this.origin, '0 0 0', bound(0, frametime, 0.1));
591 if(eff & EF_NOSHADOW)
592 this.renderflags |= RF_NOSHADOW;
593 if(eff & EF_NODEPTHTEST)
594 this.renderflags |= RF_DEPTHHACK;
595 // ignoring EF_SELECTABLE
596 if(eff & EF_DOUBLESIDED)
597 this.effects |= EF_DOUBLESIDED;
598 if(eff & EF_NOSELFSHADOW)
599 this.effects |= EF_NOSELFSHADOW;
600 if(eff & EF_DYNAMICMODELLIGHT)
601 this.renderflags |= RF_DYNAMICMODELLIGHT;
602 // ignoring EF_UNUSED18, EF_UNUSED19, EF_RESTARTANIM_BIT, EF_TELEPORT_BIT, EF_LOWPRECISION
603 if(this.csqcmodel_modelflags & MF_ROCKET)
604 tref = EFFECT_TR_ROCKET.m_id;
605 if(this.csqcmodel_modelflags & MF_GRENADE)
606 tref = EFFECT_TR_GRENADE.m_id;
607 if(this.csqcmodel_modelflags & MF_GIB)
608 tref = EFFECT_TR_BLOOD.m_id;
609 if(this.csqcmodel_modelflags & MF_ROTATE)
611 // This will be hard to replace with MAKE_VECTORS because it's called as part of the predraw function
612 // as documented in csprogs.h in the engine. The globals can then be read in many places in the engine.
613 // However MF_ROTATE is currently only used in one place - might be possible to get rid of it entirely.
614 this.renderflags |= RF_USEAXIS;
615 makevectors(this.angles + '0 100 0' * fmod(time, 3.6));
617 if(this.csqcmodel_modelflags & MF_TRACER)
618 tref = EFFECT_TR_WIZSPIKE.m_id;
619 if(this.csqcmodel_modelflags & MF_ZOMGIB)
620 tref = EFFECT_TR_SLIGHTBLOOD.m_id;
621 if(this.csqcmodel_modelflags & MF_TRACER2)
622 tref = EFFECT_TR_KNIGHTSPIKE.m_id;
623 if(this.csqcmodel_modelflags & MF_TRACER3)
624 tref = EFFECT_TR_VORESPIKE.m_id;
626 this.traileffect = tref;
629 Projectile_DrawTrail(this, this.origin);
631 Projectile_ResetTrail(this, this.origin);
633 if(this.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST)
634 this.renderflags |= RF_ADDITIVE;
635 // also special in CSQCPlayer_GlowMod_Apply
637 if(this.csqcmodel_modelflags & MF_ROCKET)
639 if(!this.snd_looping)
641 sound(this, CH_TRIGGER_SINGLE, SND_JETPACK_FLY, VOL_BASE, autocvar_cl_jetpack_attenuation);
642 this.snd_looping = CH_TRIGGER_SINGLE;
649 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation);
650 this.snd_looping = 0;
656 .int csqcmodel_predraw_run;
658 .int anim_frame1time;
660 .int anim_frame2time;
662 .int anim_saveframe1time;
663 .int anim_saveframe2;
664 .int anim_saveframe2time;
665 .int anim_prev_pmove_flags;
666 void CSQCModel_Hook_PreDraw(entity this, bool isplayer)
668 if(this.csqcmodel_predraw_run == framecount)
670 this.csqcmodel_predraw_run = framecount;
672 if(!this.modelindex || this.model == "null")
675 if(this.snd_looping > 0)
677 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation);
678 this.snd_looping = 0;
683 this.drawmask = MASK_NORMAL;
685 if((this.isplayermodel & ISPLAYER_MODEL) && this.drawmask) // this checks if it's a player MODEL!
687 CSQCPlayer_ModelAppearance_Apply(this, (this.isplayermodel & ISPLAYER_LOCAL));
688 CSQCModel_LOD_Apply(this, true);
692 skeleton_loadinfo(this);
693 bool doblend = (this.bone_upperbody >= 0);
694 CSQCPlayer_FallbackFrame_Apply(this);
697 skeleton_from_frames(this, this.csqcmodel_isdead);
701 free_skeleton_from_frames(this);
702 // just in case, clear these (we're animating in frame and frame3)
709 // we know that frame3 and frame4 fields, used by InterpolateAnimation, are left alone - but that is all we know!
710 skeleton_loadinfo(this);
711 bool doblend = (this.bone_upperbody >= 0);
713 if(this == csqcplayer)
715 if(IS_ONGROUND(this))
717 this.anim_prev_pmove_flags = this.flags;
718 if(this.flags & FL_DUCKED)
719 animdecide_setstate(this, this.anim_state | ANIMSTATE_DUCK, false);
720 else if(this.anim_state & ANIMSTATE_DUCK)
721 animdecide_setstate(this, this.anim_state - ANIMSTATE_DUCK, false);
725 tracebox(this.origin + '0 0 1', this.mins, this.maxs, this.origin - '0 0 4', MOVE_NORMAL, this);
726 if(trace_startsolid || trace_fraction < 1)
728 // predicted clients handle smoothing in the prediction code
729 this.origin = CSQCModel_ApplyStairSmoothing(this, onground, this.origin);
731 animdecide_load_if_needed(this);
732 animdecide_setimplicitstate(this, onground);
733 animdecide_setframes(this, doblend, anim_frame, anim_frame1time, anim_frame2, anim_frame2time);
735 if(this.anim_saveframe != this.anim_frame || this.anim_saveframe1time != this.anim_frame1time)
736 sf |= CSQCMODEL_PROPERTY_FRAME;
737 if(this.anim_saveframe2 != this.anim_frame2 || this.anim_saveframe2time != this.anim_frame2time)
738 sf |= CSQCMODEL_PROPERTY_FRAME2;
739 this.anim_saveframe = this.anim_frame;
740 this.anim_saveframe1time = this.anim_frame1time;
741 this.anim_saveframe2 = this.anim_frame2;
742 this.anim_saveframe2time = this.anim_frame2time;
743 // Note: we always consider lerpfrac "changed", as it uses fixed values every time anyway.
744 // This ensures that .frame etc. are always written.
745 CSQCModel_InterpolateAnimation_2To4_PreNote(this, sf | CSQCMODEL_PROPERTY_LERPFRAC);
746 this.lerpfrac = (doblend ? 0.5 : 0);
747 this.frame = this.anim_frame;
748 this.frame1time = this.anim_frame1time;
749 this.frame2 = this.anim_frame2;
750 this.frame2time = this.anim_frame2time;
751 CSQCModel_InterpolateAnimation_2To4_Note(this, sf | CSQCMODEL_PROPERTY_LERPFRAC, false);
752 CSQCModel_InterpolateAnimation_2To4_Do(this);
755 skeleton_from_frames(this, this.csqcmodel_isdead);
759 free_skeleton_from_frames(this);
760 // just in case, clear these (we're animating in frame and frame3)
767 CSQCModel_LOD_Apply(this, false);
769 CSQCModel_AutoTagIndex_Apply(this);
771 CSQCModel_Effects_Apply(this);
774 void CSQCModel_Hook_PreUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
776 // interpolate v_angle
777 this.iflags |= IFLAG_V_ANGLE_X;
778 // revert to values from server
779 CSQCModel_Effects_PreUpdate(this);
780 if((this.isplayermodel & ISPLAYER_MODEL))
783 CSQCPlayer_FallbackFrame_PreUpdate(this);
784 CSQCPlayer_ModelAppearance_PreUpdate(this);
788 void CSQCModel_Hook_PostUpdate(entity this, bool isnew, bool isplayer, bool islocalplayer)
790 // is it a player model? (shared state)
791 bool is_playermodel = (substring(this.model, 0, 14) == "models/player/" || substring(this.model, 0, 17) == "models/ok_player/" ||
792 (substring(this.model, 0, 16) == "models/monsters/" && (this.isplayermodel & BIT(1))));
793 this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_MODEL, is_playermodel);
794 this.csqcmodel_isdead = false; // workaround for dead players who become a spectator
796 // save values set by server
797 if((this.isplayermodel & ISPLAYER_MODEL))
799 CSQCPlayer_ModelAppearance_PostUpdate(this);
801 CSQCPlayer_AnimDecide_PostUpdate(this, isnew);
803 CSQCPlayer_FallbackFrame_PostUpdate(this, isnew);
805 CSQCModel_Effects_PostUpdate(this);