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 (MUST be called BEFORE LOD!)
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
97 if(self.forceplayermodels_savemodelindex && self.forceplayermodels_savemodel != "null")
101 // trust server's idea of "own player model"
102 forceplayermodels_model = self.model;
103 forceplayermodels_modelindex = self.modelindex;
104 forceplayermodels_skin = self.skin;
105 forceplayermodels_attempted = 1;
109 // forcemodel finding
110 if(!forceplayermodels_attempted)
112 // only if this failed, find it out on our own
115 setmodel(e, autocvar__cl_playermodel); // this is harmless, see below
116 forceplayermodels_model = e.model;
117 forceplayermodels_modelindex = e.modelindex;
118 forceplayermodels_skin = autocvar__cl_playerskin;
119 forceplayermodels_attempted = 1;
124 if(autocvar_cl_forceplayermodels && forceplayermodels_modelindex)
126 self.model = forceplayermodels_model;
127 self.modelindex = forceplayermodels_modelindex;
128 self.skin = forceplayermodels_skin;
132 self.model = self.forceplayermodels_savemodel;
133 self.modelindex = self.forceplayermodels_savemodelindex;
134 self.skin = self.forceplayermodels_saveskin;
138 // FEATURE: fallback frames
139 .float csqcmodel_saveframe;
140 .float csqcmodel_saveframe2;
141 .float csqcmodel_saveframe3;
142 .float csqcmodel_saveframe4;
143 .float csqcmodel_framecount;
144 void CSQCPlayer_FallbackFrame_PreUpdate(void)
146 self.frame = self.csqcmodel_saveframe;
147 self.frame2 = self.csqcmodel_saveframe2;
148 self.frame3 = self.csqcmodel_saveframe3;
149 self.frame4 = self.csqcmodel_saveframe4;
151 void CSQCPlayer_FallbackFrame_PostUpdate(void)
153 self.csqcmodel_saveframe = self.frame;
154 self.csqcmodel_saveframe2 = self.frame2;
155 self.csqcmodel_saveframe3 = self.frame3;
156 self.csqcmodel_saveframe4 = self.frame4;
158 float CSQCPlayer_FallbackFrame(float f)
160 if(frameduration(self.modelindex, f) > 0)
161 return f; // goooooood
164 case 23: return 11; // anim_melee -> anim_shoot
165 case 24: return 4; // anim_duckwalkbackwards -> anim_duckwalk
166 case 25: return 4; // anim_duckwalkstrafeleft -> anim_duckwalk
167 case 26: return 4; // anim_duckwalkstraferight -> anim_duckwalk
168 case 27: return 4; // anim_duckwalkforwardright -> anim_duckwalk
169 case 28: return 4; // anim_duckwalkforwardleft -> anim_duckwalk
170 case 29: return 4; // anim_duckwalkbackright -> anim_duckwalk
171 case 30: return 4; // anim_duckwalkbackleft -> anim_duckwalk
173 print(sprintf("Frame %d missing in model %s, and we have no fallback - FAIL!\n", f, self.model));
176 void CSQCPlayer_FallbackFrame_Apply(void)
178 self.frame = CSQCPlayer_FallbackFrame(self.frame);
179 self.frame2 = CSQCPlayer_FallbackFrame(self.frame2);
180 self.frame3 = CSQCPlayer_FallbackFrame(self.frame3);
181 self.frame4 = CSQCPlayer_FallbackFrame(self.frame4);
184 // FEATURE: auto glowmod
186 void CSQCPlayer_GlowMod_Apply(void)
188 if(self.colormap > 0)
189 self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? self.colormap : stof(getplayerkeyvalue(self.colormap - 1, "colors"))) & 0x0F, TRUE) * 2;
191 self.glowmod = '1 1 1';
194 // FEATURE: auto tag_index
196 .float tag_entity_lastmodelindex;
198 void CSQCModel_AutoTagIndex_Apply(void)
200 if(self.tag_entity && wasfreed(self.tag_entity))
201 self.tag_entity = world;
203 if(self.tag_networkentity)
207 if(self.tag_entity.entnum != self.tag_networkentity)
209 self.tag_entity = findfloat(world, entnum, self.tag_networkentity);
212 if(self.tag_entity.modelindex != self.tag_entity_lastmodelindex)
214 self.tag_entity_lastmodelindex = self.tag_entity.modelindex;
221 // the best part is: IT EXISTS
222 if(substring(self.model, 0, 17) == "models/weapons/v_")
223 if(substring(self.tag_entity.model, 0, 17) == "models/weapons/h_")
225 self.tag_index = gettagindex(self.tag_entity, "weapon");
227 self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
230 // we need to prevent this from 'appening
231 self.tag_entity = world;
233 dprint("h_ model lacks weapon attachment, but v_ model is attached to it\n");
237 if(substring(self.model, 0, 17) == "models/weapons/v_")
238 if(substring(self.tag_entity.model, 0, 14) == "models/player/")
240 self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
242 self.tag_index = gettagindex(self.tag_entity, "bip01 r hand");
245 if(substring(self.tag_entity.model, 0, 17) == "models/weapons/v_")
247 self.tag_index = gettagindex(self.tag_entity, "shot");
249 self.tag_index = gettagindex(self.tag_entity, "tag_shot");
254 // damn, see you next frame
261 // FEATURE: EF_NODRAW workalike
262 .float invisible_effects;
263 void CSQCModel_Invisible_PreUpdate(void)
265 self.effects = self.invisible_effects;
267 void CSQCModel_Invisible_PostUpdate(void)
269 self.invisible_effects = self.effects;
270 self.effects &~= CSQCMODEL_EF_INVISIBLE;
272 void CSQCModel_Invisible_Apply(void)
274 if(self.invisible_effects & CSQCMODEL_EF_INVISIBLE)
279 void CSQCModel_Hook_PreDraw(float isplayer, float islocalplayer)
281 if(!self.modelindex || self.model == "null")
287 self.drawmask = MASK_NORMAL;
291 CSQCPlayer_GlowMod_Apply();
292 CSQCPlayer_ForceModel_Apply(islocalplayer);
293 CSQCPlayer_LOD_Apply();
294 CSQCPlayer_FallbackFrame_Apply();
298 CSQCModel_AutoTagIndex_Apply();
300 CSQCModel_Invisible_Apply();
303 void CSQCModel_Hook_PreUpdate(float isplayer, float islocalplayer)
305 CSQCModel_Invisible_PreUpdate();
308 // revert to values from server
309 CSQCPlayer_FallbackFrame_PreUpdate();
310 CSQCPlayer_ForceModel_PreUpdate();
314 void CSQCModel_Hook_PostUpdate(float isplayer, float islocalplayer)
318 // save values set by server
319 CSQCPlayer_ForceModel_PostUpdate();
320 CSQCPlayer_FallbackFrame_PostUpdate();
322 CSQCModel_Invisible_PostUpdate();