3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
6 #include "command/common.qh"
7 #include "../common/state.qh"
8 #include "../lib/warpzone/common.qh"
9 #include "../common/mapobjects/subs.qh"
16 unused but required by the engine
30 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
31 Additionally it moves players back into the past before the trace and restores them afterward.
34 void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
36 // check whether antilagged traces are enabled
39 if (!IS_REAL_CLIENT(forent))
40 lag = 0; // only antilag for clients
42 // change shooter to SOLID_BBOX so the shot can hit corpses
43 int oldsolid = source.dphitcontentsmask;
45 source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
48 antilag_takeback_all(forent, lag);
52 WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent);
54 tracebox (v1, mi, ma, v2, nomonst, forent);
56 // restore players to current positions
58 antilag_restore_all(forent);
60 // restore shooter solid type
62 source.dphitcontentsmask = oldsolid;
64 void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
66 tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, false);
68 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
70 bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
71 if (autocvar_g_antilag != 2 || noantilag)
73 traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
75 void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
77 bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
78 if (autocvar_g_antilag != 2 || noantilag)
80 tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, false);
82 void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
84 tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, true);
86 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
88 bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
89 if (autocvar_g_antilag != 2 || noantilag)
91 WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
93 void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
95 bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
96 if (autocvar_g_antilag != 2 || noantilag)
98 tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, true);
101 float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) // returns the number of traces done, for benchmarking
107 //nudge = 2 * cvar("collision_impactnudge"); // why not?
110 dir = normalize(v2 - v1);
112 pos = v1 + dir * nudge;
119 if(pos * dir >= v2 * dir)
127 tracebox(pos, mi, ma, v2, nomonsters, forent);
132 LOG_TRACE("HOLY SHIT! When tracing from ", vtos(v1), " to ", vtos(v2));
133 LOG_TRACE(" Nudging gets us nowhere at ", vtos(pos));
134 LOG_TRACE(" trace_endpos is ", vtos(trace_endpos));
135 LOG_TRACE(" trace distance is ", ftos(vlen(pos - trace_endpos)));
138 stopentity = trace_ent;
142 // we started inside solid.
143 // then trace from endpos to pos
145 tracebox(t, mi, ma, pos, nomonsters, forent);
149 // t is still inside solid? bad
150 // force advance, then, and retry
151 pos = t + dir * nudge;
153 // but if we hit an entity, stop RIGHT before it
154 if(stopatentity && stopentity && stopentity != ignorestopatentity)
156 trace_ent = stopentity;
158 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
164 // we actually LEFT solid!
165 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
171 // pos is outside solid?!? but why?!? never mind, just return it.
173 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
179 void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
181 tracebox_inverted(v1, '0 0 0', '0 0 0', v2, nomonsters, forent, stopatentity, ignorestopatentity);
188 Returns a point at least 12 units away from walls
189 (useful for explosion animations, although the blast is performed where it really happened)
193 vector findbetterlocation (vector org, float mindist)
195 vector vec = mindist * '1 0 0';
199 traceline (org, org + vec, true, NULL);
201 if (trace_fraction < 1)
203 vector loc = trace_endpos;
204 traceline (loc, loc + vec, true, NULL);
205 if (trace_fraction >= 1)
221 bool LOD_customize(entity this, entity client)
223 if(autocvar_loddebug)
225 int d = autocvar_loddebug;
227 this.modelindex = this.lodmodelindex0;
228 else if(d == 2 || !this.lodmodelindex2)
229 this.modelindex = this.lodmodelindex1;
231 this.modelindex = this.lodmodelindex2;
235 // TODO csqc network this so it only gets sent once
236 vector near_point = NearestPointOnBox(this, client.origin);
237 if(vdist(near_point - client.origin, <, this.loddistance1))
238 this.modelindex = this.lodmodelindex0;
239 else if(!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2))
240 this.modelindex = this.lodmodelindex1;
242 this.modelindex = this.lodmodelindex2;
247 void LOD_uncustomize(entity this)
249 this.modelindex = this.lodmodelindex0;
252 void LODmodel_attach(entity this)
256 if(!this.loddistance1)
257 this.loddistance1 = 1000;
258 if(!this.loddistance2)
259 this.loddistance2 = 2000;
260 this.lodmodelindex0 = this.modelindex;
262 if(this.lodtarget1 != "")
264 e = find(NULL, targetname, this.lodtarget1);
267 this.lodmodel1 = e.model;
271 if(this.lodtarget2 != "")
273 e = find(NULL, targetname, this.lodtarget2);
276 this.lodmodel2 = e.model;
281 if(autocvar_loddebug < 0)
283 this.lodmodel1 = this.lodmodel2 = ""; // don't even initialize
286 if(this.lodmodel1 != "")
292 precache_model(this.lodmodel1);
293 _setmodel(this, this.lodmodel1);
294 this.lodmodelindex1 = this.modelindex;
296 if(this.lodmodel2 != "")
298 precache_model(this.lodmodel2);
299 _setmodel(this, this.lodmodel2);
300 this.lodmodelindex2 = this.modelindex;
303 this.modelindex = this.lodmodelindex0;
304 setsize(this, mi, ma);
307 if(this.lodmodelindex1)
308 if (!getSendEntity(this))
309 SetCustomizer(this, LOD_customize, LOD_uncustomize);