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 float LOD_customize()
379 // TODO csqc network this so it only gets sent once
380 d = vlen(self.origin - other.origin);
381 if(d < self.loddistance1)
382 self.modelindex = self.lodmodelindex0;
383 else if(!self.lodmodelindex2 || d < self.loddistance2)
384 self.modelindex = self.lodmodelindex1;
386 self.modelindex = self.lodmodelindex2;
391 void LOD_uncustomize()
393 self.modelindex = self.lodmodelindex0;
396 void LODmodel_attach()
400 if(!self.loddistance1)
401 self.loddistance1 = 1000;
402 if(!self.loddistance2)
403 self.loddistance2 = 2000;
404 self.lodmodelindex0 = self.modelindex;
406 if(self.lodtarget1 != "")
408 e = find(world, targetname, self.lodtarget1);
411 self.lodmodel1 = e.model;
415 if(self.lodtarget2 != "")
417 e = find(world, targetname, self.lodtarget2);
420 self.lodmodel2 = e.model;
425 if(self.lodmodel1 != "")
431 precache_model(self.lodmodel1);
432 setmodel(self, self.lodmodel1);
433 self.lodmodelindex1 = self.modelindex;
435 if(self.lodmodel2 != "")
437 precache_model(self.lodmodel2);
438 setmodel(self, self.lodmodel2);
439 self.lodmodelindex2 = self.modelindex;
442 self.modelindex = self.lodmodelindex0;
443 setsize(self, mi, ma);
446 if(self.lodmodelindex1)
447 SetCustomizer(self, LOD_customize, LOD_uncustomize);
450 void SetBrushEntityModel()
454 precache_model(self.model);
455 setmodel(self, self.model); // no precision needed
456 InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
458 setorigin(self, self.origin);
459 setsize(self, self.mins, self.maxs);
470 if (self.movedir != '0 0 0')
471 self.movedir = normalize(self.movedir);
474 if (self.angles == '0 -1 0')
475 self.movedir = '0 0 1';
476 else if (self.angles == '0 -2 0')
477 self.movedir = '0 0 -1';
480 makevectors (self.angles);
481 self.movedir = v_forward;
485 self.angles = '0 0 0';
490 // trigger angles are used for one-way touches. An angle of 0 is assumed
491 // to mean no restrictions, so use a yaw of 360 instead.
492 if (self.movedir == '0 0 0')
493 if (self.angles != '0 0 0')
495 self.solid = SOLID_TRIGGER;
496 SetBrushEntityModel();
497 self.movetype = MOVETYPE_NONE;
502 void InitSolidBSPTrigger()
504 // trigger angles are used for one-way touches. An angle of 0 is assumed
505 // to mean no restrictions, so use a yaw of 360 instead.
506 if (self.movedir == '0 0 0')
507 if (self.angles != '0 0 0')
509 self.solid = SOLID_BSP;
510 SetBrushEntityModel();
511 self.movetype = MOVETYPE_PUSH;
512 // self.modelindex = 0;
516 void InitMovingBrushTrigger()
518 // trigger angles are used for one-way touches. An angle of 0 is assumed
519 // to mean no restrictions, so use a yaw of 360 instead.
520 self.solid = SOLID_BSP;
521 SetBrushEntityModel();
522 self.movetype = MOVETYPE_PUSH;