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