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