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