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)
80 ent.think = SUB_SetFade_Think;
88 calculate self.velocity and self.nextthink to reach dest from
89 self.origin traveling at speed
92 void SUB_CalcMoveDone (void)
94 // After moving, set origin to exact final destination
96 setorigin (self, self.finaldest);
97 self.velocity = '0 0 0';
103 void SUB_CalcMove (vector tdest, float tspeed, void() func)
109 objerror ("No speed is defined!");
112 self.finaldest = tdest;
113 self.think = SUB_CalcMoveDone;
115 if (tdest == self.origin)
117 self.velocity = '0 0 0';
118 self.nextthink = self.ltime + 0.1;
122 delta = tdest - self.origin;
123 traveltime = vlen (delta) / tspeed;
125 if (traveltime < 0.1)
127 self.velocity = '0 0 0';
128 self.nextthink = self.ltime + 0.1;
132 self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
134 self.nextthink = self.ltime + traveltime;
137 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
144 SUB_CalcMove (tdest, tspeed, func);
153 calculate self.avelocity and self.nextthink to reach destangle from
156 The calling function should make sure self.think is valid
159 void SUB_CalcAngleMoveDone (void)
161 // After rotating, set angle to exact final angle
162 self.angles = self.finalangle;
163 self.avelocity = '0 0 0';
169 void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
175 objerror ("No speed is defined!");
177 delta = destangle = self.angles;
178 traveltime = vlen (delta) / tspeed;
180 self.avelocity = delta * (1 / traveltime);
183 self.finalangle = destangle;
185 self.think = SUB_CalcAngleMoveDone;
186 self.nextthink = self.ltime + traveltime;
189 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
196 SUB_CalcAngleMove (destangle, tspeed, func);
205 unused but required by the engine
219 Play a sound at the given location
222 void PointSound (vector org, string snd, float vol, float attn)
227 setorigin (speaker, org);
228 sound (speaker, CHAN_BODY, snd, vol, attn);
238 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
241 void traceline_hitcorpse (entity source, vector v1, vector v2, float nomonst, entity forent)
245 oldsolid = source.solid;
246 source.solid = SOLID_BBOX;
248 traceline (v1, v2, nomonst, forent);
250 source.solid = oldsolid;
257 Returns a point at least 12 units away from walls
258 (useful for explosion animations, although the blast is performed where it really happened)
262 vector findbetterlocation (vector org)
266 traceline (org, org - '12 0 0', TRUE, world);
267 if (trace_fraction < 1)
270 traceline (loc, loc + '12 0 0', TRUE, world);
271 if (trace_fraction >= 1)
272 org = loc + '12 0 0';
275 traceline (org, org - '-12 0 0', TRUE, world);
276 if (trace_fraction < 1)
279 traceline (loc, loc + '-12 0 0', TRUE, world);
280 if (trace_fraction >= 1)
281 org = loc + '-12 0 0';
284 traceline (org, org - '0 12 0' , TRUE, world);
285 if (trace_fraction < 1)
288 traceline (loc, loc + '0 12 0', TRUE, world);
289 if (trace_fraction >= 1)
290 org = loc + '0 12 0';
293 traceline (org, org - '0 -12 0', TRUE, world);
294 if (trace_fraction < 1)
297 traceline (loc, loc + '0 -12 0', TRUE, world);
298 if (trace_fraction >= 1)
299 org = loc + '0 -12 0';
302 traceline (org, org - '0 0 12' , TRUE, world);
303 if (trace_fraction < 1)
306 traceline (loc, loc + '0 0 12', TRUE, world);
307 if (trace_fraction >= 1)
308 org = loc + '0 0 12';
311 traceline (org, org - '0 0 -12', TRUE, world);
312 if (trace_fraction < 1)
315 traceline (loc, loc + '0 0 -12', TRUE, world);
316 if (trace_fraction >= 1)
317 org = loc + '0 0 -12';
327 Returns a random number between -1.0 and 1.0
332 return 2 * (random () - 0.5);
341 Plays an impact effect
345 void ImpactEffect (entity ent, float weapontype)
348 org2 = findbetterlocation (ent.origin);
351 if (weapontype == IT_ROCKET_LAUNCHER)
354 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 40);
355 sound (ent, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);
357 else if (weapontype == IT_GRENADE_LAUNCHER)
360 effect (org2, "models/sprites/dpexplosion1.spr32", 0, 20, 30);
361 sound (ent, CHAN_BODY, "weapons/grenade_impact.wav", 1, ATTN_NORM);
363 else if (weapontype == IT_HAGAR)
365 effect (org2, "models/sprites/dpexplosion2.spr32", 0, 20, 30);
366 sound (ent, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);
368 else if (weapontype == IT_ELECTRO) // Secondary fire
370 effect (org2, "models/sprites/plasmahitwall.spr32", 0, 20, 50);
371 sound (ent, CHAN_BODY, "weapons/plasma_hit.wav", 1, ATTN_NORM);
378 Angc used for animations
383 float angc (float a1, float a2)
415 if (self.movedir != '0 0 0')
416 self.movedir = normalize(self.movedir);
419 if (self.angles == '0 -1 0')
420 self.movedir = '0 0 1';
421 else if (self.angles == '0 -2 0')
422 self.movedir = '0 0 -1';
425 makevectors (self.angles);
426 self.movedir = v_forward;
430 self.angles = '0 0 0';
435 // trigger angles are used for one-way touches. An angle of 0 is assumed
436 // to mean no restrictions, so use a yaw of 360 instead.
437 if (self.movedir == '0 0 0')
438 if (self.angles != '0 0 0')
440 self.solid = SOLID_TRIGGER;
441 setmodel (self, self.model); // set size and link into world
442 self.movetype = MOVETYPE_NONE;
447 void() InitSolidBSPTrigger =
449 // trigger angles are used for one-way touches. An angle of 0 is assumed
450 // to mean no restrictions, so use a yaw of 360 instead.
451 if (self.movedir == '0 0 0')
452 if (self.angles != '0 0 0')
454 self.solid = SOLID_BSP;
455 setmodel (self, self.model); // set size and link into world
456 self.movetype = MOVETYPE_PUSH;
457 // self.modelindex = 0;