]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/sv_vehicles.qc
Vehicles: always show smoke when low on health, even when empty
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
1 #include "sv_vehicles.qh"
2
3 #if 0
4 bool vehicle_send(entity to, int sf)
5 {
6         WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
7         WriteByte(MSG_ENTITY, sf);
8
9         if(sf & VSF_SPAWN)
10         {
11                 WriteByte(MSG_ENTITY, self.vehicleid);
12         }
13
14         if(sf & VSF_SETUP)
15         {
16                 // send stuff?
17         }
18
19         if(sf & VSF_ENTER)
20         {
21                 // player handles the .vehicle stuff, we need only set ourselves up for driving
22
23                 // send stuff?
24         }
25
26         if(sf & VSF_EXIT)
27         {
28                 // senf stuff?
29         }
30
31         if(sf & VSF_PRECACHE)
32         {
33                 // send stuff?!
34         }
35
36         return true;
37 }
38 #endif
39
40 bool SendAuxiliaryXhair(entity this, entity to, int sf)
41 {
42
43         WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
44
45         WriteByte(MSG_ENTITY, self.cnt);
46
47         WriteCoord(MSG_ENTITY, self.origin_x);
48         WriteCoord(MSG_ENTITY, self.origin_y);
49         WriteCoord(MSG_ENTITY, self.origin_z);
50
51         WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
52         WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
53         WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
54
55         return true;
56 }
57
58 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
59 {
60         if(!IS_REAL_CLIENT(own))
61                 return;
62
63         entity axh;
64
65         axh_id = bound(0, axh_id, MAX_AXH);
66         axh = own.(AuxiliaryXhair[axh_id]);
67
68         if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
69         {
70                 axh                                      = spawn();
71                 axh.cnt                          = axh_id;
72                 axh.drawonlytoclient    = own;
73                 axh.owner                          = own;
74                 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
75         }
76
77         setorigin(axh, loc);
78         axh.colormod                    = clr;
79         axh.SendFlags              = 0x01;
80         own.(AuxiliaryXhair[axh_id]) = axh;
81 }
82
83 void CSQCVehicleSetup(entity own, int vehicle_id)
84 {
85         if(!IS_REAL_CLIENT(own))
86                 return;
87
88         msg_entity = own;
89
90         WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
91         WriteByte(MSG_ONE, vehicle_id);
92 }
93
94 vector targetdrone_getnewspot()
95 {SELFPARAM();
96         vector spot;
97         int i;
98         for(i = 0; i < 100; ++i)
99         {
100                 spot = self.origin + randomvec() * 1024;
101                 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
102                 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
103                         return spot;
104         }
105         return self.origin;
106 }
107
108 void vehicles_locktarget(float incr, float decr, float _lock_time)
109 {SELFPARAM();
110         if(self.lock_target && IS_DEAD(self.lock_target))
111         {
112                 self.lock_target        = world;
113                 self.lock_strength  = 0;
114                 self.lock_time    = 0;
115         }
116
117         if(self.lock_time > time)
118         {
119                 if(self.lock_target)
120                 if(self.lock_soundtime < time)
121                 {
122                         self.lock_soundtime = time + 0.5;
123                         play2(self.owner, "vehicles/locked.wav");
124                 }
125
126                 return;
127         }
128
129         if(trace_ent != world)
130         {
131                 if(SAME_TEAM(trace_ent, self))
132                         trace_ent = world;
133
134                 if(IS_DEAD(trace_ent))
135                         trace_ent = world;
136
137                 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
138                         trace_ent = world;
139
140                 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
141                         trace_ent = world; // invisible
142         }
143
144         if(self.lock_target == world && trace_ent != world)
145                 self.lock_target = trace_ent;
146
147         if(self.lock_target && trace_ent == self.lock_target)
148         {
149                 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
150                 {
151                         play2(self.owner, "vehicles/lock.wav");
152                         self.lock_soundtime = time + 0.8;
153                 }
154                 else if (self.lock_strength != 1 && self.lock_soundtime < time)
155                 {
156                         play2(self.owner, "vehicles/locking.wav");
157                         self.lock_soundtime = time + 0.3;
158                 }
159         }
160
161         // Have a locking target
162         // Trace hit current target
163         if(trace_ent == self.lock_target && trace_ent != world)
164         {
165                 self.lock_strength = min(self.lock_strength + incr, 1);
166                 if(self.lock_strength == 1)
167                         self.lock_time = time + _lock_time;
168         }
169         else
170         {
171                 if(trace_ent)
172                         self.lock_strength = max(self.lock_strength - decr * 2, 0);
173                 else
174                         self.lock_strength = max(self.lock_strength - decr, 0);
175
176                 if(self.lock_strength == 0)
177                         self.lock_target = world;
178         }
179 }
180
181 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
182 {SELFPARAM();
183         force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
184         v_forward  = normalize(v_forward) * -1;
185         traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
186
187         force_fromtag_power = (1 - trace_fraction) * max_power;
188         force_fromtag_normpower = force_fromtag_power / max_power;
189
190         return v_forward  * force_fromtag_power;
191 }
192
193 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
194 {SELFPARAM();
195
196         force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
197         v_forward  = normalize(v_forward) * -1;
198         traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
199
200         // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
201         if(trace_fraction == 1.0)
202         {
203                 force_fromtag_normpower = -0.25;
204                 return '0 0 -200';
205         }
206
207         force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
208         force_fromtag_normpower = force_fromtag_power / max_power;
209
210         return v_forward  * force_fromtag_power;
211 }
212
213 // projectile handling
214 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
215 {SELFPARAM();
216         // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
217         if(inflictor.owner == self.owner)
218                 return;
219
220         self.health -= damage;
221         self.velocity += force;
222         if(self.health < 1)
223         {
224                 self.takedamage = DAMAGE_NO;
225                 self.event_damage = func_null;
226                 self.think = self.use;
227                 self.nextthink = time;
228         }
229 }
230
231 void vehicles_projectile_explode()
232 {SELFPARAM();
233         if(self.owner && other != world)
234         {
235                 if(other == self.owner.vehicle)
236                         return;
237
238                 if(other == self.owner.vehicle.tur_head)
239                         return;
240         }
241
242         PROJECTILE_TOUCH;
243
244         self.event_damage = func_null;
245         RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
246
247         remove (self);
248 }
249
250 entity vehicles_projectile(string _mzlfx, string _mzlsound,
251                                                    vector _org, vector _vel,
252                                                    float _dmg, float _radi, float _force,  float _size,
253                                                    int _deahtype, float _projtype, float _health,
254                                                    bool _cull, bool _clianim, entity _owner)
255 {SELFPARAM();
256         entity proj;
257
258         proj = spawn();
259
260         PROJECTILE_MAKETRIGGER(proj);
261         setorigin(proj, _org);
262
263         proj.shot_dmg            = _dmg;
264         proj.shot_radius          = _radi;
265         proj.shot_force    = _force;
266         proj.totalfrags    = _deahtype;
267         proj.solid                      = SOLID_BBOX;
268         proj.movetype            = MOVETYPE_FLYMISSILE;
269         proj.flags                      = FL_PROJECTILE;
270         proj.bot_dodge          = true;
271         proj.bot_dodgerating  = _dmg;
272         proj.velocity            = _vel;
273         proj.touch                      = vehicles_projectile_explode;
274         proj.use                          = vehicles_projectile_explode;
275         proj.owner                      = self;
276         proj.realowner          = _owner;
277         proj.think                      = SUB_Remove_self;
278         proj.nextthink          = time + 30;
279
280         if(_health)
281         {
282                 proj.takedamage    = DAMAGE_AIM;
283                 proj.event_damage        = vehicles_projectile_damage;
284                 proj.health                = _health;
285         }
286         else
287                 proj.flags                 = FL_PROJECTILE | FL_NOTARGET;
288
289         if(_mzlsound)
290                 _sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
291
292         if(_mzlfx)
293                 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
294
295         setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
296
297         CSQCProjectile(proj, _clianim, _projtype, _cull);
298
299         return proj;
300 }
301
302 void vehicles_gib_explode()
303 {SELFPARAM();
304         sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
305         Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
306         Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
307         remove(self);
308 }
309
310 void vehicles_gib_think()
311 {SELFPARAM();
312         self.alpha -= 0.1;
313         if(self.cnt >= time)
314                 remove(self);
315         else
316                 self.nextthink = time + 0.1;
317 }
318
319 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
320 {SELFPARAM();
321         entity _gib = spawn();
322         _setmodel(_gib, _template.model);
323         vector org = gettaginfo(self, gettagindex(self, _tag));
324         setorigin(_gib, org);
325         _gib.velocity = _vel;
326         _gib.movetype = MOVETYPE_TOSS;
327         _gib.solid = SOLID_CORPSE;
328         _gib.colormod = '-0.5 -0.5 -0.5';
329         _gib.effects = EF_LOWPRECISION;
330         _gib.avelocity = _rot;
331
332         if(_burn)
333                 _gib.effects |= EF_FLAME;
334
335         if(_explode)
336         {
337                 _gib.think = vehicles_gib_explode;
338                 _gib.nextthink = time + random() * _explode;
339                 _gib.touch = vehicles_gib_explode;
340         }
341         else
342         {
343                 _gib.cnt = time + _maxtime;
344                 _gib.think = vehicles_gib_think;
345                 _gib.nextthink = time + _maxtime - 1;
346                 _gib.alpha = 1;
347         }
348         return _gib;
349 }
350
351 bool vehicle_addplayerslot(     entity _owner,
352                                                                 entity _slot,
353                                                                 int _hud,
354                                                                 string _hud_model,
355                                                                 bool() _framefunc,
356                                                                 void(bool) _exitfunc, float() _enterfunc)
357 {
358         if(!(_owner.vehicle_flags & VHF_MULTISLOT))
359                 _owner.vehicle_flags |= VHF_MULTISLOT;
360
361         _slot.PlayerPhysplug = _framefunc;
362         _slot.vehicle_exit = _exitfunc;
363         _slot.vehicle_enter = _enterfunc;
364         _slot.hud = _hud;
365         _slot.vehicle_flags = VHF_PLAYERSLOT;
366         _slot.vehicle_viewport = spawn();
367         _slot.vehicle_hudmodel = spawn();
368         _slot.vehicle_hudmodel.viewmodelforclient = _slot;
369         _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
370
371         _setmodel(_slot.vehicle_hudmodel, _hud_model);
372         setmodel(_slot.vehicle_viewport, MDL_Null);
373
374         setattachment(_slot.vehicle_hudmodel, _slot, "");
375         setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
376
377         return true;
378 }
379
380 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
381                                                  float _pichlimit_min, float _pichlimit_max,
382                                                  float _rotlimit_min, float _rotlimit_max, float _aimspeed)
383 {
384         vector vtmp, vtag;
385         float ftmp;
386         vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
387         vtmp = vectoangles(normalize(_target - vtag));
388         vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
389         vtmp = AnglesTransform_Normalize(vtmp, true);
390         ftmp = _aimspeed * frametime;
391         vtmp_y = bound(-ftmp, vtmp_y, ftmp);
392         vtmp_x = bound(-ftmp, vtmp_x, ftmp);
393         _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
394         _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
395         return vtag;
396 }
397
398 void vehicles_reset_colors()
399 {SELFPARAM();
400         entity e;
401         float _effects = 0, _colormap;
402         vector _glowmod, _colormod;
403
404         if(autocvar_g_nodepthtestplayers)
405                 _effects |= EF_NODEPTHTEST;
406
407         if(autocvar_g_fullbrightplayers)
408                 _effects |= EF_FULLBRIGHT;
409
410         if(self.team)
411                 _colormap = 1024 + (self.team - 1) * 17;
412         else
413                 _colormap = 1024;
414
415         _glowmod  = '0 0 0';
416         _colormod = '0 0 0';
417
418         // Find all ents attacked to main model and setup effects, colormod etc.
419         e = findchainentity(tag_entity, self);
420         while(e)
421         {
422                 if(e != self.vehicle_shieldent)
423                 {
424                         e.effects   = _effects; //  | EF_LOWPRECISION;
425                         e.colormod  = _colormod;
426                         e.colormap  = _colormap;
427                         e.alpha  = 1;
428                 }
429                 e = e.chain;
430         }
431         // Also check head tags
432         e = findchainentity(tag_entity, self.tur_head);
433         while(e)
434         {
435                 if(e != self.vehicle_shieldent)
436                 {
437                         e.effects   = _effects; //  | EF_LOWPRECISION;
438                         e.colormod  = _colormod;
439                         e.colormap  = _colormap;
440                         e.alpha  = 1;
441                 }
442                 e = e.chain;
443         }
444
445         self.vehicle_hudmodel.effects  = self.effects  = _effects; // | EF_LOWPRECISION;
446         self.vehicle_hudmodel.colormod = self.colormod = _colormod;
447         self.vehicle_hudmodel.colormap = self.colormap = _colormap;
448         self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
449
450         self.alpha       = 1;
451         self.avelocity = '0 0 0';
452         self.velocity  = '0 0 0';
453         self.effects   = _effects;
454 }
455
456 void vehicles_clearreturn(entity veh)
457 {
458         // Remove "return helper", if any.
459         for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
460         {
461                 if(ret.wp00 == veh)
462                 {
463                         ret.classname   = "";
464                         ret.think          = SUB_Remove_self;
465                         ret.nextthink   = time + 0.1;
466
467                         if(ret.waypointsprite_attached)
468                                 WaypointSprite_Kill(ret.waypointsprite_attached);
469
470                         return;
471                 }
472         }
473 }
474
475 void vehicles_spawn();
476 void vehicles_return()
477 {SELFPARAM();
478         Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
479
480         self.wp00.think  = vehicles_spawn;
481         self.wp00.nextthink = time;
482
483         if(self.waypointsprite_attached)
484                 WaypointSprite_Kill(self.waypointsprite_attached);
485
486         remove(self);
487 }
488
489 void vehicles_showwp_goaway()
490 {SELFPARAM();
491         if(self.waypointsprite_attached)
492                 WaypointSprite_Kill(self.waypointsprite_attached);
493
494         remove(self);
495
496 }
497
498 void vehicles_showwp()
499 {SELFPARAM();
500         entity oldself = world;
501         vector rgb;
502
503         if(self.cnt)
504         {
505                 self.think        = vehicles_return;
506                 self.nextthink  = self.cnt;
507         }
508         else
509         {
510                 self.think        = vehicles_return;
511                 self.nextthink  = time +1;
512
513                 oldself = self;
514                 setself(spawn());
515                 setmodel(self, MDL_Null);
516                 self.team = oldself.wp00.team;
517                 self.wp00 = oldself.wp00;
518                 setorigin(self, oldself.wp00.pos1);
519
520                 self.nextthink = time + 5;
521                 self.think = vehicles_showwp_goaway;
522         }
523
524         if(teamplay && self.team)
525                 rgb = Team_ColorRGB(self.team);
526         else
527                 rgb = '1 1 1';
528         entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
529         wp.colormod = rgb;
530         if(self.waypointsprite_attached)
531         {
532                 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
533                 if(this == NULL)
534                         WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
535                 WaypointSprite_Ping(self.waypointsprite_attached);
536         }
537
538         if(this)
539                 setself(this);
540 }
541
542 void vehicles_setreturn(entity veh)
543 {
544         entity ret;
545
546         vehicles_clearreturn(veh);
547
548         ret = new(vehicle_return);
549         ret.wp00           = veh;
550         ret.team                = veh.team;
551         ret.think          = vehicles_showwp;
552
553         if(IS_DEAD(veh))
554         {
555                 ret.cnt          = time + veh.respawntime;
556                 ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 5);
557         }
558         else
559         {
560                 ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 1);
561         }
562
563         setmodel(ret, MDL_Null);
564         setorigin(ret, veh.pos1 + '0 0 96');
565
566 }
567
568 void vehicle_use()
569 {SELFPARAM();
570         LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
571
572         self.tur_head.team = activator.team;
573
574         if(self.tur_head.team == 0)
575                 self.active = ACTIVE_NOT;
576         else
577                 self.active = ACTIVE_ACTIVE;
578
579         if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
580         {
581                 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
582                 if(self.effects & EF_NODRAW)
583                 {
584                         self.think = vehicles_spawn;
585                         self.nextthink = time + 3;
586                 }
587                 else
588                 {
589                         vehicles_setreturn(self);
590                         vehicles_reset_colors();
591                 }
592         }
593 }
594
595 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
596 {SELFPARAM();
597         if(self.(regen_field) < field_max)
598         if(timer + rpause < time)
599         {
600                 if(_healthscale)
601                         regen = regen * (self.vehicle_health / self.max_health);
602
603                 self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max);
604
605                 if(self.owner)
606                         self.owner.(regen_field) = (self.(regen_field) / field_max) * 100;
607         }
608 }
609
610 void shieldhit_think()
611 {SELFPARAM();
612         self.alpha -= 0.1;
613         if (self.alpha <= 0)
614         {
615                 // setmodel(self, MDL_Null);
616                 self.alpha = -1;
617                 self.effects |= EF_NODRAW;
618         }
619         else
620         {
621                 self.nextthink = time + 0.1;
622         }
623 }
624
625 void vehicles_painframe(entity this)
626 {
627         int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
628
629         if(myhealth <= 50)
630         if(this.pain_frame < time)
631         {
632                 float _ftmp = myhealth / 50;
633                 this.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
634                 pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
635
636                 if(this.vehicle_flags & VHF_DMGSHAKE)
637                         this.velocity += randomvec() * 30;
638
639                 if(this.vehicle_flags & VHF_DMGROLL)
640                         if(this.vehicle_flags & VHF_DMGHEADROLL)
641                                 this.tur_head.angles += randomvec();
642                         else
643                                 this.angles += randomvec();
644         }
645 }
646
647 void vehicles_frame(entity this, entity actor)
648 {
649         vehicles_painframe(this);
650 }
651
652 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
653 {SELFPARAM();
654         self.dmg_time = time;
655
656         // WEAPONTODO
657         if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
658                 damage *= autocvar_g_vehicles_vortex_damagerate;
659
660         if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
661                 damage *= autocvar_g_vehicles_machinegun_damagerate;
662
663         if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
664                 damage *= autocvar_g_vehicles_rifle_damagerate;
665
666         if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
667                 damage *= autocvar_g_vehicles_vaporizer_damagerate;
668
669         if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
670                 damage *= autocvar_g_vehicles_tag_damagerate;
671
672         if(DEATH_WEAPONOF(deathtype) != WEP_Null)
673                 damage *= autocvar_g_vehicles_weapon_damagerate;
674
675         self.enemy = attacker;
676
677         self.pain_finished = time;
678
679         if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
680         {
681                 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
682                 {
683                         self.vehicle_shieldent = spawn();
684                         self.vehicle_shieldent.effects = EF_LOWPRECISION;
685
686                         setmodel(self.vehicle_shieldent, MDL_VEH_SHIELD);
687                         setattachment(self.vehicle_shieldent, self, "");
688                         setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
689                         self.vehicle_shieldent.scale       = 256 / vlen(self.maxs - self.mins);
690                         self.vehicle_shieldent.think       = shieldhit_think;
691                 }
692
693                 self.vehicle_shieldent.colormod = '1 1 1';
694                 self.vehicle_shieldent.alpha = 0.45;
695                 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
696                 self.vehicle_shieldent.nextthink = time;
697                 self.vehicle_shieldent.effects &= ~EF_NODRAW;
698
699                 self.vehicle_shield -= damage;
700
701                 if(self.vehicle_shield < 0)
702                 {
703                         self.vehicle_health -= fabs(self.vehicle_shield);
704                         self.vehicle_shieldent.colormod = '2 0 0';
705                         self.vehicle_shield = 0;
706                         self.vehicle_shieldent.alpha = 0.75;
707
708                         if(sound_allowed(MSG_BROADCAST, attacker))
709                                 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);   // FIXME: PLACEHOLDER
710                 }
711                 else
712                         if(sound_allowed(MSG_BROADCAST, attacker))
713                                 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
714
715         }
716         else
717         {
718                 self.vehicle_health -= damage;
719
720                 if(sound_allowed(MSG_BROADCAST, attacker))
721                         spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
722         }
723
724         if(self.damageforcescale < 1 && self.damageforcescale > 0)
725                 self.velocity += force * self.damageforcescale;
726         else
727                 self.velocity += force;
728
729         if(self.vehicle_health <= 0)
730         {
731                 if(self.owner)
732                         if(self.vehicle_flags & VHF_DEATHEJECT)
733                                 vehicles_exit(VHEF_EJECT);
734                         else
735                                 vehicles_exit(VHEF_RELEASE);
736
737
738                 antilag_clear(self);
739
740                 Vehicle info = get_vehicleinfo(self.vehicleid);
741                 info.vr_death(info);
742                 vehicles_setreturn(self);
743         }
744 }
745
746 float vehicles_crushable(entity e)
747 {
748         if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
749                 return true;
750
751         if(IS_MONSTER(e))
752                 return true;
753
754         return false;
755 }
756
757 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
758 {SELFPARAM();
759         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
760                 return;
761
762         if(self.play_time < time)
763         {
764                 float wc = vlen(self.velocity - self.oldvelocity);
765                 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
766                 //dprint("vel: ", vtos(self.velocity), "\n");
767                 if(_minspeed < wc)
768                 {
769                         float take = min(_speedfac * wc, _maxpain);
770                         Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
771                         self.play_time = time + 0.25;
772
773                         //dprint("wc: ", ftos(wc), "\n");
774                         //dprint("take: ", ftos(take), "\n");
775                 }
776         }
777 }
778
779 // vehicle enter/exit handling
780 vector vehicles_findgoodexit(vector prefer_spot)
781 {SELFPARAM();
782         //vector exitspot;
783         float mysize;
784
785         tracebox(self.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, self.owner);
786         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
787                 return prefer_spot;
788
789         mysize = 1.5 * vlen(self.maxs - self.mins);
790         float i;
791         vector v, v2;
792         v2 = 0.5 * (self.absmin + self.absmax);
793         for(i = 0; i < 100; ++i)
794         {
795                 v = randomvec();
796                 v_z = 0;
797                 v = v2 + normalize(v) * mysize;
798                 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, self.owner);
799                 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
800                         return v;
801         }
802
803         /*
804         exitspot = (self.origin + '0 0 48') + v_forward * mysize;
805         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
806         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
807                 return exitspot;
808
809         exitspot = (self.origin + '0 0 48') - v_forward * mysize;
810         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
811         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
812                 return exitspot;
813
814         exitspot = (self.origin + '0 0 48') + v_right * mysize;
815         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
816         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
817                 return exitspot;
818
819         exitspot = (self.origin + '0 0 48') - v_right * mysize;
820         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
821         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
822                 return exitspot;
823         */
824
825         return self.origin;
826 }
827
828 void vehicles_exit(bool eject)
829 {SELFPARAM();
830         entity _vehicle;
831         entity _player;
832
833         if(vehicles_exit_running)
834         {
835                 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
836                 return;
837         }
838
839         vehicles_exit_running = true;
840         if(IS_CLIENT(self))
841         {
842                 _vehicle = self.vehicle;
843
844                 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
845                 {
846                         _vehicle.vehicle_exit(eject);
847                         setself(this);
848                         vehicles_exit_running = false;
849                         return;
850                 }
851         }
852         else
853                 _vehicle = self;
854
855         _player = _vehicle.owner;
856
857         setself(_vehicle);
858
859         if (_player)
860         {
861                 if (IS_REAL_CLIENT(_player))
862                 {
863                         msg_entity = _player;
864                         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
865                         WriteEntity( MSG_ONE, _player);
866
867                         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
868                         WriteAngle(MSG_ONE, 0);
869                         WriteAngle(MSG_ONE, _vehicle.angles_y);
870                         WriteAngle(MSG_ONE, 0);
871                 }
872
873                 setsize(_player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
874
875                 _player.takedamage              = DAMAGE_AIM;
876                 _player.solid                   = SOLID_SLIDEBOX;
877                 _player.movetype                = MOVETYPE_WALK;
878                 _player.effects            &= ~EF_NODRAW;
879                 _player.teleportable    = TELEPORT_NORMAL;
880                 _player.alpha                   = 1;
881                 _player.PlayerPhysplug  = func_null;
882                 _player.vehicle                 = world;
883                 _player.view_ofs                = STAT(PL_VIEW_OFS, NULL);
884                 _player.event_damage    = PlayerDamage;
885                 _player.hud                             = HUD_NORMAL;
886                 PS(_player).m_switchweapon = _vehicle.m_switchweapon;
887                 _player.last_vehiclecheck = time + 3;
888                 _player.vehicle_enter_delay = time + 2;
889
890                 CSQCVehicleSetup(_player, HUD_NORMAL);
891         }
892         _vehicle.flags |= FL_NOTARGET;
893
894         if(!IS_DEAD(_vehicle))
895                 _vehicle.avelocity = '0 0 0';
896
897         _vehicle.tur_head.nodrawtoclient = world;
898
899         if(!teamplay)
900                 _vehicle.team = 0;
901
902         Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
903         Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
904
905         WaypointSprite_Kill(_vehicle.wps_intruder);
906
907         MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
908
909         _vehicle.team = _vehicle.tur_head.team;
910
911         sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
912         _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
913         _vehicle.phase = time + 1;
914
915         _vehicle.vehicle_exit(eject);
916
917         vehicles_setreturn(_vehicle);
918         vehicles_reset_colors();
919         _vehicle.owner = world;
920
921         CSQCMODEL_AUTOINIT(self);
922
923         setself(this);
924         vehicles_exit_running = false;
925 }
926
927 void vehicles_touch()
928 {SELFPARAM();
929         if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
930                 return;
931
932         // Vehicle currently in use
933         if(self.owner)
934         {
935                 if(!forbidWeaponUse(self.owner))
936                 if(other != world)
937                 if((self.origin_z + self.maxs_z) > (other.origin_z))
938                 if(vehicles_crushable(other))
939                 {
940                         if(vlen(self.velocity) >= 30)
941                                 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
942
943                         return; // Dont do selfdamage when hitting "soft targets".
944                 }
945
946                 if(self.play_time < time) {
947                         Vehicle info = get_vehicleinfo(self.vehicleid);
948                         info.vr_impact(info);
949                 }
950
951                 return;
952         }
953
954         if(autocvar_g_vehicles_enter)
955                 return;
956
957         vehicles_enter(other, self);
958 }
959
960 bool vehicle_impulse(entity this, int imp)
961 {
962         entity v = this.vehicle;
963         if (!v) return false;
964         if (IS_DEAD(v)) return false;
965         bool(int) f = v.vehicles_impulse;
966         if (f && f(imp)) return true;
967         switch (imp)
968         {
969                 case IMP_weapon_drop.impulse:
970                 {
971                         stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
972                         return true;
973                 }
974         }
975         return false;
976 }
977
978 void vehicles_enter(entity pl, entity veh)
979 {SELFPARAM();
980    // Remove this when bots know how to use vehicles
981         if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
982                 return;
983
984         if((!IS_PLAYER(pl))
985         || (veh.phase >= time)
986         || (pl.vehicle_enter_delay >= time)
987         || (STAT(FROZEN, pl))
988         || (IS_DEAD(pl))
989         || (pl.vehicle)
990         ) { return; }
991
992         if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
993         if(veh.vehicle_flags & VHF_MULTISLOT)
994         if(veh.owner)
995         {
996                 setself(veh);
997                 other = pl; // TODO: fix
998
999                 if(!veh.gunner1)
1000                 if(time >= veh.gun1.phase)
1001                 if(veh.gun1.vehicle_enter)
1002                 if(veh.gun1.vehicle_enter())
1003                 {
1004                         setself(this);
1005                         return;
1006                 }
1007
1008                 if(!veh.gunner2)
1009                 if(time >= veh.gun2.phase)
1010                 if(veh.gun2.vehicle_enter)
1011                 if(veh.gun2.vehicle_enter())
1012                 {
1013                         setself(this);
1014                         return;
1015                 }
1016
1017                 setself(this);
1018         }
1019
1020         if(teamplay)
1021         if(veh.team)
1022         if(DIFF_TEAM(pl, veh))
1023         if(autocvar_g_vehicles_steal)
1024         {
1025                 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL)));
1026
1027                 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1028
1029                 if (autocvar_g_vehicles_steal_show_waypoint) {
1030                         entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1031                         wp.colormod = Team_ColorRGB(pl.team);
1032                 }
1033         }
1034         else return;
1035
1036         RemoveGrapplingHook(pl);
1037
1038         veh.vehicle_ammo1 = 0;
1039         veh.vehicle_ammo2 = 0;
1040         veh.vehicle_reload1 = 0;
1041         veh.vehicle_reload2 = 0;
1042         veh.vehicle_energy = 0;
1043
1044         veh.owner = pl;
1045         pl.vehicle = veh;
1046
1047         // .viewmodelforclient works better.
1048         //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1049
1050         veh.vehicle_hudmodel.viewmodelforclient = pl;
1051
1052         tracebox(pl.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pl.origin, false, pl);
1053         pl.crouch = false;
1054         pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
1055         setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
1056
1057         veh.event_damage        = vehicles_damage;
1058         veh.nextthink           = 0;
1059         pl.angles                       = veh.angles;
1060         pl.takedamage           = DAMAGE_NO;
1061         pl.solid                        = SOLID_NOT;
1062         pl.movetype                     = MOVETYPE_NOCLIP;
1063         pl.teleportable         = false;
1064         pl.alpha                        = -1;
1065         pl.event_damage         = func_null;
1066         pl.view_ofs                     = '0 0 0';
1067         veh.colormap            = pl.colormap;
1068         if(veh.tur_head)
1069                 veh.tur_head.colormap = pl.colormap;
1070         veh.m_switchweapon = PS(pl).m_switchweapon;
1071         pl.hud = veh.vehicleid;
1072         pl.PlayerPhysplug = veh.PlayerPhysplug;
1073
1074         pl.vehicle_ammo1 = veh.vehicle_ammo1;
1075         pl.vehicle_ammo2 = veh.vehicle_ammo2;
1076         pl.vehicle_reload1 = veh.vehicle_reload1;
1077         pl.vehicle_reload2 = veh.vehicle_reload2;
1078         pl.vehicle_energy = veh.vehicle_energy;
1079
1080         // Cant do this, hides attached objects too.
1081         //veh.exteriormodeltoclient = veh.owner;
1082         //veh.tur_head.exteriormodeltoclient = veh.owner;
1083
1084         UNSET_ONGROUND(pl);
1085         UNSET_ONGROUND(veh);
1086
1087         veh.team = pl.team;
1088         veh.flags -= FL_NOTARGET;
1089
1090         if (IS_REAL_CLIENT(pl))
1091         {
1092                 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1093
1094                 msg_entity = pl;
1095                 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1096                 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1097
1098                 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1099                 if(veh.tur_head)
1100                 {
1101                         WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1102                         WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1103                         WriteAngle(MSG_ONE, 0);                                                                   // roll
1104                 }
1105                 else
1106                 {
1107                         WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1108                         WriteAngle(MSG_ONE, veh.angles_y);        // yaw
1109                         WriteAngle(MSG_ONE, 0);                           // roll
1110                 }
1111         }
1112
1113         vehicles_clearreturn(veh);
1114
1115         CSQCVehicleSetup(pl, veh.vehicleid);
1116
1117         MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1118
1119         setself(veh);
1120         CSQCModel_UnlinkEntity(veh);
1121         Vehicle info = get_vehicleinfo(veh.vehicleid);
1122         info.vr_enter(info);
1123         setself(this);
1124
1125         antilag_clear(pl);
1126 }
1127
1128 void vehicles_think()
1129 {SELFPARAM();
1130         self.nextthink = time;
1131
1132         if(self.owner)
1133                 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1134
1135         Vehicle info = get_vehicleinfo(self.vehicleid);
1136         info.vr_think(info);
1137
1138         vehicles_painframe(self);
1139
1140         CSQCMODEL_AUTOUPDATE(self);
1141 }
1142
1143 // initialization
1144 void vehicles_spawn()
1145 {SELFPARAM();
1146         LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1147
1148         // disown & reset
1149         self.vehicle_hudmodel.viewmodelforclient = self;
1150
1151         self.owner                              = world;
1152         self.touch                              = vehicles_touch;
1153         self.event_damage               = vehicles_damage;
1154         self.iscreature                 = true;
1155         self.teleportable               = false; // no teleporting for vehicles, too buggy
1156         self.damagedbycontents  = true;
1157         self.movetype                   = MOVETYPE_WALK;
1158         self.solid                              = SOLID_SLIDEBOX;
1159         self.takedamage                 = DAMAGE_AIM;
1160         self.deadflag                   = DEAD_NO;
1161         self.bot_attack                 = true;
1162         self.flags                              = FL_NOTARGET;
1163         self.avelocity                  = '0 0 0';
1164         self.velocity                   = '0 0 0';
1165         self.think                              = vehicles_think;
1166         self.nextthink                  = time;
1167
1168         // Reset locking
1169         self.lock_strength = 0;
1170         self.lock_target = world;
1171         self.misc_bulletcounter = 0;
1172
1173         // Return to spawn
1174         self.angles = self.pos2;
1175         setorigin(self, self.pos1);
1176         // Show it
1177         Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1178
1179         if(self.vehicle_controller)
1180                 self.team = self.vehicle_controller.team;
1181
1182         FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, LAMBDA(RemoveGrapplingHook(it)));
1183
1184         vehicles_reset_colors();
1185
1186         Vehicle info = get_vehicleinfo(self.vehicleid);
1187         info.vr_spawn(info);
1188
1189         CSQCMODEL_AUTOINIT(self);
1190 }
1191
1192 bool vehicle_initialize(entity veh, bool nodrop)
1193 {SELFPARAM();
1194         if(!autocvar_g_vehicles)
1195                 return false;
1196
1197         if(!veh.vehicleid)
1198                 return false;
1199
1200         if(!veh.tur_head) {
1201                 Vehicle info = get_vehicleinfo(veh.vehicleid);
1202                 info.vr_precache(info);
1203         }
1204
1205         if(self.targetname && self.targetname != "")
1206         {
1207                 self.vehicle_controller = find(world, target, self.targetname);
1208                 if(!self.vehicle_controller)
1209                 {
1210                         bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1211                         self.active = ACTIVE_ACTIVE;
1212                 }
1213                 else
1214                 {
1215                         self.team = self.vehicle_controller.team;
1216                         self.use = vehicle_use;
1217
1218                         if(teamplay)
1219                         {
1220                                 if(self.vehicle_controller.team == 0)
1221                                         self.active = ACTIVE_NOT;
1222                                 else
1223                                         self.active = ACTIVE_ACTIVE;
1224                         }
1225                 }
1226         }
1227         else { self.active = ACTIVE_ACTIVE; }
1228
1229         if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1230                 self.team = 0;
1231
1232         if(self.mdl == "" || !self.mdl)
1233                 _setmodel(self, veh.model);
1234         else
1235                 _setmodel(self, self.mdl);
1236
1237         self.vehicle_flags |= VHF_ISVEHICLE;
1238
1239         self.vehicle_viewport           = new(vehicle_viewport);
1240         self.vehicle_hudmodel           = new(vehicle_hudmodel);
1241         self.tur_head                           = new(tur_head);
1242         self.tur_head.owner                     = self;
1243         self.takedamage                         = DAMAGE_NO;
1244         self.bot_attack                         = true;
1245         self.iscreature                         = true;
1246         self.teleportable                       = false; // no teleporting for vehicles, too buggy
1247         self.damagedbycontents          = true;
1248         self.vehicleid                          = veh.vehicleid;
1249         self.PlayerPhysplug                     = veh.PlayerPhysplug;
1250         self.event_damage                       = func_null;
1251         self.touch                                      = vehicles_touch;
1252         self.think                                      = vehicles_spawn;
1253         self.nextthink                          = time;
1254         self.effects                            = EF_NODRAW;
1255         self.dphitcontentsmask          = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1256
1257         if(autocvar_g_playerclip_collisions)
1258                 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1259
1260         if(autocvar_g_nodepthtestplayers)
1261                 self.effects |= EF_NODEPTHTEST;
1262
1263         if(autocvar_g_fullbrightplayers)
1264                 self.effects |= EF_FULLBRIGHT;
1265
1266         _setmodel(self.vehicle_hudmodel, veh.hud_model);
1267         setmodel(self.vehicle_viewport, MDL_Null);
1268
1269         if(veh.head_model != "")
1270         {
1271                 _setmodel(self.tur_head, veh.head_model);
1272                 setattachment(self.tur_head, self, veh.tag_head);
1273                 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1274                 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1275         }
1276         else
1277         {
1278                 setattachment(self.tur_head, self, "");
1279                 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1280                 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1281         }
1282
1283         setsize(self, veh.mins, veh.maxs);
1284
1285         if(!nodrop)
1286         {
1287                 setorigin(self, self.origin);
1288                 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1289                 setorigin(self, trace_endpos);
1290         }
1291
1292         self.pos1 = self.origin;
1293         self.pos2 = self.angles;
1294         self.tur_head.team = self.team;
1295
1296         Vehicle info = get_vehicleinfo(veh.vehicleid);
1297         info.vr_setup(info);
1298
1299         if(self.active == ACTIVE_NOT)
1300                 self.nextthink = 0; // wait until activated
1301         else if(autocvar_g_vehicles_delayspawn)
1302                 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1303         else
1304                 self.nextthink = time + game_starttime;
1305
1306         if(MUTATOR_CALLHOOK(VehicleSpawn))
1307                 return false;
1308
1309         return true;
1310 }