7 void CSQCPlayer_LOD_Apply(void)
10 if(self.lodmodelindex0 != self.modelindex)
12 string modelname = self.model;
15 if(!fexists(modelname))
17 print(sprintf(_("Trying to use non existing model %s. "), modelname));
18 modelname = cvar_defstring("_cl_playermodel");
19 print(sprintf(_("Reverted to %s."), modelname));
23 self.lodmodelindex0 = self.modelindex;
24 self.lodmodelindex1 = self.modelindex;
25 self.lodmodelindex2 = self.modelindex;
27 // FIXME: this only supports 3-letter extensions
28 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
34 self.lodmodelindex1 = self.modelindex;
37 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
43 self.lodmodelindex2 = self.modelindex;
46 setmodel(self, modelname); // make everything normal again
50 if(autocvar_cl_playerdetailreduction <= 0)
52 if(autocvar_cl_playerdetailreduction <= -2)
53 self.modelindex = self.lodmodelindex2;
54 else if(autocvar_cl_playerdetailreduction <= -1)
55 self.modelindex = self.lodmodelindex1;
57 self.modelindex = self.lodmodelindex0;
61 float distance = vlen(self.origin - other.origin);
62 float f = (distance + 100.0) * autocvar_cl_playerdetailreduction;
63 f *= 1.0 / bound(0.01, view_quality, 1);
64 if(f > autocvar_cl_loddistance2)
65 self.modelindex = self.lodmodelindex2;
66 else if(f > autocvar_cl_loddistance1)
67 self.modelindex = self.lodmodelindex1;
69 self.modelindex = self.lodmodelindex0;
73 // FEATURE: forcemodel
74 string forceplayermodels_model;
75 float forceplayermodels_modelindex;
76 float forceplayermodels_skin;
77 float forceplayermodels_attempted;
78 .string forceplayermodels_savemodel;
79 .float forceplayermodels_savemodelindex;
80 .float forceplayermodels_saveskin;
81 void CSQCPlayer_ForceModel_PreUpdate(void)
83 self.model = self.forceplayermodels_savemodel;
84 self.modelindex = self.forceplayermodels_savemodelindex;
85 self.skin = self.forceplayermodels_saveskin;
87 void CSQCPlayer_ForceModel_PostUpdate(void)
89 self.forceplayermodels_savemodel = self.model;
90 self.forceplayermodels_savemodelindex = self.modelindex;
91 self.forceplayermodels_saveskin = self.skin;
93 void CSQCPlayer_ForceModel_Apply(float islocalplayer)
95 // first, try finding it from the server
96 if(self.forceplayermodels_savemodelindex && self.forceplayermodels_savemodel != "null")
100 // trust server's idea of "own player model"
101 forceplayermodels_model = self.model;
102 forceplayermodels_modelindex = self.modelindex;
103 forceplayermodels_skin = self.skin;
104 forceplayermodels_attempted = 1;
108 // forcemodel finding
109 if(!forceplayermodels_attempted)
111 // only if this failed, find it out on our own
114 setmodel(e, autocvar__cl_playermodel); // this is harmless, see below
115 forceplayermodels_model = e.model;
116 forceplayermodels_modelindex = e.modelindex;
117 forceplayermodels_skin = autocvar__cl_playerskin;
118 forceplayermodels_attempted = 1;
123 if(autocvar_cl_forceplayermodels && forceplayermodels_modelindex)
125 self.model = forceplayermodels_model;
126 self.modelindex = forceplayermodels_modelindex;
127 self.skin = forceplayermodels_skin;
131 // FEATURE: fallback frames
132 .float csqcmodel_saveframe;
133 .float csqcmodel_saveframe2;
134 .float csqcmodel_saveframe3;
135 .float csqcmodel_saveframe4;
136 .float csqcmodel_framecount;
137 void CSQCPlayer_FallbackFrame_PreUpdate(void)
139 self.frame = self.csqcmodel_saveframe;
140 self.frame2 = self.csqcmodel_saveframe2;
141 self.frame3 = self.csqcmodel_saveframe3;
142 self.frame4 = self.csqcmodel_saveframe4;
144 void CSQCPlayer_FallbackFrame_PostUpdate(void)
146 self.csqcmodel_saveframe = self.frame;
147 self.csqcmodel_saveframe2 = self.frame2;
148 self.csqcmodel_saveframe3 = self.frame3;
149 self.csqcmodel_saveframe4 = self.frame4;
151 float CSQCPlayer_FallbackFrame(float f)
153 if(frameduration(self.modelindex, f) > 0)
154 return f; // goooooood
157 case 23: return 11; // anim_melee -> anim_shoot
158 case 24: return 4; // anim_duckwalkbackwards -> anim_duckwalk
159 case 25: return 4; // anim_duckwalkstrafeleft -> anim_duckwalk
160 case 26: return 4; // anim_duckwalkstraferight -> anim_duckwalk
161 case 27: return 4; // anim_duckwalkforwardright -> anim_duckwalk
162 case 28: return 4; // anim_duckwalkforwardleft -> anim_duckwalk
163 case 29: return 4; // anim_duckwalkbackright -> anim_duckwalk
164 case 30: return 4; // anim_duckwalkbackleft -> anim_duckwalk
166 print(sprintf("Frame %d missing in model %s, and we have no fallback - FAIL!\n", f, self.model));
169 void CSQCPlayer_FallbackFrame_Apply(void)
171 self.frame = CSQCPlayer_FallbackFrame(self.frame);
172 self.frame2 = CSQCPlayer_FallbackFrame(self.frame2);
173 self.frame3 = CSQCPlayer_FallbackFrame(self.frame3);
174 self.frame4 = CSQCPlayer_FallbackFrame(self.frame4);
177 // FEATURE: auto glowmod
179 void CSQCPlayer_GlowMod_Apply(void)
181 if(self.colormap > 0)
182 self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? self.colormap : stof(getplayerkeyvalue(self.colormap - 1, "colors"))) & 0x0F, TRUE) * 2;
184 self.glowmod = '1 1 1';
187 // FEATURE: auto tag_index
190 void CSQCModel_AutoTagIndex_Apply(void)
192 if(self.tag_entity && wasfreed(self.tag_entity))
193 self.tag_entity = world;
195 if(self.tag_networkentity)
198 if(self.tag_entity.entnum != self.tag_networkentity)
200 // to something NEW NEW NEW NEW!
201 self.tag_entity = findfloat(world, entnum, self.tag_networkentity);
204 // the best part is: IT EXISTS
205 if(substring(self.model, 0, 17) == "models/weapons/v_")
206 if(substring(self.tag_entity.model, 0, 17) == "models/weapons/h_")
208 self.tag_index = gettagindex(self.tag_entity, "weapon");
210 self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
213 // we need to prevent this from 'appening
214 self.tag_entity = world;
216 dprint("h_ model lacks weapon attachment, but v_ model is attached to it\n");
220 if(substring(self.model, 0, 17) == "models/weapons/v_")
221 if(substring(self.tag_entity.model, 0, 14) == "models/player/")
223 self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
225 self.tag_index = gettagindex(self.tag_entity, "bip01 r hand");
228 if(substring(self.tag_entity.model, 0, 17) == "models/weapons/v_")
230 self.tag_index = gettagindex(self.tag_entity, "shot");
232 self.tag_index = gettagindex(self.tag_entity, "tag_shot");
237 // damn, see you next frame
245 void CSQCModel_Hook_PreDraw(float isplayer, float islocalplayer)
247 if(!self.modelindex || self.model == "null")
253 self.drawmask = MASK_NORMAL;
257 CSQCPlayer_GlowMod_Apply();
258 CSQCPlayer_ForceModel_Apply(islocalplayer);
259 CSQCPlayer_LOD_Apply();
260 CSQCPlayer_FallbackFrame_Apply();
264 CSQCModel_AutoTagIndex_Apply();
267 void CSQCModel_Hook_PreUpdate(float isplayer, float islocalplayer)
271 // revert to values from server
272 CSQCPlayer_ForceModel_PreUpdate();
273 CSQCPlayer_FallbackFrame_PreUpdate();
277 void CSQCModel_Hook_PostUpdate(float isplayer, float islocalplayer)
281 // save values set by server
282 CSQCPlayer_ForceModel_PostUpdate();
283 CSQCPlayer_FallbackFrame_PostUpdate();