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)
37 void SUB_SetFade_Think (void)
39 if (self.alpha < 0.06) // don't let it reach 0, lest it become fully visible again
42 self.alpha = self.alpha - 0.05;
44 self.think = SUB_SetFade_Think;
45 self.nextthink = time + 0.1;
52 Fade 'ent' out when time >= 'when'
55 void SUB_SetFade (entity ent, float when)
65 ent.think = SUB_SetFade_Think;
73 calculate self.velocity and self.nextthink to reach dest from
74 self.origin traveling at speed
77 void SUB_CalcMoveDone (void)
79 // After moving, set origin to exact final destination
81 setorigin (self, self.finaldest);
82 self.velocity = '0 0 0';
88 void SUB_CalcMove (vector tdest, float tspeed, void() func)
94 objerror ("No speed is defined!");
97 self.finaldest = tdest;
98 self.think = SUB_CalcMoveDone;
100 if (tdest == self.origin)
102 self.velocity = '0 0 0';
103 self.nextthink = self.ltime + 0.1;
107 delta = tdest - self.origin;
108 traveltime = vlen (delta) / tspeed;
110 if (traveltime < 0.1)
112 self.velocity = '0 0 0';
113 self.nextthink = self.ltime + 0.1;
117 self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
119 self.nextthink = self.ltime + traveltime;
122 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
129 SUB_CalcMove (tdest, tspeed, func);
138 calculate self.avelocity and self.nextthink to reach destangle from
141 The calling function should make sure self.think is valid
144 void SUB_CalcAngleMoveDone (void)
146 // After rotating, set angle to exact final angle
147 self.angles = self.finalangle;
148 self.avelocity = '0 0 0';
154 void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
160 objerror ("No speed is defined!");
162 delta = destangle = self.angles;
163 traveltime = vlen (delta) / tspeed;
165 self.avelocity = delta * (1 / traveltime);
168 self.finalangle = destangle;
170 self.think = SUB_CalcAngleMoveDone;
171 self.nextthink = self.ltime + traveltime;
174 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
181 SUB_CalcAngleMove (destangle, tspeed, func);
190 unused but required by the engine
204 Play a sound at the given location
207 void PointSound (vector org, string snd, float vol, float attn)
212 setorigin (speaker, org);
213 sound (speaker, CHAN_BODY, snd, vol, attn);
223 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
226 void traceline_hitcorpse (entity source, vector v1, vector v2, float nomonst, entity forent)
230 oldsolid = source.solid;
231 source.solid = SOLID_BBOX;
233 traceline (v1, v2, nomonst, forent);
235 source.solid = oldsolid;
242 Returns a point at least 12 units away from walls
243 (useful for explosion animations, although the blast is performed where it really happened)
247 vector findbetterlocation (vector org)
251 traceline (org, org - '12 0 0', TRUE, world);
252 if (trace_fraction < 1)
255 traceline (loc, loc + '12 0 0', TRUE, world);
256 if (trace_fraction >= 1)
257 org = loc + '12 0 0';
260 traceline (org, org - '-12 0 0', TRUE, world);
261 if (trace_fraction < 1)
264 traceline (loc, loc + '-12 0 0', TRUE, world);
265 if (trace_fraction >= 1)
266 org = loc + '-12 0 0';
269 traceline (org, org - '0 12 0' , TRUE, world);
270 if (trace_fraction < 1)
273 traceline (loc, loc + '0 12 0', TRUE, world);
274 if (trace_fraction >= 1)
275 org = loc + '0 12 0';
278 traceline (org, org - '0 -12 0', TRUE, world);
279 if (trace_fraction < 1)
282 traceline (loc, loc + '0 -12 0', TRUE, world);
283 if (trace_fraction >= 1)
284 org = loc + '0 -12 0';
287 traceline (org, org - '0 0 12' , TRUE, world);
288 if (trace_fraction < 1)
291 traceline (loc, loc + '0 0 12', TRUE, world);
292 if (trace_fraction >= 1)
293 org = loc + '0 0 12';
296 traceline (org, org - '0 0 -12', TRUE, world);
297 if (trace_fraction < 1)
300 traceline (loc, loc + '0 0 -12', TRUE, world);
301 if (trace_fraction >= 1)
302 org = loc + '0 0 -12';
312 Returns a random number between -1.0 and 1.0
317 return 2 * (random () - 0.5);
326 Plays an impact effect
330 void ImpactEffect (entity ent, float weapontype)
333 org2 = findbetterlocation (ent.origin);
336 if (weapontype == IT_ROCKET_LAUNCHER)
339 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 40);
340 sound (ent, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);
342 else if (weapontype == IT_GRENADE_LAUNCHER)
345 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 30);
346 sound (ent, CHAN_BODY, "weapons/grenade_impact.wav", 1, ATTN_NORM);
348 else if (weapontype == IT_HAGAR)
350 effect (org2, "models/sprites/dpexplosion2.spr32", 0, 20, 30);
351 sound (ent, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);
353 else if (weapontype == IT_ELECTRO) // Secondary fire
355 effect (org2, "models/sprites/plasmahitwall.spr32", 0, 20, 50);
356 sound (ent, CHAN_BODY, "weapons/plasma_hit.wav", 1, ATTN_NORM);
363 Angc used for animations
368 float angc (float a1, float a2)
400 if (self.movedir != '0 0 0')
401 self.movedir = normalize(self.movedir);
404 if (self.angles == '0 -1 0')
405 self.movedir = '0 0 1';
406 else if (self.angles == '0 -2 0')
407 self.movedir = '0 0 -1';
410 makevectors (self.angles);
411 self.movedir = v_forward;
415 self.angles = '0 0 0';
420 // trigger angles are used for one-way touches. An angle of 0 is assumed
421 // to mean no restrictions, so use a yaw of 360 instead.
422 if (self.movedir == '0 0 0')
423 if (self.angles != '0 0 0')
425 self.solid = SOLID_TRIGGER;
426 setmodel (self, self.model); // set size and link into world
427 self.movetype = MOVETYPE_NONE;
432 void() InitSolidBSPTrigger =
434 // trigger angles are used for one-way touches. An angle of 0 is assumed
435 // to mean no restrictions, so use a yaw of 360 instead.
436 if (self.movedir == '0 0 0')
437 if (self.angles != '0 0 0')
439 self.solid = SOLID_BSP;
440 setmodel (self, self.model); // set size and link into world
441 self.movetype = MOVETYPE_PUSH;
442 // self.modelindex = 0;