]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/vehicles.qc
4c6fffd1d8e8c6a4a5e7daeddcf45c13f2f6ff06
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
1 float autocvar_g_vehicles_crush_dmg;
2 float autocvar_g_vehicles_crush_force;
3 float autocvar_g_vehicles_delayspawn;
4 float autocvar_g_vehicles_delayspawn_jitter;
5 float autocvar_g_vehicles_allow_flagcarry;
6
7 var float autocvar_g_vehicles_nex_damagerate = 0.5;
8 var float autocvar_g_vehicles_uzi_damagerate = 0.5;
9 var float autocvar_g_vehicles_rifle_damagerate = 0.75;
10 var float autocvar_g_vehicles_minstanex_damagerate = 0.001;
11 var float autocvar_g_vehicles_tag_damagerate = 5;
12
13 float autocvar_g_vehicles;
14
15 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
16 void vehicles_return();
17 void vehicles_enter();
18 void vehicles_touch();
19 void vehicles_reset_colors();
20 void vehicles_clearrturn();
21 void vehicles_setreturn();
22
23
24 /** AuxiliaryXhair*
25     Send additional points of interest to be drawn, to vehicle owner
26 **/
27 float MAX_AXH = 4;
28 .entity AuxiliaryXhair[MAX_AXH];
29
30 float SendAuxiliaryXhair(entity to, float sf)
31 {
32
33         WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
34
35         WriteByte(MSG_ENTITY, self.cnt);
36
37         WriteCoord(MSG_ENTITY, self.origin_x);
38         WriteCoord(MSG_ENTITY, self.origin_y);
39         WriteCoord(MSG_ENTITY, self.origin_z);
40
41     WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
42     WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
43     WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
44
45     return TRUE;
46 }
47
48 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
49 {
50     if (clienttype(own) != CLIENTTYPE_REAL)
51         return;
52
53     entity axh;
54
55     axh_id = bound(0, axh_id, MAX_AXH);
56     axh = own.(AuxiliaryXhair[axh_id]);
57
58     if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
59     {
60         axh                     = spawn();
61         axh.cnt                 = axh_id;
62         axh.drawonlytoclient    = own;
63         axh.owner               = own;
64         Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
65     }
66
67     setorigin(axh, loc);
68     axh.colormod            = clr;
69     axh.SendFlags           = 0x01;
70     own.(AuxiliaryXhair[axh_id]) = axh;
71 }
72
73 /*
74 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
75 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
76 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
77 {
78         msgexntity = own;
79
80         WriteByte(MSG_ONE, SVC_TEMPENTITY);
81         WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
82
83         WriteByte(MSG_ONE, axh_id);
84
85         WriteCoord(MSG_ONE, loc_x);
86         WriteCoord(MSG_ONE, loc_y);
87         WriteCoord(MSG_ONE, loc_z);
88
89     WriteByte(MSG_ONE, rint(clr_x * 255));
90     WriteByte(MSG_ONE, rint(clr_y * 255));
91     WriteByte(MSG_ONE, rint(clr_z * 255));
92
93 }
94 */
95 // End AuxiliaryXhair
96
97 /**
98     Notifies the client that he enterd a vehicle, and sends
99     realavent data.
100
101     only sends vehicle_id atm (wich is a HUD_* constant, ex. HUD_SPIDERBOT)
102 **/
103 void CSQCVehicleSetup(entity own, float vehicle_id)
104 {
105     if (clienttype(own) != CLIENTTYPE_REAL)
106         return;
107         
108         msg_entity = own;
109
110         WriteByte(MSG_ONE, SVC_TEMPENTITY);
111         WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
112         if(vehicle_id != 0)
113             WriteByte(MSG_ONE, vehicle_id);        
114         else
115         WriteByte(MSG_ONE, 1 + own.vehicle.vehicle_weapon2mode + HUD_VEHICLE_LAST);
116 }
117
118 /** vehicles_locktarget
119
120     Generic target locking.
121
122     Figure out if what target is "locked" (if any), for missile tracking as such.
123
124     after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
125     you have a locked in target.
126
127     Exspects a crosshair_trace() or equivalent to be
128     dont before calling.
129
130 **/
131 .entity lock_target;
132 .float  lock_strength;
133 .float  lock_time;
134 .float  lock_soundtime;
135 float   DAMAGE_TARGETDRONE = 10;
136
137 vector targetdrone_getnewspot()
138 {
139
140         vector spot;
141         float i;
142         for(i = 0; i < 100; ++i)
143         {
144                 spot = self.origin + randomvec() * 1024;
145                 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
146                 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
147                         return spot;
148         }
149         return self.origin;
150 }
151
152 #if 0
153 void targetdrone_think();
154 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
155 void targetdrone_renwe()
156 {
157         self.think = targetdrone_think;
158         self.nextthink = time + 0.1;
159         setorigin(self, targetdrone_getnewspot());
160         self.health = 200;
161         self.takedamage = DAMAGE_TARGETDRONE;
162         self.event_damage = targetdrone_damage;
163         self.solid = SOLID_BBOX;
164         setmodel(self, "models/runematch/rune.mdl");
165         self.effects = EF_LOWPRECISION;
166         self.scale = 10;
167         self.movetype = MOVETYPE_BOUNCEMISSILE;
168         setsize(self, '-100 -100 -100', '100 100 100');
169
170 }
171 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
172 {
173         self.health -= damage;
174         if(self.health <= 0)
175         {
176                 pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);
177
178                 if(!self.cnt)
179                         remove(self);
180                 else
181                 {
182                         self.think = targetdrone_renwe;
183                         self.nextthink = time + 1 + random() * 2;
184                         self.solid = SOLID_NOT;
185                         setmodel(self, "");
186                 }
187         }
188 }
189 entity targetdrone_getfear()
190 {
191         entity fear;
192         float i;
193
194         for(i = 64; i <= 1024; i += 64)
195         {
196                 fear = findradius(self.origin, i);
197                 while(fear)
198                 {
199                         if(fear.bot_dodge)
200                                 return fear;
201
202                         fear = fear.chain;
203                 }
204         }
205
206         return world;
207 }
208 void targetdrone_think()
209 {
210         self.nextthink = time + 0.1;
211
212         if(self.wp00)
213         if(self.wp00.deadflag != DEAD_NO)
214                 self.wp00 = targetdrone_getfear();
215
216         if(!self.wp00)
217                 self.wp00 = targetdrone_getfear();
218
219         vector newdir;
220
221         if(self.wp00)
222                 newdir = steerlib_push(self.wp00.origin) + randomvec() * 0.75;
223         else
224                 newdir = randomvec() * 0.75;
225
226         newdir = newdir * 0.5 + normalize(self.velocity) * 0.5;
227
228         if(self.wp00)
229                 self.velocity = normalize(newdir) * (500 + (1024 / min(vlen(self.wp00.origin - self.origin), 1024)) * 700);
230         else
231                 self.velocity = normalize(newdir) * 750;
232
233         tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 2, MOVE_NORMAL, self);
234         if(trace_fraction != 1.0)
235                 self.velocity = self.velocity * -1;
236
237         //normalize((normalize(self.velocity) * 0.5 + newdir * 0.5)) * 750;
238 }
239
240 void targetdrone_spawn(vector _where, float _autorenew)
241 {
242         entity drone = spawn();
243         setorigin(drone, _where);
244         drone.think = targetdrone_renwe;
245         drone.nextthink = time + 0.1;
246         drone.cnt = _autorenew;
247 }
248 #endif
249
250 void vehicles_locktarget(float incr, float decr, float _lock_time)
251 {
252     if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
253     {
254         self.lock_target    = world;
255         self.lock_strength  = 0;
256         self.lock_time      = 0;
257     }
258
259     if(self.lock_time > time)
260     {
261         if(self.lock_target)
262         if(self.lock_soundtime < time)
263         {
264             self.lock_soundtime = time + 0.5;
265             play2(self.owner, "vehicles/locked.wav");
266         }
267
268         return;
269     }
270
271     if(trace_ent != world)
272     {
273         if(teamplay && trace_ent.team == self.team)
274             trace_ent = world;
275
276         if(trace_ent.deadflag != DEAD_NO)
277             trace_ent = world;
278
279         if not (trace_ent.vehicle_flags & VHF_ISVEHICLE ||
280                                 trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET ||
281                                 trace_ent.takedamage == DAMAGE_TARGETDRONE)
282             trace_ent = world;
283     }
284
285     if(self.lock_target == world && trace_ent != world)
286         self.lock_target = trace_ent;
287
288     if(self.lock_target && trace_ent == self.lock_target)
289     {
290         if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
291         {
292             play2(self.owner, "vehicles/lock.wav");
293             self.lock_soundtime = time + 0.8;
294         }
295         else if (self.lock_strength != 1 && self.lock_soundtime < time)
296         {
297             play2(self.owner, "vehicles/locking.wav");
298             self.lock_soundtime = time + 0.3;
299         }
300
301     }
302
303     // Have a locking target
304     // Trace hit current target
305     if(trace_ent == self.lock_target && trace_ent != world)
306     {
307         self.lock_strength = min(self.lock_strength + incr, 1);
308         if(self.lock_strength == 1)
309             self.lock_time = time + _lock_time;
310     }
311     else
312     {
313         if(trace_ent)
314             self.lock_strength = max(self.lock_strength - decr * 2, 0);
315         else
316             self.lock_strength = max(self.lock_strength - decr, 0);
317
318         if(self.lock_strength == 0)
319             self.lock_target = world;
320     }
321 }
322
323 #define VEHICLE_UPDATE_PLAYER(ply,fld,vhname) \
324 ply.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
325
326 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
327 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
328 if(trace_fraction != 1) \
329     acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
330
331 // Hover movement support
332 float  force_fromtag_power;
333 float  force_fromtag_normpower;
334 vector force_fromtag_origin;
335 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
336 {
337     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
338     v_forward  = normalize(v_forward) * -1;
339     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
340
341     force_fromtag_power = (1 - trace_fraction) * max_power;
342     force_fromtag_normpower = force_fromtag_power / max_power;
343
344     return v_forward  * force_fromtag_power;
345 }
346
347 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
348 // Can possibly be use to move abt any surface (inclusing walls/celings)
349 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
350 {
351
352     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
353     v_forward  = normalize(v_forward) * -1;
354     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
355
356     // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
357     if(trace_fraction == 1.0)
358     {
359         force_fromtag_normpower = -0.25;
360         return '0 0 -200';
361     }
362
363     force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
364     force_fromtag_normpower = force_fromtag_power / max_power;
365
366     return v_forward  * force_fromtag_power;
367 }
368
369 // Generic vehile projectile system
370 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
371 {
372     // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
373     if(inflictor.owner == self.owner)
374         return;
375
376     self.health -= damage;
377     self.velocity += force;
378     if(self.health < 1)
379     {
380         self.takedamage = DAMAGE_NO;
381         self.event_damage = SUB_Null;
382         self.think = self.use;
383         self.nextthink = time;
384     }
385 }
386
387 void vehicles_projectile_explode()
388 {
389     if(self.owner && other != world)
390     {
391         if(other == self.owner.vehicle)
392             return;
393
394         if(other == self.owner.vehicle.tur_head)
395             return;
396     }
397
398         PROJECTILE_TOUCH;
399
400         self.event_damage = SUB_Null;
401     RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
402
403     remove (self);
404 }
405
406 entity vehicles_projectile(string _mzlfx, string _mzlsound,
407                            vector _org, vector _vel,
408                            float _dmg, float _radi, float _force,  float _size,
409                            float _deahtype, float _projtype, float _health,
410                            float _cull, float _clianim, entity _owner)
411 {
412     entity proj;
413
414     proj = spawn();
415
416     PROJECTILE_MAKETRIGGER(proj);
417     setorigin(proj, _org);
418
419     proj.shot_dmg         = _dmg;
420     proj.shot_radius      = _radi;
421     proj.shot_force       = _force;
422     proj.totalfrags       = _deahtype;
423     proj.solid            = SOLID_BBOX;
424     proj.movetype         = MOVETYPE_FLYMISSILE;
425     proj.flags            = FL_PROJECTILE;
426     proj.bot_dodge        = TRUE;
427     proj.bot_dodgerating  = _dmg;
428     proj.velocity         = _vel;
429     proj.touch            = vehicles_projectile_explode;
430     proj.use              = vehicles_projectile_explode;
431     proj.owner            = self;
432     proj.realowner        = _owner;
433     proj.think            = SUB_Remove;
434     proj.nextthink        = time + 30;
435
436     if(_health)
437     {
438         proj.takedamage       = DAMAGE_AIM;
439         proj.event_damage     = vehicles_projectile_damage;
440         proj.health           = _health;
441     }
442     else
443         proj.flags           = FL_PROJECTILE | FL_NOTARGET;
444
445     if(_mzlsound)
446         sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTN_NORM);
447
448     if(_mzlfx)
449         pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
450
451
452     setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
453
454     CSQCProjectile(proj, _clianim, _projtype, _cull);
455
456     return proj;
457 }
458 // End generic vehile projectile system
459
460 /** vehicles_spawn
461     Exetuted for all vehicles on (re)spawn.
462     Sets defaults for newly spawned units.
463 **/
464 void vehicles_spawn()
465 {
466     dprint("Spawning vehicle: ", self.netname, "\n");
467
468     // De-own & reset
469     self.vehicle_hudmodel.viewmodelforclient = self;
470
471     self.owner              = world;
472     self.touch              = vehicles_touch;
473     self.event_damage       = vehicles_damage;
474     self.iscreature         = TRUE;
475     self.damagedbycontents      = TRUE;
476     self.movetype           = MOVETYPE_WALK;
477     self.solid              = SOLID_SLIDEBOX;
478     self.takedamage         = DAMAGE_AIM;
479         self.deadflag           = DEAD_NO;
480     self.bot_attack         = TRUE;
481     self.flags              = FL_NOTARGET;
482     self.avelocity          = '0 0 0';
483     self.velocity           = '0 0 0';
484
485     // Reset locking
486     self.lock_strength      = 0;
487     self.lock_target        = world;
488     self.misc_bulletcounter = 0;
489
490     // Return to spawn
491     self.angles             = self.pos2;
492     setorigin(self, self.pos1 + '0 0 0');
493     // Show it
494     pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
495     
496     if(self.vehicle_controller)
497         self.team = self.vehicle_controller.team;
498        
499     vehicles_reset_colors();
500     self.vehicle_spawn(VHSF_NORMAL);
501 }
502
503 // Better way of determening whats crushable needed! (fl_crushable?)
504 float vehicles_crushable(entity e)
505 {
506     if(e.classname == "player")
507         return TRUE;
508
509     if(e.classname == "monster_zombie")
510         return TRUE;
511
512     return FALSE;
513 }
514
515 void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
516 {
517     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
518         return;
519
520     if(self.play_time < time)
521     {
522         float wc = vlen(self.velocity - self.oldvelocity);
523         //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
524         //dprint("vel: ", vtos(self.velocity), "\n");
525         if(_minspeed < wc)
526         {
527             float take = min(_speedfac * wc, _maxpain);
528             Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
529             self.play_time = time + 0.25;
530
531             //dprint("wc: ", ftos(wc), "\n");
532             //dprint("take: ", ftos(take), "\n");
533         }
534     }
535 }
536
537 .void() vehicle_impact;
538 void vehicles_touch()
539 {
540     // Vehicle currently in use
541     if(self.owner)
542     {
543         if(other != world)
544         if(vehicles_crushable(other))
545         {
546             if(vlen(self.velocity) != 0)
547                 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VHCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
548
549             return; // Dont do selfdamage when hitting "soft targets".
550         }
551
552         if(self.play_time < time)
553         if(self.vehicle_impact)
554             self.vehicle_impact();
555
556         return;
557     }
558
559     if(other.classname != "player")
560         return;
561
562     if(other.deadflag != DEAD_NO)
563         return;
564
565     if(other.vehicle != world)
566         return;
567
568     vehicles_enter();
569 }
570 var float autocvar_g_vehicles_allow_bots = 0;
571 void vehicles_enter()
572 {
573    // Remove this when bots know how to use vehicles
574    
575     if (clienttype(other) == CLIENTTYPE_BOT)    
576         if (autocvar_g_vehicles_allow_bots)
577             dprint("Bot enters vehicle\n"); // This is where we need to disconnect (some, all?) normal bot AI and hand over to vehicle's _aiframe()
578         else
579             return;
580
581     if(self.phase > time)
582         return;
583
584     if(teamplay)
585     if(self.team)
586     if(self.team != other.team)
587         return;
588
589     RemoveGrapplingHook(other);
590
591     self.vehicle_ammo1   = 0;
592     self.vehicle_ammo2   = 0;
593     self.vehicle_reload1 = 0;
594     self.vehicle_reload2 = 0;
595     self.vehicle_energy  = 0;
596
597     self.owner          = other;
598     self.switchweapon   = other.switchweapon;
599
600     // .viewmodelforclient works better.
601     //self.vehicle_hudmodel.drawonlytoclient = self.owner;
602
603     self.vehicle_hudmodel.viewmodelforclient = self.owner;
604
605     self.event_damage         = vehicles_damage;
606     self.nextthink            = 0;
607     self.owner.angles         = self.angles;
608     self.owner.takedamage     = DAMAGE_NO;
609     self.owner.solid          = SOLID_NOT;
610     self.owner.movetype       = MOVETYPE_NOCLIP;
611     self.owner.alpha          = -1;
612     self.owner.vehicle        = self;
613     self.owner.event_damage   = SUB_Null;
614     self.owner.view_ofs       = '0 0 0';
615     self.colormap             = self.owner.colormap;
616     if(self.tur_head)
617         self.tur_head.colormap    = self.owner.colormap;
618
619     self.owner.hud            = self.hud;
620     self.owner.PlayerPhysplug = self.PlayerPhysplug;
621
622     self.owner.vehicle_ammo1    = self.vehicle_ammo1;
623     self.owner.vehicle_ammo2    = self.vehicle_ammo2;
624     self.owner.vehicle_reload1  = self.vehicle_reload1;
625     self.owner.vehicle_reload2  = self.vehicle_reload2;
626
627     // Cant do this, hides attached objects too.
628     //self.exteriormodeltoclient = self.owner;
629     //self.tur_head.exteriormodeltoclient = self.owner;
630
631     other.flags &~= FL_ONGROUND;
632     self.flags  &~= FL_ONGROUND;
633
634     self.team                 = self.owner.team;
635     self.flags               -= FL_NOTARGET;
636     
637     if (clienttype(other) == CLIENTTYPE_REAL)
638     {
639         msg_entity = other;
640         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
641         WriteEntity(MSG_ONE, self.vehicle_viewport);
642                 
643         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
644         if(self.tur_head)
645         {
646             WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
647             WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
648             WriteAngle(MSG_ONE, 0);                                      // roll
649         }
650         else
651         {
652             WriteAngle(MSG_ONE,  self.angles_x * -1); // tilt
653             WriteAngle(MSG_ONE,  self.angles_y);      // yaw
654             WriteAngle(MSG_ONE,  0);                  // roll
655         }
656     }
657
658     vehicles_clearrturn();
659
660     CSQCVehicleSetup(self.owner, self.hud);
661
662     if(other.flagcarried)
663     {
664         if(!autocvar_g_vehicles_allow_flagcarry)
665             DropFlag(other.flagcarried, world, world);
666         else
667         {
668             other.flagcarried.scale = 1;
669             setattachment(other.flagcarried, self, "");
670             setorigin(other, '0 0 96');
671         }
672     }
673
674     self.vehicle_enter();
675     antilag_clear(other);
676 }
677
678 /** vehicles_findgoodexit
679     Locates a valid location for the player to exit the vehicle.
680     Will first try prefer_spot, then up 100 random spots arround the vehicle
681     wich are in direct line of sight and empty enougth to hold a players bbox
682 **/
683 vector vehicles_findgoodexit(vector prefer_spot)
684 {
685     //vector exitspot;
686     float mysize;
687
688     tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
689     if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
690         return prefer_spot;
691
692     mysize = vlen(self.maxs - self.mins);
693     float i;
694     vector v, v2;
695     v2 = 0.5 * (self.absmin + self.absmax);
696     for(i = 0; i < 100; ++i)
697     {
698         v = randomvec();
699         v_z = 0;
700         v = v2 + normalize(v) * mysize;
701         tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
702         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
703             return v;
704     }
705
706     /*
707     exitspot = (self.origin + '0 0 48') + v_forward * mysize;
708     tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
709     if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
710         return exitspot;
711
712     exitspot = (self.origin + '0 0 48') - v_forward * mysize;
713     tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
714     if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
715         return exitspot;
716
717     exitspot = (self.origin + '0 0 48') + v_right * mysize;
718     tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
719     if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
720         return exitspot;
721
722     exitspot = (self.origin + '0 0 48') - v_right * mysize;
723     tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
724     if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
725         return exitspot;
726     */
727
728     return self.origin;
729 }
730
731 /** vehicles_exit
732     Standarrd vehicle release fucntion.
733     custom code goes in self.vehicle_exit
734 **/
735 float vehicles_exit_running;
736 void vehicles_exit(float eject)
737 {
738     entity _vehicle;
739     entity _player;
740     entity _oldself = self;
741     
742     if(vehicles_exit_running)
743     {
744         dprint("^1vehicles_exit allready running! this is not good..\n");
745         return;
746     }
747     
748     vehicles_exit_running = TRUE;
749     if(self.flags & FL_CLIENT)
750     {
751         _vehicle = self.vehicle;
752             
753         if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
754         {
755             _vehicle.vehicle_exit(eject);
756             self = _oldself;
757             vehicles_exit_running = FALSE;
758             return;            
759         }
760     }
761     else
762         _vehicle = self;
763     
764     _player = _vehicle.owner;
765     
766     self = _vehicle;
767
768     if (_player)
769     {
770         if (clienttype(_player) == CLIENTTYPE_REAL)
771         {
772             msg_entity = _player;
773             WriteByte (MSG_ONE, SVC_SETVIEWPORT);
774             WriteEntity( MSG_ONE, _player);
775
776             WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
777             WriteAngle(MSG_ONE, 0);
778             WriteAngle(MSG_ONE, _vehicle.angles_y);
779             WriteAngle(MSG_ONE, 0);
780         }
781         
782         setsize(_player, PL_MIN,PL_MAX);
783
784         _player.takedamage     = DAMAGE_AIM;
785         _player.solid          = SOLID_SLIDEBOX;
786         _player.movetype       = MOVETYPE_WALK;
787         _player.effects        &~= EF_NODRAW;
788         _player.alpha          = 1;
789         _player.PlayerPhysplug = SUB_Null;
790         _player.vehicle        = world;
791         _player.view_ofs       = PL_VIEW_OFS;
792         _player.event_damage   = PlayerDamage;
793         _player.hud            = HUD_NORMAL;
794         _player.switchweapon   = _vehicle.switchweapon;
795
796         if(_player.flagcarried)
797         {
798             _player.flagcarried.scale = 0.6;
799             setattachment(_player.flagcarried, _player, "");
800             setorigin(_player.flagcarried, FLAG_CARRY_POS);
801         }
802
803         CSQCVehicleSetup(_player, HUD_NORMAL);
804     }
805     _vehicle.flags |= FL_NOTARGET;
806     
807     if(_vehicle.deadflag == DEAD_NO)
808         _vehicle.avelocity          = '0 0 0';
809     
810     _vehicle.tur_head.nodrawtoclient             = world;
811     
812     if(!teamplay)
813         _vehicle.team = 0;
814     else
815         _vehicle.team = _vehicle.tur_head.team;
816         
817     sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
818     _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;    
819     _vehicle.phase = time + 1;
820     
821     _vehicle.vehicle_exit(eject);
822     
823     vehicles_setreturn();
824     vehicles_reset_colors();        
825     _vehicle.owner = world;
826     self = _oldself;
827     
828     vehicles_exit_running = FALSE;
829 }
830
831
832 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
833 {
834     if(self.regen_field < field_max)
835     if(timer + rpause < time)
836     {
837         if(_healthscale)
838             regen = regen * (self.vehicle_health / self.tur_health);
839             
840         self.regen_field = min(self.regen_field + regen * delta_time, field_max);
841
842         if(self.owner)
843             self.owner.regen_field = (self.regen_field / field_max) * 100;
844     }
845 }
846
847 void shieldhit_think()
848 {
849     self.alpha -= 0.1;
850     if (self.alpha <= 0)
851     {
852         //setmodel(self, "");
853         self.alpha = -1;
854         self.effects |= EF_NODRAW;
855     }
856     else
857     {
858         self.nextthink = time + 0.1;
859     }
860 }
861
862 void vehicles_painframe()
863 {
864     if(self.owner.vehicle_health <= 50)
865     if(self.pain_frame < time)
866     {
867         float _ftmp;
868         _ftmp = self.owner.vehicle_health / 50;
869         self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
870         pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
871
872         if(self.vehicle_flags & VHF_DMGSHAKE)
873             self.velocity += randomvec() * 30;
874
875         if(self.vehicle_flags & VHF_DMGROLL)
876             if(self.vehicle_flags & VHF_DMGHEADROLL)
877                 self.tur_head.angles += randomvec();
878             else
879                 self.angles += randomvec();
880
881     }
882 }
883
884 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
885 {
886     self.dmg_time = time;
887     
888     if(DEATH_ISWEAPON(deathtype, WEP_NEX))
889         damage *= autocvar_g_vehicles_nex_damagerate;
890         
891     if(DEATH_ISWEAPON(deathtype, WEP_UZI))
892         damage *= autocvar_g_vehicles_uzi_damagerate;
893         
894     if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
895         damage *= autocvar_g_vehicles_rifle_damagerate;
896         
897     if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
898         damage *= autocvar_g_vehicles_minstanex_damagerate;
899
900     if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
901         damage *= autocvar_g_vehicles_tag_damagerate;
902     
903     self.enemy = attacker;
904     
905     if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
906     {
907         if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
908         {
909             self.vehicle_shieldent = spawn();
910             self.vehicle_shieldent.effects = EF_LOWPRECISION;
911
912             setmodel(self.vehicle_shieldent, "models/vhshield.md3");
913             setattachment(self.vehicle_shieldent, self, "");
914             setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
915             self.vehicle_shieldent.scale       = 256 / vlen(self.maxs - self.mins);
916             self.vehicle_shieldent.think       = shieldhit_think;
917         }
918
919         self.vehicle_shieldent.colormod    = '1 1 1';
920         self.vehicle_shieldent.alpha       = 0.45;
921         self.vehicle_shieldent.angles      = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
922         self.vehicle_shieldent.nextthink   = time;
923         self.vehicle_shieldent.effects &~= EF_NODRAW;
924
925         self.vehicle_shield -= damage;
926
927         if(self.vehicle_shield < 0)
928         {
929             self.vehicle_health            -= fabs(self.vehicle_shield);
930             self.vehicle_shieldent.colormod = '2 0 0';
931             self.vehicle_shield             = 0;
932             self.vehicle_shieldent.alpha    = 0.75;
933
934                 if(sound_allowed(MSG_BROADCAST, attacker))
935                 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);   // FIXME: PLACEHOLDER
936         }
937         else
938                 if(sound_allowed(MSG_BROADCAST, attacker))
939                 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM);  // FIXME: PLACEHOLDER
940
941     }
942     else
943     {
944         self.vehicle_health -= damage;
945
946         if(sound_allowed(MSG_BROADCAST, attacker))
947             spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);  // FIXME: PLACEHOLDER
948     }
949
950     self.velocity += force; // * (vlen(force) / self.mass);
951
952     if(self.vehicle_health <= 0)
953     {
954         if(self.owner)
955             if(self.vehicle_flags & VHF_DEATHEJECT)
956                 vehicles_exit(VHEF_EJECT);
957             else
958                 vehicles_exit(VHEF_RELESE);
959
960
961         antilag_clear(self);
962
963         self.vehicle_die();
964         vehicles_setreturn();
965     }
966 }
967
968 void vehicles_clearrturn()
969 {
970     entity ret;
971     // Remove "return helper", if any.
972     ret = findchain(classname, "vehicle_return");
973     while(ret)
974     {
975         if(ret.wp00 == self)
976         {
977             ret.classname   = "";
978             ret.think       = SUB_Remove;
979             ret.nextthink   = time + 0.1;
980
981             if(ret.waypointsprite_attached)
982                 WaypointSprite_Kill(ret.waypointsprite_attached);
983
984             return;
985         }
986         ret = ret.chain;
987     }
988 }
989
990 void vehicles_return()
991 {
992     pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
993
994     self.wp00.think     = vehicles_spawn;
995     self.wp00.nextthink = time;
996
997     if(self.waypointsprite_attached)
998         WaypointSprite_Kill(self.waypointsprite_attached);
999
1000     remove(self);
1001 }
1002
1003 void vehicles_showwp_goaway()
1004 {
1005     if(self.waypointsprite_attached)
1006         WaypointSprite_Kill(self.waypointsprite_attached);
1007
1008     remove(self);
1009
1010 }
1011
1012 void vehicles_showwp()
1013 {
1014     entity oldself;
1015     vector rgb;
1016
1017     if(self.cnt)
1018     {
1019         self.think      = vehicles_return;
1020         self.nextthink  = self.cnt;
1021     }
1022     else
1023     {
1024         self.think      = vehicles_return;
1025         self.nextthink  = time +1;
1026
1027         oldself = self;
1028         self = spawn();
1029         setmodel(self, "null");
1030         self.team = oldself.wp00.team;
1031         self.wp00 = oldself.wp00;
1032         setorigin(self, oldself.wp00.pos1);
1033
1034         self.nextthink = time + 5;
1035         self.think = vehicles_showwp_goaway;
1036     }
1037
1038     if(teamplay && self.team)
1039             rgb = TeamColor(self.team);
1040     else
1041             rgb = '1 1 1';
1042     WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
1043     if(self.waypointsprite_attached)
1044     {
1045         WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
1046         if(oldself == world)
1047             WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
1048         WaypointSprite_Ping(self.waypointsprite_attached);
1049     }
1050
1051     if(oldself != world)
1052         self = oldself;
1053 }
1054
1055 void vehicles_setreturn()
1056 {
1057     entity ret;
1058
1059     vehicles_clearrturn();
1060
1061     ret = spawn();
1062     ret.classname   = "vehicle_return";
1063     ret.wp00       = self;
1064     ret.team        = self.team;
1065     ret.think       = vehicles_showwp;
1066
1067     if(self.deadflag != DEAD_NO)
1068     {
1069         ret.cnt         = time + self.vehicle_respawntime;
1070         ret.nextthink   = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 5);
1071     }
1072     else
1073     {
1074         ret.nextthink   = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 1);
1075     }
1076
1077     setmodel(ret, "null");
1078     setorigin(ret, self.pos1 + '0 0 96');
1079
1080 }
1081
1082 void vehicles_reset_colors()
1083 {
1084     entity e;
1085     float _effects, _colormap;
1086     vector _glowmod, _colormod;
1087
1088     if(autocvar_g_nodepthtestplayers)
1089         _effects = EF_NODEPTHTEST;
1090
1091     if(autocvar_g_fullbrightplayers)
1092         _effects |= EF_FULLBRIGHT;
1093
1094     if(self.team)
1095         _colormap = 1024 + (self.team - 1) * 17;
1096     else
1097         _colormap = 1024;
1098
1099     _glowmod  = '0 0 0';
1100     _colormod = '0 0 0';
1101
1102     // Find all ents attacked to main model and setup effects, colormod etc.
1103     e = findchainentity(tag_entity, self);
1104     while(e)
1105     {
1106         if(e != self.vehicle_shieldent)
1107         {
1108             e.effects   = _effects; //  | EF_LOWPRECISION;
1109             e.colormod  = _colormod;
1110             e.colormap  = _colormap;
1111             e.alpha     = 1;
1112         }
1113         e = e.chain;
1114     }
1115
1116     self.vehicle_hudmodel.effects  = self.effects  = _effects; // | EF_LOWPRECISION;
1117     self.vehicle_hudmodel.colormod = self.colormod = _colormod;
1118     self.vehicle_hudmodel.colormap = self.colormap = _colormap;
1119     self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
1120
1121     self.alpha     = 1;
1122     self.avelocity = '0 0 0';
1123     self.velocity  = '0 0 0';
1124     self.effects   = _effects;
1125 }
1126
1127 void vehicle_use()
1128 {
1129     dprint("vehicle ",self.netname, " used by ", activator.classname, "\n");
1130
1131     self.tur_head.team = activator.team;
1132
1133     if(self.tur_head.team == 0)
1134         self.active = ACTIVE_NOT;
1135     else
1136         self.active = ACTIVE_ACTIVE;
1137     
1138     if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO)
1139     {
1140         dprint("^3Eat shit yall!\n");
1141         vehicles_setreturn();
1142         vehicles_reset_colors();
1143     }
1144     else if(self.active == ACTIVE_NOT && self.deadflag != DEAD_NO)
1145     {
1146         
1147     }
1148 }
1149
1150 float vehicle_addplayerslot(    entity _owner, 
1151                                 entity _slot, 
1152                                 float _hud, 
1153                                 string _hud_model,
1154                                 float() _framefunc, 
1155                                 void(float) _exitfunc)
1156 {
1157     if not (_owner.vehicle_flags & VHF_MULTISLOT)
1158         _owner.vehicle_flags |= VHF_MULTISLOT;
1159
1160     _slot.PlayerPhysplug = _framefunc;
1161     _slot.vehicle_exit = _exitfunc;
1162     _slot.hud = _hud;
1163     _slot.vehicle_flags = VHF_PLAYERSLOT;
1164     _slot.vehicle_viewport = spawn();
1165     _slot.vehicle_hudmodel = spawn();
1166     _slot.vehicle_hudmodel.viewmodelforclient = _slot;
1167     _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
1168     
1169     setmodel(_slot.vehicle_hudmodel, _hud_model);
1170     setmodel(_slot.vehicle_viewport, "null");
1171     
1172     setattachment(_slot.vehicle_hudmodel, _slot, "");
1173     setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
1174     
1175     return TRUE;
1176 }
1177
1178 float vehicle_initialize(string  net_name,
1179                          string  bodymodel,
1180                          string  topmodel,
1181                          string  hudmodel,
1182                          string  toptag,
1183                          string  hudtag,
1184                          string  viewtag,
1185                          float   vhud,
1186                          vector  min_s,
1187                          vector  max_s,
1188                          float   nodrop,
1189                          void(float _spawnflag)  spawnproc,
1190                          float   _respawntime,
1191                          float() physproc,
1192                          void()  enterproc,
1193                          void(float extflag) exitfunc,
1194                          void() dieproc,
1195                          void() thinkproc,
1196                          float  use_csqc,
1197                          float _max_health,
1198                          float _max_shield)
1199 {
1200         if(!autocvar_g_vehicles)
1201                 return FALSE;
1202         
1203     if(self.targetname)
1204     {
1205         self.vehicle_controller = find(world, target, self.targetname);
1206         if(!self.vehicle_controller)
1207         {
1208             bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1209         }
1210         else
1211         {
1212             self.team = self.vehicle_controller.team;        
1213             self.use = vehicle_use;
1214             
1215             if(teamplay)
1216             {
1217                 if(self.vehicle_controller.team == 0)
1218                     self.active = ACTIVE_NOT;
1219                 else
1220                     self.active = ACTIVE_ACTIVE;                
1221             }
1222         }
1223     }
1224     
1225     precache_sound("onslaught/ons_hit2.wav");
1226     precache_sound("onslaught/electricity_explode.wav");
1227
1228
1229     addstat(STAT_HUD, AS_INT,  hud);
1230         addstat(STAT_VEHICLESTAT_HEALTH,  AS_INT, vehicle_health);
1231         addstat(STAT_VEHICLESTAT_SHIELD,  AS_INT, vehicle_shield);
1232         addstat(STAT_VEHICLESTAT_ENERGY,  AS_INT, vehicle_energy);
1233
1234         addstat(STAT_VEHICLESTAT_AMMO1,   AS_INT, vehicle_ammo1);
1235         addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
1236
1237         addstat(STAT_VEHICLESTAT_AMMO2,   AS_INT, vehicle_ammo2);
1238         addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
1239
1240     if(bodymodel == "")
1241         error("vehicles: missing bodymodel!");
1242
1243     if(hudmodel == "")
1244         error("vehicles: missing hudmodel!");
1245
1246     if(net_name == "")
1247         self.netname = self.classname;
1248     else
1249         self.netname = net_name;
1250
1251     if(self.team && !teamplay)
1252         self.team = 0;
1253
1254     self.vehicle_flags |= VHF_ISVEHICLE;
1255
1256     setmodel(self, bodymodel);
1257
1258     self.vehicle_viewport   = spawn();
1259     self.vehicle_hudmodel   = spawn();
1260     self.tur_head           = spawn();
1261     self.tur_head.owner     = self;
1262     self.takedamage         = DAMAGE_AIM;
1263     self.bot_attack         = TRUE;
1264     self.iscreature         = TRUE;
1265     self.damagedbycontents      = TRUE;
1266     self.hud                = vhud;
1267     self.tur_health          = _max_health;
1268     self.tur_head.tur_health = _max_shield;
1269     self.vehicle_die         = dieproc;
1270     self.vehicle_exit        = exitfunc;
1271     self.vehicle_enter       = enterproc;
1272     self.PlayerPhysplug      = physproc;
1273     self.event_damage        = vehicles_damage;
1274     self.touch               = vehicles_touch;
1275     self.think               = vehicles_spawn;
1276     self.nextthink           = time;
1277     self.vehicle_respawntime = _respawntime;
1278     self.vehicle_spawn       = spawnproc;
1279     self.effects             = EF_NODRAW;
1280     if(g_assault || !autocvar_g_vehicles_delayspawn)
1281         self.nextthink = time + 0.5;
1282     else
1283         self.nextthink = time + _respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1284
1285
1286     if(autocvar_g_nodepthtestplayers)
1287         self.effects = self.effects | EF_NODEPTHTEST;
1288
1289     if(autocvar_g_fullbrightplayers)
1290         self.effects = self.effects | EF_FULLBRIGHT;
1291
1292     setmodel(self.vehicle_hudmodel, hudmodel);
1293     setmodel(self.vehicle_viewport, "null");
1294
1295     if(topmodel != "")
1296     {
1297         setmodel(self.tur_head, topmodel);
1298         setattachment(self.tur_head, self, toptag);
1299         setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
1300         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1301     }
1302     else
1303     {
1304         setattachment(self.tur_head, self, "");
1305         setattachment(self.vehicle_hudmodel, self, hudtag);
1306         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1307     }
1308
1309     setsize(self, min_s, max_s);
1310     if not (nodrop)
1311     {
1312         setorigin(self, self.origin);
1313         tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1314         setorigin(self, trace_endpos);
1315     }
1316     
1317     self.pos1 = self.origin;
1318     self.pos2 = self.angles;
1319     self.tur_head.team = self.team;
1320
1321     return TRUE;
1322 }
1323
1324 void vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname, 
1325                          float _pichlimit_min, float _pichlimit_max, 
1326                          float _rotlimit_min, float _rotlimit_max, float _aimspeed)
1327 {
1328     vector vtmp;
1329     float ftmp;
1330     
1331     vtmp = vectoangles(normalize(_target - gettaginfo(_turrret, gettagindex(_turrret, _tagname))));
1332     vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
1333     vtmp = AnglesTransform_Normalize(vtmp, TRUE);
1334
1335     ftmp = _aimspeed * sys_frametime;
1336     vtmp_y = bound(-ftmp, vtmp_y, ftmp);
1337     vtmp_x = bound(-ftmp, vtmp_x, ftmp);
1338     _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);    
1339     _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);    
1340 }
1341
1342 void vehicles_gib_explode()
1343 {
1344         sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
1345         pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
1346         remove(self);
1347 }
1348
1349 void vehicles_gib_think()
1350 {
1351         self.alpha -= 0.1;
1352         if(self.cnt >= time)
1353                 remove(self);
1354         else
1355                 self.nextthink = time + 0.1;
1356 }
1357
1358 entity vehicle_tossgib(entity _template, vector _vel, string _tag, float _burn, float _explode, float _maxtime, vector _rot)
1359 {
1360         entity _gib = spawn();
1361         setmodel(_gib, _template.model);
1362         setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
1363         _gib.velocity = _vel;
1364         _gib.movetype = MOVETYPE_TOSS;
1365         _gib.solid = SOLID_CORPSE;
1366         _gib.colormod = '-0.5 -0.5 -0.5';
1367         _gib.effects = EF_LOWPRECISION; 
1368         _gib.avelocity = _rot;
1369         
1370         if(_burn)
1371                 _gib.effects |= EF_FLAME;
1372         
1373         if(_explode)
1374         {
1375                 _gib.think = vehicles_gib_explode; 
1376                 _gib.nextthink = time + random() * _explode;
1377                 _gib.touch = vehicles_gib_explode;
1378         }
1379         else
1380         {
1381                 _gib.cnt = time + _maxtime;
1382                 _gib.think = vehicles_gib_think; 
1383                 _gib.nextthink = time + _maxtime - 1;           
1384                 _gib.alpha = 1;
1385         }
1386         return _gib;
1387 }