]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/vehicles.qc
Merge remote branch 'origin/master' into tzork/vehicles-2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
1 float autocvar_g_vehicles_crush_dmg;
2 float autocvar_g_vehicles_crush_force;
3
4 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
5 void vehicles_return();
6 void vehicles_enter();
7 void vehicles_touch();
8 void vehicles_reset_colors();
9 void vehicles_clearrturn();
10 void vehicles_setreturn();
11
12
13 /** AuxiliaryXhair*
14     Send addictional points of interest to be drawn, to vehicle owner
15 **/
16 float MAX_AXH = 4;
17 .entity AuxiliaryXhair[MAX_AXH];
18
19 float SendAuxiliaryXhair(entity to, float sf)
20 {
21
22         WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
23
24         WriteByte(MSG_ENTITY, self.cnt);
25
26         WriteCoord(MSG_ENTITY, self.origin_x);
27         WriteCoord(MSG_ENTITY, self.origin_y);
28         WriteCoord(MSG_ENTITY, self.origin_z);
29
30     WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
31     WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
32     WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
33
34     return TRUE;
35 }
36
37 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
38 {
39     entity axh;
40
41     axh_id = bound(0, axh_id, MAX_AXH);
42     axh = own.AuxiliaryXhair[axh_id];
43
44     if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
45     {
46         axh                     = spawn();
47         axh.cnt                 = axh_id;
48         axh.drawonlytoclient    = own;
49         axh.owner               = own;
50         Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
51     }
52
53     setorigin(axh, loc);
54     axh.colormod            = clr;
55     axh.SendFlags           = 0x01;
56     own.AuxiliaryXhair[axh_id] = axh;
57 }
58
59 /*
60 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
61 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
62 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
63 {
64         msg_entity = own;
65
66         WriteByte(MSG_ONE, SVC_TEMPENTITY);
67         WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
68
69         WriteByte(MSG_ONE, axh_id);
70
71         WriteCoord(MSG_ONE, loc_x);
72         WriteCoord(MSG_ONE, loc_y);
73         WriteCoord(MSG_ONE, loc_z);
74
75     WriteByte(MSG_ONE, rint(clr_x * 255));
76     WriteByte(MSG_ONE, rint(clr_y * 255));
77     WriteByte(MSG_ONE, rint(clr_z * 255));
78
79 }
80 */
81 // End AuxiliaryXhair
82
83 void CSQCVehicleSetup(entity own, float vehicle_id)
84 {
85         msg_entity = own;
86
87         WriteByte(MSG_ONE, SVC_TEMPENTITY);
88         WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
89         WriteByte(MSG_ONE, vehicle_id);
90 }
91
92 /** vehicles_locktarget
93
94     Generic target locking.
95
96     Figure out if what target is "locked" (if any), for missile tracking as such.
97
98     after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
99     you have a locked in target.
100
101     Exspects a crosshair_trace() or equivalent to be
102     dont before calling.
103
104 **/
105 .entity lock_target;
106 .float  lock_strength;
107 .float  lock_time;
108 .float  lock_soundtime;
109 void vehicles_locktarget(float incr, float decr, float _lock_time)
110 {
111     if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
112     {
113         self.lock_target    = world;
114         self.lock_strength  = 0;
115         self.lock_time      = 0;
116     }
117
118     if(self.lock_time > time)
119     {
120         if(self.lock_target)
121         if(self.lock_soundtime < time)
122         {
123             self.lock_soundtime = time + 0.5;
124             play2(self.owner, "vehicles/locked.wav");
125         }
126         
127         return;
128     }
129         
130
131     if(trace_ent != world)
132     {
133         if(teams_matter && trace_ent.team == self.team)
134             trace_ent = world;
135
136         if(trace_ent.deadflag != DEAD_NO)
137             trace_ent = world;
138
139         if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
140             trace_ent = world;
141     }
142
143     if(self.lock_target == world && trace_ent != world)
144         self.lock_target = trace_ent;
145     
146     if(self.lock_target && trace_ent == self.lock_target) 
147     {            
148         if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
149         {
150             play2(self.owner, "vehicles/lock.wav");
151             self.lock_soundtime = time + 0.8;
152         }        
153         else if (self.lock_strength != 1 && self.lock_soundtime < time)
154         {            
155             play2(self.owner, "vehicles/locking.wav");
156             self.lock_soundtime = time + 0.3;
157         }
158         
159     }    
160         
161     // Have a locking target
162     // Trace hit current target
163     if(trace_ent == self.lock_target && trace_ent != world)
164     {
165         self.lock_strength = min(self.lock_strength + incr, 1);
166         if(self.lock_strength == 1)
167             self.lock_time = time + _lock_time;
168     }
169     else
170     {
171         if(trace_ent)
172             self.lock_strength = max(self.lock_strength - decr * 2, 0);
173         else
174             self.lock_strength = max(self.lock_strength - decr, 0);
175
176         if(self.lock_strength == 0)
177             self.lock_target = world;
178     }
179 }
180
181 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
182 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
183
184 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
185 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
186 if(trace_fraction != 1) \
187     acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
188
189 // Hover movement support
190 float  force_fromtag_power;
191 float  force_fromtag_normpower;
192 vector force_fromtag_origin;
193 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
194 {
195     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
196     v_forward  = normalize(v_forward) * -1;
197     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
198
199     force_fromtag_power = (1 - trace_fraction) * max_power;
200     force_fromtag_normpower = force_fromtag_power / max_power;
201
202     return v_forward  * force_fromtag_power;
203 }
204
205 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
206 // Can possibly be use to move abt any surface (inclusing walls/celings)
207 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
208 {
209
210     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
211     v_forward  = normalize(v_forward) * -1;
212     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
213
214     // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
215     if(trace_fraction == 1.0)
216     {
217         force_fromtag_normpower = -0.25;
218         return '0 0 -200';
219     }
220
221     force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
222     force_fromtag_normpower = force_fromtag_power / max_power;
223
224     return v_forward  * force_fromtag_power;
225 }
226
227 // Generic vehile projectile system
228 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
229 {
230     self.health -= damage;
231     self.velocity += force;
232     if(self.health < 1)
233     {
234         self.takedamage = DAMAGE_NO;
235         self.event_damage = SUB_Null;
236         self.think = self.use;
237         self.nextthink = time;
238     }
239
240 }
241
242 void vehicles_projectile_explode()
243 {
244     if(self.owner && other != world)
245     {
246         if(other == self.owner.vehicle)
247             return;
248
249         if(other == self.owner.vehicle.tur_head)
250             return;
251     }
252
253         PROJECTILE_TOUCH;
254
255         self.event_damage = SUB_Null;
256     RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
257
258     remove (self);
259 }
260
261 entity vehicles_projectile(string _mzlfx, string _mzlsound,
262                            vector _org, vector _vel,
263                            float _dmg, float _radi, float _force,  float _size,
264                            float _deahtype, float _projtype, float _health,
265                            float _cull, float _clianim)
266 {
267     entity proj;
268
269     proj = spawn();
270
271     PROJECTILE_MAKETRIGGER(proj);
272     setorigin(proj, _org);
273
274     proj.shot_dmg         = _dmg;
275     proj.shot_radius      = _radi;
276     proj.shot_force       = _force;
277     proj.totalfrags       = _deahtype;
278     proj.solid            = SOLID_BBOX;
279     proj.movetype         = MOVETYPE_FLYMISSILE;
280     proj.flags            = FL_PROJECTILE;
281     proj.bot_dodge        = TRUE;
282     proj.bot_dodgerating  = _dmg;
283     proj.velocity         = _vel;
284     proj.touch            = vehicles_projectile_explode;
285     proj.use              = vehicles_projectile_explode;
286     proj.owner            = self;
287     proj.realowner        = self.owner;
288     proj.think            = SUB_Remove;
289     proj.nextthink        = time + 30;
290
291     if(_health)
292     {
293         proj.takedamage       = DAMAGE_AIM;
294         proj.event_damage     = vehicles_projectile_damage;
295         proj.health           = _health;
296     }
297     else
298         proj.flags           = FL_PROJECTILE | FL_NOTARGET;
299
300     if(_mzlsound)
301         sound (self, CHAN_WEAPON, _mzlsound, VOL_BASE, ATTN_NORM);
302
303     if(_mzlfx)
304         pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
305
306
307     setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
308
309     CSQCProjectile(proj, _clianim, _projtype, _cull);
310
311     return proj;
312 }
313 // End generic vehile projectile system
314
315 /** vehicles_spawn
316     Exetuted for all vehiles on (re)spawn.
317     Sets defaults for newly spawned units.
318 **/
319 void vehicles_spawn()
320 {
321     dprint("Spawning vehicle: ", self.netname, "\n");
322
323     // De-own & reset
324     self.vehicle_hudmodel.viewmodelforclient = self;
325
326     self.owner              = world;
327     self.touch              = vehicles_touch;
328     self.event_damage       = vehicles_damage;
329     self.iscreature         = TRUE;
330     self.movetype           = MOVETYPE_WALK;
331     self.solid              = SOLID_SLIDEBOX;
332     self.takedamage         = DAMAGE_AIM;
333         self.deadflag           = DEAD_NO;
334     self.bot_attack         = TRUE;
335     self.flags              = FL_NOTARGET;
336     self.avelocity          = '0 0 0';
337     self.velocity           = '0 0 0';
338
339     // Reset locking
340     self.lock_strength      = 0;
341     self.lock_target        = world;
342     self.misc_bulletcounter = 0;
343
344     // Return to spawn
345     self.angles             = self.pos2;
346     setorigin(self, self.pos1 + '0 0 128');
347     // Show it
348     pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
349
350     vehicles_reset_colors();
351     self.vehicle_spawn();
352 }
353
354 // Better way of determening whats crushable needed! (fl_crushable?)
355 float vehicles_crushable(entity e)
356 {
357     if(e.classname == "player")
358         return TRUE;
359
360     if(e.classname == "monster_zombie")
361         return TRUE;
362
363     return FALSE;
364 }
365
366 void vehicles_touch()
367 {
368     // Vehicle currently in use
369     if(self.owner)
370     {
371         // Colided with world?
372         if(other == world)
373         {
374             // Apply velocity based self damage here
375         }
376         else
377         {
378             if(other.vehicle_flags & VHF_ISVEHICLE)
379             {
380                 //other.velocity += self.velocity * (self.mass / other.mass);
381             }
382             else if(vehicles_crushable(other))
383             {
384                 if(vlen(self.velocity) != 0)
385                     Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VHCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
386             }
387         }
388         return;
389     }
390
391     if(other.classname != "player")
392         return;
393
394     if(other.deadflag != DEAD_NO)
395         return;
396
397     if(other.vehicle != world)
398         return;
399
400     // Remove this when bots know how to use vehicles.
401     if (clienttype(other) != CLIENTTYPE_REAL)
402         return;
403
404     vehicles_enter();
405 }
406
407 void vehicles_enter()
408 {
409    // Remove this when bots know how to use vehicles
410     if (clienttype(other) != CLIENTTYPE_REAL)
411         return;
412
413     if(self.phase > time)
414         return;
415
416     if(teams_matter)
417     if(self.team)
418     if(self.team != other.team)
419         return;
420
421     self.vehicle_ammo1   = 0;
422     self.vehicle_ammo2   = 0;
423     self.vehicle_reload1 = 0;
424     self.vehicle_reload2 = 0;
425     self.vehicle_energy  = 0;
426
427     self.owner          = other;
428     self.switchweapon   = other.switchweapon;
429
430     // .viewmodelforclient works better.
431     //self.vehicle_hudmodel.drawonlytoclient = self.owner;
432
433 #ifndef VEHICLES_CSQC
434         self.vehicle_hudmodel.viewmodelforclient = self.owner;
435 #endif
436
437     self.event_damage         = vehicles_damage;
438     self.nextthink            = 0;
439     self.owner.angles         = self.angles;
440     self.owner.takedamage     = DAMAGE_NO;
441     self.owner.solid          = SOLID_NOT;
442     self.owner.movetype       = MOVETYPE_NOCLIP;
443     self.owner.alpha          = -1;
444     self.owner.vehicle        = self;
445     self.owner.event_damage   = SUB_Null;
446     self.owner.view_ofs       = '0 0 0';
447     self.colormap             = self.owner.colormap;
448     if(self.tur_head)
449         self.tur_head.colormap    = self.owner.colormap;
450
451     self.owner.hud            = self.hud;
452     self.owner.PlayerPhysplug = self.PlayerPhysplug;
453
454     self.owner.vehicle_ammo1    = self.vehicle_ammo1;
455     self.owner.vehicle_ammo2    = self.vehicle_ammo2;
456     self.owner.vehicle_reload1  = self.vehicle_reload1;
457     self.owner.vehicle_reload2  = self.vehicle_reload2;
458
459     // Cant do this, hides attached objects too.
460     //self.exteriormodeltoclient = self.owner;
461     //self.tur_head.exteriormodeltoclient = self.owner;
462
463     other.flags &~= FL_ONGROUND;
464     self.flags  &~= FL_ONGROUND;
465
466     self.team                 = self.owner.team;
467     self.flags               -= FL_NOTARGET;
468
469 #ifndef VEHICLES_CSQC
470     msg_entity = other;
471     WriteByte (MSG_ONE, SVC_SETVIEWPORT);
472     WriteEntity(MSG_ONE, self.vehicle_viewport);
473
474     WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
475     if(self.tur_head)
476     {
477         WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
478         WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
479         WriteAngle(MSG_ONE, 0);                                      // roll
480     }
481     else
482     {
483         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
484         WriteAngle(MSG_ONE,  self.angles_x * -1); // tilt
485         WriteAngle(MSG_ONE,  self.angles_y);      // yaw
486         WriteAngle(MSG_ONE,  0);                  // roll
487     }
488 #endif
489 //#endif
490
491     vehicles_clearrturn();
492
493     CSQCVehicleSetup(self.owner, self.hud);
494
495     self.vehicle_enter();
496 }
497
498 void vehicles_exit(float eject)
499 {
500         self.flags |= FL_NOTARGET;
501
502     if (self.owner)
503     {
504         msg_entity = self.owner;
505         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
506         WriteEntity( MSG_ONE, self.owner);
507
508         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
509         WriteAngle(MSG_ONE, 0);                 // pich
510         WriteAngle(MSG_ONE, self.angles_y);     // yaw
511         WriteAngle(MSG_ONE, 0);                 // roll
512
513         setsize(self.owner, PL_MIN,PL_MAX);
514
515         self.owner.takedamage     = DAMAGE_AIM;
516         self.owner.solid          = SOLID_SLIDEBOX;
517         self.owner.movetype       = MOVETYPE_WALK;
518         self.owner.effects        &~= EF_NODRAW;
519         self.owner.alpha          = 1;
520         self.owner.PlayerPhysplug = SUB_Null;
521         self.owner.vehicle        = world;
522         self.owner.view_ofs       = PL_VIEW_OFS;
523         self.owner.event_damage   = PlayerDamage;
524         self.owner.hud            = HUD_NORMAL;
525         self.owner.switchweapon   = self.switchweapon;
526         self.owner.BUTTON_USE     = 0;
527     }
528
529     if(self.deadflag == DEAD_NO)
530         self.avelocity          = '0 0 0';
531
532     self.vehicle_hudmodel.viewmodelforclient = self;
533         self.tur_head.nodrawtoclient             = world;
534     vehicles_setreturn();
535
536     self.phase = time + 1;
537
538     if(!teams_matter)
539         self.team = 0;
540
541     self.vehicle_exit(eject);
542     self.owner = world;
543 }
544
545
546 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
547 {
548     if(self.regen_field < field_max)
549     if(self.timer + rpause < time)
550     {
551         self.regen_field = min(self.regen_field + regen * delta_time, field_max);
552
553         if(self.owner)
554             self.owner.regen_field = (self.regen_field / field_max) * 100;
555     }
556 }
557
558 void shieldhit_think()
559 {
560     self.alpha -= 0.1;
561     if (self.alpha <= 0)
562     {
563         //setmodel(self, "");
564         self.alpha = -1;
565     }
566     else
567     {
568         self.nextthink = time + 0.1;
569     }
570 }
571
572 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
573 {
574     self.dmg_time = time;
575
576     if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
577     {
578         if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
579         {
580             self.vehicle_shieldent = spawn();
581             self.vehicle_shieldent.effects = EF_LOWPRECISION;
582
583             setmodel(self.vehicle_shieldent, "models/vhshield.md3");
584             setattachment(self.vehicle_shieldent, self, "");
585             setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
586             self.vehicle_shieldent.scale       = 256 / vlen(self.maxs - self.mins);
587             self.vehicle_shieldent.think       = shieldhit_think;
588         }
589
590
591         self.vehicle_shieldent.colormod    = '1 1 1';
592         self.vehicle_shieldent.alpha       = 0.45;
593         self.vehicle_shieldent.angles      = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
594         self.vehicle_shieldent.nextthink   = time;
595
596         self.vehicle_shield -= damage;
597
598         if(self.vehicle_shield < 0)
599         {
600             self.vehicle_shieldent.colormod = '2 0 0';
601             self.vehicle_shield             = 0;
602             self.vehicle_shieldent.alpha    = 0.75;
603             self.vehicle_health            -= fabs(self.vehicle_shield);
604         }
605     }
606     else
607         self.vehicle_health -= damage;
608
609     self.velocity += force; // * (vlen(force) / self.mass);
610
611     if(self.vehicle_health <= 0)
612     {
613         if(self.owner)
614             if(self.vehicle_flags & VHF_DEATHEJECT)
615                 vehicles_exit(VHEF_EJECT);
616             else
617                 vehicles_exit(VHEF_RELESE);
618
619         self.vehicle_die();
620         vehicles_setreturn();
621     }
622 }
623
624 void vehicles_return()
625 {
626     pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
627
628     self.enemy.think     = vehicles_spawn;
629     self.enemy.nextthink = time;
630
631     remove(self);
632 }
633
634 void vehicles_clearrturn()
635 {
636     entity ret;
637     // Remove "return helper", if any.
638     ret = findchain(classname, "vehicle_return");
639     while(ret)
640     {
641         if(ret.enemy == self)
642         {
643             ret.classname   = "";
644             ret.think       = SUB_Remove;
645             ret.nextthink   = time + 0.1;
646             return;
647         }
648
649         ret = ret.chain;
650     }
651 }
652
653 void vehicles_setreturn()
654 {
655     entity ret;
656
657     vehicles_clearrturn();
658
659     ret = spawn();
660     ret.classname   = "vehicle_return";
661     ret.enemy       = self;
662     ret.think       = vehicles_return;
663     ret.nextthink   = time + self.vehicle_respawntime;
664 }
665
666 float vehicles_customizeentityforclient()
667 {
668     if(self.deadflag  == DEAD_DEAD)
669         return FALSE;
670     else
671         return TRUE;
672 }
673
674 void vehicles_configcheck(string  configname, float check_cvar)
675 {
676     if(check_cvar == 0)
677         localcmd(strcat("exec ", configname, "\n"));
678 }
679
680 void vehicles_reset_colors()
681 {
682     entity e;
683     float _effects, _colormap;
684     vector _glowmod, _colormod;
685
686     if(autocvar_g_nodepthtestplayers)
687         _effects = EF_NODEPTHTEST;
688
689     if(autocvar_g_fullbrightplayers)
690         _effects |= EF_FULLBRIGHT;
691
692     if(self.team)
693         _colormap = 1024 + (self.team - 1) * 17;
694     else
695         _colormap = 1024;
696
697     _glowmod  = '0 0 0';
698     _colormod = '0 0 0';
699
700     // Find all ents attacked to main model and setup effects, colormod etc.
701     e = findchainentity(tag_entity, self);
702     while(e)
703     {
704         if(e != self.vehicle_shieldent)
705         {
706             e.effects   = _effects  | EF_LOWPRECISION;
707             e.colormod  = _colormod;
708             e.colormap  = _colormap;
709             e.alpha     = 1;
710         }
711         e = e.chain;
712     }
713
714     self.vehicle_hudmodel.effects  = self.effects  = _effects | EF_LOWPRECISION;
715     self.vehicle_hudmodel.colormod = self.colormod = _colormod;
716     self.vehicle_hudmodel.colormap = self.colormap = _colormap;
717     self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
718
719     self.alpha     = 1;
720     self.avelocity = '0 0 0';
721     self.velocity  = '0 0 0';
722     self.effects   = _effects;
723 }
724
725 float vehicle_initialize(string  net_name,
726                          string  bodymodel,
727                          string  topmodel,
728                          string  hudmodel,
729                          string  toptag,
730                          string  hudtag,
731                          string  viewtag,
732                          float   vhud,
733                          vector  min_s,
734                          vector  max_s,
735                          float   nodrop,
736                          void()  spawnproc,
737                          float   _respawntime,
738                          float() physproc,
739                          void()  enterproc,
740                          void(float extflag) exitfunc,
741                          void() dieproc,
742                          void() thinkproc,
743                          float  use_csqc)
744 {
745     addstat(STAT_HUD, AS_INT,  hud);
746         addstat(STAT_VEHICLESTAT_HEALTH,  AS_INT, vehicle_health);
747         addstat(STAT_VEHICLESTAT_SHIELD,  AS_INT, vehicle_shield);
748         addstat(STAT_VEHICLESTAT_ENERGY,  AS_INT, vehicle_energy);
749
750         addstat(STAT_VEHICLESTAT_AMMO1,   AS_INT,   vehicle_ammo1);
751         addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
752
753         addstat(STAT_VEHICLESTAT_AMMO2,   AS_INT,   vehicle_ammo2);
754         addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
755
756     if(bodymodel == "")
757         error("vehicles: missing bodymodel!");
758
759     if(hudmodel == "")
760         error("vehicles: missing hudmodel!");
761
762     if(net_name == "")
763         self.netname = self.classname;
764     else
765         self.netname = net_name;
766
767     if(self.team && !teams_matter)
768         self.team = 0;
769
770     self.vehicle_flags |= VHF_ISVEHICLE;
771
772     setmodel(self, bodymodel);
773
774     self.vehicle_viewport   = spawn();
775     self.vehicle_hudmodel   = spawn();
776     self.tur_head           = spawn();
777     self.tur_head.owner     = self;
778     self.takedamage         = DAMAGE_AIM;
779     self.bot_attack         = TRUE;
780     self.iscreature         = TRUE;
781     self.hud                = vhud;
782
783     //self.customizeentityforclient = vehicles_customizeentityforclient;
784     self.vehicle_die         = dieproc;
785     self.vehicle_exit        = exitfunc;
786     self.vehicle_enter       = enterproc;
787     self.PlayerPhysplug      = physproc;
788     self.event_damage        = vehicles_damage;
789     self.touch               = vehicles_touch;
790     self.think               = vehicles_spawn;
791     self.nextthink           = time;
792     self.vehicle_respawntime = _respawntime;
793     self.vehicle_spawn       = spawnproc;
794
795     if(autocvar_g_nodepthtestplayers)
796         self.effects = self.effects | EF_NODEPTHTEST;
797
798     if(autocvar_g_fullbrightplayers)
799         self.effects = self.effects | EF_FULLBRIGHT;
800
801     setmodel(self.vehicle_hudmodel, hudmodel);
802     setmodel(self.vehicle_viewport, "null");
803
804
805     if(topmodel != "")
806     {
807         setmodel(self.tur_head, topmodel);
808         setattachment(self.tur_head, self, toptag);
809         setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
810         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
811     }
812     else
813     {
814         setattachment(self.tur_head, self, "");
815         setattachment(self.vehicle_hudmodel, self, hudtag);
816         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
817     }
818
819     setsize(self, min_s, max_s);
820     if not (nodrop)
821     {
822         setorigin(self, self.origin);
823         tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
824         setorigin(self, trace_endpos);
825     }
826
827     self.pos1 = self.origin;
828     self.pos2 = self.angles;
829 #ifdef VEHICLES_CSQC
830     if(use_csqc)
831         net_link_vehile();
832 #endif
833     return TRUE;
834 }
835
836
837 void bugmenot()
838 {
839     self.vehicle_exit       = self.vehicle_exit;
840     self.vehicle_enter      = self.vehicle_exit;
841     self.vehicle_die        = self.vehicle_exit;
842     self.vehicle_spawn      = self.vehicle_exit;
843     self.AuxiliaryXhair     = self.AuxiliaryXhair;
844 }