3 void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove;
4 void() SUB_CalcMoveDone;
5 void() SUB_CalcAngleMoveDone;
6 //void() SUB_UseTargets;
9 void spawnfunc_info_null (void)
12 // if anything breaks, tell the mapper to fix his map! info_null is meant to remove itself immediately.
22 void SUB_Remove (void)
31 Applies some friction to self
35 void SUB_Friction (void)
37 self.nextthink = time;
38 if(self.flags & FL_ONGROUND)
39 self.velocity = self.velocity * (1 - frametime * self.friction);
46 Makes client invisible or removes non-client
49 void SUB_VanishOrRemove (entity ent)
51 if (ent.flags & FL_CLIENT)
66 void SUB_SetFade_Think (void)
68 self.think = SUB_SetFade_Think;
69 self.nextthink = self.fade_time;
70 self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
71 if (self.alpha < 0.01)
72 SUB_VanishOrRemove(self);
73 self.alpha = bound(0.01, self.alpha, 1);
80 Fade 'ent' out when time >= 'when'
83 void SUB_SetFade (entity ent, float when, float fadetime)
85 //if (ent.flags & FL_CLIENT) // && ent.deadflag != DEAD_NO)
88 ent.fade_rate = 1/fadetime;
90 ent.think = SUB_SetFade_Think;
98 calculate self.velocity and self.nextthink to reach dest from
99 self.origin traveling at speed
102 void SUB_CalcMoveDone (void)
104 // After moving, set origin to exact final destination
106 setorigin (self, self.finaldest);
107 self.velocity = '0 0 0';
113 void SUB_CalcMove (vector tdest, float tspeed, void() func)
119 objerror ("No speed is defined!");
122 self.finaldest = tdest;
123 self.think = SUB_CalcMoveDone;
125 if (tdest == self.origin)
127 self.velocity = '0 0 0';
128 self.nextthink = self.ltime + 0.1;
132 delta = tdest - self.origin;
133 traveltime = vlen (delta) / tspeed;
135 if (traveltime < 0.1)
137 self.velocity = '0 0 0';
138 self.nextthink = self.ltime + 0.1;
142 self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
144 self.nextthink = self.ltime + traveltime;
147 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
154 SUB_CalcMove (tdest, tspeed, func);
163 calculate self.avelocity and self.nextthink to reach destangle from
166 The calling function should make sure self.think is valid
169 void SUB_CalcAngleMoveDone (void)
171 // After rotating, set angle to exact final angle
172 self.angles = self.finalangle;
173 self.avelocity = '0 0 0';
179 void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
185 objerror ("No speed is defined!");
187 delta = destangle - self.angles;
188 traveltime = vlen (delta) / tspeed;
190 self.avelocity = delta * (1 / traveltime);
193 self.finalangle = destangle;
195 self.think = SUB_CalcAngleMoveDone;
196 self.nextthink = self.ltime + traveltime;
199 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
206 SUB_CalcAngleMove (destangle, tspeed, func);
215 unused but required by the engine
229 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
230 Additionally it moves players back into the past before the trace and restores them afterward.
233 void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
236 local float oldsolid;
238 // check whether antilagged traces are enabled
241 if (clienttype(forent) != CLIENTTYPE_REAL)
242 lag = 0; // only antilag for clients
244 // change shooter to SOLID_BBOX so the shot can hit corpses
245 oldsolid = source.dphitcontentsmask;
246 source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
250 // take players back into the past
251 player = player_list;
254 antilag_takeback(player, time - lag);
255 player = player.nextplayer;
260 traceline (v1, v2, nomonst, forent);
262 // restore players to current positions
265 player = player_list;
268 antilag_restore(player);
269 player = player.nextplayer;
273 // restore shooter solid type
274 source.dphitcontentsmask = oldsolid;
276 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
278 if (cvar("g_antilag") != 2)
280 traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
287 Returns a point at least 12 units away from walls
288 (useful for explosion animations, although the blast is performed where it really happened)
292 vector findbetterlocation (vector org, float mindist)
298 vec = mindist * '1 0 0';
302 traceline (org, org + vec, TRUE, world);
304 if (trace_fraction < 1)
307 traceline (loc, loc + vec, TRUE, world);
308 if (trace_fraction >= 1)
327 Returns a random number between -1.0 and 1.0
332 return 2 * (random () - 0.5);
337 Angc used for animations
342 float angc (float a1, float a2)
369 .float lodmodelindex0;
370 .float lodmodelindex1;
371 .float lodmodelindex2;
375 vector NearestPointOnBox(entity box, vector org);
376 float LOD_customize()
382 d = cvar("loddebug");
384 self.modelindex = self.lodmodelindex0;
386 self.modelindex = self.lodmodelindex1;
388 self.modelindex = self.lodmodelindex2;
392 // TODO csqc network this so it only gets sent once
393 d = vlen(NearestPointOnBox(self, other.origin) - other.origin);
394 if(d < self.loddistance1)
395 self.modelindex = self.lodmodelindex0;
396 else if(!self.lodmodelindex2 || d < self.loddistance2)
397 self.modelindex = self.lodmodelindex1;
399 self.modelindex = self.lodmodelindex2;
404 void LOD_uncustomize()
406 self.modelindex = self.lodmodelindex0;
409 void LODmodel_attach()
413 if(!self.loddistance1)
414 self.loddistance1 = 1000;
415 if(!self.loddistance2)
416 self.loddistance2 = 2000;
417 self.lodmodelindex0 = self.modelindex;
419 if(self.lodtarget1 != "")
421 e = find(world, targetname, self.lodtarget1);
424 self.lodmodel1 = e.model;
428 if(self.lodtarget2 != "")
430 e = find(world, targetname, self.lodtarget2);
433 self.lodmodel2 = e.model;
438 if(self.lodmodel1 != "")
444 precache_model(self.lodmodel1);
445 setmodel(self, self.lodmodel1);
446 self.lodmodelindex1 = self.modelindex;
448 if(self.lodmodel2 != "")
450 precache_model(self.lodmodel2);
451 setmodel(self, self.lodmodel2);
452 self.lodmodelindex2 = self.modelindex;
455 self.modelindex = self.lodmodelindex0;
456 setsize(self, mi, ma);
459 if(self.lodmodelindex1)
460 SetCustomizer(self, LOD_customize, LOD_uncustomize);
463 void SetBrushEntityModel()
467 precache_model(self.model);
468 setmodel(self, self.model); // no precision needed
469 InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
471 setorigin(self, self.origin);
473 setsize(self, self.mins * self.scale, self.maxs * self.scale);
475 setsize(self, self.mins, self.maxs);
486 if (self.movedir != '0 0 0')
487 self.movedir = normalize(self.movedir);
490 if (self.angles == '0 -1 0')
491 self.movedir = '0 0 1';
492 else if (self.angles == '0 -2 0')
493 self.movedir = '0 0 -1';
496 makevectors (self.angles);
497 self.movedir = v_forward;
501 self.angles = '0 0 0';
506 // trigger angles are used for one-way touches. An angle of 0 is assumed
507 // to mean no restrictions, so use a yaw of 360 instead.
508 if (self.movedir == '0 0 0')
509 if (self.angles != '0 0 0')
511 self.solid = SOLID_TRIGGER;
512 SetBrushEntityModel();
513 self.movetype = MOVETYPE_NONE;
518 void InitSolidBSPTrigger()
520 // trigger angles are used for one-way touches. An angle of 0 is assumed
521 // to mean no restrictions, so use a yaw of 360 instead.
522 if (self.movedir == '0 0 0')
523 if (self.angles != '0 0 0')
525 self.solid = SOLID_BSP;
526 SetBrushEntityModel();
527 self.movetype = MOVETYPE_PUSH;
528 // self.modelindex = 0;
532 void InitMovingBrushTrigger()
534 // trigger angles are used for one-way touches. An angle of 0 is assumed
535 // to mean no restrictions, so use a yaw of 360 instead.
536 self.solid = SOLID_BSP;
537 SetBrushEntityModel();
538 self.movetype = MOVETYPE_PUSH;