1 void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove;
2 void() SUB_CalcMoveDone;
3 void() SUB_CalcAngleMoveDone;
5 //void() SUB_UseTargets;
32 void SUB_Remove (void)
41 Makes ent invisible or removes it if ent.norespawn
44 void SUB_VanishOrRemove (entity ent)
54 ent.effects = EF_NODRAW;
58 void SUB_SetFade_Think (void)
60 self.think = SUB_SetFade_Think;
61 self.nextthink = self.fade_time;
62 self.alpha = 1 - (time - self.fade_time) * 0.5;
65 if (self.alpha < 0.01) // don't let it reach 0, lest it become fully visible again
66 SUB_VanishOrRemove(self);
73 Fade 'ent' out when time >= 'when'
76 void SUB_SetFade (entity ent, float when)
78 if (self.flags & FL_CLIENT) // && self.deadflag != DEAD_NO)
82 ent.think = SUB_SetFade_Think;
90 calculate self.velocity and self.nextthink to reach dest from
91 self.origin traveling at speed
94 void SUB_CalcMoveDone (void)
96 // After moving, set origin to exact final destination
98 setorigin (self, self.finaldest);
99 self.velocity = '0 0 0';
105 void SUB_CalcMove (vector tdest, float tspeed, void() func)
111 objerror ("No speed is defined!");
114 self.finaldest = tdest;
115 self.think = SUB_CalcMoveDone;
117 if (tdest == self.origin)
119 self.velocity = '0 0 0';
120 self.nextthink = self.ltime + 0.1;
124 delta = tdest - self.origin;
125 traveltime = vlen (delta) / tspeed;
127 if (traveltime < 0.1)
129 self.velocity = '0 0 0';
130 self.nextthink = self.ltime + 0.1;
134 self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
136 self.nextthink = self.ltime + traveltime;
139 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
146 SUB_CalcMove (tdest, tspeed, func);
155 calculate self.avelocity and self.nextthink to reach destangle from
158 The calling function should make sure self.think is valid
161 void SUB_CalcAngleMoveDone (void)
163 // After rotating, set angle to exact final angle
164 self.angles = self.finalangle;
165 self.avelocity = '0 0 0';
171 void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
177 objerror ("No speed is defined!");
179 delta = destangle = self.angles;
180 traveltime = vlen (delta) / tspeed;
182 self.avelocity = delta * (1 / traveltime);
185 self.finalangle = destangle;
187 self.think = SUB_CalcAngleMoveDone;
188 self.nextthink = self.ltime + traveltime;
191 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
198 SUB_CalcAngleMove (destangle, tspeed, func);
207 unused but required by the engine
221 Play a sound at the given location
224 void PointSound (vector org, string snd, float vol, float attn)
229 setorigin (speaker, org);
230 sound (speaker, CHAN_BODY, snd, vol, attn);
240 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
243 void traceline_hitcorpse (entity source, vector v1, vector v2, float nomonst, entity forent)
247 oldsolid = source.solid;
248 source.solid = SOLID_BBOX;
250 traceline (v1, v2, nomonst, forent);
252 source.solid = oldsolid;
259 Returns a point at least 12 units away from walls
260 (useful for explosion animations, although the blast is performed where it really happened)
264 vector findbetterlocation (vector org)
268 traceline (org, org - '12 0 0', TRUE, world);
269 if (trace_fraction < 1)
272 traceline (loc, loc + '12 0 0', TRUE, world);
273 if (trace_fraction >= 1)
274 org = loc + '12 0 0';
277 traceline (org, org - '-12 0 0', TRUE, world);
278 if (trace_fraction < 1)
281 traceline (loc, loc + '-12 0 0', TRUE, world);
282 if (trace_fraction >= 1)
283 org = loc + '-12 0 0';
286 traceline (org, org - '0 12 0' , TRUE, world);
287 if (trace_fraction < 1)
290 traceline (loc, loc + '0 12 0', TRUE, world);
291 if (trace_fraction >= 1)
292 org = loc + '0 12 0';
295 traceline (org, org - '0 -12 0', TRUE, world);
296 if (trace_fraction < 1)
299 traceline (loc, loc + '0 -12 0', TRUE, world);
300 if (trace_fraction >= 1)
301 org = loc + '0 -12 0';
304 traceline (org, org - '0 0 12' , TRUE, world);
305 if (trace_fraction < 1)
308 traceline (loc, loc + '0 0 12', TRUE, world);
309 if (trace_fraction >= 1)
310 org = loc + '0 0 12';
313 traceline (org, org - '0 0 -12', TRUE, world);
314 if (trace_fraction < 1)
317 traceline (loc, loc + '0 0 -12', TRUE, world);
318 if (trace_fraction >= 1)
319 org = loc + '0 0 -12';
329 Returns a random number between -1.0 and 1.0
334 return 2 * (random () - 0.5);
343 Plays an impact effect
347 void ImpactEffect (entity ent, float weapontype)
350 org2 = findbetterlocation (ent.origin);
353 if (weapontype == IT_ROCKET_LAUNCHER)
356 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 40);
357 sound (ent, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);
359 else if (weapontype == IT_GRENADE_LAUNCHER)
362 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 30);
363 sound (ent, CHAN_BODY, "weapons/grenade_impact.wav", 1, ATTN_NORM);
365 else if (weapontype == IT_HAGAR)
367 effect (org2, "models/sprites/dpexplosion2.spr32", 0, 20, 30);
370 sound (ent, CHAN_BODY, "weapons/hagexp1.wav", 1, ATTN_NORM);
372 sound (ent, CHAN_BODY, "weapons/hagexp2.wav", 1, ATTN_NORM);
374 sound (ent, CHAN_BODY, "weapons/hagexp3.wav", 1, ATTN_NORM);
381 Angc used for animations
386 float angc (float a1, float a2)
418 if (self.movedir != '0 0 0')
419 self.movedir = normalize(self.movedir);
422 if (self.angles == '0 -1 0')
423 self.movedir = '0 0 1';
424 else if (self.angles == '0 -2 0')
425 self.movedir = '0 0 -1';
428 makevectors (self.angles);
429 self.movedir = v_forward;
433 self.angles = '0 0 0';
438 // trigger angles are used for one-way touches. An angle of 0 is assumed
439 // to mean no restrictions, so use a yaw of 360 instead.
440 if (self.movedir == '0 0 0')
441 if (self.angles != '0 0 0')
443 self.solid = SOLID_TRIGGER;
444 setmodel (self, self.model); // set size and link into world
445 self.movetype = MOVETYPE_NONE;
450 void() InitSolidBSPTrigger =
452 // trigger angles are used for one-way touches. An angle of 0 is assumed
453 // to mean no restrictions, so use a yaw of 360 instead.
454 if (self.movedir == '0 0 0')
455 if (self.angles != '0 0 0')
457 self.solid = SOLID_BSP;
458 setmodel (self, self.model); // set size and link into world
459 self.movetype = MOVETYPE_PUSH;
460 // self.modelindex = 0;